LCOV - code coverage report
Current view: top level - legacy/ascend910/common/debug/profiling - plugin_runner.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 52.2 % 69 36
Test Date: 2026-07-28 12:11:00 Functions: 62.5 % 8 5

            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 "plugin_runner.h"
      12              : #include "adapter_rts_common.h"
      13              : #include "externalinput_pub.h"
      14              : 
      15              : using namespace hccl;
      16          927 : PluginRunner::PluginRunner(ProfilerBase *profiler) : profiler_(profiler) {}
      17              : 
      18         2781 : PluginRunner::~PluginRunner() {}
      19              : 
      20              : template <typename T> 
      21          123 : void PluginRunner::operator () (rtStream_t stream, TaskType taskType, const T &para) const
      22              : {   
      23              :     //capture模式下hrtGetStreamId获取的是原来的流对应ID,与实际执行流不是同一个
      24              :     //capture模式下hrtGetTaskIdAndStreamID获取实际执行的streamID和taskID
      25          123 :     u32 threadLastTaskID = 0;
      26          123 :     u32 threadLastStreamID = 0;
      27          123 :     s32 streamID = 0;
      28          123 :     bool isOneSideTask = false;
      29          123 :     bool isCapture = false;
      30          123 :     CHK_PRT(isStreamCapture(stream, isCapture));
      31              : 
      32          123 :     if (profiler_ == nullptr) {
      33            0 :         return;
      34              :     }
      35          123 :     CHK_PRT(hrtGetTaskIdAndStreamID(threadLastTaskID, threadLastStreamID));
      36              : 
      37          123 :     std::string tag;
      38          123 :     CHK_PRT(ProfilerBase::GetTagByStream(threadLastStreamID, tag));
      39          123 :     if (tag.find("BatchPut_") != std::string::npos || tag.find("BatchGet_") != std::string::npos) {
      40            0 :         isOneSideTask = true;
      41              :     }
      42              : 
      43              :     HcclResult ret;
      44          123 :     if (GetExternalInputHcclEnableFfts() &&
      45          123 :         GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE && !isOneSideTask) {
      46            0 :         ret = hrtGetStreamId(stream, streamID);
      47            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS,
      48              :             HCCL_ERROR("[PluginRunner][Operator]rtGet stream id fail. return[%d]", ret),);
      49              : 
      50            0 :         u32 castStreamID = static_cast<u32>(streamID);
      51            0 :         if (isCapture) {
      52            0 :             ret = hrtGetTaskIdAndStreamID(threadLastTaskID, threadLastStreamID);
      53            0 :             CHK_PRT_RET(ret != HCCL_SUCCESS,
      54              :                 HCCL_ERROR("[PluginRunner][Operator]rtGet task id and stream id fail. return[%d]", ret),);
      55            0 :             profiler_->Save(castStreamID, threadLastStreamID, threadLastTaskID, taskType, para);
      56              :         } else {
      57            0 :             profiler_->Save(castStreamID, threadLastTaskID, taskType, para);
      58              :         }
      59              :     } else {
      60          123 :         ret = hrtGetTaskIdAndStreamID(threadLastTaskID, threadLastStreamID);
      61          123 :         CHK_PRT_RET(ret != HCCL_SUCCESS,
      62              :             HCCL_ERROR("[PluginRunner][Operator]rtGet task id and stream id fail. return[%d]", ret),);
      63              : 
      64          123 :         if (isCapture) {
      65            0 :             ret = hrtGetStreamId(stream, streamID);
      66            0 :             CHK_PRT_RET(ret != HCCL_SUCCESS,
      67              :                 HCCL_ERROR("[PluginRunner][Operator]rtGet task id and stream id fail. return[%d]", ret),);
      68            0 :             u32 castStreamID = static_cast<u32>(streamID);
      69            0 :             profiler_->Save(castStreamID, threadLastStreamID, threadLastTaskID, taskType, para);
      70              :         } else {
      71          123 :             profiler_->Save(threadLastStreamID, threadLastTaskID, taskType, para);
      72              :         }
      73              :     }
      74          123 : }
      75              : 
      76              : template void PluginRunner::operator ()<TaskParaDMA>(rtStream_t, TaskType, const TaskParaDMA&) const;
      77              : template void PluginRunner::operator ()<TaskParaReduce>(rtStream_t, TaskType, const TaskParaReduce&) const;
      78              : template void PluginRunner::operator ()<TaskParaNotify>(rtStream_t, TaskType, const TaskParaNotify&) const;
      79              : 
      80            0 : void PluginRunner::operator () (rtStream_t stream, const void *descBuf, size_t descBufLen) const
      81              : {
      82            0 :     u32 threadLastTaskID = 0;
      83            0 :     u32 threadLastStreamID = 0;
      84            0 :     s32 streamID = 0;
      85              :     HcclResult ret;
      86            0 :     bool isCapture = false;
      87            0 :     CHK_PRT(isStreamCapture(stream, isCapture));
      88              : 
      89            0 :     CHK_PRT_RET(profiler_ == nullptr, HCCL_WARNING("profiler_ is nullptr"),);
      90            0 :     ret = hrtGetTaskIdAndStreamID(threadLastTaskID, threadLastStreamID);
      91            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
      92              :     HCCL_ERROR("[PluginRunner][Operator]rtGet task id and stream id fail. return[%d]", ret),);
      93              : 
      94            0 :     if (isCapture) {
      95            0 :         ret = hrtGetStreamId(stream, streamID);
      96            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS,
      97              :             HCCL_ERROR("[PluginRunner][Operator]rtGet stream id fail. return[%d]", ret),);
      98            0 :         u32 castStreamID = static_cast<u32>(streamID);
      99            0 :         profiler_->Save(castStreamID, threadLastStreamID, threadLastTaskID, descBuf, descBufLen);
     100              :     } else {
     101            0 :         profiler_->Save(threadLastStreamID, threadLastTaskID, descBuf, descBufLen);
     102              :     }
     103              : }
     104              : 
     105            0 : void PluginRunner::operator () (const TaskParaHost &paraHost) const
     106              : {
     107            0 :     if (profiler_ != nullptr) {
     108            0 :         profiler_->SaveToLog(paraHost);
     109              :     }
     110            0 : }
     111              : 
     112           15 : void PluginRunner::operator () (rtStream_t stream, const TaskParaAiv &paraAiv) const
     113              : {
     114           15 :     u32 threadLastTaskID = 0;
     115           15 :     u32 threadLastStreamID = 0;
     116           15 :     s32 streamID = 0;
     117              :     HcclResult result;
     118           15 :     bool isCapture = false;
     119           15 :     CHK_PRT(isStreamCapture(stream, isCapture));
     120           15 :     result = hrtGetTaskIdAndStreamID(threadLastTaskID, threadLastStreamID);
     121           15 :     CHK_PRT_RET(result != HCCL_SUCCESS,
     122              :             HCCL_ERROR("[PluginRunner][Operator]rtGet task id and stream id fail. return[%d]", result),);
     123           15 :     CHK_PRT_RET(profiler_ == nullptr, HCCL_WARNING("profiler_ is nullptr"),);
     124           15 :     if (isCapture) {
     125            9 :         result = hrtGetStreamId(stream, streamID);
     126            9 :         CHK_PRT_RET(result != HCCL_SUCCESS,
     127              :             HCCL_ERROR("[PluginRunner][Operator]rtGet stream id fail. return[%d]", result),);
     128            9 :         u32 castStreamID = static_cast<u32>(streamID);
     129            9 :         profiler_->Save(castStreamID, threadLastStreamID, threadLastTaskID, paraAiv);
     130              :     } else {
     131            6 :         profiler_->Save(threadLastStreamID, threadLastTaskID, paraAiv);
     132              :     }
     133              : }
        

Generated by: LCOV version 2.0-1