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

Generated by: LCOV version 2.0-1