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

Generated by: LCOV version 2.0-1