LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_executor/ins_alg_executor/all_gather - ins_v2_all_gather_sole_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 153 0
Test Date: 2026-08-04 10:52:23 Functions: 0.0 % 112 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_gather_sole_executor.h"
      12              : 
      13              : #include "log.h"
      14              : 
      15              : #include "ins_coll_alg_registry.h"
      16              : 
      17              : #include "topo_match_mesh.h"
      18              : #include "topo_match_nhr.h"
      19              : #include "topo_match_concurr_mesh.h"
      20              : 
      21              : #include "ins_temp_all_gather_mesh.h"
      22              : #include "ins_temp_all_gather_mesh_2D.h"
      23              : #include "ins_temp_all_gather_nhr.h"
      24              : #ifndef CCL_KERNEL_AICPU
      25              : #include "ccu_temp_all_gather_mesh_1D_mem2mem_with_stride.h"
      26              : #include "ccu_temp_all_gather_nhr_1D_mem2mem.h"
      27              : #include "ccu_temp_all_gather_mesh_2D_mem2mem.h"
      28              : #include "aiv_temp_all_gather_mesh_1D.h"
      29              : #include "ccu_temp_all_gather_mesh_1D_2die.h"
      30              : #endif
      31              : 
      32              : namespace Hccl {
      33              : constexpr u64 MAX_OFFLOAD_SCRATCH_SIZE = 200 * 1024 * 1024;  // 200M
      34              : 
      35              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      36            0 : InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::InsV2AllGatherSoleExecutor() : InsCollAlgBase()
      37            0 : {}
      38              : 
      39              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      40            0 : InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::~InsV2AllGatherSoleExecutor()
      41            0 : {}
      42              : 
      43              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      44            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::InitCommInfo(const RankGraph *rankGraph)
      45              : {
      46            0 :     AlgTopoMatch topoMatch(myRank_, rankSize_, rankGraph, devType_);
      47            0 :     CHK_RET(topoMatch.MatchTopo(vTopo_, virtRanks_, virtRankMap_));
      48            0 :     return HcclResult::HCCL_SUCCESS;
      49            0 : }
      50              : 
      51              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      52            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::InitCommInfo(const AlgTopoInfo &topoInfo)
      53              : {
      54            0 :     if (topoInfo.vTopo.size() < 1) {
      55            0 :         return HcclResult::HCCL_E_INTERNAL;
      56              :     }
      57            0 :     vTopo_ = topoInfo.vTopo[0];              // 本通信域内的通信平面
      58            0 :     virtRankMap_ = topoInfo.virtRankMap[0];  // 本通信域内的 rank 映射表
      59            0 :     virtRanks_ = topoInfo.virtRanks[0];      // 本通信域内的 rank 集合
      60            0 :     return HcclResult::HCCL_SUCCESS;
      61              : }
      62              : 
      63              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      64            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::CreateTemplates(
      65              :     std::shared_ptr<InsAlgTemplate> &algTemplatePtr)
      66              : {
      67            0 :     HCCL_DEBUG("[InsV2AllGatherSoleExecutor][CreateTemplates]");
      68            0 :     algTemplatePtr = std::make_shared<InsAlgTemplate>(myRank_, rankSize_, vTopo_, virtRankMap_);
      69            0 :     CHK_PTR_NULL(algTemplatePtr);  // 检查是否成功分配内存
      70            0 :     algTemplatePtr->SetDmaMode(dmaMode_);
      71            0 :     algTemplatePtr->SetDataType(dataType_);
      72            0 :     algTemplatePtr->SetCollOp(op_);
      73            0 :     return HcclResult::HCCL_SUCCESS;
      74              : }
      75              : 
      76              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      77            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::GetTemplateResRequest(
      78              :     const RankGraph *rankGraph, std::shared_ptr<InsAlgTemplate> &algTemplate, AlgTempResReq &tempResReq) const
      79              : {
      80            0 :     if (enableDetour_) {
      81            0 :         HCCL_DEBUG("[InsV2AllGatherSoleExecutor] [%s] Rank[%d], CalcRes with detouring enabled.", __func__, myRank_);
      82            0 :         CHK_RET(algTemplate->CalcResDetour(rankGraph, tempResReq));
      83              :     } else {
      84            0 :         HCCL_DEBUG("[InsV2AllGatherSoleExecutor] [%s] Rank[%d], CalcRes with detouring disabled.", __func__, myRank_);
      85            0 :         CHK_RET(algTemplate->CalcRes(tempResReq));
      86              :     }
      87            0 :     return HcclResult::HCCL_SUCCESS;
      88              : }
      89              : 
      90              : template <typename AlgTopoMatch, typename InsAlgTemplate>
      91            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::GetTemplateResRequest(
      92              :     ConnectedLinkMgr *linkMgr, std::shared_ptr<InsAlgTemplate> &algTemplate, AlgTempResReq &tempResReq) const
      93              : {
      94            0 :     if (enableDetour_) {
      95            0 :         HCCL_DEBUG("[InsV2AllGatherSoleExecutor] [%s] Rank[%d], CalcRes with detouring enabled.", __func__, myRank_);
      96            0 :         CHK_RET(algTemplate->CalcResDetour(linkMgr, tempResReq));
      97              :     } else {
      98            0 :         HCCL_DEBUG("[InsV2AllGatherSoleExecutor] [%s] Rank[%d], CalcRes with detouring disabled.", __func__, myRank_);
      99            0 :         CHK_RET(algTemplate->CalcRes(tempResReq));
     100              :     }
     101            0 :     return HcclResult::HCCL_SUCCESS;
     102              : }
     103              : 
     104              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     105            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::CalNumBlocks(u32& numBlocks, u64 dataSize, u32 numBlocksLimit)
     106              : {
     107            0 :     std::shared_ptr<InsAlgTemplate> algTemplate = nullptr;
     108            0 :     CHK_RET(CreateTemplates(algTemplate));
     109            0 :     CHK_RET(algTemplate->CalNumBlocks(numBlocks, dataSize, numBlocksLimit));
     110            0 :     return HcclResult::HCCL_SUCCESS;
     111            0 : }
     112              : 
     113              : // HOST 侧算法入口
     114              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     115            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::Orchestrate(
     116              :     const RankGraph *rankGraph, const CollAlgOperator &op, const CollAlgParams &params, InsQuePtr insQue)
     117              : {
     118            0 :     HCCL_DEBUG("[InsV2AllGatherSoleExecutor][Orchestrate] Orchestrate HOST Start");
     119            0 :     CHK_RET(Init(op, params, insQue));
     120            0 :     CHK_RET(InitCommInfo(rankGraph));
     121              : 
     122            0 :     std::shared_ptr<InsAlgTemplate> algTemplate = nullptr;
     123            0 :     CHK_RET(CreateTemplates(algTemplate));
     124              : 
     125            0 :     AlgTempResReq tempResReq;
     126            0 :     CHK_RET(GetTemplateResRequest(rankGraph, algTemplate, tempResReq));
     127              : 
     128            0 :     HCCL_DEBUG("[InsV2AllGatherSoleExecutor][Orchestrate] Rank[%d], template [%s], requiredQue Num [%u].",
     129              :         myRank_,
     130              :         algTemplate->Describe().c_str(),
     131              :         tempResReq.queNum);
     132            0 :     CHK_RET(InitQueue(tempResReq.queNum, tempInsQue_));
     133            0 :     CHK_RET(PrepResLinks(myRank_, rankGraph, linkPriority_, tempResReq.links, tempResLinks_));
     134            0 :     CHK_RET(OrchestrateLoop(algTemplate));
     135            0 :     return HcclResult::HCCL_SUCCESS;
     136            0 : }
     137              : 
     138              : // AICPU 侧算法入口
     139              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     140            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::Orchestrate(const AlgTopoInfo &topoInfo,
     141              :     const CollAlgOperator &op, const CollAlgParams &params, ConnectedLinkMgr *linkMgr, InsQuePtr insQue)
     142              : {
     143            0 :     HCCL_DEBUG("[InsV2AllGatherSoleExecutor][Orchestrate] Orchestrate AICPU Start");
     144            0 :     CHK_RET(Init(op, params, insQue));
     145            0 :     dataType_ = op.dataType;
     146              :     
     147            0 :     CHK_RET(InitCommInfo(topoInfo));
     148              : 
     149            0 :     std::shared_ptr<InsAlgTemplate> algTemplate = nullptr;
     150            0 :     CHK_RET(CreateTemplates(algTemplate));
     151            0 :     algTemplate->SetDataType(dataType_);
     152            0 :     std::map<u32, u32>rank2PathNumMap;
     153            0 :     CHK_RET(SetPathNumMapByLinkMgrMultiLevel(linkMgr, virtRanks_, myRank_, rank2PathNumMap));
     154            0 :     algTemplate->setPathNumMap(rank2PathNumMap);
     155              :  
     156            0 :     AlgTempResReq tempResReq;
     157            0 :     CHK_RET(GetTemplateResRequest(linkMgr, algTemplate, tempResReq));
     158              : 
     159            0 :     HCCL_DEBUG("[InsV2AllGatherSoleExecutor][Orchestrate] Rank[%d], template [%s], requiredQue Num [%u].",
     160              :         myRank_,
     161              :         algTemplate->Describe().c_str(),
     162              :         tempResReq.queNum);
     163            0 :     CHK_RET(InitQueue(tempResReq.queNum, tempInsQue_));
     164            0 :     CHK_RET(PrepResLinks(myRank_, tempResReq.links, linkMgr, tempResLinks_));
     165            0 :     CHK_RET(OrchestrateLoop(algTemplate));
     166            0 :     return HcclResult::HCCL_SUCCESS;
     167            0 : }
     168              : 
     169              : // 切分数据并调用 template
     170              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     171            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::OrchestrateLoop(
     172              :     std::shared_ptr<InsAlgTemplate> algTemplate)
     173              : {
     174            0 :     HCCL_INFO("[InsV2AllGatherSoleExecutor][OrchestrateOpbase] Start, template[%s]", algTemplate->Describe().c_str());
     175            0 :     u32 dataSizePerVolume = DataTypeSizeGet(dataType_);
     176            0 :     dataSize_ = dataCount_ * dataSizePerVolume;
     177              : 
     178            0 :     TemplateDataParams tempAlgParams;
     179            0 :     tempAlgParams.inputRepeatStride = 0;
     180            0 :     tempAlgParams.outputRepeatStride = 0;
     181            0 :     tempAlgParams.buffInfo.inBuffType = BufferType::INPUT;
     182            0 :     tempAlgParams.buffInfo.outBuffType = BufferType::OUTPUT;
     183            0 :     tempAlgParams.buffInfo.scratBuffType = BufferType::SCRATCH;
     184            0 :     tempAlgParams.repeatNum = 1;  // 不需要重复 
     185              : 
     186            0 :     TempFuncs tempFuncs;
     187            0 :     tempFuncs.isForepart = true;
     188            0 :     tempFuncs.isBottom = true;
     189            0 :     tempFuncs.opMode = opMode_;
     190            0 :     tempFuncs.enableCounterNotify = IsEnableCounterNotify();
     191              : 
     192            0 :     u64 maxDataSizePerLoop = 0;
     193            0 :     u64 transportBoundDataSize = UB_MAX_DATA_SIZE;  // algTemplate->CalcLoopMaxCount();
     194              : 
     195            0 :     u32 templateScratchMultiplier = algTemplate->CalcScratchMultiple(BufferType::INPUT, BufferType::OUTPUT);
     196            0 :     if (templateScratchMultiplier != 0) {
     197            0 :         u64 scratchBoundDataSize = maxTmpMemSize_ / templateScratchMultiplier;
     198            0 :         maxDataSizePerLoop = std::min(transportBoundDataSize, scratchBoundDataSize);
     199              :     } else {
     200            0 :         maxDataSizePerLoop = transportBoundDataSize;
     201              :     }
     202            0 :     u64 maxDataCountPerLoop = maxDataSizePerLoop / dataTypeSize_;
     203            0 :     HCCL_INFO("[InsV2AllGatherSoleExecutor][OrchestrateOpbase] maxDataCountPerLoop[%llu], maxDataSizePerLoop[%llu], "
     204              :               "transportBoundDataSize[%llu], templateScratchMultiplier[%llu]",
     205              :         maxDataCountPerLoop,
     206              :         maxDataSizePerLoop,
     207              :         transportBoundDataSize,
     208              :         templateScratchMultiplier);
     209            0 :     CHK_PRT_RET(maxDataCountPerLoop == 0,
     210              :         HCCL_ERROR("[InsV2AllGatherSoleExecutor][OrchestrateOpbase] maxDataCountPerLoop is 0"),
     211              :         HCCL_E_INTERNAL);
     212              : 
     213            0 :     u64 processedDataCount = 0; // 已经处理的数据count
     214            0 :     u64 loopTimes = dataCount_ / maxDataCountPerLoop + static_cast<u64>(dataCount_ % maxDataCountPerLoop != 0);
     215            0 :     for (u64 loop = 0; loop < loopTimes; loop++) {
     216            0 :         u64 currDataCount = (loop == loopTimes - 1) ? dataCount_ - processedDataCount : maxDataCountPerLoop;
     217              : 
     218            0 :         tempAlgParams.buffInfo.inBuffBaseOff = processedDataCount * dataTypeSize_;
     219            0 :         tempAlgParams.buffInfo.outBuffBaseOff = processedDataCount * dataTypeSize_;
     220            0 :         tempAlgParams.buffInfo.scratchBuffBaseOff = 0;
     221            0 :         tempAlgParams.sliceSize = currDataCount * dataTypeSize_;
     222            0 :         tempAlgParams.tailSize = tempAlgParams.sliceSize;
     223            0 :         tempAlgParams.inputSliceStride = 0;           // 输入数据仅有 1 个 slice, 不需要 stride
     224            0 :         tempAlgParams.outputSliceStride = dataSize_;  // 每张卡的数据间隔为算子输入大小
     225              : 
     226            0 :         CHK_RET(algTemplate->GenExtIns(tempFuncs, tempAlgParams, tempResLinks_, tempInsQue_));
     227            0 :         processedDataCount += currDataCount;
     228              :     }
     229              : 
     230            0 :     return HcclResult::HCCL_SUCCESS;
     231            0 : }
     232              : 
     233              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     234            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::CalcRes(
     235              :     const RankGraph *rankGraph, CollAlgResReq &algResReq)
     236              : {
     237              :     // Topo Match
     238            0 :     CHK_RET(InitCommInfo(rankGraph));
     239              : 
     240              :     // instantiate a template
     241            0 :     InsAlgTemplate tempAlg(myRank_, rankSize_, vTopo_, virtRankMap_);
     242              : 
     243            0 :     std::shared_ptr<InsAlgTemplate> algTemplate = nullptr;
     244            0 :     CHK_RET(CreateTemplates(algTemplate));
     245              : 
     246              :     // 通过判断哪层通信域能有到所有remoteRank的path,判断当前算法跑在哪一层
     247            0 :     std::map<u32, u32>rank2PathNumMap;
     248            0 :     HCCL_INFO("[InsV2AllGatherSoleExecutor] CalcRes SetPathNumMap");
     249            0 :     CHK_RET(SetPathNumMapByRankGraphMultiLevel(rankGraph, virtRanks_, myRank_, rank2PathNumMap));
     250            0 :     algTemplate->setPathNumMap(rank2PathNumMap);  
     251            0 :     AlgTempResReq tempResReq;
     252            0 :     CHK_RET(GetTemplateResRequest(rankGraph, algTemplate, tempResReq));
     253              : 
     254            0 :     CHK_RET(CalcLinkInfo(myRank_, rankGraph, tempResReq.links, algResReq.levelRankPairs));
     255            0 :     algResReq.topoInfo.UpdateSingleLevelTopo(virtRanks_, virtRankMap_, vTopo_);   
     256            0 :     algResReq.queueNotifys = tempResReq.queNotifys;
     257            0 :     algResReq.primQueueNum = tempResReq.streamNum;
     258            0 :     algResReq.localWaitGroupCntNotify = tempResReq.localWaitGroupCntNotify;
     259            0 :     algResReq.localBcastPostCntNotify = tempResReq.localBcastPostCntNotify;
     260            0 :     HCCL_DEBUG("[InsV2AllGatherSoleExecutor] [%s] Rank[%d], requiredQueNum [%u].", __func__, myRank_, algResReq.primQueueNum);
     261            0 :     CHK_RET(CalcResLinks(myRank_, rankGraph, linkPriority_, tempResReq.links, algResReq.links));
     262              : 
     263            0 :     return HcclResult::HCCL_SUCCESS;
     264            0 : }
     265              : 
     266              : template <typename AlgTopoMatch, typename InsAlgTemplate>
     267            0 : HcclResult InsV2AllGatherSoleExecutor<AlgTopoMatch, InsAlgTemplate>::CalcResOffload(
     268              :     const RankGraph *rankGraph, const u64 &dataSize, CollOffloadOpResReq &resReq)
     269              : {
     270              :     // Topo Match
     271              :     (void)dataSize;
     272            0 :     CHK_RET(InitCommInfo(rankGraph));
     273              : 
     274            0 :     std::shared_ptr<InsAlgTemplate> algTemplate = nullptr;
     275            0 :     CHK_RET(CreateTemplates(algTemplate));
     276              : 
     277              :     // 通过判断哪层通信域能有到所有remoteRank的path,判断当前算法跑在哪一层    
     278            0 :     std::map<u32, u32>rank2PathNumMap;
     279            0 :     HCCL_INFO("[InsV2AllGatherSoleExecutor] CalcResOffload SetPathNumMap");
     280            0 :     CHK_RET(SetPathNumMapByRankGraphMultiLevel(rankGraph, virtRanks_, myRank_, rank2PathNumMap));
     281            0 :     algTemplate->setPathNumMap(rank2PathNumMap);  
     282            0 :     AlgTempResReq tempResReq;
     283            0 :     CHK_RET(GetTemplateResRequest(rankGraph, algTemplate, tempResReq));
     284            0 :     resReq.requiredScratchMemSize = UB_MAX_DATA_SIZE;
     285            0 :     resReq.requiredSubQueNum = tempResReq.streamNum - 1;
     286              : 
     287            0 :     return HcclResult::HCCL_SUCCESS;
     288            0 : }
     289              : 
     290              : INS_REGISTER_IMPL_BY_TEMP(OpType::ALLGATHER, InsAllGatherMesh, InsV2AllGatherSoleExecutor, TopoMatchMesh,
     291              :                           InsTempAllGatherMesh1D);
     292              : INS_REGISTER_IMPL_BY_TEMP(OpType::ALLGATHER, InsAllGatherMesh2D, InsV2AllGatherSoleExecutor, TopoMatchConcurrMesh,
     293              :                           InsTempAllGatherMesh2D);
     294              : INS_REGISTER_IMPL_BY_TEMP(OpType::ALLGATHER, InsAllGatherNHR, InsV2AllGatherSoleExecutor, TopoMatchNHR,
     295              :                           InsTempAllGatherNHR);
     296              : #ifndef CCL_KERNEL_AICPU
     297              : INS_REGISTER_IMPL_BY_TEMP(OpType::ALLGATHER, AivAllGatherMesh1D, InsV2AllGatherSoleExecutor,
     298              :     TopoMatchMesh, AivTempAllGatherMesh1D);
     299              : INS_REGISTER_IMPL_BY_TEMP(OpType::ALLGATHER, CcuAllGatherMesh1DMem2MemWithStride, InsV2AllGatherSoleExecutor,
     300              :     TopoMatchMesh, CcuTempAllGatherMesh1DMem2MemWithStride);
     301              : INS_REGISTER_IMPL_BY_TEMP(
     302              :     OpType::ALLGATHER, CcuAllGatherNHR1D, InsV2AllGatherSoleExecutor, TopoMatchMesh, CcuTempAllGatherNHRMem2Mem1D);
     303              : INS_REGISTER_IMPL_BY_TEMP(OpType::ALLGATHER, CcuAllGatherMeshMem2Mem2D, InsV2AllGatherSoleExecutor,
     304              :     TopoMatchConcurrMesh, CcuTempAllGatherMeshMem2Mem2D);
     305              : INS_REGISTER_IMPL_BY_TEMP(OpType::ALLGATHER, CcuAllGatherMesh1D2Die, InsV2AllGatherSoleExecutor,
     306              :     TopoMatchMesh, CcuTempAllGatherMesh1D2Die);
     307              : #endif
     308              : }  // namespace Hccl
        

Generated by: LCOV version 2.0-1