LCOV - code coverage report
Current view: top level - coll_communicator_mgr/dfx/profiling/aicpu - dfx_profiling_handler_lite.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 82.4 % 330 272
Test Date: 2026-08-18 17:47:01 Functions: 94.1 % 34 32

            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              : #include "dfx_profiling_handler_lite.h"
      12              : #include "res_pub.h"
      13              : #include "log.h"
      14              : #include "sqe_a5.h"
      15              : #include "prof_sal_lite.h"
      16              : #include <limits>
      17              : #include <map>
      18              : 
      19              : namespace aicpu {
      20              : enum DfxStatusT : uint8_t { AICPU_ERROR_NONE = 0, AICPU_ERROR_FAILED = 1 };
      21              : DfxStatusT __attribute__((weak)) GetTaskAndStreamId(uint64_t& taskId, uint32_t& streamId);
      22              : } // namespace aicpu
      23              : 
      24              : namespace Hccl {
      25              : 
      26              : static constexpr u32 aging = 1;
      27              : constexpr std::uint32_t HCCLINFO_REPORT_BATCH_NUM = 2;
      28              : DfxProfilingHandlerLite DfxProfilingHandlerLite::instance_;
      29              : 
      30              : static const std::map<OpTypeVal, std::string> OP_TYPE_NAME_MAP = {
      31              :     {OpTypeVal::OP_TYPE_ALLREDUCE, "OpType::ALLREDUCE"},
      32              :     {OpTypeVal::OP_TYPE_BROADCAST, "OpType::BROADCAST"},
      33              :     {OpTypeVal::OP_TYPE_ALLGATHER, "OpType::ALLGATHER"},
      34              :     {OpTypeVal::OP_TYPE_REDUCESCATTER, "OpType::REDUCESCATTER"},
      35              :     {OpTypeVal::OP_TYPE_SEND, "OpType::SEND"},
      36              :     {OpTypeVal::OP_TYPE_RECV, "OpType::RECV"},
      37              :     {OpTypeVal::OP_TYPE_BARRIER, "OpType::BARRIER"},
      38              :     {OpTypeVal::OP_TYPE_ALLTOALL, "OpType::ALLTOALL"},
      39              :     {OpTypeVal::OP_TYPE_REDUCE, "OpType::REDUCE"},
      40              :     {OpTypeVal::OP_TYPE_GATHER, "OpType::GATHER"},
      41              :     {OpTypeVal::OP_TYPE_SCATTER, "OpType::SCATTER"},
      42              :     {OpTypeVal::OP_TYPE_ALLTOALLV, "OpType::ALLTOALLV"},
      43              :     {OpTypeVal::OP_TYPE_ALLTOALLVC, "OpType::ALLTOALLVC"},
      44              :     {OpTypeVal::OP_TYPE_HALFALLTOALLV, "OpType::HALFALLTOALLV"},
      45              :     {OpTypeVal::OP_TYPE_BATCHSENDRECV, "OpType::BATCHSENDRECV"},
      46              :     {OpTypeVal::OP_TYPE_BATCHGET, "OpType::BATCHGET"},
      47              :     {OpTypeVal::OP_TYPE_BATCHPUT, "OpType::BATCHPUT"},
      48              :     {OpTypeVal::OP_TYPE_ALLGATHERV, "OpType::ALLGATHERV"},
      49              :     {OpTypeVal::OP_TYPE_REDUCESCATTERV, "OpType::REDUCESCATTERV"},
      50              : };
      51              : 
      52              : static const std::map<TaskParamTypeVal, std::string> TASK_PARAM_TYPE_NAME_MAP = {
      53              :     {TaskParamTypeVal::TASK_SDMA, "Memcpy"},
      54              :     {TaskParamTypeVal::TASK_RDMA, "RDMASend"},
      55              :     {TaskParamTypeVal::TASK_REDUCE_INLINE, "Reduce_Inline"},
      56              :     {TaskParamTypeVal::TASK_REDUCE_TBE, "Reduce_TBE"},
      57              :     {TaskParamTypeVal::TASK_NOTIFY_RECORD, "Notify_Record"},
      58              :     {TaskParamTypeVal::TASK_NOTIFY_WAIT, "Notify_Wait"},
      59              :     {TaskParamTypeVal::TASK_SEND_NOTIFY, "Send_Notify"},
      60              :     {TaskParamTypeVal::TASK_SEND_PAYLOAD, "Send_Payload"},
      61              :     {TaskParamTypeVal::TASK_WRITE_WITH_NOTIFY, "Write_With_Notify"},
      62              :     {TaskParamTypeVal::TASK_UB_INLINE_WRITE, "Ub_Inline_Write"},
      63              :     {TaskParamTypeVal::TASK_UB_REDUCE_INLINE, "Ub_Reduce_Inline"},
      64              :     {TaskParamTypeVal::TASK_UB, "Ub_Write_Or_Read"},
      65              :     {TaskParamTypeVal::TASK_WRITE_REDUCE_WITH_NOTIFY, "Reuce_With_Notify"},
      66              :     {TaskParamTypeVal::TASK_CCU, "Ccu"},
      67              :     {TaskParamTypeVal::TASK_AICPU_KERNEL, "AicpuKernel"},
      68              :     {TaskParamTypeVal::TASK_AICPU_REDUCE, "Aicpu_Reduce"},
      69              :     {TaskParamTypeVal::TASK_AIV, "AivKernel"},
      70              :     {TaskParamTypeVal::TASK_DPU_KERNEL, "DpuKernel"},
      71              :     {TaskParamTypeVal::TASK_DPU_THREAD_FENCE, "Dpu_ThreadFence"},
      72              :     {TaskParamTypeVal::TASK_DPU_CHANNEL_FENCE, "Dpu_ChannelFence"},
      73              :     {TaskParamTypeVal::TASK_DPU_INLINE_WRITE, "Dpu_Notify_Record"},
      74              :     {TaskParamTypeVal::TASK_DPU_NOTIFY_WAIT, "Dpu_Notify_Wait"},
      75              :     {TaskParamTypeVal::TASK_DPU_WRITE_WITH_NOTIFY, "Dpu_Write_With_Notify"},
      76              : };
      77              : 
      78              : static const std::map<AlgTypeVal, std::string> ALG_TYPE_NAME_MAP = {
      79              :     {AlgTypeVal::ALG_TYPE_NOT_SPECIFIED, "AlgType::NOT_SPECIFIED"},
      80              :     {AlgTypeVal::ALG_TYPE_RING, "AlgType::RING"},
      81              :     {AlgTypeVal::ALG_TYPE_MULTI_RING, "AlgType::MULTI_RING"},
      82              :     {AlgTypeVal::ALG_TYPE_MESH, "AlgType::MESH"},
      83              :     {AlgTypeVal::ALG_TYPE_RECURSIVE_HD, "AlgType::RECURSIVE_HD"},
      84              :     {AlgTypeVal::ALG_TYPE_BINARY_HD, "AlgType::BINARY_HD"},
      85              :     {AlgTypeVal::ALG_TYPE_PAIR_WISE, "AlgType::PAIR_WISE"},
      86              : };
      87              : 
      88           48 : DfxProfilingHandlerLite::DfxProfilingHandlerLite() {}
      89              : 
      90           48 : DfxProfilingHandlerLite::~DfxProfilingHandlerLite() {}
      91              : 
      92          215 : DfxProfilingHandlerLite& DfxProfilingHandlerLite::GetInstance() { return instance_; }
      93              : 
      94           33 : void DfxProfilingHandlerLite::SetCachedCommInfo(u64 groupName, u32 localRank, u32 rankSize)
      95              : {
      96           33 :     cachedGroupName_ = groupName;
      97           33 :     cachedLocalRank_ = localRank;
      98           33 :     cachedRankSize_ = rankSize;
      99           33 : }
     100              : 
     101           29 : void DfxProfilingHandlerLite::SetCachedChannelRemoteRankIdMap(const std::unordered_map<u64, u32>* mapPtr)
     102              : {
     103           29 :     cachedChannelRemoteRankIdMap_ = mapPtr;
     104           29 : }
     105              : 
     106            4 : HcclResult DfxProfilingHandlerLite::SetCurrDfxOpInfo(const DfxDfxOpInfo* dfxOpInfo)
     107              : {
     108            4 :     currDfxOpInfo_ = dfxOpInfo;
     109            4 :     return HCCL_SUCCESS;
     110              : }
     111              : 
     112            2 : const DfxDfxOpInfo* DfxProfilingHandlerLite::GetCurrDfxOpInfo() const { return currDfxOpInfo_; }
     113              : 
     114           33 : void DfxProfilingHandlerLite::BindProfilingHandles()
     115              : {
     116           33 :     if (MsprofReportBatchAdditionalInfo == nullptr) {
     117           33 :         if (AdprofReportAdditionalInfo != nullptr) {
     118           33 :             reportAdditionalInfo_ = AdprofReportAdditionalInfo;
     119              :         }
     120           33 :         if (AdprofGetHashId != nullptr) {
     121           33 :             getProfHashId_ = AdprofGetHashId;
     122              :         }
     123           33 :         if (AdprofReportBatchAdditionalInfo != nullptr) {
     124           33 :             reportBatchAdditionalInfo_ = AdprofReportBatchAdditionalInfo;
     125              :         }
     126              :     } else {
     127            0 :         if (MsprofReportAdditionalInfo != nullptr) {
     128            0 :             reportAdditionalInfo_ = [](uint32_t flag, const void* data, uint32_t len) -> int32_t {
     129            0 :                 return MsprofReportAdditionalInfo(flag, const_cast<void*>(data), len);
     130              :             };
     131              :         }
     132            0 :         if (MsprofStr2Id != nullptr) {
     133            0 :             getProfHashId_ = MsprofStr2Id;
     134              :         }
     135            0 :         reportBatchAdditionalInfo_ = [](uint32_t flag, const void* data, uint32_t len) -> int32_t {
     136            0 :             return MsprofReportBatchAdditionalInfo(flag, const_cast<void*>(data), len);
     137              :         };
     138              :     }
     139           33 : }
     140              : 
     141           33 : void DfxProfilingHandlerLite::InitHashCaches()
     142              : {
     143          792 :     for (const auto& item : TASK_PARAM_TYPE_NAME_MAP) {
     144          759 :         u8 taskTypeValue = static_cast<u8>(item.first);
     145            0 :         taskTypeHashCache_[static_cast<uint32_t>(taskTypeValue)]
     146          759 :             = GetProfHashId(item.second.c_str(), item.second.length());
     147              :     }
     148           33 :     cachedAlgTypeHashId_ = GetProfHashId("AlgType::NHR", strlen("AlgType::NHR"));
     149          660 :     for (const auto& item : OP_TYPE_NAME_MAP) {
     150          627 :         u8 opTypeValue = static_cast<u8>(item.first);
     151          627 :         if (opTypeHashCache_.find(opTypeValue) == opTypeHashCache_.end()) {
     152          627 :             opTypeHashCache_[opTypeValue] = GetProfHashId(item.second.c_str(), item.second.length());
     153              :         }
     154              :     }
     155          264 :     for (const auto& item : ALG_TYPE_NAME_MAP) {
     156          231 :         u8 algTypeValue = static_cast<u8>(item.first);
     157          231 :         if (algTypeHashCache_.find(algTypeValue) == algTypeHashCache_.end()) {
     158          231 :             algTypeHashCache_[algTypeValue] = GetProfHashId(item.second.c_str(), item.second.length());
     159              :         }
     160              :     }
     161           33 : }
     162              : 
     163           59 : HcclResult DfxProfilingHandlerLite::Init()
     164              : {
     165           59 :     if (initializedFlag_) {
     166           26 :         return HCCL_SUCCESS;
     167              :     }
     168           33 :     cachedTid_ = SalGetTidLite();
     169           33 :     BindProfilingHandles();
     170           33 :     if (reportAdditionalInfo_ == nullptr) {
     171            0 :         HCCL_ERROR(
     172              :             "[DfxProfilingHandlerLite][Init] reportAdditionalInfo_ is nullptr, profiling report will be skipped");
     173            0 :         return HCCL_E_PROFILING;
     174              :     }
     175           33 :     if (getProfHashId_ == nullptr) {
     176            0 :         HCCL_ERROR("[DfxProfilingHandlerLite][Init] getProfHashId_ is nullptr, profiling hash will be invalid");
     177            0 :         return HCCL_E_PROFILING;
     178              :     }
     179           33 :     InitHashCaches();
     180           33 :     initializedFlag_ = true;
     181           33 :     return HCCL_SUCCESS;
     182              : }
     183              : 
     184            2 : void DfxProfilingHandlerLite::ReportHcclOpInfo(const DfxDfxOpInfo& opInfo) const
     185              : {
     186            2 :     if (!GetProfL0State()) {
     187            1 :         HCCL_INFO("[DfxProfilingHandlerLite][ReportHcclOpInfo] l0 is false.");
     188            1 :         return;
     189              :     }
     190            1 :     if (aicpu::GetTaskAndStreamId == nullptr) {
     191            0 :         HCCL_WARNING("[DfxProfilingHandlerLite][ReportHcclOpInfo] GetTaskAndStreamId is nullptr.");
     192            0 :         return;
     193              :     }
     194            1 :     uint64_t taskId = 0U;
     195            1 :     uint32_t streamId = 0;
     196            1 :     if (aicpu::GetTaskAndStreamId(taskId, streamId) != aicpu::DfxStatusT::AICPU_ERROR_NONE) {
     197            0 :         HCCL_ERROR("[DfxProfilingHandlerLite][ReportHcclOpInfo] Failed to get task id and stream id.");
     198            0 :         return;
     199              :     }
     200            1 :     if (taskId > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) {
     201            0 :         HCCL_ERROR("[DfxProfilingHandlerLite][ReportHcclOpInfo] taskId is larger than u32.");
     202            0 :         return;
     203              :     }
     204            1 :     MsprofAdditionalInfo reporterData{};
     205            1 :     reporterData.level = MSPROF_REPORT_AICPU_LEVEL;
     206            1 :     reporterData.type = MSPROF_REPORT_AICPU_HCCL_OP_INFO;
     207            1 :     reporterData.threadId = cachedTid_;
     208            1 :     reporterData.dataLen = sizeof(MsprofAicpuHCCLOPInfo);
     209            1 :     reporterData.timeStamp = ProfGetCurCpuTimestampLite();
     210            1 :     auto* hcclOpInfo = reinterpret_cast<MsprofAicpuHCCLOPInfo*>(reporterData.data);
     211              : 
     212            1 :     hcclOpInfo->algType = cachedAlgTypeHashId_;
     213            1 :     hcclOpInfo->taskId = static_cast<uint32_t>(taskId);
     214            1 :     hcclOpInfo->streamId = streamId;
     215            1 :     hcclOpInfo->count = opInfo.count;
     216            1 :     hcclOpInfo->dataType = opInfo.dataType;
     217            1 :     hcclOpInfo->groupName = cachedGroupName_;
     218            1 :     hcclOpInfo->ranksize = cachedRankSize_;
     219            1 :     HCCL_INFO(
     220              :         "[DfxProfilingHandlerLite][ReportHcclOpInfo] relay:%u, retry:%u, dataType:%u, algType:%u, count:%llu, "
     221              :         "groupName:%lu, ranksize:%u, taskId:%u, streamId:%u",
     222              :         hcclOpInfo->relay, hcclOpInfo->retry, hcclOpInfo->dataType, hcclOpInfo->algType, hcclOpInfo->count,
     223              :         hcclOpInfo->groupName, hcclOpInfo->ranksize, hcclOpInfo->taskId, hcclOpInfo->streamId);
     224            1 :     ReportAdditionInfo(reporterData);
     225              : }
     226              : 
     227            2 : void DfxProfilingHandlerLite::ReportMainStreamTask(const DfxFlagTaskInfo& flagTaskInfo) const
     228              : {
     229            2 :     if (!GetProfL0State()) {
     230            1 :         HCCL_INFO("[DfxProfilingHandlerLite][ReportMainStreamTask] l0 is false.");
     231            1 :         return;
     232              :     }
     233            1 :     if (aicpu::GetTaskAndStreamId == nullptr) {
     234            0 :         HCCL_WARNING("[DfxProfilingHandlerLite][ReportMainStreamTask] aicpu::GetTaskAndStreamId is nullptr.");
     235            0 :         return;
     236              :     }
     237            1 :     uint64_t aicpuKernelTaskId = 0U;
     238            1 :     uint32_t aicpuKernelStreamId = 0;
     239            1 :     if (aicpu::GetTaskAndStreamId(aicpuKernelTaskId, aicpuKernelStreamId) != aicpu::DfxStatusT::AICPU_ERROR_NONE) {
     240            0 :         HCCL_ERROR("[DfxProfilingHandlerLite][ReportMainStreamTask] Failed to get task id and stream id.");
     241            0 :         return;
     242              :     }
     243            1 :     if (aicpuKernelTaskId > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) {
     244            0 :         HCCL_ERROR("[DfxProfilingHandlerLite][ReportMainStreamTask] aicpuKernelTaskId is larger than u32.");
     245            0 :         return;
     246              :     }
     247            1 :     MsprofAdditionalInfo reporterData{};
     248            1 :     reporterData.level = MSPROF_REPORT_AICPU_LEVEL;
     249            1 :     reporterData.type = MSPROF_REPORT_AICPU_HCCL_FLAG_TASK;
     250            1 :     reporterData.threadId = cachedTid_;
     251            1 :     reporterData.dataLen = sizeof(MsprofAicpuHcclMainStreamTask);
     252            1 :     reporterData.timeStamp = ProfGetCurCpuTimestampLite();
     253            1 :     auto* flagtask = reinterpret_cast<MsprofAicpuHcclMainStreamTask*>(reporterData.data);
     254            1 :     flagtask->taskId = static_cast<uint16_t>(flagTaskInfo.taskId >> 16);
     255            1 :     flagtask->streamId = static_cast<uint16_t>(flagTaskInfo.taskId);
     256            1 :     flagtask->type = flagTaskInfo.type;
     257            1 :     uint32_t aicpuKernelTaskIdLow32 = static_cast<uint32_t>(aicpuKernelTaskId);
     258            1 :     flagtask->aicpuTaskId = static_cast<uint16_t>(aicpuKernelTaskIdLow32 >> 16);
     259            1 :     flagtask->aicpuStreamId = static_cast<uint16_t>(aicpuKernelTaskIdLow32);
     260            1 :     HCCL_INFO(
     261              :         "[DfxProfilingHandlerLite][ReportMainStreamTask] streamId:%u, taskId:%u, type:%u,"
     262              :         "aicpuStreamId:%u, aicpuTaskId:%u",
     263              :         flagtask->streamId, flagtask->taskId, flagtask->type, flagtask->aicpuStreamId, flagtask->aicpuTaskId);
     264            1 :     ReportAdditionInfo(reporterData);
     265              : }
     266              : 
     267            3 : void DfxProfilingHandlerLite::ReportAdditionInfo(const MsprofAdditionalInfo& reporterData) const
     268              : {
     269            3 :     if (reportAdditionalInfo_(aging, &reporterData, sizeof(MsprofAdditionalInfo)) != 0) {
     270            0 :         HCCL_ERROR("[DfxProfilingHandlerLite] ReportAdditionalInfo failed.");
     271              :     }
     272            3 : }
     273              : 
     274            7 : bool DfxProfilingHandlerLite::FillBatchReporterData(
     275              :     uint32_t batchId, const MsprofAicpuHcclTaskInfo* taskInfos, MsprofAdditionalInfo& addInfo) const
     276              : {
     277            7 :     addInfo.level = MSPROF_REPORT_AICPU_LEVEL;
     278            7 :     addInfo.type = MSPROF_REPORT_AICPU_MC2_BATCH_HCCL_INFO;
     279            7 :     addInfo.threadId = cachedTid_;
     280            7 :     addInfo.timeStamp = 0;
     281            7 :     addInfo.dataLen = sizeof(MsprofAicpuHcclTaskInfo) * batchId;
     282            7 :     s32 sret = memcpy_s(addInfo.data, sizeof(addInfo.data), taskInfos, addInfo.dataLen);
     283            7 :     if (sret != 0) {
     284            0 :         HCCL_WARNING("[DfxProfilingHandlerLite][FillBatchReporterData] memcpy failed, sret[%d]", sret);
     285            0 :         return false;
     286              :     }
     287            7 :     return true;
     288              : }
     289              : 
     290            5 : bool DfxProfilingHandlerLite::ReportBatchAddInfo(
     291              :     uint32_t batchId, const MsprofAicpuHcclTaskInfo* taskInfos, MsprofAdditionalInfo* addInfoVec, uint32_t& addInfoIndx,
     292              :     uint32_t maxBatchNum, bool isLastBatch) const
     293              : {
     294            5 :     if (!FillBatchReporterData(batchId, taskInfos, addInfoVec[addInfoIndx])) {
     295            0 :         return false;
     296              :     }
     297            5 :     addInfoIndx++;
     298            5 :     if (addInfoIndx == maxBatchNum || isLastBatch) {
     299            3 :         if (reportBatchAdditionalInfo_(aging, addInfoVec, addInfoIndx * sizeof(MsprofAdditionalInfo)) != 0) {
     300            0 :             HCCL_WARNING("[DfxProfilingHandlerLite][ReportStreamTaskDetails] reportBatchAdditionalInfo failed");
     301            0 :             return false;
     302              :         }
     303            3 :         addInfoIndx = 0;
     304              :     }
     305            5 :     return true;
     306              : }
     307              : 
     308            1 : void DfxProfilingHandlerLite::UpdateProfSwitch()
     309              : {
     310            1 :     IsProfSwitchOn(DfxProfilingLevel::L0);
     311            1 :     IsProfSwitchOn(DfxProfilingLevel::L1);
     312            1 : }
     313              : 
     314            4 : bool DfxProfilingHandlerLite::IsProfOn(uint64_t feature) const
     315              : {
     316            4 :     if (MsprofReportBatchAdditionalInfo == nullptr) {
     317            4 :         if (AdprofCheckFeatureIsOn == nullptr) {
     318            0 :             return false;
     319              :         }
     320            4 :         return AdprofCheckFeatureIsOn(feature) > 0;
     321              :     } else {
     322            0 :         if (feature == ADPROF_TASK_TIME_L1) {
     323            0 :             return enableHcclL1_;
     324            0 :         } else if (feature == ADPROF_TASK_TIME_L0) {
     325            0 :             return enableHcclL0_;
     326              :         }
     327              :     }
     328            0 :     return false;
     329              : }
     330              : 
     331            3 : bool DfxProfilingHandlerLite::IsProfSwitchOn(DfxProfilingLevel level)
     332              : {
     333            3 :     bool res = false;
     334            3 :     if (level == DfxProfilingLevel::L0) {
     335            1 :         res = IsProfOn(ADPROF_TASK_TIME_L0);
     336            1 :         enableHcclL0_ = res;
     337            2 :     } else if (level == DfxProfilingLevel::L1) {
     338            2 :         res = IsProfOn(ADPROF_TASK_TIME_L1);
     339            2 :         enableHcclL1_ = res;
     340              :     }
     341            3 :     return res;
     342              : }
     343              : 
     344            4 : void DfxProfilingHandlerLite::SetProL1On(bool val)
     345              : {
     346            4 :     HCCL_INFO("[%s] val = [%d]", __func__, val);
     347            4 :     enableHcclL1_ = val;
     348            4 : }
     349              : 
     350            4 : void DfxProfilingHandlerLite::SetProL0On(bool val)
     351              : {
     352            4 :     HCCL_INFO("[%s] val = [%d]", __func__, val);
     353            4 :     enableHcclL0_ = val;
     354            4 : }
     355              : 
     356         1679 : uint64_t DfxProfilingHandlerLite::GetProfHashId(const char* name, uint32_t len) const
     357              : {
     358         1679 :     if (name == nullptr || len == 0) {
     359            3 :         HCCL_WARNING("HashData is empty.  name:%s, len:%u", name, len);
     360            3 :         return DFX_INVALID_U64;
     361              :     }
     362         1676 :     if (getProfHashId_ != nullptr) {
     363         1676 :         return getProfHashId_(name, len);
     364              :     }
     365            0 :     return DFX_INVALID_U64;
     366              : }
     367              : 
     368            2 : uint64_t DfxProfilingHandlerLite::GetCachedAlgTypeHashId() const { return cachedAlgTypeHashId_; }
     369              : 
     370           22 : void DfxProfilingHandlerLite::GetTaskDetailInfosFromDfxTaskInfo(
     371              :     const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
     372              : {
     373           22 :     if (!it->IsTaskTypeValid()) {
     374            1 :         HCCL_WARNING("[DfxProfilingHandlerLite] invalid taskType[%u], skip task detail", it->taskType);
     375            1 :         return;
     376              :     }
     377              : 
     378           21 :     auto cacheIt = taskTypeHashCache_.find(static_cast<uint32_t>(it->taskType));
     379           21 :     taskDetailsInfos.itemId = (cacheIt != taskTypeHashCache_.end()) ? cacheIt->second : DFX_INVALID_U64;
     380              : 
     381           21 :     FillCclTagAndRemoteRank(it, taskDetailsInfos);
     382              : 
     383           21 :     taskDetailsInfos.groupName = cachedGroupName_;
     384           21 :     taskDetailsInfos.localRank = cachedLocalRank_;
     385           21 :     taskDetailsInfos.rankSize = cachedRankSize_;
     386           21 :     taskDetailsInfos.stage = 0;
     387           21 :     taskDetailsInfos.timeStamp = ProfGetCurCpuTimestampLite();
     388           21 :     taskDetailsInfos.durationEstimated = 0;
     389              : 
     390           21 :     switch (static_cast<TaskParamTypeVal>(it->taskType)) {
     391            8 :         case TaskParamTypeVal::TASK_SDMA:
     392              :         case TaskParamTypeVal::TASK_RDMA:
     393            8 :             FillSdmaRdmaDetail(it, taskDetailsInfos);
     394            8 :             break;
     395            2 :         case TaskParamTypeVal::TASK_REDUCE_INLINE:
     396            2 :             FillReduceInlineDetail(it, taskDetailsInfos);
     397            2 :             break;
     398            7 :         case TaskParamTypeVal::TASK_UB:
     399              :         case TaskParamTypeVal::TASK_UB_INLINE_WRITE:
     400              :         case TaskParamTypeVal::TASK_UB_REDUCE_INLINE:
     401              :         case TaskParamTypeVal::TASK_WRITE_WITH_NOTIFY:
     402              :         case TaskParamTypeVal::TASK_WRITE_REDUCE_WITH_NOTIFY:
     403            7 :             FillUbDmaDetail(it, taskDetailsInfos);
     404            7 :             break;
     405            3 :         case TaskParamTypeVal::TASK_NOTIFY_RECORD:
     406              :         case TaskParamTypeVal::TASK_NOTIFY_WAIT:
     407            3 :             FillNotifyDetail(it, taskDetailsInfos);
     408            3 :             break;
     409            1 :         default:
     410            1 :             FillDefaultDetail(it, taskDetailsInfos);
     411            1 :             break;
     412              :     }
     413              : 
     414           21 :     FillCommonTailFields(it, taskDetailsInfos);
     415              : }
     416              : 
     417            4 : void DfxProfilingHandlerLite::ReportStreamTaskDetailsLog(TaskInfoCircularQueue& taskQueue) const
     418              : {
     419            4 :     if (LIKELY(HcclCheckLogLevel(HCCL_LOG_INFO) == 0)) {
     420            0 :         return;
     421              :     }
     422            4 :     u16 begin = taskQueue.GetBegin();
     423            4 :     u16 count = taskQueue.GetCount();
     424            9 :     for (u16 idx = begin, i = 0; i < count; idx = (idx + 1) % taskQueue.GetCapacity(), i++) {
     425            5 :         DfxTaskInfo* ptr = taskQueue.GetSlot(idx);
     426            5 :         if (ptr == nullptr) {
     427            0 :             continue;
     428              :         }
     429            5 :         HCCL_INFO(
     430              :             "[DfxProfilingHandlerLite] DumpTaskDetails sqId:%u, taskId:%u, taskType:%u", ptr->sqId, ptr->taskId,
     431              :             ptr->taskType);
     432              :     }
     433              : }
     434              : 
     435            3 : void DfxProfilingHandlerLite::ReportStreamTaskDetails(TaskInfoCircularQueue& taskQueue) const
     436              : {
     437            3 :     u16 begin = taskQueue.GetBegin();
     438            3 :     u16 count = taskQueue.GetCount();
     439            3 :     if (taskQueue.IsEmpty()) {
     440            1 :         return;
     441              :     }
     442              : 
     443            2 :     ReportStreamTaskDetailsLog(taskQueue);
     444              : 
     445            2 :     MsprofAicpuHcclTaskInfo taskInfos[HCCLINFO_REPORT_BATCH_NUM] = {};
     446            2 :     bool isSupportBatchReport = (reportBatchAdditionalInfo_ != nullptr);
     447            2 :     constexpr int32_t MAX_BATCH_REPORT_NUM = 512;
     448         1024 :     MsprofAdditionalInfo addInfoVec[MAX_BATCH_REPORT_NUM] = {};
     449            2 :     uint32_t addInfoIndx = 0;
     450            2 :     uint32_t batchId = 0;
     451            2 :     u32 totalTasks = count;
     452            2 :     u32 reportedTasks = 0;
     453              : 
     454            6 :     for (u16 idx = begin, i = 0; i < count; idx = (idx + 1) % taskQueue.GetCapacity(), i++) {
     455            4 :         DfxTaskInfo* ptr = taskQueue.GetSlot(idx);
     456            4 :         if (ptr == nullptr) {
     457            0 :             continue;
     458              :         }
     459            4 :         GetTaskDetailInfosFromDfxTaskInfo(ptr, taskInfos[batchId++]);
     460            4 :         reportedTasks++;
     461            4 :         if (batchId == HCCLINFO_REPORT_BATCH_NUM || reportedTasks == totalTasks) {
     462            3 :             if (!isSupportBatchReport) {
     463            0 :                 MsprofAdditionalInfo reporterData{};
     464            0 :                 if (!FillBatchReporterData(batchId, taskInfos, reporterData)) {
     465            0 :                     return;
     466              :                 }
     467            0 :                 ReportAdditionInfo(reporterData);
     468              :             } else {
     469            3 :                 if (!ReportBatchAddInfo(
     470              :                         batchId, taskInfos, addInfoVec, addInfoIndx, MAX_BATCH_REPORT_NUM,
     471              :                         reportedTasks == totalTasks)) {
     472            0 :                     return;
     473              :                 }
     474              :             }
     475            3 :             batchId = 0;
     476            3 :             memset_s(taskInfos, sizeof(taskInfos), 0, sizeof(taskInfos));
     477              :         }
     478              :     }
     479              : }
     480              : 
     481            2 : void DfxProfilingHandlerLite::FillReduceInlineDetail(
     482              :     const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
     483              : {
     484            2 :     taskDetailsInfos.notifyID = it->taskPara.Reduce.notifyId;
     485            2 :     taskDetailsInfos.srcAddr = it->taskPara.Reduce.srcAddr;
     486            2 :     taskDetailsInfos.dstAddr = it->taskPara.Reduce.dstAddr;
     487            2 :     taskDetailsInfos.dataSize = static_cast<uint64_t>(it->taskPara.Reduce.size);
     488            2 :     taskDetailsInfos.linkType = it->linkType;
     489            2 :     taskDetailsInfos.opType = it->taskPara.Reduce.reduceOp;
     490            2 : }
     491              : 
     492            8 : void DfxProfilingHandlerLite::FillSdmaRdmaDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
     493              : {
     494            8 :     taskDetailsInfos.linkType = it->linkType;
     495            8 :     taskDetailsInfos.opType = 0;
     496            8 :     taskDetailsInfos.notifyID = DFX_INVALID_U64;
     497            8 :     void* sqePtr = reinterpret_cast<void*>(it->taskPara.Dma.sqeAddr);
     498            8 :     if (sqePtr != nullptr) {
     499            0 :         auto* header = reinterpret_cast<Hccl::Rt91095StarsSqeHeader*>(sqePtr);
     500            0 :         if (static_cast<Hccl::Rt91095StarsSqeType>(header->type) == Hccl::Rt91095StarsSqeType::RT_91095_SQE_TYPE_SDMA) {
     501            0 :             auto* dmaSqe = reinterpret_cast<Hccl::Rt91095StarsMemcpySqe*>(sqePtr);
     502              :             taskDetailsInfos.srcAddr
     503            0 :                 = (static_cast<u64>(dmaSqe->u.strideMode0.srcAddrHigh) << 32) | dmaSqe->u.strideMode0.srcAddrLow;
     504              :             taskDetailsInfos.dstAddr
     505            0 :                 = (static_cast<u64>(dmaSqe->u.strideMode0.dstAddrHigh) << 32) | dmaSqe->u.strideMode0.dstAddrLow;
     506            0 :             taskDetailsInfos.dataSize = dmaSqe->u.strideMode0.lengthMove;
     507              :         }
     508              :     }
     509            8 : }
     510              : 
     511            7 : void DfxProfilingHandlerLite::FillUbDmaDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
     512              : {
     513            7 :     taskDetailsInfos.notifyID = it->taskPara.ubDma.notifyId;
     514            7 :     taskDetailsInfos.srcAddr = it->taskPara.ubDma.srcAddr;
     515            7 :     taskDetailsInfos.dstAddr = it->taskPara.ubDma.dstAddr;
     516            7 :     taskDetailsInfos.dataSize = static_cast<uint64_t>(it->taskPara.ubDma.size);
     517            7 :     taskDetailsInfos.linkType = it->linkType;
     518            7 :     if (it->taskType == static_cast<u8>(TaskParamTypeVal::TASK_UB_REDUCE_INLINE)
     519            5 :         || it->taskType == static_cast<u8>(TaskParamTypeVal::TASK_WRITE_REDUCE_WITH_NOTIFY)) {
     520            3 :         taskDetailsInfos.opType = it->taskPara.Reduce.reduceOp;
     521              :     } else {
     522            4 :         taskDetailsInfos.opType = 0;
     523              :     }
     524            7 : }
     525              : 
     526            3 : void DfxProfilingHandlerLite::FillNotifyDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
     527              : {
     528            3 :     taskDetailsInfos.linkType = it->linkType;
     529            3 :     taskDetailsInfos.notifyID = DFX_INVALID_U64;
     530            3 :     void* sqePtr = reinterpret_cast<void*>(it->taskPara.Notify.sqeAddr);
     531            3 :     if (sqePtr != nullptr) {
     532            0 :         auto* header = reinterpret_cast<Hccl::Rt91095StarsSqeHeader*>(sqePtr);
     533            0 :         if (static_cast<Hccl::Rt91095StarsSqeType>(header->type)
     534            0 :                 == Hccl::Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_RECORD
     535            0 :             || static_cast<Hccl::Rt91095StarsSqeType>(header->type)
     536            0 :                    == Hccl::Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT) {
     537            0 :             auto* notifySqe = reinterpret_cast<Hccl::Rt91095StarsNotifySqe*>(sqePtr);
     538            0 :             taskDetailsInfos.notifyID = notifySqe->notifyId;
     539              :         }
     540              :     }
     541            3 : }
     542              : 
     543            1 : void DfxProfilingHandlerLite::FillDefaultDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
     544              : {
     545            1 :     taskDetailsInfos.linkType = it->linkType;
     546            1 :     taskDetailsInfos.notifyID = DFX_INVALID_U64;
     547            1 : }
     548              : 
     549           24 : void DfxProfilingHandlerLite::FillCclTagAndRemoteRank(
     550              :     const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
     551              : {
     552           24 :     if (it->dfxOpInfo != DFX_INVALID_U64) {
     553            3 :         auto* opInfo = reinterpret_cast<const DfxDfxOpInfo*>(it->dfxOpInfo);
     554            3 :         auto opTypeCclTagIt = opTypeHashCache_.find(opInfo->opType);
     555            3 :         taskDetailsInfos.cclTag = (opTypeCclTagIt != opTypeHashCache_.end()) ? opTypeCclTagIt->second : DFX_INVALID_U64;
     556            3 :         taskDetailsInfos.remoteRank = INVALID_U32;
     557            3 :         if (cachedChannelRemoteRankIdMap_ != nullptr && it->channelHandle != DFX_INVALID_U64) {
     558            2 :             auto rankIt = cachedChannelRemoteRankIdMap_->find(it->channelHandle);
     559            2 :             if (rankIt != cachedChannelRemoteRankIdMap_->end()) {
     560            2 :                 taskDetailsInfos.remoteRank = rankIt->second;
     561              :             }
     562              :         }
     563              :     } else {
     564           21 :         taskDetailsInfos.cclTag = DFX_INVALID_U64;
     565           21 :         taskDetailsInfos.remoteRank = INVALID_U32;
     566              :     }
     567           24 : }
     568              : 
     569           24 : void DfxProfilingHandlerLite::FillCommonTailFields(
     570              :     const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
     571              : {
     572           24 :     taskDetailsInfos.taskId = it->taskId;
     573           24 :     taskDetailsInfos.streamId = it->sqId;
     574           24 :     taskDetailsInfos.planeID = 0;
     575           24 :     if (it->dfxOpInfo != DFX_INVALID_U64) {
     576            2 :         taskDetailsInfos.dataType = reinterpret_cast<const DfxDfxOpInfo*>(it->dfxOpInfo)->dataType;
     577              :     }
     578           24 :     taskDetailsInfos.transportType = static_cast<int32_t>(it->transportType);
     579           24 :     if (taskDetailsInfos.remoteRank == Hccl::DFX_INVALID_RANKID) {
     580           21 :         taskDetailsInfos.remoteRank = taskDetailsInfos.localRank;
     581              :     }
     582           24 :     taskDetailsInfos.rdmaType = 0;
     583           24 :     taskDetailsInfos.role = static_cast<uint32_t>(DfxTaskRole::NEW_TASK_ROLE_DST);
     584           24 :     taskDetailsInfos.workFlowMode = static_cast<uint32_t>(DfxWorkflowMode::NEW_WORKFLOW_MODE_OP_BASE);
     585           24 : }
     586              : 
     587              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1