LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_broadcast - coll_broadcast_mesh_aiv_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 84 0
Test Date: 2026-08-17 10:19:35 Functions: 0.0 % 7 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 "coll_broadcast_mesh_aiv_executor.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15            0 : CollBroadcastMeshAivExecutor::CollBroadcastMeshAivExecutor(
      16            0 :     const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
      17            0 :     : CollBroadcastExecutor(dispatcher, topoMatcher)
      18              : {
      19            0 :     DMAReduceFlag_ = false;
      20            0 :     desc_.isAivMode = true;
      21            0 : }
      22              : 
      23            0 : HcclResult CollBroadcastMeshAivExecutor::CalcStreamNum(u32& streamNum)
      24              : {
      25            0 :     streamNum = 0; // AIV通信不需要申请从流
      26            0 :     HCCL_INFO("[CollBroadcastMeshAivExecutor][CalcStreamNum] tag[%s] streamNum[%u].", tag_.c_str(), streamNum);
      27            0 :     return HCCL_SUCCESS;
      28              : }
      29              : 
      30            0 : HcclResult CollBroadcastMeshAivExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      31              : {
      32              :     TransportMemType inputType;
      33            0 :     if (GetWorkflowMode() != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      34            0 :         inputType = TransportMemType::AIV_INPUT;
      35              :     } else {
      36            0 :         inputType = TransportMemType::CCL_INPUT;
      37              :     }
      38            0 :     TransportMemType outputType = TransportMemType::AIV_OUTPUT;
      39            0 :     HCCL_INFO(
      40              :         "[CollBroadcastMeshAivExecutor][CalcTransportMemType] tag[%s] inputType[%d],"
      41              :         " outputType[%d].",
      42              :         tag_.c_str(), inputType, outputType);
      43            0 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
      44            0 :     return HCCL_SUCCESS;
      45              : }
      46              : 
      47            0 : HcclResult CollBroadcastMeshAivExecutor::CalNumBlocks(u32& numBlocks, u32 rankSize, u64 dataSize, HcclCMDType cmdType)
      48              : {
      49            0 :     numBlocks = rankSize; // 默认情况使用rankSize个AIV
      50            0 :     CHK_PRT_RET(
      51              :         numBlocks_ < numBlocks,
      52              :         HCCL_ERROR(
      53              :             "[CollBroadcastMeshAivExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].", numBlocks_,
      54              :             numBlocks),
      55              :         HCCL_E_PARA);
      56              : 
      57            0 :     HCCL_INFO(
      58              :         "[CollBroadcastMeshAivExecutor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u]", numBlocks,
      59              :         numBlocks_, numBlocks);
      60            0 :     return HCCL_SUCCESS;
      61              : }
      62              : 
      63            0 : HcclResult CollBroadcastMeshAivExecutor::CalcLevel0CommInfo(
      64              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      65              : {
      66            0 :     CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
      67            0 :     commParaLevel0.meshSinglePlane = true;
      68            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
      69            0 :     return HCCL_SUCCESS;
      70            0 : }
      71              : 
      72            0 : HcclResult CollBroadcastMeshAivExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
      73              : {
      74            0 :     HcclUs startut = TIME_NOW();
      75            0 :     tag_ = param.tag;
      76            0 :     algResResp_ = &algRes;
      77              : 
      78            0 :     HcclResult ret = HCCL_SUCCESS;
      79            0 :     ExecMem execMem;
      80            0 :     execMem.count = param.DataDes.count;
      81            0 :     execMem.inputPtr = param.inputPtr;
      82            0 :     execMem.outputPtr = param.inputPtr; // broadcast使用一块内存
      83              : 
      84            0 :     if (GetWorkflowMode() != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      85            0 :         execMem.inputMem = algRes.aivInputMem;
      86              :     } else {
      87            0 :         execMem.inputMem = algRes.cclInputMem;
      88              :     }
      89            0 :     execMem.outputMem = algRes.aivOutputMem;
      90              : 
      91            0 :     ret = KernelRun(param, execMem);
      92              : 
      93            0 :     CHK_PRT_RET(
      94              :         ret != HCCL_SUCCESS,
      95              :         HCCL_ERROR(
      96              :             "[CollBroadcastMeshAivExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel run failed",
      97              :             HCCL_ERROR_CODE(ret), param.tag.c_str()),
      98              :         ret);
      99              : 
     100            0 :     HCCL_INFO(
     101              :         "tag[%s], Broadcast executor orchestrate success, take time [%lld]us", param.tag.c_str(),
     102              :         DURATION_US(TIME_NOW() - startut));
     103            0 :     return HCCL_SUCCESS;
     104            0 : }
     105              : 
     106            0 : HcclResult CollBroadcastMeshAivExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
     107              : {
     108            0 :     HCCL_INFO("[CollBroadcastMeshAivExecutor][KernelRun]broadcast aiv enter.");
     109              : 
     110            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
     111            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     112              : 
     113              :     void* buffersIn[MAX_RANK_SIZE];
     114              :     void* buffersOut[MAX_RANK_SIZE];
     115              : 
     116            0 :     u32 rootRank = 0;
     117            0 :     HcclResult ret = GetRankByUserRank(COMM_LEVEL0, COMM_INDEX_0, param.root, rootRank);
     118            0 :     CHK_PRT_RET(
     119              :         ret != HCCL_SUCCESS,
     120              :         HCCL_ERROR("[BroadCastOperator][CollBroadcastMeshAivExecutor]invalid root[%u] to get userrank", param.root),
     121              :         ret);
     122              : 
     123            0 :     u32 localRank = level0CommInfo.localRank;
     124            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     125            0 :     HCCL_DEBUG("[CollBroadcastMeshAivExecutor][KernelRun] userRank [%u] localRank [%u]", topoAttr_.userRank, localRank);
     126            0 :     for (u32 i = 0; i < localRankSize; i++) {
     127            0 :         if (i != localRank) {
     128            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
     129            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
     130              :         } else {
     131            0 :             buffersIn[i] = execMem.inputMem.ptr(); // ccl buffer
     132            0 :             buffersOut[i] = execMem.outputMem.ptr();
     133              :         }
     134              :     }
     135              : 
     136            0 :     bool isOpbase = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
     137            0 :     AivOpArgs opArgs{HcclCMDType::HCCL_CMD_BROADCAST, execMem.inputPtr, execMem.outputPtr, execMem.count,
     138            0 :                      param.DataDes.dataType,          param.reduceType, rootRank,          isOpbase};
     139            0 :     AivTopoArgs topoArgs{localRank, localRankSize};
     140            0 :     topoArgs.identify = algoAttr_.identifier;
     141              :     u32 numBlocks;
     142            0 :     CHK_PRT_RET(
     143              :         CalNumBlocks(numBlocks, localRankSize) != HCCL_SUCCESS, HCCL_ERROR("[%s] CalNumBlocks failed", __func__),
     144              :         HCCL_E_PARA);
     145            0 :     numBlocks_ = numBlocks;
     146            0 :     AivResourceArgs resourceArgs{param.tag,  param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
     147            0 :                                  numBlocks_, param.aivTag};
     148            0 :     AivAlgArgs algArgs{};
     149            0 :     algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
     150            0 :     algArgs.execTimeOutSet = true;
     151            0 :     struct AivProfilingInfo aivProfilingInfo;
     152            0 :     aivProfilingInfo.counter = opCounter_;
     153            0 :     ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo); // 执行kernelLaunch
     154            0 :     CHK_PRT_RET(
     155              :         ret != HCCL_SUCCESS,
     156              :         HCCL_ERROR("[CollBroadcastMeshAivExecutor][KernelRun]broadcast aiv failed, return[%d]", ret), ret);
     157              : 
     158            0 :     ExtraArgs extraArgs;
     159            0 :     CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, false));
     160              : 
     161            0 :     HCCL_INFO("[CollBroadcastMeshAivExecutor][KernelRun]broadcast aiv run success.");
     162              : 
     163            0 :     return HCCL_SUCCESS;
     164            0 : }
     165              : 
     166              : REGISTER_EXEC("BroadcastMeshAivExecutor", BroadcastMeshAiv, CollBroadcastMeshAivExecutor);
     167              : 
     168              : } // namespace hccl
        

Generated by: LCOV version 2.0-1