LCOV - code coverage report
Current view: top level - coll_communicator_mgr/dfx/profiling/aicpu - dfx_profiling_handler_lite.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 2 2

            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              : 
      11              : #ifndef HCCL_DFXPROFILING_HANDLER_LITE_H
      12              : #define HCCL_DFXPROFILING_HANDLER_LITE_H
      13              : 
      14              : #include <vector>
      15              : #include <unordered_map>
      16              : #include "hccl/hccl_types.h"
      17              : #include "prof_common.h"
      18              : #include "aprof_pub.h"
      19              : #include "dfx_circular_queue.h"
      20              : #include "res_pub.h"
      21              : 
      22              : extern "C" {
      23              : __attribute__((weak)) int32_t
      24              : MsprofReportBatchAdditionalInfo(uint32_t nonPersistantFlag, const VOID_PTR data, uint32_t length);
      25              : __attribute__((weak)) int32_t
      26              : AdprofReportBatchAdditionalInfo(uint32_t nonPersistantFlag, const void* data, uint32_t length);
      27              : __attribute__((weak)) int32_t AdprofReportAdditionalInfo(uint32_t agingFlag, const void* data, uint32_t length);
      28              : __attribute__((weak)) int32_t
      29              : MsprofReportAdditionalInfo(uint32_t nonPersistantFlag, const VOID_PTR data, uint32_t length);
      30              : __attribute__((weak)) int32_t AdprofCheckFeatureIsOn(uint64_t feature);
      31              : __attribute__((weak)) int32_t MsprofRegisterCallback(uint32_t moduleId, ProfCommandHandle handle);
      32              : __attribute__((weak)) uint64_t AdprofGetHashId(const char* hashInfo, size_t length);
      33              : __attribute__((weak)) uint64_t MsprofStr2Id(const char* hashInfo, size_t length);
      34              : };
      35              : 
      36              : namespace Hccl {
      37              : enum DfxMainStreamTaskType : uint8_t { HEAD = 0, TAIL = 1 };
      38              : 
      39              : enum DfxProfilingLevel : uint8_t { L0 = 0, L1 = 1 };
      40              : 
      41              : struct DfxFlagTaskInfo {
      42              :     uint32_t taskId;
      43              :     DfxMainStreamTaskType type;
      44              : };
      45              : 
      46              : class DfxProfilingHandlerLite {
      47              : public:
      48              :     ~DfxProfilingHandlerLite();
      49              :     DfxProfilingHandlerLite(const DfxProfilingHandlerLite& that) = delete;
      50              :     DfxProfilingHandlerLite& operator=(const DfxProfilingHandlerLite& that) = delete;
      51              :     static DfxProfilingHandlerLite& GetInstance();
      52              :     HcclResult Init();
      53              :     void ReportHcclOpInfo(const DfxDfxOpInfo& opInfo) const;
      54              :     void ReportMainStreamTask(const DfxFlagTaskInfo& flagTaskInfo) const;
      55              :     uint64_t GetCachedAlgTypeHashId() const;
      56              :     void UpdateProfSwitch();
      57              :     void SetProL0On(bool val);
      58              :     void SetProL1On(bool val);
      59            4 :     inline bool GetProfL0State() const { return enableHcclL0_; }
      60            1 :     inline bool GetProfL1State() const { return enableHcclL1_; }
      61              :     uint64_t GetProfHashId(const char* name, uint32_t len) const;
      62              : 
      63              :     void ReportStreamTaskDetails(TaskInfoCircularQueue& taskQueue) const;
      64              :     void ReportStreamTaskDetailsLog(TaskInfoCircularQueue& taskQueue) const;
      65              :     void SetCachedCommInfo(u64 groupName, u32 localRank, u32 rankSize);
      66              :     void SetCachedChannelRemoteRankIdMap(const std::unordered_map<u64, u32>* mapPtr);
      67              :     HcclResult SetCurrDfxOpInfo(const DfxDfxOpInfo* dfxOpInfo);
      68              :     const DfxDfxOpInfo* GetCurrDfxOpInfo() const;
      69              : 
      70              : private:
      71              :     explicit DfxProfilingHandlerLite();
      72              :     void BindProfilingHandles();
      73              :     void InitHashCaches();
      74              :     void ReportAdditionInfo(const MsprofAdditionalInfo& reporterData) const;
      75              : 
      76              :     bool IsProfOn(uint64_t feature) const;
      77              :     bool IsProfSwitchOn(DfxProfilingLevel level);
      78              :     bool FillBatchReporterData(
      79              :         uint32_t batchId, const MsprofAicpuHcclTaskInfo* taskInfos, MsprofAdditionalInfo& addInfo) const;
      80              :     bool ReportBatchAddInfo(
      81              :         uint32_t batchId, const MsprofAicpuHcclTaskInfo* taskInfos, MsprofAdditionalInfo* addInfoVec,
      82              :         uint32_t& addInfoIndx, uint32_t maxBatchNum, bool isLastBatch) const;
      83              : 
      84              :     void GetTaskDetailInfosFromDfxTaskInfo(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
      85              : 
      86              :     void FillReduceInlineDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
      87              :     void FillSdmaRdmaDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
      88              :     void FillUbDmaDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
      89              :     void FillNotifyDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
      90              :     void FillDefaultDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
      91              :     void FillCclTagAndRemoteRank(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
      92              :     void FillCommonTailFields(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const;
      93              : 
      94              : private:
      95              :     static DfxProfilingHandlerLite instance_;
      96              :     bool enableHcclL0_{false};
      97              :     bool enableHcclL1_{false};
      98              :     bool initializedFlag_{false};
      99              :     uint64_t cachedGroupName_{DFX_INVALID_U64};
     100              :     u32 cachedRankSize_{0};
     101              :     u32 cachedLocalRank_{INVALID_U32};
     102              :     uint32_t cachedTid_{0};
     103              :     std::unordered_map<uint32_t, uint64_t> taskTypeHashCache_;
     104              :     std::unordered_map<u8, uint64_t> opTypeHashCache_;
     105              :     std::unordered_map<u8, uint64_t> algTypeHashCache_;
     106              :     uint64_t cachedAlgTypeHashId_{0};
     107              :     const std::unordered_map<u64, u32>* cachedChannelRemoteRankIdMap_{nullptr};
     108              :     const DfxDfxOpInfo* currDfxOpInfo_{nullptr};
     109              :     using ReportAdditionalInfoHandle = int32_t (*)(uint32_t, const void*, uint32_t);
     110              :     ReportAdditionalInfoHandle reportAdditionalInfo_{nullptr};
     111              :     using ReportBatchAdditionalInfoHandle = int32_t (*)(uint32_t, const void*, uint32_t);
     112              :     ReportBatchAdditionalInfoHandle reportBatchAdditionalInfo_{nullptr};
     113              :     using GetProfHashIdHandle = uint64_t (*)(const char*, size_t);
     114              :     GetProfHashIdHandle getProfHashId_{nullptr};
     115              : };
     116              : 
     117              : } // namespace Hccl
     118              : 
     119              : #endif // HCCL_DFXPROFILING_HANDLER_LITE_H
        

Generated by: LCOV version 2.0-1