LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/hcom - hcom_device_profiling.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 15 0
Test Date: 2026-08-18 17:47:01 Functions: 0.0 % 5 0

            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 "common.h"
      14              : #include "hccl/hcom.h"
      15              : #include "hccl/hccl_types.h"
      16              : #include "hcom_device_profiling.h"
      17              : #include "stream_pub.h"
      18              : #ifdef CCL_KERNEL_AICPU
      19              : #include "device/inc/profiling_manager_device.h"
      20              : #endif
      21              : #include "thread.h"
      22              : using namespace hccl;
      23              : 
      24            0 : extern HcclResult HcommProfilingInit(ThreadHandle* threads, u32 threadNum)
      25              : {
      26              : #ifdef CCL_KERNEL_AICPU
      27              :     bool profL0Open = dfx::ProfilingManager::IsProfL0On();
      28              :     bool profL1Open = dfx::ProfilingManager::IsProfL1On();
      29              :     HCCL_DEBUG("[%s] profL0Open:%d, profL1Open:%d", __func__, profL0Open, profL1Open);
      30              :     if (!profL1Open) {
      31              :         HCCL_INFO("[%s] L1 is off", __func__);
      32              :         return HCCL_SUCCESS;
      33              :     }
      34              :     for (u32 i = 0; i < threadNum; i++) {
      35              :         const SqeRingBuffer& sqeBuffer = GetStream(threads[i])->GetSqeContextPtr()->buffer;
      36              :         u16 taskId = sqeBuffer.tailSqeIdx;
      37              :         HCCL_DEBUG("[%s] thread id = [%u] task id = [%u]", __func__, GetStream(threads[i])->id(), taskId);
      38              :         CHK_RET(dfx::ProfilingManager::UpdateStartReportSqeIdx(GetStream(threads[i])->id(), taskId));
      39              :     }
      40              : #else
      41            0 :     HCCL_INFO("[%s] not support, do nothing", __func__);
      42              : #endif
      43            0 :     return HCCL_SUCCESS;
      44              : }
      45              : 
      46            0 : extern HcclResult HcommProfilingReportMainStreamAndFirstTask(ThreadHandle thread)
      47              : {
      48              : #ifdef CCL_KERNEL_AICPU
      49              :     bool profL0Open = dfx::ProfilingManager::IsProfL0On();
      50              :     bool profL1Open = dfx::ProfilingManager::IsProfL1On();
      51              :     HCCL_DEBUG("[%s] profL0Open:%d, profL1Open:%d", __func__, profL0Open, profL1Open);
      52              :     Stream* stream = GetStream(thread);
      53              :     if (stream == nullptr) {
      54              :         HCCL_ERROR("[%s] stream is nullptr", __func__);
      55              :         return HCCL_E_PTR;
      56              :     }
      57              :     HcclSqeContext* sqeContext = stream->GetSqeContextPtr();
      58              :     if (sqeContext == nullptr) {
      59              :         HCCL_ERROR("[%s] sqeContext is nullptr", __func__);
      60              :         return HCCL_E_PTR;
      61              :     }
      62              :     const SqeRingBuffer& sqeBuffer = sqeContext->buffer;
      63              :     uint16_t HEAD_TASK = 0;
      64              :     u16 taskId = sqeBuffer.tailSqeTaskId;
      65              :     HCCL_DEBUG("[%s] thread id = [%u] task id = [%u]", __func__, stream->id(), taskId);
      66              :     return dfx::ProfilingManager::ReportMainStreamTask(*stream, taskId, HEAD_TASK);
      67              : #else
      68            0 :     HCCL_INFO("[%s] not support, do nothing", __func__);
      69              : #endif
      70            0 :     return HCCL_SUCCESS;
      71              : }
      72              : 
      73            0 : extern HcclResult HcommProfilingReportMainStreamAndLastTask(ThreadHandle thread)
      74              : {
      75              : #ifdef CCL_KERNEL_AICPU
      76              :     const SqeRingBuffer& sqeBuffer = GetStream(thread)->GetSqeContextPtr()->buffer;
      77              :     uint16_t TAIL_TASK = 1;
      78              :     u16 taskId = sqeBuffer.tailSqeTaskId - 1;
      79              :     HCCL_DEBUG("[%s] thread id = [%u] task id = [%u]", __func__, GetStream(thread)->id(), taskId);
      80              :     return dfx::ProfilingManager::ReportMainStreamTask(*GetStream(thread), taskId, TAIL_TASK);
      81              : #else
      82            0 :     HCCL_INFO("[%s] not support, do nothing", __func__);
      83              : #endif
      84            0 :     return HCCL_SUCCESS;
      85              : }
      86              : 
      87              : // device 侧的op
      88            0 : extern HcclResult HcommProfilingReportDeviceHcclOpInfo(HcomProInfo profInfo)
      89              : {
      90              : #ifdef CCL_KERNEL_AICPU
      91              :     MsprofAicpuHCCLOPInfo hcclOpInfo{};
      92              :     hcclOpInfo.relay = 0; // 目前全是false
      93              :     hcclOpInfo.retry = 0; // 目前全是false
      94              :     hcclOpInfo.dataType = static_cast<HcclDataType>(profInfo.dataType);
      95              :     hcclOpInfo.count = profInfo.dataCount;
      96              :     uint64_t groupHashId = dfx::ProfilingManager::GetProfHashId(profInfo.commName, profInfo.commNameLen);
      97              :     hcclOpInfo.groupName = groupHashId;
      98              :     hcclOpInfo.ranksize = profInfo.rankSize;
      99              :     std::string algTypeStr(profInfo.algType);
     100              :     hcclOpInfo.streamId = 0; // kfc的流, 目前没有默认为0 AicpuGetStreamId()
     101              :     AlgType algType;
     102              :     CHK_PRT_RET(
     103              :         TransferStrToAlgType(algTypeStr, algType) == false,
     104              :         HCCL_ERROR("[%s] Fail to transfer [%s] to AlgType", __func__, algTypeStr.c_str()), HCCL_E_PARA);
     105              :     algTypeStr = TransferAlgType(algType);
     106              :     HCCL_INFO(
     107              :         "[%s] groupName = [%u], commName = [%s], ranksize = [%u], taskId = [%u], streamId = [%u], dataType = [%u], "
     108              :         "algTypeStr = [%s]",
     109              :         __func__, hcclOpInfo.groupName, profInfo.commName, hcclOpInfo.ranksize, hcclOpInfo.taskId, hcclOpInfo.streamId,
     110              :         hcclOpInfo.dataType, algTypeStr.c_str());
     111              :     CHK_RET(dfx::ProfilingManager::ReportHcclOpInfo(hcclOpInfo, algTypeStr));
     112              :     return HCCL_SUCCESS;
     113              : #else
     114            0 :     HCCL_INFO("[%s] not support, do nothing", __func__);
     115              : #endif
     116            0 :     return HCCL_SUCCESS;
     117              : }
     118              : 
     119            0 : extern HcclResult HcommProfilingEnd(ThreadHandle* threads, u32 threadNum)
     120              : {
     121              : #ifdef CCL_KERNEL_AICPU
     122              :     // 上报task
     123              :     if (dfx::ProfilingManager::GetProfL1State()) {
     124              :         for (u32 i = 0; i < threadNum; i++) {
     125              :             HCCL_DEBUG("[%s] thread id = [%u]", __func__, GetStream(threads[i])->id());
     126              :             CHK_RET(dfx::ProfilingManager::ReportTaskInfo(
     127              :                 GetStream(threads[i])->id(), GetStream(threads[i])->GetSqeContextPtr()));
     128              :         }
     129              :     }
     130              : 
     131              :     for (u32 i = 0; i < threadNum; i++) {
     132              :         HCCL_DEBUG("[%s] thread id = [%u]", __func__, GetStream(threads[i])->id());
     133              :         CHK_RET(GetStream(threads[i])->ClearLocalBuff());
     134              :         CHK_RET(dfx::ProfilingManager::UpdateStartReportSqeIdx(GetStream(threads[i])->id(), 0));
     135              :     }
     136              : #else
     137            0 :     HCCL_INFO("[%s] not support, do nothing", __func__);
     138              : #endif
     139            0 :     return HCCL_SUCCESS;
     140              : }
        

Generated by: LCOV version 2.0-1