LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/hcom - hcom_host_profiling.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 9.0 % 67 6
Test Date: 2026-08-18 17:47:01 Functions: 20.0 % 5 1

            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 "profiling_manager_pub.h"
      12              : #include "hccl_comm_pub.h"
      13              : #include "hccl/hcom.h"
      14              : #include "hcom_host_profiling.h"
      15              : #include "adapter_prof.h"
      16              : #include "hccl/hccl_types.h"
      17              : #include "hcomm_thread_c_adpt.h"
      18              : 
      19              : using namespace hccl;
      20            2 : extern HcclResult HcommProfilingReportKernel(uint64_t beginTime, const char* profName)
      21              : {
      22            2 :     std::string profNames(profName);
      23            2 :     uint64_t endTime = hrtMsprofSysCycleTime();
      24            2 :     uint32_t threadId = SalGetTid();
      25            4 :     return ProfilingManagerPub::CallMsprofReportNodeInfo(beginTime, endTime, profName, threadId);
      26            2 : }
      27              : 
      28              : // 上报acl host
      29            0 : extern HcclResult HcommProfilingReportOp(HcomProInfo profInfo)
      30              : {
      31              :     // 数据恢复
      32            0 :     HcclCMDType cmdTypeTemp = static_cast<HcclCMDType>(profInfo.cmdType);
      33            0 :     HcclDataType dataTypeTemp = static_cast<HcclDataType>(profInfo.dataType);
      34            0 :     uint64_t groupName = hrtMsprofGetHashId(profInfo.commName, strlen(profInfo.commName));
      35            0 :     std::string algTypeStr(profInfo.algType);
      36              : 
      37            0 :     AlgType algType;
      38            0 :     CHK_PRT_RET(
      39              :         TransferStrToAlgType(algTypeStr, algType) == false,
      40              :         HCCL_ERROR("[%s] Fail to transfer [%s] to AlgType", __func__, algTypeStr.c_str()), HCCL_E_PARA);
      41              : 
      42            0 :     HCCL_INFO(
      43              :         "[%s] cmdType[%u], dataType[%u], groupName[%llu], groupNameStr[%s], algTypeStr[%s], blockDim[%u]", __func__,
      44              :         cmdTypeTemp, dataTypeTemp, groupName, profInfo.commName, profInfo.algType, profInfo.blockDim);
      45              : 
      46            0 :     CHK_RET_AND_PRINT_IDE(
      47              :         ProfilingManagerPub::CallMsprofReportHostApi(
      48              :             cmdTypeTemp, profInfo.beginTime, profInfo.dataCount, dataTypeTemp, algType, groupName, profInfo.blockDim),
      49              :         profInfo.commName);
      50            0 :     return HCCL_SUCCESS;
      51            0 : }
      52              : 
      53            0 : extern HcclResult HcommProfilingRegThread(HcomProInfo profInfo, ThreadHandle* threads)
      54              : {
      55            0 :     CHK_PTR_NULL(threads);
      56            0 :     std::string identifier(profInfo.commName);
      57            0 :     std::string tag(profInfo.tag);
      58            0 :     HCCL_PROFILER_ADD_GROUPRANK(identifier, profInfo.rankSize, profInfo.userRank);
      59            0 :     if (profInfo.isAiv) {
      60            0 :         HCCL_PROFILER_ADD_TAG_AIV(tag, identifier, GetWorkflowMode());
      61              :     } else {
      62            0 :         HCCL_PROFILER_ADD_TAG(tag, identifier, GetWorkflowMode());
      63              :     }
      64              : 
      65            0 :     uint32_t mainStreamId = reinterpret_cast<Thread*>(threads[0])->GetStream()->id();
      66            0 :     HCCL_INFO(
      67              :         "[%s] mainStreamId[%u], identifier[%s], tag[%s]", __func__, mainStreamId, profInfo.commName, profInfo.tag);
      68            0 :     HCCL_PROFILER_ADD_OPDATA_OP(
      69              :         profInfo.tag, profInfo.dataCount, nullptr, nullptr, static_cast<HcclDataType>(profInfo.dataType), profInfo.root,
      70              :         profInfo.commName, HcclReduceOp::HCCL_REDUCE_RESERVED);
      71              : 
      72            0 :     std::string algTypeStr(profInfo.algType);
      73            0 :     AlgType algType;
      74            0 :     CHK_PRT_RET(
      75              :         TransferStrToAlgType(algTypeStr, algType) == false,
      76              :         HCCL_ERROR("[%s] Fail to transfer [%s] to AlgType", __func__, algTypeStr.c_str()), HCCL_E_PARA);
      77            0 :     HCCL_PROFILER_ADD_STREAM_BY_STREAMID(mainStreamId, tag, 0, algType);
      78              : 
      79            0 :     if (((GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE)
      80            0 :          && !hccl::ProfilingManagerPub::GetAdditionInfoState() && !hccl::ProfilingManagerPub::GetTaskApiState())
      81            0 :         && !profInfo.isCapture) {
      82            0 :         return HCCL_SUCCESS;
      83              :     }
      84              :     // 从流信息profiling开关打开的话再注册
      85            0 :     for (u32 streamIndex = 1; streamIndex <= profInfo.slaveThreadNum; streamIndex++) {
      86            0 :         uint32_t slaveStreamId = reinterpret_cast<Thread*>(threads[streamIndex])->GetStream()->id();
      87            0 :         HCCL_INFO("[%s] slaveStreamId[%u]", __func__, slaveStreamId);
      88            0 :         HCCL_PROFILER_ADD_STREAM_BY_STREAMID(slaveStreamId, profInfo.tag, streamIndex, algType);
      89              :     }
      90            0 :     return HCCL_SUCCESS;
      91            0 : }
      92              : 
      93            0 : extern HcclResult HcommProfilingUnRegThread(HcomProInfo profInfo, ThreadHandle* threads)
      94              : {
      95            0 :     CHK_PTR_NULL(threads);
      96            0 :     std::string tag(profInfo.tag);
      97            0 :     std::string identifier(profInfo.commName);
      98              : 
      99            0 :     HCCL_PROFILER_DEL_TAG(tag);
     100            0 :     HCCL_PROFILER_DEL_GROUPRANK(identifier);
     101              : 
     102            0 :     uint32_t mainStreamId = reinterpret_cast<Thread*>(threads[0])->GetStream()->id();
     103            0 :     HCCL_PROFILER_DEL_STREAM_BY_STREAMID(mainStreamId);
     104            0 :     HCCL_PROFILER_DEL_OPDATA(tag);
     105            0 :     if (((GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE)
     106            0 :          && !hccl::ProfilingManagerPub::GetAdditionInfoState() && !hccl::ProfilingManagerPub::GetTaskApiState())
     107            0 :         && !profInfo.isCapture) {
     108            0 :         return HCCL_SUCCESS;
     109              :     }
     110              : 
     111            0 :     for (u32 streamIndex = 1; streamIndex <= profInfo.slaveThreadNum; streamIndex++) {
     112            0 :         uint32_t slaveStreamId = reinterpret_cast<Thread*>(threads[streamIndex])->GetStream()->id();
     113            0 :         HCCL_INFO("[%s] slaveStreamId[%u]", __func__, slaveStreamId);
     114            0 :         HCCL_PROFILER_DEL_STREAM_BY_STREAMID(slaveStreamId);
     115              :     }
     116            0 :     return HCCL_SUCCESS;
     117            0 : }
     118              : 
     119            0 : extern uint64_t HcommGetProfilingSysCycleTime()
     120              : {
     121            0 :     DevType devType = DevType::DEV_TYPE_COUNT;
     122            0 :     CHK_RET(hrtGetDeviceType(devType));
     123            0 :     if (devType != DevType::DEV_TYPE_950 && devType != DevType::DEV_TYPE_960) {
     124            0 :         return hrtMsprofSysCycleTime();
     125              :     }
     126            0 :     return Hccl::DlProfFunction::GetInstance().dlMsprofSysCycleTime();
     127              : }
        

Generated by: LCOV version 2.0-1