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

Generated by: LCOV version 2.0-1