LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_gather - coll_all_gather_mesh_aiv_for_910_93_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 136 0
Test Date: 2026-08-04 10:52:23 Functions: 0.0 % 10 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_all_gather_mesh_aiv_for_910_93_executor.h"
      12              : 
      13              : namespace hccl {
      14            0 : CollAllGatherMeshAivFor91093Executor::CollAllGatherMeshAivFor91093Executor(const HcclDispatcher dispatcher,
      15            0 :     std::unique_ptr<TopoMatcher> &topoMatcher): 
      16            0 :     CollAllGatherExecutor(dispatcher, topoMatcher)
      17              : {
      18            0 :     DMAReduceFlag_ = false;
      19            0 :     desc_.isAivMode = true;
      20            0 :     desc_.isAivCrossNode = true;
      21            0 : }
      22              :  
      23            0 : HcclResult CollAllGatherMeshAivFor91093Executor::CalcStreamNum(u32& streamNum)
      24              : {
      25            0 :     streamNum = 0; // AIV通信不需要申请从流
      26            0 :     HCCL_INFO("[CollAllGatherMeshAivFor91093Executor][CalcStreamNum] tag[%s] streamNum[%u].",
      27              :         tag_.c_str(), streamNum);
      28            0 :     return HCCL_SUCCESS;
      29              : }
      30              :  
      31            0 : HcclResult CollAllGatherMeshAivFor91093Executor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      32              : {
      33            0 :     TransportMemType inputType = TransportMemType::RESERVED;
      34            0 :     TransportMemType outputType = TransportMemType::RESERVED;
      35            0 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      36            0 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
      37            0 :     return HCCL_SUCCESS;
      38              : }
      39              :  
      40            0 : HcclResult CollAllGatherMeshAivFor91093Executor::CalcTransportMemType(TransportMemType &inputType,
      41              :     TransportMemType &outputType)
      42              : {
      43            0 :     inputType = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE ?
      44              :         TransportMemType::CCL_INPUT : TransportMemType::PARAM_INPUT);
      45            0 :     outputType = TransportMemType::AIV_OUTPUT;
      46            0 :     HCCL_INFO("[CollAllGatherMeshAivFor91093Executor][CalcTransportMemType] tag[%s] inputType[%d],"
      47              :         " outputType[%d].", tag_.c_str(), inputType, outputType);
      48            0 :     return HCCL_SUCCESS;
      49              : }
      50              : 
      51            0 : HcclResult CollAllGatherMeshAivFor91093Executor::CalcLevel0CommInfo(TransportMemType inputType,
      52              :     TransportMemType outputType,
      53              :     std::vector<LevelNSubCommTransport>& opTransport)
      54              : {
      55            0 :     CommParaInfo commCombinePara(COMM_COMBINE_ORDER, CommType::COMM_TAG_MESH);
      56            0 :     commCombinePara.meshSinglePlane = true;
      57            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commCombinePara, opTransport[COMM_COMBINE_ORDER], inputType, outputType));
      58              :  
      59            0 :     LevelNSubCommTransport &commTransportLevel0 = opTransport[COMM_COMBINE_ORDER];
      60            0 :     for (u32 subCommIndex = 0; subCommIndex < commTransportLevel0.size(); subCommIndex++) {
      61            0 :         for (auto &transportRequest : commTransportLevel0[subCommIndex].transportRequests) {
      62            0 :             transportRequest.isUsedRdma = false;
      63              :         }
      64              :     }
      65            0 :     return HCCL_SUCCESS;
      66            0 : }
      67              : 
      68            0 : HcclResult CollAllGatherMeshAivFor91093Executor::CalNumBlocks(u32& numBlocks, u32 rankSize, u64 dataSize, HcclCMDType cmdType)
      69              : {
      70            0 :     u32 minNumBlocks = (rankSize + MAX_TARGET_NUM - 1) / MAX_TARGET_NUM;
      71            0 :     numBlocks = rankSize; // 默认情况使用rankSize个AIV
      72              : 
      73              :     // A3超节点内多机场景
      74              :     // 多核并行优化
      75            0 :     if (rankSize > HALF_MAX_NUM_BLOCKS || dataSize < AIV_A3_CROSSNODE_TINY_SIZE) {
      76            0 :         numBlocks = rankSize;
      77            0 :     } else if (rankSize > ONE_THIRD_MAX_NUM_BLOCKS || dataSize < AIV_A3_CROSSNODE_SMALL_SIZE) {
      78            0 :         numBlocks = rankSize * NUM_BLOCKS_FACTOR_TWO;
      79            0 :     } else if (rankSize > ONE_FOURTH_MAX_NUM_BLOCKS) {
      80            0 :         numBlocks = rankSize * NUM_BLOCKS_FACTOR_THREE;
      81              :     } else {
      82            0 :         numBlocks = rankSize * NUM_BLOCKS_FACTOR_FOUR;
      83              :     }
      84            0 :     HCCL_DEBUG("[CollAllGatherMeshAivFor91093Executor][CalNumBlocks]aivCore at least is [%u]", minNumBlocks);
      85            0 :     u32 bestNumBlocks = numBlocks;
      86            0 :     numBlocks = numBlocks_ < rankSize ? numBlocks_ : (numBlocks_ < numBlocks ? numBlocks_ / rankSize * rankSize : numBlocks);
      87              : 
      88            0 :     CHK_PRT_RET(numBlocks < minNumBlocks,
      89              :         HCCL_ERROR("[CollAllGatherMeshAivFor91093Executor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].",
      90              :         numBlocks_, minNumBlocks),
      91              :         HCCL_E_PARA);
      92              : 
      93            0 :     HCCL_INFO("[CollAllGatherMeshAivFor91093Executor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u].",
      94              :         numBlocks, numBlocks_, bestNumBlocks);
      95            0 :     return HCCL_SUCCESS;
      96              : }
      97              : 
      98            0 : HcclResult CollAllGatherMeshAivFor91093Executor::GetAivExecParam(const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs &args)
      99              : {
     100            0 :     HcclUs startut = TIME_NOW();
     101            0 :     tag_ = param.tag;
     102            0 :     algResResp_ = &algRes;
     103              :  
     104            0 :     HcclResult ret = HCCL_SUCCESS;
     105            0 :     ExecMem execMem;
     106            0 :     execMem.count = param.DataDes.count;
     107            0 :     execMem.inputPtr = param.inputPtr;
     108            0 :     execMem.outputPtr = param.outputPtr;
     109              :  
     110            0 :     execMem.inputMem = algRes.paramInputMem;
     111            0 :     execMem.outputMem = algRes.aivOutputMem;
     112            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_COMBINE_ORDER, COMM_INDEX_0);
     113              :     
     114            0 :     u32 localRank = level0CommInfo.localRank;
     115            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     116            0 :     HCCL_DEBUG("[CollAllGatherMeshAivFor91093Executor][GetAivExecParam] userRank [%d] localRank [%d]",
     117              :         topoAttr_.userRank, localRank);
     118              : 
     119            0 :     args.buffersIn[0] = execMem.inputMem.ptr();
     120            0 :     args.buffersOut[0] = execMem.outputMem.ptr();
     121            0 :     constexpr u32 BUFFER_IDX_ONE = 1;
     122            0 :     args.buffersOut[BUFFER_IDX_ONE] =  algRes.aivCommInfoMem.ptr(); // 通信域信息  
     123              : 
     124            0 :     args.rank = localRank;
     125            0 :     args.rankSize = localRankSize;
     126            0 :     args.len = execMem.count;
     127            0 :     args.dataType = param.DataDes.dataType;
     128            0 :     args.unitSize = SIZE_TABLE[param.DataDes.dataType];
     129            0 :     args.reduceOp = param.reduceType;
     130            0 :     args.devType = static_cast<u32>(topoAttr_.deviceType);
     131            0 :     HCCL_INFO("SPK [CollAllGatherMeshAivFor91093Executor][GetAivExecParam], rank[%llu], rankSize[%llu], len[%llu],datatype[%llu], op[%llu]",
     132              :         args.rank, args.rankSize, args.len, args.dataType, args.reduceOp);
     133              : 
     134            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     135              :         HCCL_ERROR("[CollAllGatherMeshAivFor91093Executor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
     136              :             "run failed", HCCL_ERROR_CODE(ret), param.tag.c_str()), ret);
     137              :  
     138            0 :     HCCL_INFO("tag[%s], AllGather executor getalgexecparam success, take time [%lld]us.",
     139              :         param.tag.c_str(), DURATION_US(TIME_NOW() - startut));
     140            0 :     return HCCL_SUCCESS;    
     141            0 : }
     142              : 
     143            0 : HcclResult CollAllGatherMeshAivFor91093Executor::PrepareCommInfoToDevice(AlgResourceResponse& algResource)
     144              : {
     145            0 :     HCCL_INFO("[CollAllGatherMeshAivFor91093Executor][PrepareCommInfoToDevice]AllGather aiv copy comm info to device.");
     146            0 :     CHK_RET(CopyAivCommInfoToDevice(COMM_COMBINE_ORDER, COMM_INDEX_0, algResource));
     147            0 :     return HCCL_SUCCESS;
     148              : }
     149              : 
     150            0 : HcclResult CollAllGatherMeshAivFor91093Executor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
     151              : {
     152            0 :     HcclUs startut = TIME_NOW();
     153            0 :     tag_ = param.tag;
     154            0 :     algResResp_ = &algRes;
     155              :  
     156            0 :     ExecMem execMem;
     157            0 :     execMem.count = param.DataDes.count;
     158            0 :     execMem.inputPtr = param.inputPtr;
     159            0 :     execMem.outputPtr = param.outputPtr;
     160              :  
     161            0 :     execMem.inputMem = (workflowMode_ != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE ?
     162            0 :         algRes.paramInputMem : algRes.cclInputMem);
     163            0 :     execMem.outputMem = algRes.aivOutputMem;
     164            0 :     HcclResult ret = KernelRun(param, execMem);
     165              : 
     166            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     167              :         HCCL_ERROR("[CollAllGatherMeshAivFor91093Executor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
     168              :             "run failed", HCCL_ERROR_CODE(ret), param.tag.c_str()), ret);
     169              :  
     170            0 :     HCCL_INFO("tag[%s], AllGather executor orchestrate success, take time [%lld]us.",
     171              :         param.tag.c_str(), DURATION_US(TIME_NOW() - startut));
     172            0 :     return HCCL_SUCCESS;
     173            0 : }
     174              :  
     175            0 : HcclResult CollAllGatherMeshAivFor91093Executor::KernelRun(const OpParam &param, ExecMem &execMem)
     176              : {
     177            0 :     HCCL_CONFIG_INFO(HCCL_ALG,"[CollAllGatherMeshAivFor91093Executor][KernelRun]AllGather aiv enter.");
     178              :  
     179            0 :     CHK_RET(CheckCommSize(COMM_COMBINE_ORDER, COMM_INDEX_0 + 1));
     180            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_COMBINE_ORDER, COMM_INDEX_0);
     181              : 
     182              :     void *buffersIn[MAX_RANK_SIZE];
     183              :     void *buffersOut[MAX_RANK_SIZE];
     184              : 
     185            0 :     u32 localRank = level0CommInfo.localRank;
     186            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     187            0 :     HCCL_DEBUG("[CollAllGatherMeshAivFor91093Executor][KernelRun] userRank [%d] localRank [%d].",
     188              :         topoAttr_.userRank, localRank);
     189              : 
     190            0 :     buffersIn[0] = execMem.inputMem.ptr();
     191            0 :     buffersOut[0] = execMem.outputMem.ptr();
     192            0 :     constexpr u32 BUFFER_IDX_ONE = 1;
     193            0 :     buffersOut[BUFFER_IDX_ONE] = algResResp_->aivCommInfoMem.ptr(); // 通信域信息
     194              : 
     195            0 :     bool isOpbase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
     196            0 :     AivOpArgs opArgs {
     197            0 :         HcclCMDType::HCCL_CMD_ALLGATHER, execMem.inputPtr, execMem.outputPtr, execMem.count,
     198            0 :         param.DataDes.dataType, param.reduceType, 0, isOpbase
     199            0 :     };
     200              : 
     201            0 :     AivTopoArgs topoArgs { localRank, localRankSize, MAX_RANK_SIZE, 0, topoAttr_.serverNum, topoAttr_.deviceType, algoAttr_.identifier };
     202              :     u32 numBlocks;
     203            0 :     CHK_PRT_RET(CalNumBlocks(numBlocks, localRankSize, opArgs.count * SIZE_TABLE[opArgs.dataType]) != HCCL_SUCCESS,
     204              :         HCCL_ERROR("[%s] CalNumBlocks failed", __func__),
     205              :         HCCL_E_PARA);
     206            0 :     numBlocks_ = numBlocks;
     207              :     AivResourceArgs resourceArgs {
     208            0 :         param.tag, param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(), numBlocks_, param.aivTag
     209            0 :     };
     210            0 :     AivAlgArgs algArgs {};
     211            0 :     algArgs.argsType = KernelArgsType::ARGS_TYPE_SIMPLE;
     212            0 :     if(numBlocks_ >= localRankSize) {
     213            0 :         algArgs.step = localRankSize; 
     214              :     } else {
     215            0 :         algArgs.step = numBlocks_;
     216              :     }
     217            0 :     algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
     218            0 :     algArgs.execTimeOutSet = true;
     219            0 :     struct AivProfilingInfo aivProfilingInfo;
     220            0 :     aivProfilingInfo.counter = opCounter_;
     221              : 
     222            0 :     HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
     223              : 
     224            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     225              :         HCCL_ERROR("[CollAllGatherMeshAivFor91093Executor][KernelRun]AllGather aiv failed, return[%d]", ret),
     226              :         ret);
     227              : 
     228            0 :     ExtraArgs extraArgs;
     229            0 :     CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, true));
     230              :  
     231            0 :     HCCL_INFO("[CollAllGatherMeshAivFor91093Executor][KernelRun]AllGather aiv run success");
     232            0 :     return HCCL_SUCCESS;
     233            0 : }
     234              :  
     235              : REGISTER_EXEC("AllGatherMeshAivFor91093Executor", AllGatherMeshAivFor91093, CollAllGatherMeshAivFor91093Executor);
     236              :  
     237              : } // namespace hccl
        

Generated by: LCOV version 2.0-1