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

Generated by: LCOV version 2.0-1