LCOV - code coverage report
Current view: top level - legacy/ascend910/common/debug/profiling - profiler_base.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.8 % 224 210
Test Date: 2026-08-18 17:47:01 Functions: 95.0 % 20 19

            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 <sys/time.h> /* 获取时间 */
      12              : 
      13              : #include "profiler_base_pub.h"
      14              : #include "adapter_rts_common.h"
      15              : #include "coll_alg_utils.h"
      16              : 
      17              : using namespace hccl;
      18              : std::array<std::map<s32, StreamRecordInfo>, MAX_MODULE_DEVICE_NUM> ProfilerBase::streamRecordInfoMap_;
      19              : std::array<std::map<const std::string, const std::string>, MAX_MODULE_DEVICE_NUM> ProfilerBase::tagGroupMap_;
      20              : std::array<std::map<const std::string, const HcclWorkflowMode>, MAX_MODULE_DEVICE_NUM> ProfilerBase::tagModeMap_;
      21              : std::array<std::map<const std::string, GroupRankInfo>, MAX_MODULE_DEVICE_NUM> ProfilerBase::groupRankMap_;
      22              : std::array<std::map<const std::string, OpDataInfo>, MAX_MODULE_DEVICE_NUM> ProfilerBase::tagOpDataMap_;
      23              : std::array<std::map<const std::string, u32>, MAX_MODULE_DEVICE_NUM> ProfilerBase::groupIndexMap_;
      24              : std::array<std::map<const std::string, u32>, MAX_MODULE_DEVICE_NUM> ProfilerBase::aivGroupIndexMap_;
      25              : std::array<std::map<const std::string, u32>, MAX_MODULE_DEVICE_NUM> ProfilerBase::sendRecvGroupIndexMap_;
      26              : std::array<std::map<const std::string, std::string>, MAX_MODULE_DEVICE_NUM> ProfilerBase::groupUdiMap_;
      27              : std::array<std::mutex, MAX_MODULE_DEVICE_NUM> ProfilerBase::streamMutex_;
      28              : bool ProfilerBase::isSendRecv_[MAX_MODULE_DEVICE_NUM];
      29              : u32 ProfilerBase::index_[MAX_MODULE_DEVICE_NUM];
      30              : 
      31              : const std::array<uint32_t, HCCL_REDUCE_RESERVED> ProfilerBase::opString
      32              :     = {static_cast<u32>(OpDict::SUM), static_cast<u32>(OpDict::PROD), static_cast<u32>(OpDict::MAX),
      33              :        static_cast<u32>(OpDict::MIN)};
      34              : 
      35              : const std::array<uint32_t, HCCL_DATA_TYPE_RESERVED> ProfilerBase::dataTypeString
      36              :     = {static_cast<u32>(DataType::DINT8),  static_cast<u32>(DataType::DINT16), static_cast<u32>(DataType::DINT32),
      37              :        static_cast<u32>(DataType::DFP16),  static_cast<u32>(DataType::DFP32),  static_cast<u32>(DataType::DINT64),
      38              :        static_cast<u32>(DataType::DUINT64)};
      39              : // 16位浮点在CPU中找不到对应的数据类型, 故直接写立即数 : 2
      40              : const std::array<s32, HCCL_DATA_TYPE_RESERVED> ProfilerBase::sizeOf
      41              :     = {sizeof(s8), sizeof(short), sizeof(s32), 2, sizeof(float), sizeof(s64), sizeof(u64)};
      42          959 : ProfilerBase::ProfilerBase(u32 deviceLogicId) : deviceLogicId_(deviceLogicId) {}
      43              : 
      44          959 : ProfilerBase::~ProfilerBase() {}
      45              : 
      46           25 : HcclResult ProfilerBase::AddStream(s32 streamID, const std::string& tag, s32 planeID, const AlgType& algType)
      47              : {
      48           25 :     s32 deviceLogicId = -1;
      49           25 :     CHK_RET(hrtGetDevice(&deviceLogicId));
      50              : 
      51              :     u32 maxDeviceNum;
      52           25 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
      53           25 :     CHK_PRT_RET(
      54              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
      55              :         HCCL_ERROR(
      56              :             "[Add][Stream]deviceLogicId_[%d]"
      57              :             "is bigger than HCCL_AISERVER_DEVICE_NUM[%u]",
      58              :             deviceLogicId, maxDeviceNum),
      59              :         HCCL_E_INTERNAL);
      60           25 :     HCCL_DEBUG(
      61              :         "AddStream: streamID[%d], tag[%s], planeId[%d], algType[%s], deviceLogicId[%d]", streamID, tag.c_str(), planeID,
      62              :         AlgTypeToStr(algType).c_str(), deviceLogicId);
      63              :     {
      64           25 :         std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
      65           25 :         streamRecordInfoMap_[deviceLogicId][streamID] = StreamRecordInfo(planeID, algType, tag);
      66           25 :     }
      67           25 :     return HCCL_SUCCESS;
      68              : }
      69              : 
      70           21 : HcclResult ProfilerBase::DelStream(s32 streamID)
      71              : {
      72           21 :     s32 deviceLogicId = -1;
      73           21 :     CHK_RET(hrtGetDevice(&deviceLogicId));
      74              : 
      75              :     u32 maxDeviceNum;
      76           21 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
      77           21 :     CHK_PRT_RET(
      78              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
      79              :         HCCL_WARNING(
      80              :             "deviceLogicId_[%d] is bigger"
      81              :             "than maxDeviceNum[%u]",
      82              :             deviceLogicId, maxDeviceNum),
      83              :         HCCL_E_INTERNAL);
      84              : 
      85              :     {
      86           21 :         std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
      87           21 :         HCCL_DEBUG(
      88              :             "DelStream: streamID[%d] tag[%s], planeId[%d], algType[%s], deviceLogicId[%d]", streamID,
      89              :             streamRecordInfoMap_[deviceLogicId][streamID].tag.c_str(),
      90              :             streamRecordInfoMap_[deviceLogicId][streamID].planeId,
      91              :             AlgTypeToStr(streamRecordInfoMap_[deviceLogicId][streamID].algType).c_str(), deviceLogicId);
      92           21 :         streamRecordInfoMap_[deviceLogicId].erase(streamID);
      93           21 :     }
      94           21 :     return HCCL_SUCCESS;
      95              : }
      96              : 
      97           25 : HcclResult ProfilerBase::AddTag(
      98              :     const std::string& tag, const std::string& group, const HcclWorkflowMode& workFlowMode, bool isSendRecv, bool isAiv)
      99              : {
     100           25 :     s32 deviceLogicId = -1;
     101           25 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     102           25 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     103              :     u32 maxDeviceNum;
     104           25 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     105           25 :     CHK_PRT_RET(
     106              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     107              :         HCCL_ERROR(
     108              :             "deviceLogicId_[%d] is bigger than"
     109              :             " maxDeviceNum[%u]",
     110              :             deviceLogicId, maxDeviceNum),
     111              :         HCCL_E_INTERNAL);
     112           25 :     HCCL_DEBUG(
     113              :         "AddTag: tag[%s] group[%s] deviceLogicId[%d] aivGroupIndexMap_ %d", tag.c_str(), group.c_str(), deviceLogicId,
     114              :         aivGroupIndexMap_[deviceLogicId][group]);
     115              :     {
     116           25 :         std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     117           25 :         tagGroupMap_[deviceLogicId].emplace(tag, group);
     118           25 :         tagModeMap_[deviceLogicId].emplace(tag, workFlowMode);
     119            5 :         auto& targetMap = isAiv ? aivGroupIndexMap_[deviceLogicId] :
     120           25 :                                   (isSendRecv ? sendRecvGroupIndexMap_[deviceLogicId] : groupIndexMap_[deviceLogicId]);
     121           25 :         const auto& emplaceResult = targetMap.emplace(group, 0);
     122           25 :         auto& it = emplaceResult.first;
     123           25 :         it->second++;
     124           25 :         index_[deviceLogicId] = it->second;
     125           25 :         isSendRecv_[deviceLogicId] = isSendRecv;
     126           25 :         HCCL_DEBUG(
     127              :             "IndexMap: tag[%s] group[%s] groupIndexMap_[%d]:%u sendRecvGroupIndexMap_[%d]:%u AivGroupIndexMap_[%d] %u",
     128              :             tag.c_str(), group.c_str(), deviceLogicId, groupIndexMap_[deviceLogicId][group], deviceLogicId,
     129              :             sendRecvGroupIndexMap_[deviceLogicId][group], deviceLogicId, aivGroupIndexMap_[deviceLogicId][group]);
     130           25 :     }
     131           25 :     return HCCL_SUCCESS;
     132              : }
     133              : 
     134           21 : HcclResult ProfilerBase::DelTag(const std::string& tag)
     135              : {
     136           21 :     s32 deviceLogicId = -1;
     137           21 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     138           21 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     139              :     u32 maxDeviceNum;
     140           21 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     141           21 :     CHK_PRT_RET(
     142              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     143              :         HCCL_WARNING(
     144              :             "deviceLogicId_[%d] is bigger"
     145              :             "than maxDeviceNum[%u]",
     146              :             deviceLogicId, maxDeviceNum),
     147              :         HCCL_E_INTERNAL);
     148           21 :     HCCL_DEBUG(
     149              :         "DelTag: tag[%s] group[%s] deviceLogicId[%d]", tag.c_str(), tagGroupMap_[deviceLogicId][tag].c_str(),
     150              :         deviceLogicId);
     151              :     {
     152           21 :         std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     153           21 :         tagGroupMap_[deviceLogicId].erase(tag);
     154           21 :         tagModeMap_[deviceLogicId].erase(tag);
     155           21 :     }
     156           21 :     return HCCL_SUCCESS;
     157              : }
     158              : 
     159           25 : HcclResult ProfilerBase::AddOpData(
     160              :     const std::string& tag, u64 count, const void* src, const void* dst, HcclDataType dataType, u32 rootId,
     161              :     const std::string& group, HcclReduceOp reduceType)
     162              : {
     163           25 :     s32 deviceLogicId = -1;
     164           25 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     165           25 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     166              :     u32 maxDeviceNum;
     167           25 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     168           25 :     CHK_PRT_RET(
     169              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     170              :         HCCL_ERROR(
     171              :             "deviceLogicId_[%d] is bigger than"
     172              :             " maxDeviceNum[%u]",
     173              :             deviceLogicId, maxDeviceNum),
     174              :         HCCL_E_INTERNAL);
     175           25 :     HCCL_DEBUG(
     176              :         "AddOpData: tag[%s] count[%u] src[%p] dst[%p] dataType[%s] deviceLogicId[%d] group[%s]", tag.c_str(), count,
     177              :         src, dst, GetDataTypeEnumStr(dataType).c_str(), deviceLogicId, group.c_str());
     178              :     {
     179           25 :         std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     180           25 :         OpDataInfo opData;
     181           25 :         opData.count = count;
     182           25 :         opData.deviceId = deviceLogicId;
     183           25 :         opData.src = src;
     184           25 :         opData.dst = dst;
     185           25 :         opData.dataType = dataType;
     186           25 :         opData.index = index_[deviceLogicId];
     187           25 :         opData.rootId = rootId;
     188           25 :         (void)gettimeofday(&opData.tv, nullptr);
     189           25 :         opData.reduceType = reduceType;
     190           25 :         tagOpDataMap_[deviceLogicId][tag] = opData;
     191           25 :     }
     192           25 :     return HCCL_SUCCESS;
     193              : }
     194              : 
     195           22 : HcclResult ProfilerBase::DelOpData(const std::string& tag)
     196              : {
     197           22 :     s32 deviceLogicId = -1;
     198           22 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     199           22 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     200              :     u32 maxDeviceNum;
     201           22 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     202           22 :     CHK_PRT_RET(
     203              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     204              :         HCCL_WARNING(
     205              :             "deviceLogicId_[%d] is bigger"
     206              :             "than maxDeviceNum[%u]",
     207              :             deviceLogicId, maxDeviceNum),
     208              :         HCCL_E_INTERNAL);
     209           22 :     HCCL_DEBUG("DelOpData: tag[%s] deviceLogicId[%d]", tag.c_str(), deviceLogicId);
     210              :     {
     211           22 :         std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     212           22 :         tagOpDataMap_[deviceLogicId].erase(tag);
     213           22 :     }
     214           22 :     return HCCL_SUCCESS;
     215              : }
     216              : 
     217           25 : HcclResult ProfilerBase::AddGroupRankInfo(
     218              :     const std::string& group, u32 rankSize, u32 rankId, [[maybe_unused]] bool isSendRecv, u32 remoteRankId)
     219              : {
     220           25 :     s32 deviceLogicId = -1;
     221           25 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     222           25 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     223              :     u32 maxDeviceNum;
     224           25 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     225           25 :     CHK_PRT_RET(
     226              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     227              :         HCCL_ERROR(
     228              :             "deviceLogicId_[%d] is bigger than"
     229              :             " maxDeviceNum[%u]",
     230              :             deviceLogicId, maxDeviceNum),
     231              :         HCCL_E_INTERNAL);
     232           25 :     HCCL_DEBUG(
     233              :         "AddGroupRankInfo: group[%s] rankSize[%u] rankId[%u] deviceLogicId[%d]", group.c_str(), rankSize, rankId,
     234              :         deviceLogicId);
     235              :     {
     236           25 :         std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     237           25 :         GroupRankInfo groupRankInfo;
     238           25 :         groupRankInfo.rankSize = rankSize;
     239           25 :         groupRankInfo.rankId = rankId;
     240           25 :         groupRankInfo.remoteRankId = remoteRankId;
     241           25 :         groupRankMap_[deviceLogicId][group] = groupRankInfo;
     242           25 :     }
     243           25 :     return HCCL_SUCCESS;
     244              : }
     245              : 
     246           22 : HcclResult ProfilerBase::DelGroupRankInfo(const std::string& group)
     247              : {
     248           22 :     s32 deviceLogicId = -1;
     249           22 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     250           22 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     251              :     u32 maxDeviceNum;
     252           22 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     253           22 :     CHK_PRT_RET(
     254              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     255              :         HCCL_WARNING(
     256              :             "deviceLogicId_[%d] is bigger"
     257              :             "than maxDeviceNum[%u]",
     258              :             deviceLogicId, maxDeviceNum),
     259              :         HCCL_E_INTERNAL);
     260           22 :     HCCL_DEBUG("DelGroupRankInfo: group[%s] deviceLogicId[%d]", group.c_str(), deviceLogicId);
     261              :     {
     262           22 :         std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     263           22 :         groupRankMap_[deviceLogicId].erase(group);
     264           22 :     }
     265           22 :     return HCCL_SUCCESS;
     266              : }
     267              : 
     268          182 : HcclResult ProfilerBase::GetTagByStream(u32& streamID, std::string& tag)
     269              : {
     270          182 :     s32 deviceLogicId = -1;
     271          182 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     272          182 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     273              :     u32 maxDeviceNum;
     274          182 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     275          182 :     CHK_PRT_RET(
     276              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     277              :         HCCL_WARNING(
     278              :             "deviceLogicId_[%d] is bigger"
     279              :             "than maxDeviceNum[%u]",
     280              :             deviceLogicId, maxDeviceNum),
     281              :         HCCL_E_INTERNAL);
     282              : 
     283          182 :     std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     284          182 :     auto& streamMap = streamRecordInfoMap_[deviceLogicId];
     285          182 :     auto it = streamMap.find(streamID);
     286          182 :     CHK_PRT_RET((it == streamMap.end()), HCCL_DEBUG("stream id[%u] not found in profiler.", streamID), HCCL_SUCCESS);
     287          122 :     tag = it->second.tag;
     288          122 :     return HCCL_SUCCESS;
     289          182 : }
     290              : 
     291           47 : HcclResult ProfilerBase::GetAlgTypeByStream(u32& streamID, AlgType& algType)
     292              : {
     293           47 :     s32 deviceLogicId = -1;
     294           47 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     295           47 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[GetAlgTypeByStream]rts get device error"), ret);
     296              :     u32 maxDeviceNum;
     297           47 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     298           47 :     CHK_PRT_RET(
     299              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     300              :         HCCL_WARNING(
     301              :             "[GetAlgTypeByStream] "
     302              :             "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]",
     303              :             deviceLogicId, maxDeviceNum),
     304              :         HCCL_E_INTERNAL);
     305              : 
     306           47 :     std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     307           47 :     auto& streamMap = streamRecordInfoMap_[deviceLogicId];
     308           47 :     auto it = streamMap.find(streamID);
     309           47 :     CHK_PRT_RET(
     310              :         (it == streamMap.end()), HCCL_DEBUG("[GetAlgTypeByStream] stream id[%u] not found in profiler.", streamID),
     311              :         HCCL_SUCCESS);
     312           29 :     algType = it->second.algType;
     313           29 :     return HCCL_SUCCESS;
     314           47 : }
     315              : 
     316            6 : HcclResult ProfilerBase::GetGroupNameByTag(const std::string& tag, std::string& group)
     317              : {
     318            6 :     s32 deviceLogicId = -1;
     319            6 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     320            6 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[GetGroupNameByTag]rts get device error"), ret);
     321              :     u32 maxDeviceNum;
     322            6 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     323            6 :     CHK_PRT_RET(
     324              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     325              :         HCCL_WARNING(
     326              :             "[GetGroupNameByTag] "
     327              :             "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]",
     328              :             deviceLogicId, maxDeviceNum),
     329              :         HCCL_E_INTERNAL);
     330              : 
     331            6 :     std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     332            6 :     CHK_PRT_RET(
     333              :         tagGroupMap_[deviceLogicId].find(tag) == tagGroupMap_[deviceLogicId].end(),
     334              :         HCCL_DEBUG("[GetGroupNameByTag] tag[%s] not found in profiler.", tag.c_str()), HCCL_SUCCESS);
     335            0 :     group = tagGroupMap_[deviceLogicId][tag];
     336            0 :     return HCCL_SUCCESS;
     337            6 : }
     338              : 
     339            6 : HcclResult ProfilerBase::GetRankInfoByGroup(const std::string& group, GroupRankInfo& groupRankInfo)
     340              : {
     341            6 :     s32 deviceLogicId = -1;
     342            6 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     343            6 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[GetRankInfoByGroup]rts get device error"), ret);
     344              :     u32 maxDeviceNum;
     345            6 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     346            6 :     CHK_PRT_RET(
     347              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     348              :         HCCL_WARNING(
     349              :             "[GetRankInfoByGroup] "
     350              :             "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]",
     351              :             deviceLogicId, maxDeviceNum),
     352              :         HCCL_E_INTERNAL);
     353              : 
     354            6 :     std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     355            6 :     CHK_PRT_RET(
     356              :         groupRankMap_[deviceLogicId].find(group) == groupRankMap_[deviceLogicId].end(),
     357              :         HCCL_DEBUG("[GetRankInfoByGroup] group[%s] not found in profiler.", group.c_str()), HCCL_SUCCESS);
     358            0 :     groupRankInfo = groupRankMap_[deviceLogicId][group];
     359            0 :     return HCCL_SUCCESS;
     360            6 : }
     361              : 
     362            6 : HcclResult ProfilerBase::GetOpDataInfoByTag(const std::string& tag, OpDataInfo& opDataInfo)
     363              : {
     364            6 :     s32 deviceLogicId = -1;
     365            6 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     366            6 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[GetOpDataInfoByTag]rts get device error"), ret);
     367              :     u32 maxDeviceNum;
     368            6 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     369            6 :     CHK_PRT_RET(
     370              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     371              :         HCCL_WARNING(
     372              :             "[GetOpDataInfoByTag] "
     373              :             "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]",
     374              :             deviceLogicId, maxDeviceNum),
     375              :         HCCL_E_INTERNAL);
     376              : 
     377            6 :     std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     378            6 :     CHK_PRT_RET(
     379              :         tagOpDataMap_[deviceLogicId].find(tag) == tagOpDataMap_[deviceLogicId].end(),
     380              :         HCCL_DEBUG("[GetOpDataInfoByTag] tag[%u] not found in profiler.", tag.c_str()), HCCL_SUCCESS);
     381            0 :     opDataInfo = tagOpDataMap_[deviceLogicId][tag];
     382            0 :     return HCCL_SUCCESS;
     383            6 : }
     384              : 
     385           80 : void ProfilerBase::GetSubmittedOpCnt(u32& index)
     386              : {
     387           80 :     s32 deviceLogicId = -1;
     388           80 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     389           80 :     index = 0;
     390           80 :     if (ret != HCCL_SUCCESS) {
     391            0 :         HCCL_ERROR("[GetSubmittedOpCnt]rts get device error");
     392            0 :         return;
     393              :     }
     394              :     u32 maxDeviceNum;
     395           80 :     ret = GetMaxDevNum(maxDeviceNum);
     396           81 :     if (ret != HCCL_SUCCESS) {
     397            0 :         HCCL_ERROR("[GetMaxDevNum] get maxDeviceNum error");
     398            0 :         return;
     399              :     }
     400           81 :     if (static_cast<u32>(deviceLogicId) >= maxDeviceNum) {
     401            0 :         HCCL_WARNING(
     402              :             "[GetSubmittedOpCnt] "
     403              :             "deviceLogicId_[%d] is bigger than maxDeviceNum[%u]",
     404              :             deviceLogicId, maxDeviceNum);
     405            0 :         return;
     406              :     }
     407              : 
     408           81 :     std::unique_lock<std::mutex> lock(streamMutex_[deviceLogicId]);
     409           81 :     HCCL_DEBUG("GetSubmittedOpCnt: index_[%d][%u]", deviceLogicId, index_[deviceLogicId]);
     410           81 :     index = index_[deviceLogicId];
     411           81 :     return;
     412           81 : }
     413              : 
     414            5 : HcclResult ProfilerBase::AddGroupUdi(const std::string& group, const std::string& udi)
     415              : {
     416            5 :     s32 deviceLogicId = -1;
     417            5 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     418            5 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     419              :     u32 maxDeviceNum;
     420            5 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     421            5 :     CHK_PRT_RET(
     422              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     423              :         HCCL_ERROR(
     424              :             "deviceLogicId_[%d] is bigger than"
     425              :             " maxDeviceNum[%u]",
     426              :             deviceLogicId, maxDeviceNum),
     427              :         HCCL_E_INTERNAL);
     428            5 :     HCCL_RUN_INFO("AddGroupUdi: group[%s] udi[%s] deviceLogicId[%d]", group.c_str(), udi.c_str(), deviceLogicId);
     429            5 :     std::lock_guard<std::mutex> lock(streamMutex_[deviceLogicId]);
     430            5 :     groupUdiMap_[deviceLogicId].insert(std::make_pair<const std::string&, const std::string&>(group, udi));
     431            5 :     return HCCL_SUCCESS;
     432            5 : }
     433              : 
     434          235 : HcclResult ProfilerBase::DelGroupUdi(const std::string& group)
     435              : {
     436          235 :     s32 deviceLogicId = -1;
     437          235 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     438          235 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     439              :     u32 maxDeviceNum;
     440          235 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     441          235 :     CHK_PRT_RET(
     442              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     443              :         HCCL_ERROR(
     444              :             "deviceLogicId_[%d] is bigger than"
     445              :             " maxDeviceNum[%u]",
     446              :             deviceLogicId, maxDeviceNum),
     447              :         HCCL_E_INTERNAL);
     448          235 :     HCCL_DEBUG("DelGroupUdi: group[%s] deviceLogicId[%d]", group.c_str(), deviceLogicId);
     449          235 :     std::lock_guard<std::mutex> lock(streamMutex_[deviceLogicId]);
     450          235 :     groupUdiMap_[deviceLogicId].erase(group);
     451          235 :     return HCCL_SUCCESS;
     452          235 : }
     453              : 
     454           12 : HcclResult ProfilerBase::GetUdiByGroup(const std::string& group, std::string& udi)
     455              : {
     456           12 :     s32 deviceLogicId = -1;
     457           12 :     HcclResult ret = hrtGetDevice(&deviceLogicId);
     458           12 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("rts get device error"), ret);
     459              :     u32 maxDeviceNum;
     460           12 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     461           12 :     CHK_PRT_RET(
     462              :         static_cast<u32>(deviceLogicId) >= maxDeviceNum,
     463              :         HCCL_ERROR(
     464              :             "deviceLogicId_[%d] is bigger than"
     465              :             " maxDeviceNum[%u]",
     466              :             deviceLogicId, maxDeviceNum),
     467              :         HCCL_E_INTERNAL);
     468           12 :     HCCL_DEBUG("GetUdiByGroup: group[%s] deviceLogicId[%d]", group.c_str(), deviceLogicId);
     469           12 :     std::lock_guard<std::mutex> lock(streamMutex_[deviceLogicId]);
     470           12 :     CHK_PRT_RET(
     471              :         groupUdiMap_[deviceLogicId].find(group) == groupUdiMap_[deviceLogicId].end(),
     472              :         HCCL_DEBUG("[GetUdiByGroup] group[%s] not found in profiler.", group.c_str()), HCCL_SUCCESS);
     473            0 :     udi = groupUdiMap_[deviceLogicId].find(group)->second;
     474            0 :     return HCCL_SUCCESS;
     475           12 : }
        

Generated by: LCOV version 2.0-1