LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_to_all - coll_all_to_all_mesh_aiv_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 64.3 % 185 119
Test Date: 2026-08-18 17:47:01 Functions: 80.0 % 10 8

            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_executor.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15            5 : CollAlltoAllMeshAivExecutor::CollAlltoAllMeshAivExecutor(
      16            5 :     const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
      17            5 :     : CollAlltoAllExecutor(dispatcher, topoMatcher)
      18              : {
      19            5 :     desc_.isAivMode = true;
      20            5 : }
      21              : 
      22            5 : HcclResult CollAlltoAllMeshAivExecutor::CalcStreamNum(u32& streamNum)
      23              : {
      24            5 :     streamNum = 0; // AIV通信不需要申请从流
      25            5 :     HCCL_INFO("[CollAlltoAllMeshAivExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
      26            5 :     return HCCL_SUCCESS;
      27              : }
      28              : 
      29            5 : HcclResult CollAlltoAllMeshAivExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      30              : {
      31            5 :     TransportMemType inputType = TransportMemType::RESERVED;
      32            5 :     TransportMemType outputType = TransportMemType::RESERVED;
      33            5 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      34            5 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
      35            5 :     return HCCL_SUCCESS;
      36              : }
      37              : 
      38            5 : HcclResult CollAlltoAllMeshAivExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
      39              : {
      40            5 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      41            5 :         inputType = TransportMemType::CCL_INPUT;
      42            5 :         outputType = TransportMemType::AIV_OUTPUT;
      43              :     } else {
      44            0 :         inputType = TransportMemType::PARAM_INPUT;
      45            0 :         outputType = TransportMemType::AIV_OUTPUT;
      46              :     }
      47            5 :     HCCL_INFO(
      48              :         "[CollAlltoAllMeshAivExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]", tag_.c_str(),
      49              :         inputType, outputType);
      50            5 :     return HCCL_SUCCESS;
      51              : }
      52              : 
      53            5 : HcclResult CollAlltoAllMeshAivExecutor::CalcLevel0CommInfo(
      54              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      55              : {
      56            5 :     CommParaInfo commParaLevel0(COMM_MESH_L0, CommType::COMM_TAG_MESH);
      57            5 :     commParaLevel0.meshSinglePlane = true;
      58            5 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_MESH_L0], inputType, outputType));
      59            5 :     return HCCL_SUCCESS;
      60            5 : }
      61              : 
      62            5 : HcclResult CollAlltoAllMeshAivExecutor::CalNumBlocks(u32& numBlocks, u32 rankSize, u64 dataSize, HcclCMDType cmdType)
      63              : {
      64            5 :     numBlocks = rankSize; // 默认情况使用rankSize个AIV
      65              : 
      66            5 :     bool isOpBase = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
      67            5 :     if (cmdType == HcclCMDType::HCCL_CMD_ALLTOALL) {
      68            0 :         if (topoAttr_.deviceType == DevType::DEV_TYPE_910_93 && !isOpBase) {
      69            0 :             numBlocks = rankSize * NUM_BLOCKS_FOUR_PER_RANK_A3 > MAX_NUM_BLOCKS ?
      70              :                             rankSize * NUM_BLOCKS_THREE_PER_RANK_A3 :
      71              :                             rankSize * NUM_BLOCKS_FOUR_PER_RANK_A3;
      72            0 :         } else if (isOpBase && dataSize >= AIV_ALL_TO_ALL_BIG_SIZE) {
      73            0 :             numBlocks = NUM_BLOCKS_FACTOR_TWO * rankSize; // 单机场景,单算子AlltoAll使用2倍 rankSize个aiv
      74              :         }
      75            5 :     } else if (cmdType == HcclCMDType::HCCL_CMD_ALLTOALLVC || cmdType == HcclCMDType::HCCL_CMD_ALLTOALLV) {
      76            5 :         if (topoAttr_.deviceType == DevType::DEV_TYPE_910_93
      77            0 :             && ((isOpBase && cmdType == HcclCMDType::HCCL_CMD_ALLTOALLV)
      78            0 :                 || (!isOpBase && cmdType == HcclCMDType::HCCL_CMD_ALLTOALLVC))) {
      79              :             // A3单机单算子场景,numBlocks_为3倍或者4倍的ranksize
      80            0 :             numBlocks = rankSize * NUM_BLOCKS_FOUR_PER_RANK_A3 > MAX_NUM_BLOCKS ?
      81              :                             rankSize * NUM_BLOCKS_THREE_PER_RANK_A3 :
      82              :                             rankSize * NUM_BLOCKS_FOUR_PER_RANK_A3;
      83            5 :         } else if (isOpBase) {
      84            5 :             numBlocks = NUM_BLOCKS_FACTOR_TWO * rankSize; // 单机场景,单算子AlltoAll使用2倍 rankSize个aiv
      85              :         }
      86              :     }
      87              : 
      88            5 :     u32 bestNumBlocks = numBlocks;
      89            5 :     if (topoAttr_.deviceType == DevType::DEV_TYPE_910B
      90            0 :         || (isOpBase && topoAttr_.deviceType == DevType::DEV_TYPE_910_93 && cmdType != HcclCMDType::HCCL_CMD_ALLTOALLV)
      91            0 :         || (!isOpBase && topoAttr_.deviceType == DevType::DEV_TYPE_910_93
      92            0 :             && cmdType == HcclCMDType::HCCL_CMD_ALLTOALLV)) {
      93            5 :         CHK_PRT_RET(
      94              :             numBlocks_ < numBlocks,
      95              :             HCCL_WARNING(
      96              :                 "[CollAlltoAllMeshAivExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].", numBlocks_,
      97              :                 numBlocks),
      98              :             HCCL_E_PARA);
      99            0 :     } else if (
     100            0 :         (isOpBase && topoAttr_.deviceType == DevType::DEV_TYPE_910_93 && cmdType == HcclCMDType::HCCL_CMD_ALLTOALLV)
     101            0 :         || (!isOpBase && topoAttr_.deviceType == DevType::DEV_TYPE_910_93
     102            0 :             && cmdType != HcclCMDType::HCCL_CMD_ALLTOALLV)) {
     103            0 :         CHK_PRT_RET(
     104              :             numBlocks_ < rankSize,
     105              :             HCCL_WARNING(
     106              :                 "[CollAlltoAllMeshAivExecutor][CalNumBlocks]aivCore[%u] is invalid, at least need [%u].", numBlocks_,
     107              :                 rankSize),
     108              :             HCCL_E_PARA);
     109            0 :         if (numBlocks_ < numBlocks) {
     110            0 :             numBlocks = numBlocks_ / rankSize * rankSize;
     111              :         }
     112              :     }
     113              : 
     114            5 :     HCCL_INFO(
     115              :         "[CollAlltoAllMeshAivExecutor][CalNumBlocks] numBlocks is set to [%u], limit[%u], recommanded[%u]", numBlocks,
     116              :         numBlocks_, bestNumBlocks);
     117            5 :     return HCCL_SUCCESS;
     118              : }
     119              : 
     120            5 : HcclResult CollAlltoAllMeshAivExecutor::Orchestrate(OpParam& param, AlgResourceResponse& algRes)
     121              : {
     122            5 :     HcclUs startut = TIME_NOW();
     123            5 :     tag_ = param.tag;
     124            5 :     algResResp_ = &algRes;
     125              : 
     126            5 :     HcclResult ret = HCCL_SUCCESS;
     127            5 :     ExecMem execMem;
     128            5 :     execMem.count = param.DataDes.count;
     129            5 :     execMem.inputPtr = param.inputPtr;
     130            5 :     execMem.outputPtr = param.outputPtr;
     131              : 
     132            5 :     if (workflowMode_ != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
     133            0 :         execMem.inputMem = algRes.paramInputMem;
     134            0 :         execMem.outputMem = algRes.aivOutputMem; // 存放flag
     135            0 :         ret = KernelRun(param, execMem);
     136              :     } else {
     137            5 :         execMem.inputMem = algRes.cclInputMem;
     138            5 :         execMem.outputMem = algRes.aivOutputMem;
     139            5 :         ret = KernelRun(param, execMem);
     140              :     }
     141              : 
     142            5 :     CHK_PRT_RET(
     143              :         ret != HCCL_SUCCESS,
     144              :         HCCL_ERROR(
     145              :             "[CollAlltoAllMeshAivExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel run failed",
     146              :             HCCL_ERROR_CODE(ret), param.tag.c_str()),
     147              :         ret);
     148              : 
     149            5 :     HCCL_INFO(
     150              :         "tag[%s], AlltoAll executor orchestrate success, take time [%lld]us.", param.tag.c_str(),
     151              :         DURATION_US(TIME_NOW() - startut));
     152            5 :     return HCCL_SUCCESS;
     153            5 : }
     154              : 
     155              : HcclResult
     156            0 : CollAlltoAllMeshAivExecutor::GetAdjInfo([[maybe_unused]] AlgResourceResponse& algRes, [[maybe_unused]] AdjInfo& adjInfo)
     157              : {
     158            0 :     return HCCL_SUCCESS;
     159              : }
     160              : 
     161            0 : HcclResult CollAlltoAllMeshAivExecutor::GetAivExecParam(
     162              :     const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs& args)
     163              : {
     164            0 :     HcclUs startut = TIME_NOW();
     165            0 :     tag_ = param.tag;
     166            0 :     algResResp_ = &algRes;
     167              : 
     168            0 :     HcclResult ret = HCCL_SUCCESS;
     169            0 :     ExecMem execMem;
     170            0 :     execMem.count = param.All2AllDataDes.sendCount;
     171            0 :     execMem.inputPtr = param.inputPtr;
     172            0 :     execMem.outputPtr = param.outputPtr;
     173              : 
     174              :     // 单算子大数据量
     175            0 :     execMem.inputMem = algRes.paramInputMem;
     176            0 :     execMem.outputMem = algRes.aivOutputMem;
     177              : 
     178            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_MESH_L0, COMM_INDEX_0);
     179              : 
     180            0 :     u32 localRank = level0CommInfo.localRank;
     181            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     182            0 :     HCCL_DEBUG(
     183              :         "[CollAlltoAllMeshAivExecutor][GetAivExecParam] userRank [%d] localRank [%d]", topoAttr_.userRank, localRank);
     184              : 
     185            0 :     for (u32 i = 0; i < localRankSize; i++) {
     186            0 :         if (i != localRank) {
     187            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(args.buffersIn[i])));
     188            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(args.buffersOut[i])));
     189              :         } else {
     190            0 :             args.buffersIn[i] = execMem.inputMem.ptr();
     191            0 :             args.buffersOut[i] = execMem.outputMem.ptr();
     192              :         }
     193              :     }
     194            0 :     args.rank = localRank;
     195            0 :     args.rankSize = localRankSize;
     196            0 :     args.len = execMem.count;
     197            0 :     args.dataType = param.All2AllDataDes.sendType;
     198            0 :     args.unitSize = SIZE_TABLE[param.All2AllDataDes.sendType];
     199            0 :     args.devType = static_cast<u32>(topoAttr_.deviceType);
     200            0 :     CHK_PRT_RET(
     201              :         ret != HCCL_SUCCESS,
     202              :         HCCL_ERROR(
     203              :             "[CollAlltoAllMeshAivExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
     204              :             "run failed",
     205              :             HCCL_ERROR_CODE(ret), param.tag.c_str()),
     206              :         ret);
     207              : 
     208            0 :     HCCL_INFO(
     209              :         "tag[%s], AlltoAll executor getalgexecparam success, take time [%lld]us.", param.tag.c_str(),
     210              :         DURATION_US(TIME_NOW() - startut));
     211            0 :     return HCCL_SUCCESS;
     212            0 : }
     213              : 
     214            5 : HcclResult CollAlltoAllMeshAivExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
     215              : {
     216            5 :     HCCL_CONFIG_INFO(HCCL_ALG, "[CollAlltoAllMeshAivExecutor][KernelRun]AllToAll aiv enter");
     217              : 
     218            5 :     CHK_RET(CheckCommSize(COMM_MESH_L0, COMM_INDEX_0 + 1));
     219            5 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_MESH_L0, COMM_INDEX_0);
     220              : 
     221              :     void* buffersIn[MAX_RANK_SIZE];
     222              :     void* buffersOut[MAX_RANK_SIZE];
     223              : 
     224            5 :     u32 localRank = level0CommInfo.localRank;
     225            5 :     u32 localRankSize = level0CommInfo.localRankSize;
     226            5 :     HCCL_DEBUG("[CollAlltoAllMeshAivExecutor][KernelRun] userRank [%u] localRank [%u]", topoAttr_.userRank, localRank);
     227              : 
     228           10 :     for (u32 i = 0; i < localRankSize; i++) {
     229            5 :         if (i != localRank) {
     230            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
     231            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
     232              :         } else {
     233            5 :             buffersIn[i] = execMem.inputMem.ptr();
     234            5 :             buffersOut[i] = execMem.outputMem.ptr();
     235              :         }
     236              :     }
     237              : 
     238            5 :     ExtraArgs extraArgs;
     239            5 :     bool isOpbase = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
     240              :     HcclResult ret;
     241            5 :     u64 dataSize
     242            5 :         = (param.opType == HcclCMDType::HCCL_CMD_ALLTOALL ?
     243            0 :                param.All2AllDataDes.sendCount * SIZE_TABLE[param.All2AllDataDes.sendType] :
     244              :                0);
     245              : 
     246            5 :     AivOpArgs opArgs{
     247              :         HcclCMDType::HCCL_CMD_ALLTOALL,
     248            5 :         execMem.inputPtr,
     249            5 :         execMem.outputPtr,
     250              :         0,
     251            5 :         param.All2AllDataDes.sendType,
     252              :         HCCL_REDUCE_RESERVED,
     253              :         0,
     254            5 :         isOpbase};
     255           10 :     AivTopoArgs topoArgs{localRank, localRankSize, MAX_RANK_SIZE, 0, topoAttr_.serverNum, topoAttr_.deviceType};
     256            5 :     topoArgs.identify = algoAttr_.identifier;
     257           15 :     AivResourceArgs resourceArgs{param.tag, param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
     258            5 :                                  0,         param.aivTag};
     259            5 :     AivAlgArgs algArgs{};
     260            5 :     algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
     261            5 :     algArgs.execTimeOutSet = true;
     262            5 :     struct AivProfilingInfo aivProfilingInfo;
     263            5 :     aivProfilingInfo.counter = opCounter_;
     264              : 
     265            5 :     if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALL
     266            0 :         && ((isOpbase && dataSize < AIV_ALL_TO_ALL_BIG_SIZE)
     267            0 :             || (!isOpbase && topoAttr_.deviceType == DevType::DEV_TYPE_910_93))) {
     268            0 :         opArgs.count = param.All2AllDataDes.sendCount;
     269              :         u32 numBlocks;
     270            0 :         CHK_PRT_RET(
     271              :             CalNumBlocks(numBlocks, localRankSize, dataSize, opArgs.cmdType) != HCCL_SUCCESS,
     272              :             HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
     273            0 :         numBlocks_ = numBlocks;
     274            0 :         resourceArgs.numBlocks = numBlocks_;
     275            0 :         ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
     276            5 :     } else if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALLVC || param.opType == HcclCMDType::HCCL_CMD_ALLTOALL) {
     277            2 :         for (u32 i = 0; i < localRankSize; i++) {
     278            1 :             u64 rankCount = 0;
     279            2 :             for (u32 j = 0; j < localRankSize; j++) {
     280            1 :                 u64 curSendCount
     281            1 :                     = *(static_cast<const u64*>(param.All2AllDataDes.sendCountMatrix) + i * localRankSize + j);
     282            1 :                 extraArgs.sendCountMatrix[i * localRankSize + j] = curSendCount;
     283            1 :                 rankCount += curSendCount;
     284              :             }
     285            1 :             if (rankCount > extraArgs.maxCount) {
     286            1 :                 extraArgs.maxCount = rankCount;
     287              :             }
     288              :         }
     289            1 :         opArgs.count = extraArgs.maxCount;
     290            1 :         opArgs.cmdType = HcclCMDType::HCCL_CMD_ALLTOALLVC;
     291              :         u32 numBlocks;
     292            1 :         CHK_PRT_RET(
     293              :             CalNumBlocks(numBlocks, localRankSize, dataSize, opArgs.cmdType) != HCCL_SUCCESS,
     294              :             HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
     295            1 :         numBlocks_ = numBlocks;
     296            1 :         resourceArgs.numBlocks = numBlocks_;
     297            1 :         ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo);
     298            1 :     } else {
     299            8 :         for (u32 i = 0; i < localRankSize; i++) {
     300            4 :             extraArgs.sendCounts[i] = *(static_cast<const u64*>(param.All2AllDataDes.sendCounts) + i);
     301            4 :             extraArgs.sendDispls[i] = *(static_cast<const u64*>(param.All2AllDataDes.sdispls) + i);
     302            4 :             extraArgs.recvCounts[i] = *(static_cast<const u64*>(param.All2AllDataDes.recvCounts) + i);
     303            4 :             extraArgs.recvDispls[i] = *(static_cast<const u64*>(param.All2AllDataDes.rdispls) + i);
     304              :         }
     305              : 
     306            4 :         opArgs.cmdType = HcclCMDType::HCCL_CMD_ALLTOALLV;
     307              :         u32 numBlocks;
     308            4 :         CHK_PRT_RET(
     309              :             CalNumBlocks(numBlocks, localRankSize, dataSize, opArgs.cmdType) != HCCL_SUCCESS,
     310              :             HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
     311            4 :         numBlocks_ = numBlocks;
     312            4 :         resourceArgs.numBlocks = numBlocks_;
     313            4 :         ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo);
     314              :     }
     315            5 :     CHK_PRT_RET(
     316              :         ret != HCCL_SUCCESS, HCCL_ERROR("[CollAlltoAllMeshAivExecutor][KernelRun]AllToAll aiv failed, return[%d]", ret),
     317              :         ret);
     318              : 
     319            5 :     if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALL && isOpbase) {
     320            0 :         CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, false));
     321              :     }
     322              : 
     323            5 :     HCCL_INFO("[CollAlltoAllMeshAivExecutor][KernelRun]AllToAll aiv run success");
     324            5 :     return HCCL_SUCCESS;
     325            5 : }
     326              : 
     327              : REGISTER_EXEC("AlltoAllMeshAivExecutor", AlltoAllMeshAiv, CollAlltoAllMeshAivExecutor);
     328              : 
     329              : } // namespace hccl
        

Generated by: LCOV version 2.0-1