LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_reduce - coll_all_reduce_mesh_aiv_for_910_93_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 163 0
Test Date: 2026-08-18 17:47:01 Functions: 0.0 % 13 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_reduce_mesh_aiv_for_910_93_executor.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15            0 : CollAllReduceMeshAivFor91093Executor::CollAllReduceMeshAivFor91093Executor(
      16            0 :     const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
      17            0 :     : CollAllReduceExecutor(dispatcher, topoMatcher)
      18              : {
      19            0 :     DMAReduceFlag_ = false;
      20            0 :     desc_.isAivMode = true;
      21            0 :     desc_.isAivCrossNode = true;
      22            0 :     desc_.deterministic = 1;
      23            0 : }
      24              : 
      25            0 : HcclResult CollAllReduceMeshAivFor91093Executor::CalcStreamNum(u32& streamNum)
      26              : {
      27            0 :     streamNum = 0; // AIV通信不需要申请从流
      28            0 :     HCCL_INFO("[CollAllReduceMeshAivFor91093Executor][CalcStreamNum] tag[%s] streamNum[%u].", tag_.c_str(), streamNum);
      29            0 :     return HCCL_SUCCESS;
      30              : }
      31              : 
      32            0 : HcclResult CollAllReduceMeshAivFor91093Executor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      33              : {
      34            0 :     TransportMemType inputType = TransportMemType::RESERVED;
      35            0 :     TransportMemType outputType = TransportMemType::RESERVED;
      36            0 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      37            0 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
      38            0 :     return HCCL_SUCCESS;
      39              : }
      40              : 
      41              : HcclResult
      42            0 : CollAllReduceMeshAivFor91093Executor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
      43              : {
      44              :     inputType
      45            0 :         = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE ? TransportMemType::CCL_INPUT :
      46              :                                                                            TransportMemType::SCRATCH);
      47            0 :     outputType = TransportMemType::AIV_OUTPUT;
      48            0 :     HCCL_INFO(
      49              :         "[CollAllReduceMeshAivFor91093Executor][CalcTransportMemType] tag[%s] inputType[%d],"
      50              :         " outputType[%d].",
      51              :         tag_.c_str(), inputType, outputType);
      52            0 :     return HCCL_SUCCESS;
      53              : }
      54              : 
      55            0 : HcclResult CollAllReduceMeshAivFor91093Executor::CalcLevel0CommInfo(
      56              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      57              : {
      58            0 :     CommParaInfo commCombinePara(COMM_COMBINE_ORDER, CommType::COMM_TAG_MESH);
      59            0 :     commCombinePara.meshSinglePlane = true;
      60            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commCombinePara, opTransport[COMM_COMBINE_ORDER], inputType, outputType));
      61              : 
      62            0 :     LevelNSubCommTransport& commTransportLevel0 = opTransport[COMM_COMBINE_ORDER];
      63            0 :     for (u32 subCommIndex = 0; subCommIndex < commTransportLevel0.size(); subCommIndex++) {
      64            0 :         for (auto& transportRequest : commTransportLevel0[subCommIndex].transportRequests) {
      65            0 :             transportRequest.isUsedRdma = false;
      66              :         }
      67              :     }
      68            0 :     return HCCL_SUCCESS;
      69            0 : }
      70              : 
      71            0 : void CollAllReduceMeshAivFor91093Executor::ParseParam(const OpParam& param)
      72              : {
      73            0 :     tag_ = param.tag;
      74              : 
      75            0 :     u64 reservedSize = (topoAttr_.userRankSize + 1) * (topoAttr_.userRankSize + 1) * SIZE_TABLE[param.DataDes.dataType];
      76              : 
      77            0 :     totalSize_ = BUFFER_DIVIDE * param.DataDes.count * SIZE_TABLE[param.DataDes.dataType] + reservedSize;
      78            0 : }
      79              : 
      80            0 : HcclResult CollAllReduceMeshAivFor91093Executor::CalcScratchMemSize(u64& scratchMemSize)
      81              : {
      82            0 :     scratchMemSize = 0;
      83              :     // 确定性时图模式需要计算scratchMem
      84            0 :     scratchMemSize = totalSize_;
      85            0 :     HCCL_INFO("[%s]tag[%s] scratchMemSize[%llu]", __func__, tag_.c_str(), scratchMemSize);
      86            0 :     return HCCL_SUCCESS;
      87              : }
      88              : 
      89            0 : HcclResult CollAllReduceMeshAivFor91093Executor::CalNumBlocks(
      90              :     u32& numBlocks, u32 rankSize, [[maybe_unused]] u64 dataSize, [[maybe_unused]] HcclCMDType cmdType)
      91              : {
      92              :     // Step1. Calculate the best block dimension
      93            0 :     u32 bestNumBlocks = (rankSize < MAX_NUM_BLOCKS ? rankSize : MAX_NUM_BLOCKS);
      94            0 :     u32 minNumBlocks = std::max((rankSize + MAX_TARGET_NUM - 1) / MAX_TARGET_NUM, NUM_BLOCKS_FACTOR_TWO);
      95              : 
      96              :     // Step2. Compare User Given numBlocks_ with bestNumBlocks
      97            0 :     numBlocks = bestNumBlocks;
      98            0 :     if (numBlocks_ < numBlocks) {
      99            0 :         if (numBlocks_ > rankSize) {
     100            0 :             numBlocks = numBlocks_ / rankSize * rankSize;
     101            0 :             minNumBlocks = (minNumBlocks + rankSize - 1) / rankSize * rankSize;
     102              :         } else {
     103            0 :             numBlocks = numBlocks_ / NUM_BLOCKS_FACTOR_TWO * NUM_BLOCKS_FACTOR_TWO;
     104            0 :             minNumBlocks = (minNumBlocks + NUM_BLOCKS_FACTOR_TWO - 1) / NUM_BLOCKS_FACTOR_TWO * NUM_BLOCKS_FACTOR_TWO;
     105              :         }
     106              :     }
     107              : 
     108            0 :     CHK_PRT_RET(
     109              :         numBlocks < minNumBlocks,
     110              :         HCCL_ERROR(
     111              :             "[CollAllReduceMeshAivFor91093Executor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].",
     112              :             numBlocks_, minNumBlocks),
     113              :         HCCL_E_PARA);
     114              : 
     115            0 :     HCCL_INFO(
     116              :         "[CollAllReduceMeshAivFor91093Executor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u]",
     117              :         numBlocks, numBlocks_, bestNumBlocks);
     118            0 :     return HCCL_SUCCESS;
     119              : }
     120              : 
     121            0 : HcclResult CollAllReduceMeshAivFor91093Executor::GetAivExecParam(
     122              :     const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs& args)
     123              : {
     124            0 :     HcclUs startut = TIME_NOW();
     125            0 :     tag_ = param.tag;
     126            0 :     algResResp_ = &algRes;
     127              : 
     128            0 :     HcclResult ret = HCCL_SUCCESS;
     129            0 :     ExecMem execMem;
     130            0 :     execMem.count = param.DataDes.count;
     131            0 :     execMem.inputPtr = param.inputPtr;
     132            0 :     execMem.outputPtr = param.outputPtr;
     133              : 
     134            0 :     execMem.inputMem = algRes.scratchMem;
     135              : 
     136            0 :     execMem.outputMem = algRes.aivOutputMem;
     137            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_COMBINE_ORDER, COMM_INDEX_0);
     138              : 
     139            0 :     u32 localRank = level0CommInfo.localRank;
     140            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     141            0 :     HCCL_DEBUG(
     142              :         "[CollAllReduceMeshAivFor91093Executor][GetAivExecParam] userRank [%d] localRank [%d]", topoAttr_.userRank,
     143              :         localRank);
     144              : 
     145            0 :     args.buffersIn[0] = execMem.inputMem.ptr();
     146            0 :     args.buffersOut[0] = execMem.outputMem.ptr();
     147            0 :     constexpr u32 BUFFER_IDX_ONE = 1;
     148            0 :     args.buffersOut[BUFFER_IDX_ONE] = algRes.aivCommInfoMem.ptr(); // 通信域信息
     149              : 
     150            0 :     args.rank = localRank;
     151            0 :     args.rankSize = localRankSize;
     152            0 :     args.len = execMem.count;
     153            0 :     args.dataType = param.DataDes.dataType;
     154            0 :     args.unitSize = SIZE_TABLE[param.DataDes.dataType];
     155            0 :     args.reduceOp = param.reduceType;
     156              : 
     157            0 :     HCCL_INFO(
     158              :         "SPK [CollAllReduceMeshAivFor91093Executor][GetAivExecParam], rank[%llu], rankSize[%llu], "
     159              :         "len[%llu],datatype[%llu], op[%llu]",
     160              :         args.rank, args.rankSize, args.len, args.dataType, args.reduceOp);
     161              : 
     162            0 :     CHK_PRT_RET(
     163              :         ret != HCCL_SUCCESS,
     164              :         HCCL_ERROR(
     165              :             "[CollAllReduceMeshAivFor91093Executor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
     166              :             "run failed",
     167              :             HCCL_ERROR_CODE(ret), param.tag.c_str()),
     168              :         ret);
     169              : 
     170            0 :     HCCL_INFO(
     171              :         "tag[%s], AllReduce executor getalgexecparam success, take time [%lld]us.", param.tag.c_str(),
     172              :         DURATION_US(TIME_NOW() - startut));
     173            0 :     return HCCL_SUCCESS;
     174            0 : }
     175              : 
     176            0 : HcclResult CollAllReduceMeshAivFor91093Executor::CopyAivCommInfoToDevice(
     177              :     const CommPlane levelIndex, const u32 subLevelIndex, AlgResourceResponse& algResource)
     178              : {
     179            0 :     algResResp_ = &algResource;
     180            0 :     CHK_RET(CheckCommSize(levelIndex, subLevelIndex + 1));
     181            0 :     SubCommInfo commInfo = GetSubCommInfo(levelIndex, subLevelIndex);
     182            0 :     u32 localRank = commInfo.localRank;
     183            0 :     u32 localRankSize = commInfo.localRankSize;
     184              : 
     185            0 :     void* buffersInOut[MAX_RANK_SIZE_A3 * 2] = {};
     186            0 :     bool isOpbaseMode = GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE;
     187              : 
     188            0 :     for (u32 i = 0; i < localRankSize; i++) {
     189            0 :         u32 idx = (i << 1);
     190            0 :         if (i != localRank) {
     191            0 :             CHK_RET(commInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersInOut[idx])));
     192            0 :             CHK_RET(commInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersInOut[idx + 1])));
     193              :         } else {
     194            0 :             buffersInOut[idx] = isOpbaseMode ? algResource.cclInputMem.ptr() : algResource.scratchMem.ptr();
     195            0 :             buffersInOut[idx + 1] = algResource.aivOutputMem.ptr();
     196              :         }
     197              :     }
     198            0 :     const u32 bufferNum = 2;
     199            0 :     CHK_RET(hrtMemSyncCopy(
     200              :         algResource.aivCommInfoMem.ptr(), sizeof(u64) * localRankSize * bufferNum, buffersInOut,
     201              :         sizeof(u64) * localRankSize * bufferNum, HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
     202            0 :     return HCCL_SUCCESS;
     203            0 : }
     204              : 
     205            0 : HcclResult CollAllReduceMeshAivFor91093Executor::PrepareCommInfoToDevice(AlgResourceResponse& algResource)
     206              : {
     207            0 :     HCCL_INFO("[CollAllReduceMeshAivFor91093Executor][PrepareCommInfoToDevice]"
     208              :               "allreduce aiv copy comm info to device.");
     209            0 :     CHK_RET(CopyAivCommInfoToDevice(COMM_COMBINE_ORDER, COMM_INDEX_0, algResource));
     210            0 :     return HCCL_SUCCESS;
     211              : }
     212              : 
     213            0 : HcclResult CollAllReduceMeshAivFor91093Executor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
     214              : {
     215            0 :     HcclUs startut = TIME_NOW();
     216            0 :     tag_ = param.tag;
     217            0 :     algResResp_ = &algRes;
     218              : 
     219            0 :     ExecMem execMem;
     220            0 :     execMem.count = param.DataDes.count;
     221            0 :     execMem.inputPtr = param.inputPtr;
     222            0 :     execMem.outputPtr = param.outputPtr;
     223              : 
     224              :     execMem.inputMem
     225            0 :         = (workflowMode_ != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE ? algRes.scratchMem : algRes.cclInputMem);
     226            0 :     execMem.outputMem = algRes.aivOutputMem;
     227            0 :     HcclResult ret = KernelRun(param, execMem);
     228              : 
     229            0 :     CHK_PRT_RET(
     230              :         ret != HCCL_SUCCESS,
     231              :         HCCL_ERROR(
     232              :             "[CollAllReduceMeshAivFor91093Executor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
     233              :             "run failed",
     234              :             HCCL_ERROR_CODE(ret), param.tag.c_str()),
     235              :         ret);
     236              : 
     237            0 :     HCCL_INFO(
     238              :         "tag[%s], allreduce executor orchestrate success, take time [%lld]us.", param.tag.c_str(),
     239              :         DURATION_US(TIME_NOW() - startut));
     240            0 :     return HCCL_SUCCESS;
     241            0 : }
     242              : 
     243            0 : HcclResult CollAllReduceMeshAivFor91093Executor::KernelRun(const OpParam& param, ExecMem& execMem)
     244              : {
     245            0 :     HCCL_CONFIG_INFO(HCCL_ALG, "[%s] allreduce aiv enter.", __func__);
     246              : 
     247            0 :     CHK_RET(CheckCommSize(COMM_COMBINE_ORDER, COMM_INDEX_0 + 1));
     248            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_COMBINE_ORDER, COMM_INDEX_0);
     249              : 
     250              :     void* buffersIn[MAX_RANK_SIZE];
     251              :     void* buffersOut[MAX_RANK_SIZE];
     252              : 
     253            0 :     u32 localRank = level0CommInfo.localRank;
     254            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     255            0 :     HCCL_DEBUG(
     256              :         "[CollAllReduceMeshAivFor91093Executor][KernelRun] userRank [%d] localRank [%d]", topoAttr_.userRank,
     257              :         localRank);
     258              : 
     259            0 :     buffersIn[0] = execMem.inputMem.ptr();
     260            0 :     buffersOut[0] = execMem.outputMem.ptr();
     261            0 :     constexpr u32 BUFFER_IDX_ONE = 1;
     262            0 :     buffersOut[BUFFER_IDX_ONE] = algResResp_->aivCommInfoMem.ptr(); // 通信域信息
     263              : 
     264            0 :     bool isOpbase = GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE;
     265              : 
     266            0 :     AivOpArgs opArgs{
     267              :         HcclCMDType::HCCL_CMD_ALLREDUCE,
     268            0 :         execMem.inputPtr,
     269            0 :         execMem.outputPtr,
     270            0 :         execMem.count,
     271            0 :         param.DataDes.dataType,
     272            0 :         param.reduceType,
     273              :         0,
     274            0 :         isOpbase};
     275              :     AivTopoArgs topoArgs{localRank,           localRankSize,        MAX_RANK_SIZE,       0,
     276            0 :                          topoAttr_.serverNum, topoAttr_.deviceType, algoAttr_.identifier};
     277              : 
     278              :     u32 numBlocks;
     279            0 :     CHK_PRT_RET(
     280              :         CalNumBlocks(numBlocks, localRankSize, opArgs.count * SIZE_TABLE[opArgs.dataType]) != HCCL_SUCCESS,
     281              :         HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
     282            0 :     numBlocks_ = numBlocks;
     283              : 
     284            0 :     AivResourceArgs resourceArgs{param.tag,  param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
     285            0 :                                  numBlocks_, param.aivTag};
     286            0 :     AivAlgArgs algArgs{};
     287            0 :     algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
     288            0 :     algArgs.execTimeOutSet = true;
     289            0 :     algArgs.argsType = KernelArgsType::ARGS_TYPE_SIMPLE;
     290            0 :     struct AivProfilingInfo aivProfilingInfo;
     291            0 :     if (topoMatcher_->GetDeterministicConfig() != DETERMINISTIC_DISABLE) {
     292            0 :         algArgs.deterministic = 1;
     293              :     }
     294            0 :     aivProfilingInfo.counter = opCounter_;
     295              : 
     296            0 :     HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
     297            0 :     CHK_PRT_RET(
     298              :         ret != HCCL_SUCCESS,
     299              :         HCCL_ERROR("[CollAllReduceMeshAivFor91093Executor][KernelRun]allreduce aiv failed, return[%d]", ret), ret);
     300              : 
     301            0 :     ExtraArgs extraArgs;
     302            0 :     CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, true));
     303              : 
     304            0 :     HCCL_INFO("[CollAllReduceMeshAivFor91093Executor][KernelRun]allreduce aiv run success.");
     305            0 :     return HCCL_SUCCESS;
     306            0 : }
     307              : 
     308              : REGISTER_EXEC("AllReduceMeshAivFor91093Executor", AllReduceMeshAivFor91093, CollAllReduceMeshAivFor91093Executor);
     309              : 
     310              : } // namespace hccl
        

Generated by: LCOV version 2.0-1