Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #ifndef HCCL_PROFILING_HANDLER_LITE_H
11 : #define HCCL_PROFILING_HANDLER_LITE_H
12 :
13 : #include <vector>
14 : #include <unordered_map>
15 : #include "hccl/hccl_types.h"
16 : #include "prof_common.h"
17 : #include "aprof_pub.h"
18 : #include "task_info.h"
19 : #include "profiling_common.h"
20 :
21 : extern "C" {
22 : __attribute__((weak)) int32_t
23 : MsprofReportBatchAdditionalInfo(uint32_t nonPersistantFlag, const VOID_PTR data, uint32_t length);
24 : __attribute__((weak)) int32_t
25 : AdprofReportBatchAdditionalInfo(uint32_t nonPersistantFlag, const void* data, uint32_t length);
26 : __attribute__((weak)) int32_t AdprofReportAdditionalInfo(uint32_t agingFlag, const void* data, uint32_t length);
27 : __attribute__((weak)) int32_t
28 : MsprofReportAdditionalInfo(uint32_t nonPersistantFlag, const VOID_PTR data, uint32_t length);
29 : __attribute__((weak)) int32_t AdprofCheckFeatureIsOn(uint64_t feature);
30 : __attribute__((weak)) int32_t MsprofRegisterCallback(uint32_t moduleId, ProfCommandHandle handle);
31 : __attribute__((weak)) uint64_t AdprofGetHashId(const char* hashInfo, size_t length);
32 : __attribute__((weak)) uint64_t MsprofStr2Id(const char* hashInfo, size_t length);
33 : };
34 :
35 : namespace aicpu {
36 10 : MAKE_ENUM(status_t, AICPU_ERROR_NONE = 0, AICPU_ERROR_FAILED = 1)
37 : status_t __attribute__((weak)) GetTaskAndStreamId(uint64_t& taskId, uint32_t& streamId);
38 : } // namespace aicpu
39 :
40 : namespace Hccl {
41 19 : MAKE_ENUM(MainStreamTaskType, HEAD = 0, TAIL = 1)
42 :
43 45 : MAKE_ENUM(ProfilingLevel, L0, L1)
44 :
45 : struct FlagTaskInfo {
46 : uint32_t taskId;
47 : MainStreamTaskType type;
48 : };
49 :
50 : class ProfilingHandlerLite {
51 : public:
52 : ~ProfilingHandlerLite();
53 : ProfilingHandlerLite(const ProfilingHandlerLite& that) = delete;
54 : ProfilingHandlerLite& operator=(const ProfilingHandlerLite& that) = delete;
55 : static ProfilingHandlerLite& GetInstance();
56 : HcclResult Init();
57 : void ReportHcclOpInfo(const DfxOpInfo& opInfo) const;
58 : void ReportHcclTaskDetails(const std::vector<TaskInfo*>& taskInfo) const;
59 : void ReportMainStreamTask(const FlagTaskInfo& flagTaskInfo) const;
60 : void SetCachedCclTag();
61 : void SetCachedGroupName(const std::string& groupName, u32 rankSize);
62 : uint64_t GetCachedAlgTypeHashId() const { return cachedAlgTypeHashId_; }
63 : void UpdateProfSwitch();
64 : void SetProL0On(bool val);
65 : void SetProL1On(bool val);
66 19 : inline bool GetProfL0State() const { return enableHcclL0_; }
67 8 : inline bool GetProfL1State() const { return enableHcclL1_; }
68 : uint64_t GetProfHashId(const char* name, uint32_t len) const;
69 :
70 : private:
71 : explicit ProfilingHandlerLite();
72 : void ReportAdditionInfo(const MsprofAdditionalInfo& reporterData) const;
73 :
74 : bool IsProfOn(uint64_t feature) const;
75 : bool IsProfSwitchOn(ProfilingLevel level);
76 : bool IsL1fromOffToOn();
77 :
78 : void DumpTaskDetails(const MsprofAicpuHcclTaskInfo& taskDetailsInfos, const TaskInfo* taskInfo) const;
79 : void GetTaskDetailInfos(const TaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
80 : void FillTaskParamDetails(const TaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
81 : bool FillBatchReporterData(
82 : uint32_t batchId, const MsprofAicpuHcclTaskInfo* taskInfos, MsprofAdditionalInfo& addInfo) const;
83 : void ReportHcclTaskDetailsLog(const std::vector<TaskInfo*>& taskInfo) const;
84 : bool ReportBatchAddInfo(
85 : uint32_t batchId, const MsprofAicpuHcclTaskInfo* taskInfos, MsprofAdditionalInfo* addInfoVec,
86 : uint32_t& addInfoIndx, uint32_t maxBatchNum, bool isLastBatch) const;
87 :
88 : private:
89 : static ProfilingHandlerLite instance_;
90 : bool enableHcclL0_{false};
91 : bool enableHcclL1_{false};
92 : bool initializedFlag_{false};
93 : uint64_t cachedGroupName_{INVALID_U64};
94 : uint64_t cachedAlgTypeHashId_{0};
95 : u32 cachedRankSize_{0};
96 : uint32_t cachedTid_{0};
97 : std::unordered_map<uint32_t, uint64_t> taskTypeHashCache_;
98 : std::unordered_map<std::string, uint64_t> cachedCclTag_;
99 : using ReportAdditionalInfoHandle = int32_t (*)(uint32_t, const void*, uint32_t);
100 : ReportAdditionalInfoHandle reportAdditionalInfo_{nullptr};
101 : using ReportBatchAdditionalInfoHandle = int32_t (*)(uint32_t, const void*, uint32_t);
102 : ReportBatchAdditionalInfoHandle reportBatchAdditionalInfo_{nullptr};
103 : using GetProfHashIdHandle = uint64_t (*)(const char*, size_t);
104 : GetProfHashIdHandle getProfHashId_{nullptr};
105 : };
106 : } // namespace Hccl
107 :
108 : #endif // HCCL_PROFILING_HANDLER_LITE_H
|