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

Generated by: LCOV version 2.0-1