LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_reduce_scatter - coll_reduce_scatter_aiv_deter_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 121 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_aiv_deter_executor.h"
      12              :  
      13              : namespace hccl {
      14              :  
      15            0 : CollReduceScatterAivDeterExecutor::CollReduceScatterAivDeterExecutor(const HcclDispatcher dispatcher,
      16            0 :                                                            std::unique_ptr<TopoMatcher> &topoMatcher)
      17            0 :     : CollReduceScatterExecutor(dispatcher, topoMatcher)
      18              : {
      19            0 :     DMAReduceFlag_ = false;
      20            0 :     desc_.isAivMode = true;
      21            0 : }
      22              :  
      23            0 : HcclResult CollReduceScatterAivDeterExecutor::CalcStreamNum(u32& streamNum)
      24              : {
      25            0 :     streamNum = 0; // AIV通信不需要申请从流
      26            0 :     HCCL_INFO("[CollReduceScatterAivDeterExecutor][CalcStreamNum] tag[%s] streamNum[%u].", tag_.c_str(), streamNum);
      27            0 :     return HCCL_SUCCESS;
      28              : }
      29              :  
      30            0 : HcclResult CollReduceScatterAivDeterExecutor::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            0 : HcclResult CollReduceScatterAivDeterExecutor::CalcTransportMemType(TransportMemType &inputType, TransportMemType &outputType)
      40              : {
      41            0 :     inputType = TransportMemType::CCL_INPUT;
      42            0 :     outputType = TransportMemType::AIV_OUTPUT;
      43            0 :     HCCL_INFO("[CollReduceScatterAivDeterExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d].",
      44              :         tag_.c_str(), inputType, outputType);
      45            0 :     return HCCL_SUCCESS;
      46              : }
      47              :  
      48            0 : HcclResult CollReduceScatterAivDeterExecutor::CalcLevel0CommInfo(TransportMemType inputType,
      49              :     TransportMemType outputType,
      50              :     std::vector<LevelNSubCommTransport>& opTransport)
      51              : {
      52            0 :     CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
      53            0 :     commParaLevel0.meshSinglePlane = true;
      54            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
      55            0 :     return HCCL_SUCCESS;
      56            0 : }
      57              :  
      58            0 : HcclResult CollReduceScatterAivDeterExecutor::CalNumBlocks(u32& numBlocks, u32 rankSize, u64 dataSize, HcclCMDType cmdType)
      59              : {
      60            0 :     numBlocks = rankSize; // 默认情况使用rankSize个AIV
      61              :  
      62            0 :     numBlocks = NUM_BLOCKS_FACTOR_TWO * rankSize; // 小数据量使用2倍rankSize的AIV core
      63            0 :     if (dataSize*rankSize >= AIV_REDUCE_SCATTER_DETER_SMALL_SIZE) {
      64            0 :         numBlocks = NUM_BLOCKS_FACTOR_THREE * rankSize;
      65              :     }
      66              : 
      67            0 :     HCCL_INFO("[CollReduceScatterAivDeterExecutor][CalNumBlocks] datasize is [%u], numBlocks is set to [%u]", dataSize, numBlocks);
      68            0 :     return HCCL_SUCCESS;
      69              : }
      70              :  
      71            0 : HcclResult CollReduceScatterAivDeterExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
      72              : {
      73            0 :     HcclUs startut = TIME_NOW();
      74            0 :     tag_ = param.tag;
      75            0 :     algResResp_ = &algRes;
      76              :  
      77            0 :     HcclResult ret = HCCL_SUCCESS;
      78            0 :     ExecMem execMem;
      79            0 :     execMem.count = param.DataDes.count;
      80            0 :     execMem.inputPtr = param.inputPtr;
      81            0 :     execMem.outputPtr = param.outputPtr;
      82              :     // 确定性场景不支持图模式
      83            0 :     execMem.inputMem = algRes.cclInputMem;
      84            0 :     execMem.outputMem = algRes.aivOutputMem; 
      85              : 
      86            0 :     ret = KernelRun(param, execMem);
      87            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
      88              :         HCCL_ERROR("[CollReduceScatterAivDeterExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel run failed",
      89              :             HCCL_ERROR_CODE(ret), param.tag.c_str()), ret);
      90              :  
      91            0 :     HCCL_INFO("tag[%s], ReduceScatter executor orchestrate success, take time [%lld]us",
      92              :         param.tag.c_str(), DURATION_US(TIME_NOW() - startut));
      93            0 :     return HCCL_SUCCESS;
      94            0 : }
      95              :  
      96            0 : HcclResult CollReduceScatterAivDeterExecutor::GetAivExecParam(const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs &args)
      97              : {
      98            0 :     HcclUs startut = TIME_NOW();
      99            0 :     tag_ = param.tag;
     100            0 :     algResResp_ = &algRes;
     101              :  
     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.cclInputMem;
     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("[CollReduceScatterAivDeterExecutor][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              :  
     128            0 :     HCCL_INFO("SPK, buffersIn [%p] [%p] [%p] [%p]"
     129              :         "buffersOut [%p] [%p] [%p] [%p]", args.buffersIn[0], args.buffersIn[1], args.buffersIn[2], args.buffersIn[3],
     130              :         args.buffersOut[0], args.buffersOut[1], args.buffersOut[2], args.buffersOut[3]);
     131            0 :     args.rank = localRank;
     132            0 :     args.rankSize = localRankSize;
     133            0 :     args.len = execMem.count;
     134            0 :     args.dataType = param.DataDes.dataType;
     135            0 :     args.unitSize = SIZE_TABLE[param.DataDes.dataType];
     136            0 :     args.reduceOp = param.reduceType;
     137            0 :     args.devType = static_cast<u32>(topoAttr_.deviceType);
     138            0 :     HCCL_INFO("SPK [CollReduceScatterAivDeterExecutor][GetAivExecParam], rank[%llu], rankSize[%llu], len[%llu],datatype[%llu], op[%llu]", args.rank, args.rankSize, args.len, args.dataType, args.reduceOp);
     139              :  
     140            0 :     HCCL_INFO("tag[%s], ReduceScatter executor getalgexecparam success, take time [%lld]us.",
     141              :         param.tag.c_str(), DURATION_US(TIME_NOW() - startut));
     142            0 :     return HCCL_SUCCESS;
     143            0 : }
     144              :  
     145            0 : HcclResult CollReduceScatterAivDeterExecutor::KernelRun(const OpParam &param, ExecMem &execMem)
     146              : {
     147            0 :     HCCL_CONFIG_INFO(HCCL_ALG, "[CollReduceScatterAivDeterExecutor][KernelRun]ReduceScatter aiv enter.");
     148              :  
     149            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
     150            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     151              : 
     152              :     void *buffersIn[MAX_RANK_SIZE];
     153              :     void *buffersOut[MAX_RANK_SIZE];
     154              :  
     155            0 :     u32 localRank = level0CommInfo.localRank;
     156            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     157            0 :     HCCL_DEBUG("[CollReduceScatterAivDeterExecutor][KernelRun] userRank [%u] localRank [%u]", topoAttr_.userRank, localRank);
     158              :  
     159            0 :     for (u32 i = 0; i < localRankSize; i++) {
     160            0 :         if (i != localRank) {
     161            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
     162            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
     163              :         } else {
     164            0 :             buffersIn[i] = execMem.inputMem.ptr();
     165            0 :             buffersOut[i] = execMem.outputMem.ptr();
     166              :         }
     167              :     }
     168              :  
     169            0 :     bool isOpbase = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
     170            0 :     AivOpArgs opArgs {
     171            0 :         HcclCMDType::HCCL_CMD_REDUCE_SCATTER, execMem.inputPtr, execMem.outputPtr, execMem.count,
     172            0 :         param.DataDes.dataType, param.reduceType, 0, isOpbase
     173            0 :     };
     174            0 :     AivTopoArgs topoArgs { localRank, localRankSize, MAX_RANK_SIZE, 0, 1, topoAttr_.deviceType };
     175            0 :     topoArgs.identify = algoAttr_.identifier;
     176              :     
     177            0 :     u64 dataSize = SIZE_TABLE[param.DataDes.dataType] * execMem.count;
     178              :     u32 numBlocks;
     179            0 :     CHK_PRT_RET(CalNumBlocks(numBlocks, localRankSize, dataSize) != HCCL_SUCCESS,
     180              :         HCCL_ERROR("[%s] CalNumBlocks failed", __func__),
     181              :         HCCL_E_PARA);
     182            0 :     numBlocks_ = numBlocks;
     183              :     AivResourceArgs resourceArgs {
     184            0 :         param.tag, param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(), numBlocks_, param.aivTag
     185            0 :     };
     186            0 :     AivAlgArgs algArgs {};
     187            0 :     algArgs.deterministic = 1;
     188            0 :     algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
     189            0 :     algArgs.execTimeOutSet = true;
     190            0 :     struct AivProfilingInfo aivProfilingInfo;
     191            0 :     aivProfilingInfo.counter = opCounter_;
     192            0 :     HCCL_INFO("[CollReduceScatterAivDeterExecutor][KernelRun]ReduceScatter bufferin[%d] bufferout[%d]",execMem.inputMem.size(), execMem.outputMem.size());
     193              : 
     194            0 :     HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
     195              :     
     196            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     197              :         HCCL_ERROR("[CollReduceScatterAivDeterExecutor][KernelRun]ReduceScatter aiv failed, return[%d]", ret), ret);
     198              : 
     199            0 :     ExtraArgs extraArgs;
     200            0 :     CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, false));
     201              :  
     202            0 :     HCCL_INFO("[CollReduceScatterAivDeterExecutor][KernelRun]ReduceScatter aiv run success.");
     203            0 :     return HCCL_SUCCESS;
     204            0 : }
     205              :  
     206              : REGISTER_EXEC("ReduceScatterAivDeterExecutor", ReduceScatterAivDeter, CollReduceScatterAivDeterExecutor);
     207              :  
     208              : } // namespace hccl
        

Generated by: LCOV version 2.0-1