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-18 17:47:01 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(
      64              :     u32& numBlocks, u32 rankSize, [[maybe_unused]] u64 dataSize, [[maybe_unused]] HcclCMDType cmdType)
      65              : {
      66            0 :     numBlocks = rankSize; // 默认情况使用rankSize个AIV
      67              : 
      68            0 :     bool isOpBase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
      69            0 :     if (topoAttr_.deviceType == DevType::DEV_TYPE_910_93 && !isOpBase) {
      70            0 :         numBlocks = rankSize * NUM_BLOCKS_FOUR_PER_RANK_A3 > MAX_NUM_BLOCKS ? rankSize * NUM_BLOCKS_THREE_PER_RANK_A3 :
      71              :                                                                               rankSize * NUM_BLOCKS_FOUR_PER_RANK_A3;
      72            0 :     } else if (isOpBase) {
      73            0 :         numBlocks += 1; // 单机场景,单算子AllGather大数据使用(rankSize + 1)个aiv
      74              :     }
      75              : 
      76            0 :     u32 bestNumBlocks = numBlocks;
      77            0 :     CHK_PRT_RET(
      78              :         numBlocks_ < rankSize,
      79              :         HCCL_WARNING(
      80              :             "[CollAllGatherMeshAivExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].", numBlocks_,
      81              :             rankSize),
      82              :         HCCL_E_PARA);
      83            0 :     CHK_PRT_RET(
      84              :         isOpBase && numBlocks_ < bestNumBlocks,
      85              :         HCCL_WARNING(
      86              :             "[CollAllGatherMeshAivExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].", numBlocks_,
      87              :             bestNumBlocks),
      88              :         HCCL_E_PARA);
      89              : 
      90            0 :     if (numBlocks_ < numBlocks) {
      91            0 :         numBlocks = numBlocks_ / rankSize * rankSize;
      92              :     }
      93              : 
      94            0 :     HCCL_INFO(
      95              :         "[CollAllGatherMeshAivExecutor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u]", numBlocks,
      96              :         numBlocks_, bestNumBlocks);
      97            0 :     return HCCL_SUCCESS;
      98              : }
      99              : 
     100            0 : HcclResult CollAllGatherMeshAivExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
     101              : {
     102            0 :     HcclUs startut = TIME_NOW();
     103            0 :     tag_ = param.tag;
     104            0 :     algResResp_ = &algRes;
     105              : 
     106            0 :     HcclResult ret = HCCL_SUCCESS;
     107            0 :     ExecMem execMem;
     108            0 :     execMem.count = param.DataDes.count;
     109            0 :     execMem.inputPtr = param.inputPtr;
     110            0 :     execMem.outputPtr = param.outputPtr;
     111              : 
     112              :     // 单算子大数据量
     113            0 :     if (workflowMode_ != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
     114            0 :         execMem.inputMem = algRes.paramInputMem;
     115            0 :         execMem.outputMem = algRes.aivOutputMem;
     116            0 :         ret = KernelRun(param, execMem);
     117              :     } else {
     118            0 :         execMem.inputMem = algRes.cclInputMem; // 仍然使用CCLIN
     119            0 :         execMem.outputMem = algRes.aivOutputMem;
     120            0 :         ret = KernelRun(param, execMem);
     121              :     }
     122              : 
     123            0 :     CHK_PRT_RET(
     124              :         ret != HCCL_SUCCESS,
     125              :         HCCL_ERROR(
     126              :             "[CollAllGatherMeshAivExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
     127              :             "run failed",
     128              :             HCCL_ERROR_CODE(ret), param.tag.c_str()),
     129              :         ret);
     130              : 
     131            0 :     HCCL_INFO(
     132              :         "tag[%s], AllGather executor orchestrate success, take time [%lld]us.", param.tag.c_str(),
     133              :         DURATION_US(TIME_NOW() - startut));
     134            0 :     return HCCL_SUCCESS;
     135            0 : }
     136              : 
     137            0 : HcclResult CollAllGatherMeshAivExecutor::GetAivExecParam(
     138              :     const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs& args)
     139              : {
     140            0 :     HcclUs startut = TIME_NOW();
     141            0 :     tag_ = param.tag;
     142            0 :     algResResp_ = &algRes;
     143              : 
     144            0 :     HcclResult ret = HCCL_SUCCESS;
     145            0 :     ExecMem execMem;
     146            0 :     execMem.count = param.DataDes.count;
     147            0 :     execMem.inputPtr = param.inputPtr;
     148            0 :     execMem.outputPtr = param.outputPtr;
     149              : 
     150              :     // 单算子大数据量
     151            0 :     execMem.inputMem = algRes.paramInputMem;
     152            0 :     execMem.outputMem = algRes.aivOutputMem;
     153              : 
     154            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     155              : 
     156            0 :     u32 localRank = level0CommInfo.localRank;
     157            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     158            0 :     HCCL_DEBUG(
     159              :         "[CollAllGatherMeshAivExecutor][GetAivExecParam] userRank [%d] localRank [%d]", topoAttr_.userRank, localRank);
     160              : 
     161            0 :     for (u32 i = 0; i < localRankSize; i++) {
     162            0 :         if (i != localRank) {
     163            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(args.buffersIn[i])));
     164            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(args.buffersOut[i])));
     165              :         } else {
     166            0 :             args.buffersIn[i] = execMem.inputMem.ptr();
     167            0 :             args.buffersOut[i] = execMem.outputMem.ptr();
     168              :         }
     169              :     }
     170            0 :     args.rank = localRank;
     171            0 :     args.rankSize = localRankSize;
     172            0 :     args.len = execMem.count;
     173            0 :     args.dataType = param.DataDes.dataType;
     174            0 :     args.unitSize = SIZE_TABLE[param.DataDes.dataType];
     175            0 :     args.reduceOp = param.reduceType;
     176            0 :     args.devType = static_cast<u32>(topoAttr_.deviceType);
     177            0 :     CHK_PRT_RET(
     178              :         ret != HCCL_SUCCESS,
     179              :         HCCL_ERROR(
     180              :             "[CollAllGatherMeshAivExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
     181              :             "run failed",
     182              :             HCCL_ERROR_CODE(ret), param.tag.c_str()),
     183              :         ret);
     184              : 
     185            0 :     HCCL_INFO(
     186              :         "tag[%s], AllGather executor getalgexecparam success, take time [%lld]us.", param.tag.c_str(),
     187              :         DURATION_US(TIME_NOW() - startut));
     188            0 :     return HCCL_SUCCESS;
     189            0 : }
     190              : 
     191            0 : HcclResult CollAllGatherMeshAivExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
     192              : {
     193            0 :     HCCL_INFO("[CollAllGatherMeshAivExecutor][KernelRun]AllGather aiv enter.");
     194              : 
     195            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
     196            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     197              : 
     198              :     void* buffersIn[MAX_RANK_SIZE];
     199              :     void* buffersOut[MAX_RANK_SIZE];
     200              : 
     201            0 :     u32 localRank = level0CommInfo.localRank;
     202            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     203            0 :     HCCL_DEBUG("[CollAllGatherMeshAivExecutor][KernelRun] userRank [%d] localRank [%d]", topoAttr_.userRank, localRank);
     204              : 
     205            0 :     for (u32 i = 0; i < localRankSize; i++) {
     206            0 :         if (i != localRank) {
     207            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
     208            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
     209              :         } else {
     210            0 :             buffersIn[i] = execMem.inputMem.ptr();
     211            0 :             buffersOut[i] = execMem.outputMem.ptr();
     212              :         }
     213              :     }
     214              : 
     215            0 :     bool isOpbase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
     216            0 :     AivOpArgs opArgs{
     217              :         HcclCMDType::HCCL_CMD_ALLGATHER,
     218            0 :         execMem.inputPtr,
     219            0 :         execMem.outputPtr,
     220            0 :         execMem.count,
     221            0 :         param.DataDes.dataType,
     222            0 :         param.reduceType,
     223              :         0,
     224            0 :         isOpbase};
     225            0 :     AivTopoArgs topoArgs{localRank, localRankSize, MAX_RANK_SIZE, 0, 1, topoAttr_.deviceType, algoAttr_.identifier};
     226              :     u32 numBlocks;
     227            0 :     CHK_PRT_RET(
     228              :         CalNumBlocks(numBlocks, localRankSize) != HCCL_SUCCESS, HCCL_ERROR("[%s] CalNumBlocks failed", __func__),
     229              :         HCCL_E_PARA);
     230            0 :     numBlocks_ = numBlocks;
     231            0 :     AivResourceArgs resourceArgs{param.tag,  param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
     232            0 :                                  numBlocks_, param.aivTag};
     233            0 :     AivAlgArgs algArgs{};
     234            0 :     struct AivProfilingInfo aivProfilingInfo;
     235            0 :     algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
     236            0 :     algArgs.execTimeOutSet = true;
     237            0 :     aivProfilingInfo.counter = opCounter_;
     238              : 
     239            0 :     HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
     240            0 :     CHK_PRT_RET(
     241              :         ret != HCCL_SUCCESS,
     242              :         HCCL_ERROR("[CollAllGatherMeshAivExecutor][KernelRun]AllGather aiv failed, return[%d]", ret), ret);
     243              : 
     244            0 :     ExtraArgs extraArgs;
     245            0 :     CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, false));
     246              : 
     247            0 :     HCCL_INFO("[CollAllGatherMeshAivExecutor][KernelRun]AllGather aiv run success.");
     248            0 :     return HCCL_SUCCESS;
     249            0 : }
     250              : 
     251              : REGISTER_EXEC("AllGatherMeshAivExecutor", AllGatherMeshAiv, CollAllGatherMeshAivExecutor);
     252              : 
     253              : } // namespace hccl
        

Generated by: LCOV version 2.0-1