LCOV - code coverage report
Current view: top level - legacy/ascend910/common/debug/profiling/inc - profiler_base_pub.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.9 % 9 8
Test Date: 2026-07-28 12:11:00 Functions: 75.0 % 4 3

            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 PROFILER_BASE_PUB_H
      12              : #define PROFILER_BASE_PUB_H
      13              : 
      14              : #include <memory>
      15              : #include <mutex>
      16              : #include <string>
      17              : #include <map>
      18              : #include <thread>
      19              : 
      20              : #include <hccl/hccl_types.h>
      21              : #include "hccl_common.h"
      22              : #include "common.h"
      23              : #include "workflow_pub.h"
      24              : #include "dispatcher_task_types.h"
      25              : #include "alg_profiling.h"
      26              : #include "profiler_base_pub_extend.h"
      27              : 
      28              : namespace hccl {
      29              : enum class StepType {
      30              :     STEP_STAGE = 0,
      31              :     STEP_STEP,
      32              :     STEP_MAX
      33              : };
      34              : 
      35              : enum class OpDict {
      36              :     SUM = 0,
      37              :     PROD,
      38              :     MAX,
      39              :     MIN
      40              : };
      41              : 
      42              : enum class DataType {
      43              :     DINT8 = 0,
      44              :     DINT16,
      45              :     DINT32,
      46              :     DFP16,
      47              :     DFP32,
      48              :     DINT64,
      49              :     DUINT64
      50              : };
      51              : 
      52              : struct GroupRankInfo {
      53              :     u32 rankSize{0};
      54              :     u32 rankId{0};
      55              :     u32 remoteRankId{INVALID_VALUE_RANKSIZE};
      56              : };
      57              : 
      58              : struct OpDataInfo {
      59              :     u64 count{0};
      60              :     const void *src{nullptr};
      61              :     const void *dst{nullptr};
      62              :     u32 index{0};
      63              :     u32 rootId{0};
      64              :     u32 deviceId{0};
      65              :     HcclDataType dataType{HcclDataType::HCCL_DATA_TYPE_RESERVED};
      66              :     HcclReduceOp reduceType{HcclReduceOp::HCCL_REDUCE_RESERVED};
      67              :     struct timeval tv{0};
      68              : };
      69              : 
      70              : struct StreamRecordInfo {
      71              :     s32 planeId;
      72              :     AlgType algType;
      73              :     std::string tag;
      74           27 :     StreamRecordInfo() = default;
      75           27 :     StreamRecordInfo(s32 plane, const AlgType &type, const std::string &strTag) : planeId(plane), algType(type), tag(strTag) {}
      76            0 :     StreamRecordInfo(const StreamRecordInfo &that) : planeId(that.planeId), algType(that.algType), tag(that.tag) {}
      77           27 :     StreamRecordInfo &operator=(const StreamRecordInfo &that)
      78              :     {
      79           27 :         if (&that != this) {
      80           27 :             planeId = that.planeId;
      81           27 :             algType = that.algType;
      82           27 :             tag = that.tag;
      83              :         }
      84           27 :         return *this;
      85              :     }
      86              : };
      87              : 
      88              : class ProfilerBase {
      89              : public:
      90              :     /* * 输出文本时, 获取op, dataType的字符串以及单位数据长度的数组 */
      91              :     static const std::array<uint32_t, HCCL_REDUCE_RESERVED> opString;
      92              :     static const std::array<uint32_t, HCCL_DATA_TYPE_RESERVED> dataTypeString;
      93              :     static const std::array<s32, HCCL_DATA_TYPE_RESERVED> sizeOf;
      94              : 
      95              :     explicit ProfilerBase(u32 deviceLogicId);
      96              :     virtual ~ProfilerBase();
      97              : 
      98              :     virtual HcclResult Run(const StepData &stepData) = 0;
      99              :     virtual HcclResult Flush() = 0;
     100              :     static HcclResult AddStream(s32 streamID, const std::string &tag, s32 planeID, const AlgType &algType);
     101              :     static HcclResult DelStream(s32 streamID);
     102              :     static HcclResult AddTag(const std::string &tag, const std::string &group, const HcclWorkflowMode &workFlowMode,
     103              :         bool isSendRecv = false, bool isAiv = false);
     104              :     static HcclResult DelTag(const std::string &tag);
     105              :     static HcclResult AddOpData(const std::string &tag, u64 count, const void *src, const void *dst,
     106              :         HcclDataType dataType, u32 rootId, const std::string &group, HcclReduceOp reduceType = HCCL_REDUCE_RESERVED);
     107              :     static HcclResult DelOpData(const std::string &tag);
     108              :     static HcclResult AddGroupRankInfo(const std::string &group, u32 rankSize, u32 rankId, bool isSendRecv = false,
     109              :         u32 remoteRankId = INVALID_VALUE_RANKSIZE);
     110              :     static HcclResult DelGroupRankInfo(const std::string &tag);
     111              :     static HcclResult GetTagByStream(u32 &streamID, std::string &tag);
     112              :     static HcclResult GetAlgTypeByStream(u32 &streamID, AlgType &algType);
     113              :     static HcclResult GetGroupNameByTag(const std::string &tag, std::string &group);
     114              :     static HcclResult GetRankInfoByGroup(const std::string &group, GroupRankInfo &groupRankInfo);
     115              :     static HcclResult GetOpDataInfoByTag(const std::string &tag, OpDataInfo &opDataInfo);
     116              :     static HcclResult AddGroupUdi(const std::string &group, const std::string &udi);
     117              :     static HcclResult DelGroupUdi(const std::string &group);
     118              :     static HcclResult GetUdiByGroup(const std::string &group, std::string &udi);
     119              :     static void GetSubmittedOpCnt(u32 &index);
     120              :     virtual HcclResult Save(u32 &streamID, u32 &taskID, TaskType &taskType, const TaskParaDMA &para) = 0;
     121              :     virtual HcclResult Save(u32 &streamID, u32 &taskID, TaskType &taskType, const TaskParaReduce &para) = 0;
     122              :     virtual HcclResult Save(u32 &streamID, u32 &taskID, TaskType &taskType, const TaskParaNotify &para) = 0;
     123              :     virtual HcclResult Save(u32 streamID, u32 taskID, const TaskParaAiv &para) = 0;
     124              :     virtual HcclResult Save(u32 &streamID, u32 &taskID, const void *descBuf = nullptr, size_t descBufLen = 0) = 0;
     125              :     virtual HcclResult Save(u32 captureStreamID, u32 streamID, u32 taskID, TaskType &taskType, const TaskParaDMA &para) = 0;
     126              :     virtual HcclResult Save(u32 captureStreamID, u32 streamID, u32 taskID, TaskType &taskType, const TaskParaReduce &para) = 0;
     127              :     virtual HcclResult Save(u32 captureStreamID, u32 streamID, u32 taskID, TaskType &taskType, const TaskParaNotify &para) = 0;
     128              :     virtual HcclResult Save(u32 captureStreamID, u32 streamID, u32 taskID, const void *descBuf = nullptr, size_t descBufLen = 0) = 0;
     129              :     virtual HcclResult Save(u32 captureStreamID, u32 streamID, u32 taskID, const TaskParaAiv &paraAiv) = 0;
     130              :     virtual HcclResult SaveToLog(const TaskParaHost &paraHost) = 0;
     131              : 
     132              : protected:
     133              :     static std::array<std::map<s32, StreamRecordInfo>, MAX_MODULE_DEVICE_NUM> streamRecordInfoMap_;
     134              :     static std::array<std::map<const std::string, const std::string>, MAX_MODULE_DEVICE_NUM> tagGroupMap_;
     135              :     static std::array<std::map<const std::string, const HcclWorkflowMode>, MAX_MODULE_DEVICE_NUM> tagModeMap_;
     136              :     static std::array<std::mutex, MAX_MODULE_DEVICE_NUM> streamMutex_;
     137              :     static std::array<std::map<const std::string, GroupRankInfo>, MAX_MODULE_DEVICE_NUM> groupRankMap_;
     138              :     static std::array<std::map<const std::string, OpDataInfo>, MAX_MODULE_DEVICE_NUM> tagOpDataMap_;
     139              :     static std::array<std::map<const std::string, u32>, MAX_MODULE_DEVICE_NUM> groupIndexMap_;
     140              :     static std::array<std::map<const std::string, u32>, MAX_MODULE_DEVICE_NUM> aivGroupIndexMap_;
     141              :     static std::array<std::map<const std::string, u32>, MAX_MODULE_DEVICE_NUM> sendRecvGroupIndexMap_;
     142              :     static std::array<std::map<const std::string, std::string>, MAX_MODULE_DEVICE_NUM> groupUdiMap_;
     143              :     const u32 deviceLogicId_;
     144              :     static bool isSendRecv_[MAX_MODULE_DEVICE_NUM];
     145              :     static u32 index_[MAX_MODULE_DEVICE_NUM];
     146              : 
     147              : private:
     148              : };
     149              : } // namespace hccl
     150              : 
     151              : #endif /* PROFILER_BASE_PUB_H */
        

Generated by: LCOV version 2.0-1