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

Generated by: LCOV version 2.0-1