LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_executor/ins_alg_executor/all_to_all - ins_v2_all_to_all_v_sole_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 148 0
Test Date: 2026-08-18 17:47:01 Functions: 0.0 % 14 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 "ins_v2_all_to_all_v_sole_executor.h"
      12              : #include "log.h"
      13              : #include "ins_coll_alg_registry.h"
      14              : #include "topo_match_mesh.h"
      15              : #ifndef CCL_KERNEL_AICPU
      16              : #include "aiv_temp_all_to_all_v_mesh_1D.h"
      17              : #endif
      18              : 
      19              : namespace Hccl {
      20              : constexpr u64 MAX_OFFLOAD_SCRATCH_SIZE = 200 * 1024 * 1024; // 200M
      21              : 
      22              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      23            0 : InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::InsV2AlltoAllVSoleExecutor() : InsCollAlgBase()
      24            0 : {}
      25              : 
      26              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      27            0 : InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::~InsV2AlltoAllVSoleExecutor()
      28            0 : {}
      29              : 
      30              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      31            0 : HcclResult InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::InitParams(
      32              :     const CollAlgOperator& op, const CollAlgParams& params)
      33              : {
      34            0 :     op_ = op;
      35            0 :     opMode_ = params.opMode;
      36            0 :     maxTmpMemSize_ = params.maxTmpMemSize;
      37            0 :     CHK_PRT_RET(
      38              :         (maxTmpMemSize_ == 0), HCCL_ERROR("[InitParams] maxTmpMemSize equals to zero."), HcclResult::HCCL_E_PARA);
      39              : 
      40            0 :     CHK_PRT_RET(
      41              :         (op.opType != OpType::ALLTOALLV), HCCL_ERROR("[InitParams] opType is invalid."), HcclResult::HCCL_E_PARA);
      42              : 
      43            0 :     CHK_PRT_RET(
      44              :         op.all2AllVDataDes.sendCounts == nullptr || op.all2AllVDataDes.sdispls == nullptr,
      45              :         HCCL_ERROR("[InsV2AlltoAllVSoleExecutor][InitParams] sendCounts or sdispls is nullptr"), HCCL_E_PTR);
      46              : 
      47            0 :     dataType_ = op.all2AllVDataDes.sendType;
      48            0 :     dataCount_ = static_cast<u64*>(op.all2AllVDataDes.sendCounts)[myRank_]; // send留给本卡的那一片数据
      49            0 :     outputDataType_ = op.all2AllVDataDes.recvType;
      50            0 :     CHK_PRT_RET(
      51              :         dataType_ != outputDataType_,
      52              :         HCCL_ERROR("[InsV2AlltoAllVSoleExecutor][InitParams] dataType_ != outputDataType_"), HCCL_E_PTR);
      53              : 
      54            0 :     dataTypeSize_ = DataTypeSizeGet(dataType_);
      55            0 :     dataSize_ = dataCount_ * dataTypeSize_;
      56              : 
      57            0 :     HCCL_DEBUG("dataType_ is [%u], dataCount_ is [%u]", dataType_, dataCount_);
      58              : 
      59            0 :     CHK_PRT_RET(
      60              :         InitOpInfo(op, opType_, redOp_, root_), HCCL_ERROR("[InitParams] unable to init OpInfo."),
      61              :         HcclResult::HCCL_E_PARA);
      62            0 :     return HcclResult::HCCL_SUCCESS;
      63              : }
      64              : 
      65              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      66            0 : HcclResult InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::InitCommInfo(const RankGraph* rankGraph)
      67              : {
      68            0 :     AlgTopoMatch topoMatch(myRank_, rankSize_, rankGraph, devType_);
      69            0 :     CHK_RET(topoMatch.MatchTopo(vTopo_, virtRanks_, virtRankMap_));
      70            0 :     return HcclResult::HCCL_SUCCESS;
      71            0 : }
      72              : 
      73              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      74            0 : HcclResult InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::InitCommInfo(const AlgTopoInfo& topoInfo)
      75              : {
      76            0 :     CHK_PRT_RET(
      77              :         (topoInfo.vTopo.empty()), HCCL_ERROR("[InsV2AlltoAllVSoleExecutor][InitCommInfo], topoInfo.vTopo is empty"),
      78              :         HcclResult::HCCL_E_PARA);
      79            0 :     CHK_PRT_RET(
      80              :         (topoInfo.virtRankMap.empty()),
      81              :         HCCL_ERROR("[InsV2AlltoAllVSoleExecutor][InitCommInfo], topoInfo.virtRankMap is empty"),
      82              :         HcclResult::HCCL_E_PARA);
      83            0 :     CHK_PRT_RET(
      84              :         (topoInfo.virtRanks.empty()),
      85              :         HCCL_ERROR("[InsV2AlltoAllVSoleExecutor][InitCommInfo], topoInfo.virtRanks is empty"), HcclResult::HCCL_E_PARA);
      86              : 
      87            0 :     vTopo_ = topoInfo.vTopo[0];             // 本通信域内的通信平面
      88            0 :     virtRankMap_ = topoInfo.virtRankMap[0]; // 本通信域内的 rank 映射表
      89            0 :     virtRanks_ = topoInfo.virtRanks[0];     // 本通信域内的 rank 集合
      90            0 :     return HcclResult::HCCL_SUCCESS;
      91              : }
      92              : 
      93              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      94            0 : HcclResult InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::CreateTemplates(
      95              :     std::shared_ptr<InsAlgTemplate>& algTemplatePtr)
      96              : {
      97            0 :     HCCL_DEBUG("[InsV2AlltoAllVSoleExecutor][CreateTemplates]");
      98            0 :     algTemplatePtr = std::make_shared<InsAlgTemplate>(myRank_, rankSize_, vTopo_, virtRankMap_);
      99            0 :     CHK_PTR_NULL(algTemplatePtr); // 检查是否成功分配内存
     100            0 :     algTemplatePtr->SetDmaMode(dmaMode_);
     101            0 :     algTemplatePtr->SetDataType(dataType_);
     102            0 :     algTemplatePtr->SetCollOp(op_);
     103            0 :     return HcclResult::HCCL_SUCCESS;
     104              : }
     105              : 
     106              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     107            0 : HcclResult InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::GetTemplateResRequest(
     108              :     const RankGraph* rankGraph, std::shared_ptr<InsAlgTemplate>& algTemplate, AlgTempResReq& tempResReq) const
     109              : {
     110            0 :     if (enableDetour_) {
     111            0 :         HCCL_DEBUG("[InsV2AlltoAllVSoleExecutor] Rank[%d], CalcRes with detouring enabled.", myRank_);
     112            0 :         CHK_RET(algTemplate->CalcResDetour(rankGraph, tempResReq));
     113              :     } else {
     114            0 :         HCCL_DEBUG("[InsV2AlltoAllVSoleExecutor] Rank[%d], CalcRes with detouring enabled.", myRank_);
     115            0 :         CHK_RET(algTemplate->CalcRes(tempResReq));
     116              :     }
     117              : 
     118            0 :     return HcclResult::HCCL_SUCCESS;
     119              : }
     120              : 
     121              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     122            0 : HcclResult InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::GetTemplateResRequest(
     123              :     ConnectedLinkMgr* linkMgr, std::shared_ptr<InsAlgTemplate>& algTemplate, AlgTempResReq& tempResReq) const
     124              : {
     125            0 :     if (enableDetour_) {
     126            0 :         HCCL_INFO("[InsV2AlltoAllVSoleExecutor] Rank[%d], CalcRes with detouring enabled.", myRank_);
     127            0 :         CHK_RET(algTemplate->CalcResDetour(linkMgr, tempResReq));
     128              :     } else {
     129            0 :         HCCL_INFO("[InsV2AlltoAllVSoleExecutor] Rank[%d], CalcRes with detouring enabled.", myRank_);
     130            0 :         CHK_RET(algTemplate->CalcRes(tempResReq));
     131              :     }
     132            0 :     return HcclResult::HCCL_SUCCESS;
     133              : }
     134              : 
     135              : // HOST 侧算法入口
     136              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     137            0 : HcclResult InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::Orchestrate(
     138              :     const RankGraph* rankGraph, const CollAlgOperator& op, const CollAlgParams& params, InsQuePtr insQue)
     139              : {
     140            0 :     HCCL_INFO("[InsV2AlltoAllVSoleExecutor][Orchestrate] Orchestrate HOST Start");
     141            0 :     CHK_RET(Init(op, params, insQue));
     142            0 :     CHK_RET(InitCommInfo(rankGraph));
     143              : 
     144            0 :     std::shared_ptr<InsAlgTemplate> algTemplate = nullptr;
     145            0 :     CHK_RET(CreateTemplates(algTemplate));
     146              : 
     147            0 :     AlgTempResReq tempResReq;
     148            0 :     CHK_RET(GetTemplateResRequest(rankGraph, algTemplate, tempResReq));
     149              : 
     150            0 :     HCCL_DEBUG(
     151              :         "[InsV2AlltoAllVSoleExecutor][Orchestrate] Rank[%d], template [%s], requiredQue Num [%u].", myRank_,
     152              :         algTemplate->Describe().c_str(), tempResReq.queNum);
     153            0 :     CHK_RET(InitQueue(tempResReq.queNum, tempInsQue_));
     154            0 :     CHK_RET(PrepResLinks(myRank_, rankGraph, linkPriority_, tempResReq.links, tempResLinks_));
     155              : 
     156            0 :     CHK_RET(OrchestrateLoop(algTemplate));
     157            0 :     HCCL_INFO("[InsV2AlltoAllVSoleExecutor][Orchestrate] Orchestrate HOST End");
     158            0 :     return HcclResult::HCCL_SUCCESS;
     159            0 : }
     160              : 
     161              : // AICPU 侧算法入口
     162              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     163            0 : HcclResult InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::Orchestrate(
     164              :     const AlgTopoInfo& topoInfo, const CollAlgOperator& op, const CollAlgParams& params, ConnectedLinkMgr* linkMgr,
     165              :     InsQuePtr insQue)
     166              : {
     167            0 :     HCCL_INFO("[InsV2AlltoAllVSoleExecutor][Orchestrate] Orchestrate AICPU Start");
     168            0 :     CHK_RET(Init(op, params, insQue));
     169            0 :     CHK_RET(InitCommInfo(topoInfo));
     170              : 
     171            0 :     std::shared_ptr<InsAlgTemplate> algTemplate = nullptr;
     172            0 :     CHK_RET(CreateTemplates(algTemplate));
     173              : 
     174            0 :     AlgTempResReq tempResReq;
     175            0 :     CHK_RET(GetTemplateResRequest(linkMgr, algTemplate, tempResReq));
     176              : 
     177            0 :     CHK_RET(InitQueue(tempResReq.queNum, tempInsQue_));
     178            0 :     CHK_RET(PrepResLinks(myRank_, tempResReq.links, linkMgr, tempResLinks_));
     179              : 
     180            0 :     CHK_RET(OrchestrateLoop(algTemplate));
     181            0 :     HCCL_INFO("[InsV2AlltoAllVSoleExecutor][Orchestrate] Orchestrate AICPU End");
     182            0 :     return HcclResult::HCCL_SUCCESS;
     183            0 : }
     184              : 
     185              : // 切分数据并调用 template
     186              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     187              : HcclResult
     188            0 : InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::OrchestrateLoop(std::shared_ptr<InsAlgTemplate> algTemplate)
     189              : {
     190            0 :     HCCL_INFO("[InsV2AlltoAllVSoleExecutor][Orchestrate] Start, template[%s]", algTemplate->Describe().c_str());
     191            0 :     u32 dataSizePerVolume = DataTypeSizeGet(dataType_);
     192            0 :     dataSize_ = dataCount_ * dataSizePerVolume;
     193              : 
     194            0 :     TemplateDataParams tempAlgParams;
     195            0 :     tempAlgParams.buffInfo.outBuffType = BufferType::OUTPUT;
     196            0 :     tempAlgParams.buffInfo.scratBuffType = BufferType::SCRATCH;
     197            0 :     tempAlgParams.buffInfo.inBuffType = BufferType::INPUT;
     198            0 :     tempAlgParams.repeatNum = 1; // 不需要重复
     199            0 :     tempAlgParams.inputRepeatStride = 0;
     200            0 :     tempAlgParams.outputRepeatStride = 0;
     201              : 
     202            0 :     TempFuncs tempFuncs;
     203            0 :     tempFuncs.enableCounterNotify = IsEnableCounterNotify();
     204            0 :     tempFuncs.isForepart = true;
     205            0 :     tempFuncs.isBottom = true;
     206            0 :     tempFuncs.opMode = opMode_;
     207              : 
     208            0 :     u64 maxDataSizePerLoop = 0;
     209            0 :     u64 transportBoundDataSize = UB_MAX_DATA_SIZE;
     210            0 :     u32 templateScratchMultiplier = algTemplate->CalcScratchMultiple(BufferType::INPUT, BufferType::OUTPUT);
     211            0 :     if (templateScratchMultiplier != 0) {
     212            0 :         u64 scratchBoundDataSize = maxTmpMemSize_ / templateScratchMultiplier;
     213            0 :         maxDataSizePerLoop = std::min(transportBoundDataSize, scratchBoundDataSize);
     214              :     } else {
     215            0 :         maxDataSizePerLoop = transportBoundDataSize;
     216              :     }
     217              : 
     218              :     // 先将cclBuffer切块,看每一块大小
     219            0 :     u64 scratchDataCountPerLoopPerRank = maxDataSizePerLoop / dataTypeSize_ / rankSize_;
     220            0 :     HCCL_INFO(
     221              :         "[InsV2AlltoAllVSoleExecutor][OrchestrateLoop] scratchDataCountPerLoopPerRank[%llu], maxDataSizePerLoop[%llu], "
     222              :         "transportBoundDataSize[%llu], templateScratchMultiplier[%llu]",
     223              :         scratchDataCountPerLoopPerRank, maxDataSizePerLoop, transportBoundDataSize, templateScratchMultiplier);
     224            0 :     CHK_PRT_RET(
     225              :         scratchDataCountPerLoopPerRank == 0,
     226              :         HCCL_ERROR("[InsV2AlltoAllVSoleExecutor][OrchestrateLoop] scratchDataCountPerLoopPerRank is 0"),
     227              :         HCCL_E_INTERNAL);
     228              : 
     229            0 :     CHK_PRT_RET(
     230              :         op_.all2AllVDataDes.sendCounts == nullptr || op_.all2AllVDataDes.sdispls == nullptr
     231              :             || op_.all2AllVDataDes.recvCounts == nullptr || op_.all2AllVDataDes.rdispls == nullptr,
     232              :         HCCL_ERROR(
     233              :             "[InsV2AlltoAllVSoleExecutor][OrchestrateLoop] sendCounts or sdispls or recvCounts or rdispls is nullptr"),
     234              :         HCCL_E_PTR);
     235              : 
     236              : #ifndef CCL_KERNEL_AICPU
     237              :     // aiv不在这里切分数据,先全量下kernel,到kernel去做循环
     238            0 :     tempAlgParams.buffInfo.inBuffBaseOff = 0;
     239            0 :     tempAlgParams.buffInfo.outBuffBaseOff = 0;
     240            0 :     tempAlgParams.buffInfo.scratchBuffBaseOff = 0;
     241              :     tempAlgParams.sliceSize
     242            0 :         = scratchDataCountPerLoopPerRank * dataTypeSize_; // 这里就是每个rank可以用的ccl buffer的大小;
     243            0 :     tempAlgParams.inputSliceStride = 0;
     244            0 :     tempAlgParams.outputSliceStride = 0;
     245              : 
     246            0 :     CHK_RET(algTemplate->GenExtIns(tempFuncs, tempAlgParams, tempResLinks_, tempInsQue_));
     247              : #endif
     248              : 
     249            0 :     HCCL_INFO("[InsV2AlltoAllVSoleExecutor][Orchestrate] End, template[%s]", algTemplate->Describe().c_str());
     250            0 :     return HcclResult::HCCL_SUCCESS;
     251            0 : }
     252              : 
     253              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     254              : HcclResult
     255            0 : InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::CalcRes(const RankGraph* rankGraph, CollAlgResReq& algResReq)
     256              : {
     257              :     // Topo Match
     258            0 :     CHK_RET(InitCommInfo(rankGraph));
     259              : 
     260              :     // instantiate a template
     261            0 :     InsAlgTemplate tempAlg(myRank_, rankSize_, vTopo_, virtRankMap_);
     262              : 
     263            0 :     std::shared_ptr<InsAlgTemplate> algTemplate = nullptr;
     264            0 :     CHK_RET(CreateTemplates(algTemplate));
     265              : 
     266            0 :     AlgTempResReq tempResReq;
     267            0 :     CHK_RET(GetTemplateResRequest(rankGraph, algTemplate, tempResReq));
     268              : 
     269            0 :     CHK_RET(CalcLinkInfo(myRank_, rankGraph, tempResReq.links, algResReq.levelRankPairs));
     270            0 :     algResReq.topoInfo.UpdateSingleLevelTopo(virtRanks_, virtRankMap_, vTopo_);
     271            0 :     algResReq.queueNotifys = tempResReq.queNotifys;
     272            0 :     algResReq.primQueueNum = tempResReq.streamNum;
     273            0 :     algResReq.localWaitGroupCntNotify = tempResReq.localWaitGroupCntNotify;
     274            0 :     algResReq.localBcastPostCntNotify = tempResReq.localBcastPostCntNotify;
     275            0 :     CHK_RET(CalcResLinks(myRank_, rankGraph, linkPriority_, tempResReq.links, algResReq.links));
     276              : 
     277            0 :     return HcclResult::HCCL_SUCCESS;
     278            0 : }
     279              : 
     280              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     281            0 : HcclResult InsV2AlltoAllVSoleExecutor<AlgTopoMatch, InsAlgTemplate>::CalcResOffload(
     282              :     const RankGraph* rankGraph, const u64& dataSize, CollOffloadOpResReq& resReq)
     283              : {
     284            0 :     HCCL_INFO("[InsV2AlltoAllVSoleExecutor][CalcResOffload] dataSize is [%u]", dataSize);
     285              :     // Topo Match
     286            0 :     CHK_RET(InitCommInfo(rankGraph));
     287              : 
     288            0 :     std::shared_ptr<InsAlgTemplate> algTemplate = nullptr;
     289            0 :     CHK_RET(CreateTemplates(algTemplate));
     290              : 
     291            0 :     AlgTempResReq tempResReq;
     292            0 :     CHK_RET(GetTemplateResRequest(rankGraph, algTemplate, tempResReq));
     293            0 :     resReq.requiredScratchMemSize = MAX_OFFLOAD_SCRATCH_SIZE;
     294            0 :     resReq.requiredSubQueNum = tempResReq.streamNum - 1;
     295              : 
     296            0 :     return HcclResult::HCCL_SUCCESS;
     297            0 : }
     298              : 
     299              : #ifndef CCL_KERNEL_AICPU
     300              : INS_REGISTER_IMPL_BY_TEMP(
     301              :     OpType::ALLTOALLV, AivAlltoAllVMesh1D, InsV2AlltoAllVSoleExecutor, TopoMatchMesh, AivTempAlltoAllVMesh1D);
     302              : #endif
     303              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1