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-17 10:19:35 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            0 : HcclResult CollAlltoAllMeshAivExecutor::GetAdjInfo(AlgResourceResponse& algRes, AdjInfo& adjInfo)
     156              : {
     157            0 :     return HCCL_SUCCESS;
     158              : }
     159              : 
     160            0 : HcclResult CollAlltoAllMeshAivExecutor::GetAivExecParam(
     161              :     const OpParam& param, AlgResourceResponse& algRes, AivSuperKernelArgs& args)
     162              : {
     163            0 :     HcclUs startut = TIME_NOW();
     164            0 :     tag_ = param.tag;
     165            0 :     algResResp_ = &algRes;
     166              : 
     167            0 :     HcclResult ret = HCCL_SUCCESS;
     168            0 :     ExecMem execMem;
     169            0 :     execMem.count = param.All2AllDataDes.sendCount;
     170            0 :     execMem.inputPtr = param.inputPtr;
     171            0 :     execMem.outputPtr = param.outputPtr;
     172              : 
     173              :     // 单算子大数据量
     174            0 :     execMem.inputMem = algRes.paramInputMem;
     175            0 :     execMem.outputMem = algRes.aivOutputMem;
     176              : 
     177            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_MESH_L0, COMM_INDEX_0);
     178              : 
     179            0 :     u32 localRank = level0CommInfo.localRank;
     180            0 :     u32 localRankSize = level0CommInfo.localRankSize;
     181            0 :     HCCL_DEBUG(
     182              :         "[CollAlltoAllMeshAivExecutor][GetAivExecParam] userRank [%d] localRank [%d]", topoAttr_.userRank, localRank);
     183              : 
     184            0 :     for (u32 i = 0; i < localRankSize; i++) {
     185            0 :         if (i != localRank) {
     186            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(args.buffersIn[i])));
     187            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(args.buffersOut[i])));
     188              :         } else {
     189            0 :             args.buffersIn[i] = execMem.inputMem.ptr();
     190            0 :             args.buffersOut[i] = execMem.outputMem.ptr();
     191              :         }
     192              :     }
     193            0 :     args.rank = localRank;
     194            0 :     args.rankSize = localRankSize;
     195            0 :     args.len = execMem.count;
     196            0 :     args.dataType = param.All2AllDataDes.sendType;
     197            0 :     args.unitSize = SIZE_TABLE[param.All2AllDataDes.sendType];
     198            0 :     args.devType = static_cast<u32>(topoAttr_.deviceType);
     199            0 :     CHK_PRT_RET(
     200              :         ret != HCCL_SUCCESS,
     201              :         HCCL_ERROR(
     202              :             "[CollAlltoAllMeshAivExecutor][Orchestrate]errNo[0x%016llx] tag[%s] executor kernel "
     203              :             "run failed",
     204              :             HCCL_ERROR_CODE(ret), param.tag.c_str()),
     205              :         ret);
     206              : 
     207            0 :     HCCL_INFO(
     208              :         "tag[%s], AlltoAll executor getalgexecparam success, take time [%lld]us.", param.tag.c_str(),
     209              :         DURATION_US(TIME_NOW() - startut));
     210            0 :     return HCCL_SUCCESS;
     211            0 : }
     212              : 
     213            5 : HcclResult CollAlltoAllMeshAivExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
     214              : {
     215            5 :     HCCL_CONFIG_INFO(HCCL_ALG, "[CollAlltoAllMeshAivExecutor][KernelRun]AllToAll aiv enter");
     216              : 
     217            5 :     CHK_RET(CheckCommSize(COMM_MESH_L0, COMM_INDEX_0 + 1));
     218            5 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_MESH_L0, COMM_INDEX_0);
     219              : 
     220              :     void* buffersIn[MAX_RANK_SIZE];
     221              :     void* buffersOut[MAX_RANK_SIZE];
     222              : 
     223            5 :     u32 localRank = level0CommInfo.localRank;
     224            5 :     u32 localRankSize = level0CommInfo.localRankSize;
     225            5 :     HCCL_DEBUG("[CollAlltoAllMeshAivExecutor][KernelRun] userRank [%u] localRank [%u]", topoAttr_.userRank, localRank);
     226              : 
     227           10 :     for (u32 i = 0; i < localRankSize; i++) {
     228            5 :         if (i != localRank) {
     229            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::INPUT_MEM, &(buffersIn[i])));
     230            0 :             CHK_RET(level0CommInfo.links[i]->GetRemoteMem(UserMemType::OUTPUT_MEM, &(buffersOut[i])));
     231              :         } else {
     232            5 :             buffersIn[i] = execMem.inputMem.ptr();
     233            5 :             buffersOut[i] = execMem.outputMem.ptr();
     234              :         }
     235              :     }
     236              : 
     237            5 :     ExtraArgs extraArgs;
     238            5 :     bool isOpbase = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
     239              :     HcclResult ret;
     240            5 :     u64 dataSize
     241            5 :         = (param.opType == HcclCMDType::HCCL_CMD_ALLTOALL ?
     242            0 :                param.All2AllDataDes.sendCount * SIZE_TABLE[param.All2AllDataDes.sendType] :
     243              :                0);
     244              : 
     245            5 :     AivOpArgs opArgs{
     246              :         HcclCMDType::HCCL_CMD_ALLTOALL,
     247            5 :         execMem.inputPtr,
     248            5 :         execMem.outputPtr,
     249              :         0,
     250            5 :         param.All2AllDataDes.sendType,
     251              :         HCCL_REDUCE_RESERVED,
     252              :         0,
     253            5 :         isOpbase};
     254           10 :     AivTopoArgs topoArgs{localRank, localRankSize, MAX_RANK_SIZE, 0, topoAttr_.serverNum, topoAttr_.deviceType};
     255            5 :     topoArgs.identify = algoAttr_.identifier;
     256           15 :     AivResourceArgs resourceArgs{param.tag, param.stream.ptr(), buffersIn, buffersOut, execMem.inputMem.size(),
     257            5 :                                  0,         param.aivTag};
     258            5 :     AivAlgArgs algArgs{};
     259            5 :     algArgs.execTimeOut = topoMatcher_->GetExecTimeOutConfig();
     260            5 :     algArgs.execTimeOutSet = true;
     261            5 :     struct AivProfilingInfo aivProfilingInfo;
     262            5 :     aivProfilingInfo.counter = opCounter_;
     263              : 
     264            5 :     if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALL
     265            0 :         && ((isOpbase && dataSize < AIV_ALL_TO_ALL_BIG_SIZE)
     266            0 :             || (!isOpbase && topoAttr_.deviceType == DevType::DEV_TYPE_910_93))) {
     267            0 :         opArgs.count = param.All2AllDataDes.sendCount;
     268              :         u32 numBlocks;
     269            0 :         CHK_PRT_RET(
     270              :             CalNumBlocks(numBlocks, localRankSize, dataSize, opArgs.cmdType) != HCCL_SUCCESS,
     271              :             HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
     272            0 :         numBlocks_ = numBlocks;
     273            0 :         resourceArgs.numBlocks = numBlocks_;
     274            0 :         ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, aivProfilingInfo);
     275            5 :     } else if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALLVC || param.opType == HcclCMDType::HCCL_CMD_ALLTOALL) {
     276            2 :         for (u32 i = 0; i < localRankSize; i++) {
     277            1 :             u64 rankCount = 0;
     278            2 :             for (u32 j = 0; j < localRankSize; j++) {
     279            1 :                 u64 curSendCount
     280            1 :                     = *(static_cast<const u64*>(param.All2AllDataDes.sendCountMatrix) + i * localRankSize + j);
     281            1 :                 extraArgs.sendCountMatrix[i * localRankSize + j] = curSendCount;
     282            1 :                 rankCount += curSendCount;
     283              :             }
     284            1 :             if (rankCount > extraArgs.maxCount) {
     285            1 :                 extraArgs.maxCount = rankCount;
     286              :             }
     287              :         }
     288            1 :         opArgs.count = extraArgs.maxCount;
     289            1 :         opArgs.cmdType = HcclCMDType::HCCL_CMD_ALLTOALLVC;
     290              :         u32 numBlocks;
     291            1 :         CHK_PRT_RET(
     292              :             CalNumBlocks(numBlocks, localRankSize, dataSize, opArgs.cmdType) != HCCL_SUCCESS,
     293              :             HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
     294            1 :         numBlocks_ = numBlocks;
     295            1 :         resourceArgs.numBlocks = numBlocks_;
     296            1 :         ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo);
     297            1 :     } else {
     298            8 :         for (u32 i = 0; i < localRankSize; i++) {
     299            4 :             extraArgs.sendCounts[i] = *(static_cast<const u64*>(param.All2AllDataDes.sendCounts) + i);
     300            4 :             extraArgs.sendDispls[i] = *(static_cast<const u64*>(param.All2AllDataDes.sdispls) + i);
     301            4 :             extraArgs.recvCounts[i] = *(static_cast<const u64*>(param.All2AllDataDes.recvCounts) + i);
     302            4 :             extraArgs.recvDispls[i] = *(static_cast<const u64*>(param.All2AllDataDes.rdispls) + i);
     303              :         }
     304              : 
     305            4 :         opArgs.cmdType = HcclCMDType::HCCL_CMD_ALLTOALLV;
     306              :         u32 numBlocks;
     307            4 :         CHK_PRT_RET(
     308              :             CalNumBlocks(numBlocks, localRankSize, dataSize, opArgs.cmdType) != HCCL_SUCCESS,
     309              :             HCCL_ERROR("[%s] CalNumBlocks failed", __func__), HCCL_E_PARA);
     310            4 :         numBlocks_ = numBlocks;
     311            4 :         resourceArgs.numBlocks = numBlocks_;
     312            4 :         ret = ExecuteKernelLaunch(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo);
     313              :     }
     314            5 :     CHK_PRT_RET(
     315              :         ret != HCCL_SUCCESS, HCCL_ERROR("[CollAlltoAllMeshAivExecutor][KernelRun]AllToAll aiv failed, return[%d]", ret),
     316              :         ret);
     317              : 
     318            5 :     if (param.opType == HcclCMDType::HCCL_CMD_ALLTOALL && isOpbase) {
     319            0 :         CHK_RET(SetOpCache(opArgs, topoArgs, resourceArgs, algArgs, extraArgs, aivProfilingInfo, false));
     320              :     }
     321              : 
     322            5 :     HCCL_INFO("[CollAlltoAllMeshAivExecutor][KernelRun]AllToAll aiv run success");
     323            5 :     return HCCL_SUCCESS;
     324            5 : }
     325              : 
     326              : REGISTER_EXEC("AlltoAllMeshAivExecutor", AlltoAllMeshAiv, CollAlltoAllMeshAivExecutor);
     327              : 
     328              : } // namespace hccl
        

Generated by: LCOV version 2.0-1