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

Generated by: LCOV version 2.0-1