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 % 124 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_aiv_deter_executor.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15            0 : CollReduceScatterAivDeterExecutor::CollReduceScatterAivDeterExecutor(
      16            0 :     const HcclDispatcher dispatcher, 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              : HcclResult
      40            0 : CollReduceScatterAivDeterExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
      41              : {
      42            0 :     inputType = TransportMemType::CCL_INPUT;
      43            0 :     outputType = TransportMemType::AIV_OUTPUT;
      44            0 :     HCCL_INFO(
      45              :         "[CollReduceScatterAivDeterExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d].",
      46              :         tag_.c_str(), inputType, outputType);
      47            0 :     return HCCL_SUCCESS;
      48              : }
      49              : 
      50            0 : HcclResult CollReduceScatterAivDeterExecutor::CalcLevel0CommInfo(
      51              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      52              : {
      53            0 :     CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
      54            0 :     commParaLevel0.meshSinglePlane = true;
      55            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
      56            0 :     return HCCL_SUCCESS;
      57            0 : }
      58              : 
      59            0 : HcclResult CollReduceScatterAivDeterExecutor::CalNumBlocks(
      60              :     u32& numBlocks, u32 rankSize, u64 dataSize, [[maybe_unused]] HcclCMDType cmdType)
      61              : {
      62            0 :     numBlocks = rankSize; // 默认情况使用rankSize个AIV
      63              : 
      64            0 :     numBlocks = NUM_BLOCKS_FACTOR_TWO * rankSize; // 小数据量使用2倍rankSize的AIV core
      65            0 :     if (dataSize * rankSize >= AIV_REDUCE_SCATTER_DETER_SMALL_SIZE) {
      66            0 :         numBlocks = NUM_BLOCKS_FACTOR_THREE * rankSize;
      67              :     }
      68              : 
      69            0 :     HCCL_INFO(
      70              :         "[CollReduceScatterAivDeterExecutor][CalNumBlocks] datasize is [%u], numBlocks is set to [%u]", dataSize,
      71              :         numBlocks);
      72            0 :     return HCCL_SUCCESS;
      73              : }
      74              : 
      75            0 : HcclResult CollReduceScatterAivDeterExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
      76              : {
      77            0 :     HcclUs startut = TIME_NOW();
      78            0 :     tag_ = param.tag;
      79            0 :     algResResp_ = &algRes;
      80              : 
      81            0 :     HcclResult ret = HCCL_SUCCESS;
      82            0 :     ExecMem execMem;
      83            0 :     execMem.count = param.DataDes.count;
      84            0 :     execMem.inputPtr = param.inputPtr;
      85            0 :     execMem.outputPtr = param.outputPtr;
      86              :     // 确定性场景不支持图模式
      87            0 :     execMem.inputMem = algRes.cclInputMem;
      88            0 :     execMem.outputMem = algRes.aivOutputMem;
      89              : 
      90            0 :     ret = KernelRun(param, execMem);
      91            0 :     CHK_PRT_RET(
      92              :         ret != HCCL_SUCCESS,
      93              :         HCCL_ERROR(
      94              :             "[CollReduceScatterAivDeterExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel run failed",
      95              :             HCCL_ERROR_CODE(ret), param.tag.c_str()),
      96              :         ret);
      97              : 
      98            0 :     HCCL_INFO(
      99              :         "tag[%s], ReduceScatter executor orchestrate success, take time [%lld]us", param.tag.c_str(),
     100              :         DURATION_US(TIME_NOW() - startut));
     101            0 :     return HCCL_SUCCESS;
     102            0 : }
     103              : 
     104            0 : HcclResult CollReduceScatterAivDeterExecutor::GetAivExecParam(
     105              :     const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs& args)
     106              : {
     107            0 :     HcclUs startut = TIME_NOW();
     108            0 :     tag_ = param.tag;
     109            0 :     algResResp_ = &algRes;
     110              : 
     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.cclInputMem;
     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              :         "[CollReduceScatterAivDeterExecutor][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              : 
     138            0 :     HCCL_INFO(
     139              :         "SPK, buffersIn [%p] [%p] [%p] [%p]"
     140              :         "buffersOut [%p] [%p] [%p] [%p]",
     141              :         args.buffersIn[0], args.buffersIn[1], args.buffersIn[2], args.buffersIn[3], args.buffersOut[0],
     142              :         args.buffersOut[1], args.buffersOut[2], args.buffersOut[3]);
     143            0 :     args.rank = localRank;
     144            0 :     args.rankSize = localRankSize;
     145            0 :     args.len = execMem.count;
     146            0 :     args.dataType = param.DataDes.dataType;
     147            0 :     args.unitSize = SIZE_TABLE[param.DataDes.dataType];
     148            0 :     args.reduceOp = param.reduceType;
     149            0 :     args.devType = static_cast<u32>(topoAttr_.deviceType);
     150            0 :     HCCL_INFO(
     151              :         "SPK [CollReduceScatterAivDeterExecutor][GetAivExecParam], rank[%llu], rankSize[%llu], "
     152              :         "len[%llu],datatype[%llu], op[%llu]",
     153              :         args.rank, args.rankSize, args.len, args.dataType, args.reduceOp);
     154              : 
     155            0 :     HCCL_INFO(
     156              :         "tag[%s], ReduceScatter executor getalgexecparam success, take time [%lld]us.", param.tag.c_str(),
     157              :         DURATION_US(TIME_NOW() - startut));
     158            0 :     return HCCL_SUCCESS;
     159            0 : }
     160              : 
     161            0 : HcclResult CollReduceScatterAivDeterExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
     162              : {
     163            0 :     HCCL_CONFIG_INFO(HCCL_ALG, "[CollReduceScatterAivDeterExecutor][KernelRun]ReduceScatter aiv enter.");
     164              : 
     165            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
     166            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     167              : 
     168              :     void* buffersIn[MAX_RANK_SIZE];
     169              :     void* buffersOut[MAX_RANK_SIZE];
     170              : 
     171            0 :     u32 localRank = level0CommInfo.localRank;
     172            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     173            0 :     HCCL_DEBUG(
     174              :         "[CollReduceScatterAivDeterExecutor][KernelRun] userRank [%u] localRank [%u]", topoAttr_.userRank, localRank);
     175              : 
     176            0 :     for (u32 i = 0; i < localRankSize; i++) {
     177            0 :         if (i != localRank) {
     178            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
     179            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
     180              :         } else {
     181            0 :             buffersIn[i] = execMem.inputMem.ptr();
     182            0 :             buffersOut[i] = execMem.outputMem.ptr();
     183              :         }
     184              :     }
     185              : 
     186            0 :     bool isOpbase = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
     187            0 :     AivOpArgs opArgs{
     188              :         HcclCMDType::HCCL_CMD_REDUCE_SCATTER,
     189            0 :         execMem.inputPtr,
     190            0 :         execMem.outputPtr,
     191            0 :         execMem.count,
     192            0 :         param.DataDes.dataType,
     193            0 :         param.reduceType,
     194              :         0,
     195            0 :         isOpbase};
     196            0 :     AivTopoArgs topoArgs{localRank, localRankSize, MAX_RANK_SIZE, 0, 1, topoAttr_.deviceType};
     197            0 :     topoArgs.identify = algoAttr_.identifier;
     198              : 
     199            0 :     u64 dataSize = SIZE_TABLE[param.DataDes.dataType] * execMem.count;
     200              :     u32 numBlocks;
     201            0 :     CHK_PRT_RET(
     202              :         CalNumBlocks(numBlocks, localRankSize, dataSize) != HCCL_SUCCESS,
     203              :         HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
     204            0 :     numBlocks_ = numBlocks;
     205            0 :     AivResourceArgs resourceArgs{param.tag,  param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
     206            0 :                                  numBlocks_, param.aivTag};
     207            0 :     AivAlgArgs algArgs{};
     208            0 :     algArgs.deterministic = 1;
     209            0 :     algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
     210            0 :     algArgs.execTimeOutSet = true;
     211            0 :     struct AivProfilingInfo aivProfilingInfo;
     212            0 :     aivProfilingInfo.counter = opCounter_;
     213            0 :     HCCL_INFO(
     214              :         "[CollReduceScatterAivDeterExecutor][KernelRun]ReduceScatter bufferin[%d] bufferout[%d]",
     215              :         execMem.inputMem.size(), execMem.outputMem.size());
     216              : 
     217            0 :     HcclResult ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
     218              : 
     219            0 :     CHK_PRT_RET(
     220              :         ret != HCCL_SUCCESS,
     221              :         HCCL_ERROR("[CollReduceScatterAivDeterExecutor][KernelRun]ReduceScatter aiv failed, return[%d]", ret), ret);
     222              : 
     223            0 :     ExtraArgs extraArgs;
     224            0 :     CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, false));
     225              : 
     226            0 :     HCCL_INFO("[CollReduceScatterAivDeterExecutor][KernelRun]ReduceScatter aiv run success.");
     227            0 :     return HCCL_SUCCESS;
     228            0 : }
     229              : 
     230              : REGISTER_EXEC("ReduceScatterAivDeterExecutor", ReduceScatterAivDeter, CollReduceScatterAivDeterExecutor);
     231              : 
     232              : } // namespace hccl
        

Generated by: LCOV version 2.0-1