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

Generated by: LCOV version 2.0-1