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

Generated by: LCOV version 2.0-1