LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_executor/ins_alg_executor/reduce - ins_reduce_parallel_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 249 0
Test Date: 2026-07-28 12:11:00 Functions: 0.0 % 42 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_reduce_parallel_executor.h"
      12              : #include <cmath>
      13              : #include "log.h"
      14              : #include "ins_coll_alg_registry.h"
      15              : #include "topo_match_mesh_nhr.h"
      16              : #include "topo_match_mesh_nhr_pcie.h"
      17              : #include "alg_data_trans_wrapper.h"
      18              : #include "ins_temp_reduce_nhr.h"
      19              : #include "ins_temp_reduce_mesh_1D.h"
      20              : #include "ccu_temp_reduce_nhr_1D_mem2mem.h"
      21              : #include "ccu_temp_reduce_mesh_1D_mem2mem.h"
      22              : 
      23              : namespace Hccl {
      24              : constexpr u64 MAX_OFFLOAD_SCRATCH_SIZE = 200 * 1024 * 1024;  // 200M
      25              : 
      26              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
      27            0 : InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::InsReduceParallelExecutor()
      28            0 :     : InsCollAlgBase()
      29              : {
      30            0 : }
      31              : 
      32              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
      33            0 : InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::~InsReduceParallelExecutor()
      34              : {
      35            0 : }
      36              : 
      37              : 
      38              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
      39            0 : HcclResult InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::CalcResOffload(
      40              :     const RankGraph *rankGraph, const u64 &dataSize, CollOffloadOpResReq &resReq)
      41              : {
      42            0 :     HCCL_INFO("[InsReduceParallelExecutor] CalcResOffload begins.");
      43              :     (void)dataSize;
      44            0 :     u64 scratchMemSize = MAX_OFFLOAD_SCRATCH_SIZE;
      45            0 :     resReq.requiredScratchMemSize = scratchMemSize; // 200MB
      46              :     // Topo Match
      47            0 :     AlgTopoMatch topoMatch(myRank_, rankSize_, rankGraph, devType_);
      48            0 :     CHK_RET(topoMatch.MatchTopo(vTopo_, virtRanks_, virtRankMap_));
      49            0 :     CHK_RET(CalcLocalRankSize(myRank_, virtRanks_, intraLocalRankSize_, interLocalRankSize_));
      50            0 :     InsAlgTemplate0 intraTempAlg(myRank_, intraLocalRankSize_, vTopo_[0], virtRankMap_[0]);
      51            0 :     InsAlgTemplate1 interTempAlg(myRank_, interLocalRankSize_, vTopo_[1], virtRankMap_[1]);
      52              : 
      53              :     // calculate required insQues and prepare queue
      54            0 :     AlgTempResReq resReqIntra;
      55            0 :     AlgTempResReq resReqInter;
      56            0 :     if (enableDetour_) {
      57            0 :         HCCL_DEBUG("[InsReduceParallelExecutor] Rank[%d], CalcRes with detouring enabled.", myRank_);
      58            0 :         CHK_RET(intraTempAlg.CalcResDetour(rankGraph, resReqIntra));
      59              :     } else {
      60            0 :         HCCL_DEBUG("[InsReduceParallelExecutor] Rank[%d], CalcRes with detouring disabled.", myRank_);
      61            0 :         CHK_RET(intraTempAlg.CalcRes(resReqIntra));
      62              :     }
      63              : 
      64            0 :     CHK_RET(interTempAlg.CalcRes(resReqInter));
      65            0 :     resReq.requiredSubQueNum = resReqIntra.streamNum + resReqInter.streamNum - 1;
      66            0 :     return HcclResult::HCCL_SUCCESS;
      67            0 : }
      68              : 
      69              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
      70            0 : HcclResult InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::CalcRes(
      71              :     const RankGraph *rankGraph, CollAlgResReq &algResReq)
      72              : {
      73            0 :     HCCL_INFO("[InsReduceParallelExecutor] CalcRes begins.");
      74              :     // Topo Match
      75            0 :     AlgTopoMatch topoMatch(myRank_, rankSize_, rankGraph, devType_);
      76            0 :     CHK_RET(topoMatch.MatchTopo(vTopo_, virtRanks_, virtRankMap_));
      77            0 :     algResReq.topoInfo.UpdateMultiLevelTopo(virtRanks_, virtRankMap_, vTopo_);
      78            0 :     CHK_RET(CalcLocalRankSize(myRank_, virtRanks_, intraLocalRankSize_, interLocalRankSize_));
      79              : 
      80              :     // instantiate a template
      81            0 :     InsAlgTemplate0 intraTempAlg(myRank_, intraLocalRankSize_, vTopo_[0], virtRankMap_[0]);
      82            0 :     InsAlgTemplate1 interTempAlg(myRank_, interLocalRankSize_, vTopo_[1], virtRankMap_[1]);
      83              : 
      84              :     // calculate required insQues and prepare queue
      85            0 :     AlgTempResReq resReqIntra;
      86            0 :     AlgTempResReq resReqInter;
      87            0 :     if (enableDetour_) {
      88            0 :         HCCL_DEBUG("[InsReduceParallelExecutor] Rank[%d], CalcRes with detouring enabled.", myRank_);
      89            0 :         CHK_RET(intraTempAlg.CalcResDetour(rankGraph, resReqIntra));
      90              :     } else {
      91            0 :         HCCL_DEBUG("[InsReduceParallelExecutor] Rank[%d], CalcRes with detouring disabled.", myRank_);
      92            0 :         CHK_RET(intraTempAlg.CalcRes(resReqIntra));
      93              :     }
      94            0 :     CHK_RET(interTempAlg.CalcRes(resReqInter));
      95              : 
      96            0 :     CHK_RET(CalcLinkInfo(myRank_, rankGraph, resReqIntra.links, algResReq.levelRankPairs));
      97            0 :     CHK_RET(CalcLinkInfo(myRank_, rankGraph, resReqInter.links, algResReq.levelRankPairs));
      98            0 :     algResReq.primQueueNum = resReqIntra.streamNum + resReqInter.streamNum;
      99            0 :     std::vector<std::tuple<QId, QId, u32>> notifyRequests;
     100              : 
     101            0 :     u32 slaveNum = algResReq.primQueueNum - 1;
     102            0 :     notifyRequests.reserve(slaveNum); //每个从流需要1个
     103            0 :     for (QId q = 1; q < algResReq.primQueueNum; q++) {
     104            0 :         notifyRequests.emplace_back(std::make_tuple(0, q, 0));
     105            0 :         notifyRequests.emplace_back(std::make_tuple(q, 0, 0));
     106              :     }
     107              : 
     108              :     // nhr算法只有一个stream
     109            0 :     for (QId q = resReqIntra.streamNum; q < algResReq.primQueueNum; q++) {
     110            0 :         if(resReqIntra.streamNum == q){
     111            0 :             continue;
     112              :         }
     113            0 :         notifyRequests.emplace_back(std::make_tuple(resReqIntra.streamNum, q, 0));
     114            0 :         notifyRequests.emplace_back(std::make_tuple(q, resReqIntra.streamNum, 0));
     115            0 :         HCCL_DEBUG("[InsReduceParallelExecutor] CalcRes notifyRequests:%u->%u. %u->%u",
     116              :             resReqIntra.streamNum, q, q, resReqIntra.streamNum);
     117              :     }
     118              : 
     119            0 :     algResReq.queueNotifys = notifyRequests;
     120            0 :     HCCL_DEBUG("[InsReduceParallelExecutor] algResReq.primQueueNum %u", algResReq.primQueueNum);
     121            0 :     CHK_RET(CalcResLinks(myRank_, rankGraph, linkPriority_, resReqIntra.links, algResReq.links));
     122            0 :     CHK_RET(CalcResLinks(myRank_, rankGraph, linkPriority_, resReqInter.links, algResReq.links));
     123              : 
     124            0 :     return HcclResult::HCCL_SUCCESS;
     125            0 : }
     126              : 
     127              : // HOST 侧算法入口,将对应的 instruction 添加到指令队列中
     128              : // 传入的insQue为一条主流
     129              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
     130            0 : void InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::GenTemplateAlgParams0(
     131              :     const u64 dataOffset, const u64 dataCount, const u64 scratchOffset, TemplateDataParams &tempAlgParams) const
     132              : {
     133            0 :     tempAlgParams.buffInfo.inBuffType =  BufferType::INPUT;
     134            0 :     tempAlgParams.buffInfo.outBuffType = BufferType::OUTPUT;
     135            0 :     tempAlgParams.buffInfo.scratBuffType = BufferType::SCRATCH;
     136            0 :     tempAlgParams.buffInfo.inBuffBaseOff = dataOffset;
     137            0 :     tempAlgParams.buffInfo.outBuffBaseOff = dataOffset;
     138            0 :     tempAlgParams.buffInfo.scratchBuffBaseOff = scratchOffset;
     139            0 :     tempAlgParams.sliceSize = dataCount * dataTypeSize_;
     140            0 :     tempAlgParams.tailSize = tempAlgParams.sliceSize;
     141            0 :     tempAlgParams.inputSliceStride = 0; // 输入数据仅有 1 个 slice, 不需要 stride
     142            0 :     tempAlgParams.outputSliceStride = 0;
     143            0 :     tempAlgParams.repeatNum = 1;
     144            0 :     return;
     145              : }
     146              : 
     147              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
     148            0 : void InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::GenTemplateAlgParams1(
     149              :     const u64 dataOffset, const u64 dataCount, const u64 scratchOffset, TemplateDataParams &tempAlgParams) const
     150              : {
     151            0 :     tempAlgParams.buffInfo.inBuffType =  BufferType::OUTPUT;
     152            0 :     tempAlgParams.buffInfo.outBuffType = BufferType::OUTPUT;
     153            0 :     tempAlgParams.buffInfo.scratBuffType = BufferType::SCRATCH;
     154            0 :     tempAlgParams.buffInfo.inBuffBaseOff = dataOffset;
     155            0 :     tempAlgParams.buffInfo.outBuffBaseOff = dataOffset;
     156            0 :     tempAlgParams.buffInfo.scratchBuffBaseOff = scratchOffset;
     157            0 :     tempAlgParams.sliceSize = dataCount * dataTypeSize_;
     158            0 :     tempAlgParams.tailSize = tempAlgParams.sliceSize;
     159            0 :     tempAlgParams.inputSliceStride = 0; // 输入数据仅有 1 个 slice, 不需要 stride
     160            0 :     tempAlgParams.outputSliceStride = 0;
     161            0 :     tempAlgParams.repeatNum = 1;
     162            0 :     return;
     163              : }
     164              : 
     165              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
     166            0 : void InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::GetParallelDataSplitRate(
     167              :     std::vector<float> &splitDataSize) const
     168              : {
     169              :     // 先做等分,后续根据性能做调整
     170            0 :     double splitData = 0.5;
     171            0 :     splitDataSize.push_back(static_cast<float>(splitData));
     172            0 :     splitDataSize.push_back(static_cast<float>(splitData));
     173            0 :     return;
     174              : }
     175              : 
     176              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
     177            0 : HcclResult InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::CalcLocalRoot()
     178              : {
     179            0 :     CHK_PRT_RET(root_ >= rankSize_,
     180              :         HCCL_ERROR("[CalcLocalRoot] root[%u] is out of rankSize[%u]", root_, rankSize_),
     181              :         HcclResult::HCCL_E_INTERNAL);
     182              : 
     183            0 :     u32 intraLocalRootIdx = root_ % intraLocalRankSize_;
     184            0 :     intraLocalRoot_ = static_cast<u32>(vTopo_.at(0).at(0).at(intraLocalRootIdx));
     185            0 :     u32 interLocalRootIdx = root_ / intraLocalRankSize_;
     186            0 :     interLocalRoot_ = static_cast<u32>(vTopo_.at(1).at(0).at(interLocalRootIdx));
     187              : 
     188            0 :     HCCL_INFO("[CalcLocalRoot] localRoot: myRank[%d] intraLocalRoot[%u] interLocalRoot[%u]",
     189              :         myRank_, intraLocalRoot_, interLocalRoot_);
     190            0 :     return HcclResult::HCCL_SUCCESS;
     191              : }
     192              : 
     193              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
     194            0 : HcclResult InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::PrepareResForTemplate(
     195              :     const RankGraph *rankGraph, InsAlgTemplate0 &tempAlgIntra, InsAlgTemplate1 &tempAlgInter)
     196              : {
     197            0 :     AlgTempResReq resReqIntra;
     198            0 :     AlgTempResReq resReqInter;
     199            0 :     if (enableDetour_) {
     200            0 :         HCCL_DEBUG("[%s] Rank[%d], detouring enabled.", __func__, myRank_);
     201            0 :         CHK_RET(tempAlgIntra.CalcResDetour(rankGraph, resReqIntra));
     202              :     } else {
     203            0 :         HCCL_DEBUG("[%s] Rank[%d], detouring disabled.", __func__, myRank_);
     204            0 :         CHK_RET(tempAlgIntra.CalcRes(resReqIntra));
     205              :     }
     206            0 :     CHK_RET(tempAlgInter.CalcRes(resReqInter));
     207              : 
     208              :     // 申请算法模板所需资源
     209            0 :     if(!(resReqIntra.queNum > 0 && resReqInter.queNum > 0)) {
     210            0 :         HCCL_ERROR("[InsReduceParallelExecutor]resReqIntra.queNum and resReqInter.queNum must larger than 0.");
     211            0 :         return HcclResult::HCCL_E_INTERNAL;
     212              :     }
     213            0 :     u32 totalQueueNum = resReqIntra.queNum + resReqInter.queNum;
     214            0 :     CHK_RET(InitQueue(totalQueueNum, reqQue_));
     215            0 :     for(u32 i = 0 ; i < reqQue_.size(); i++) {
     216            0 :         if (i < resReqIntra.queNum) {
     217            0 :             intraQue_.push_back(reqQue_[i]);
     218              :         } else {
     219            0 :             interQue_.push_back(reqQue_[i]);
     220              :         }
     221              :     }
     222            0 :     syncQueues_.emplace_back(intraQue_[0]);
     223            0 :     syncQueues_.emplace_back(interQue_[0]);
     224              : 
     225            0 :     CHK_RET(PrepResLinks(myRank_, rankGraph, linkPriority_, resReqIntra.links, intraLinks_));
     226            0 :     CHK_RET(PrepResLinks(myRank_, rankGraph, linkPriority_, resReqInter.links, interLinks_));
     227            0 :     HCCL_INFO("[InsReduceParallelExecutor] intraLinks_ size[%zu], interLinks_ size[%zu]",
     228              :         intraLinks_.size(), interLinks_.size());
     229            0 :     return HCCL_SUCCESS;
     230            0 : }
     231              : 
     232              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
     233            0 : HcclResult InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::PrepareResForTemplate(
     234              :     ConnectedLinkMgr *linkMgr, InsAlgTemplate0 &tempAlgIntra, InsAlgTemplate1 &tempAlgInter)
     235              : {
     236            0 :     AlgTempResReq resReqIntra;
     237            0 :     AlgTempResReq resReqInter;
     238            0 :     if (enableDetour_) {
     239            0 :         HCCL_DEBUG("[%s] Rank[%d], CalcRes with detour enabled", __func__, myRank_);
     240            0 :         CHK_RET(tempAlgIntra.CalcResDetour(linkMgr, resReqIntra));
     241              :     } else {
     242            0 :         CHK_RET(tempAlgIntra.CalcRes(resReqIntra));
     243              :     }
     244            0 :     CHK_RET(tempAlgInter.CalcRes(resReqInter));
     245              : 
     246              :     // 申请算法模板所需资源
     247            0 :     if(!(resReqIntra.queNum > 0 && resReqInter.queNum > 0)) {
     248            0 :         HCCL_ERROR("[InsReduceParallelExecutor]resReqIntra.queNum and resReqInter.queNum must > 0.");
     249            0 :         return HcclResult::HCCL_E_INTERNAL;
     250              :     }
     251            0 :     u32 totalQueueNum = resReqIntra.queNum + resReqInter.queNum;
     252            0 :     CHK_RET(InitQueue(totalQueueNum, reqQue_));
     253            0 :     for(u32 i = 0 ; i < reqQue_.size(); i++) {
     254            0 :         if (i < resReqIntra.queNum) {
     255            0 :             intraQue_.push_back(reqQue_[i]);
     256              :         } else {
     257            0 :             interQue_.push_back(reqQue_[i]);
     258              :         }
     259              :     }
     260            0 :     syncQueues_.emplace_back(intraQue_[0]);
     261            0 :     syncQueues_.emplace_back(interQue_[0]);
     262              : 
     263            0 :     CHK_RET(PrepResLinks(myRank_, resReqIntra.links, linkMgr, intraLinks_));
     264            0 :     CHK_RET(PrepResLinks(myRank_, resReqInter.links, linkMgr, interLinks_));
     265            0 :     HCCL_INFO("[InsReduceParallelExecutor] intraLinks_ size[%zu], interLinks_ size[%zu]", intraLinks_.size(), interLinks_.size());
     266            0 :     return HCCL_SUCCESS;
     267            0 : }
     268              : 
     269              : // Aicpu展开
     270              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
     271            0 : HcclResult InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::Orchestrate(
     272              :     const AlgTopoInfo &topoInfo, const CollAlgOperator &op, const CollAlgParams &params, ConnectedLinkMgr *linkMgr,
     273              :     InsQuePtr insQue)
     274              : {
     275            0 :     HCCL_INFO("[InsReduceParallelExecutor] AICPU Orchestrate begins.");
     276              :     // init and check params
     277            0 :     CHK_RET(Init(op, params, insQue));
     278              :     // 所以获取取级通信域的信息
     279            0 :     vTopo_ = topoInfo.vTopo;               // 本通信域内的通信平面
     280            0 :     virtRankMap_ = topoInfo.virtRankMap;   // 本通信域内的 rank 映射表
     281            0 :     virtRanks_ = topoInfo.virtRanks;       // 本通信域内的 rank 集合
     282              : 
     283              :     // 计算localRankSize和localRoot
     284            0 :     CHK_RET(CalcLocalRankSize(myRank_, virtRanks_, intraLocalRankSize_, interLocalRankSize_));
     285            0 :     CHK_RET(CalcLocalRoot());
     286              : 
     287              :     // 实例化算法模板类
     288            0 :     InsAlgTemplate0 tempAlgIntra(myRank_, intraLocalRankSize_, vTopo_[0], virtRankMap_[0]); //server内算法,比如mesh
     289            0 :     InsAlgTemplate1 tempAlgInter(myRank_, interLocalRankSize_, vTopo_[1], virtRankMap_[1]); //server间算法,比如nhr
     290              : 
     291            0 :     tempAlgIntra.SetDmaMode(dmaMode_);
     292            0 :     tempAlgIntra.InitReduceInfo(redOp_, dataType_);
     293            0 :     tempAlgIntra.SetRoot(intraLocalRoot_);
     294            0 :     tempAlgIntra.SetCollOp(op);
     295              : 
     296            0 :     tempAlgInter.SetDmaMode(dmaMode_);
     297            0 :     tempAlgInter.InitReduceInfo(redOp_, dataType_);
     298            0 :     tempAlgInter.SetRoot(interLocalRoot_);
     299            0 :     tempAlgInter.SetCollOp(op);
     300              : 
     301              :     // 计算算法模板所需资源
     302            0 :     CHK_RET(PrepareResForTemplate(linkMgr, tempAlgIntra, tempAlgInter));
     303            0 :     CHK_RET(GenInsQues(tempAlgIntra, tempAlgInter));
     304            0 :     HCCL_INFO("[InsReduceParallelExecutor] AICPU Orchestrate success.");
     305            0 :     return HcclResult::HCCL_SUCCESS;
     306            0 : }
     307              : 
     308              : // Host展开
     309              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
     310            0 : HcclResult InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::Orchestrate(
     311              :     const RankGraph *rankGraph, const CollAlgOperator &op, const CollAlgParams &params, InsQuePtr insQue)
     312              : {
     313            0 :     HCCL_INFO("[InsReduceParallelExecutor] Host Orchestrate begins.");
     314              :     // init and check params
     315            0 :     CHK_RET(Init(op, params, insQue));
     316              : 
     317              :     // Topo Match
     318            0 :     AlgTopoMatch topoMatch(myRank_, rankSize_, rankGraph, devType_);
     319            0 :     CHK_RET(topoMatch.MatchTopo(vTopo_, virtRanks_, virtRankMap_));
     320              : 
     321              :     // 计算localRankSize和localRoot
     322            0 :     CHK_RET(CalcLocalRankSize(myRank_, virtRanks_, intraLocalRankSize_, interLocalRankSize_));
     323            0 :     CHK_RET(CalcLocalRoot());
     324              : 
     325              :     // 实例化算法模板类
     326            0 :     InsAlgTemplate0 tempAlgIntra(myRank_, intraLocalRankSize_, vTopo_[0], virtRankMap_[0]); //server内算法,比如mesh
     327            0 :     InsAlgTemplate1 tempAlgInter(myRank_, interLocalRankSize_, vTopo_[1], virtRankMap_[1]); //server间算法,比如nhr
     328              : 
     329            0 :     tempAlgIntra.SetDmaMode(dmaMode_);
     330            0 :     tempAlgIntra.SetCollOp(op);
     331            0 :     tempAlgIntra.InitReduceInfo(redOp_, dataType_);
     332            0 :     tempAlgIntra.SetRoot(intraLocalRoot_);
     333              : 
     334            0 :     tempAlgInter.SetDmaMode(dmaMode_);
     335            0 :     tempAlgInter.InitReduceInfo(redOp_, dataType_);
     336            0 :     tempAlgInter.SetCollOp(op);
     337            0 :     tempAlgInter.SetRoot(interLocalRoot_);
     338              : 
     339              :     // 计算算法模板所需资源
     340            0 :     CHK_RET(PrepareResForTemplate(rankGraph, tempAlgIntra, tempAlgInter));
     341            0 :     CHK_RET(GenInsQues(tempAlgIntra, tempAlgInter));
     342            0 :     HCCL_INFO("[InsReduceParallelExecutor] Host Orchestrate success.");
     343            0 :     return HcclResult::HCCL_SUCCESS;
     344            0 : }
     345              : 
     346              : template <typename AlgTopoMatch, typename InsAlgTemplate0, typename InsAlgTemplate1>
     347            0 : HcclResult InsReduceParallelExecutor<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>::GenInsQues(
     348              :     InsAlgTemplate0 &tempAlgIntra, InsAlgTemplate1 &tempAlgInter)
     349              : {
     350            0 :     std::vector<float> dataSplitSize;
     351            0 :     GetParallelDataSplitRate(dataSplitSize);
     352            0 :     u64 alignedSize = 16 * 1024; //假设需要16K对齐
     353            0 :     BufferType inBuffType = BufferType::INPUT;
     354            0 :     BufferType outBuffType = BufferType::OUTPUT;
     355            0 :     u32 intraScatchteMultipleStage0 = tempAlgIntra.CalcScratchMultiple(inBuffType, outBuffType);
     356            0 :     u32 interScatchteMultipleStage0 = tempAlgInter.CalcScratchMultiple(inBuffType, outBuffType);
     357            0 :     u32 intraScatchteMultipleStage1 = tempAlgIntra.CalcScratchMultiple(outBuffType, outBuffType);
     358            0 :     u32 interScatchteMultipleStage1 = tempAlgInter.CalcScratchMultiple(outBuffType, outBuffType);
     359            0 :     u32 scratchMultipleIntra = static_cast<u32>(std::max(std::ceil(dataSplitSize[0] * intraScatchteMultipleStage0),
     360            0 :         std::ceil(dataSplitSize[1] * intraScatchteMultipleStage1)));
     361            0 :     u32 scratchMultipleInter = static_cast<u32>(std::max(std::ceil(dataSplitSize[1] * interScatchteMultipleStage0),
     362            0 :         std::ceil(dataSplitSize[0] * interScatchteMultipleStage1)));
     363            0 :     u32 totalScratchMultiple = scratchMultipleIntra + scratchMultipleInter;
     364            0 :     u64 scratchMemBlockSize = maxTmpMemSize_;
     365            0 :     if (totalScratchMultiple > 0) {
     366            0 :         scratchMemBlockSize = (maxTmpMemSize_ / alignedSize / totalScratchMultiple) * alignedSize;
     367              :     }
     368            0 :     u64 intraScratchOffset = 0;
     369            0 :     u64 interScratchOffset = scratchMultipleIntra * scratchMemBlockSize;
     370              : 
     371              :     // dataSplitSize为分数,这里maxCountPerLoop对10取整
     372            0 :     u64 maxCountPerLoop = (std::min(static_cast<u64>(scratchMemBlockSize),
     373            0 :         static_cast<u64>(UB_MAX_DATA_SIZE)) / dataTypeSize_ / 10) * 10;
     374              : 
     375            0 :     u32 loopTimes = dataCount_ / maxCountPerLoop + ((dataCount_ % maxCountPerLoop == 0) ? 0 : 1);
     376              : 
     377            0 :     TemplateDataParams tempAlgParamsIntra0, tempAlgParamsInter0;
     378            0 :     TemplateDataParams tempAlgParamsInter1, tempAlgParamsIntra1;
     379            0 :     TempFuncs tempFuncs;
     380            0 :     tempFuncs.opMode = opMode_;
     381            0 :     tempFuncs.enableCounterNotify = false;
     382            0 :     tempFuncs.isBottom = true;
     383            0 :     tempFuncs.isForepart = true;
     384            0 :     for (u32 loopIndex = 0; loopIndex < loopTimes; loopIndex++) {
     385            0 :         u64 currCount = (loopIndex == loopTimes - 1) ? (dataCount_ - loopIndex * maxCountPerLoop) : maxCountPerLoop;
     386            0 :         u64 dataCountPerLoopAixs0 = static_cast<u64>(dataSplitSize[0] * currCount);
     387            0 :         u64 dataCountPerLoopAixs1 = currCount - dataCountPerLoopAixs0;
     388              :         //第一步开始前同步
     389              : 
     390            0 :         CHK_RET(PreSyncQues(syncQueues_, 0));
     391            0 :         u64 dataOffset0 = loopIndex * maxCountPerLoop * dataTypeSize_;
     392            0 :         u64 dataOffset1 = dataOffset0 + dataCountPerLoopAixs0 * dataTypeSize_;
     393              :         //数据0的server内的mesh算法
     394            0 :         GenTemplateAlgParams0(dataOffset0, dataCountPerLoopAixs0, intraScratchOffset, tempAlgParamsIntra0);
     395              :         //把每个template需要的queue传进去,比如stars的mesh要传多条queue
     396            0 :         CHK_RET(tempAlgIntra.GenExtIns(tempFuncs, tempAlgParamsIntra0, intraLinks_, intraQue_));
     397              :         //数据1的server间的nhr算法
     398            0 :         GenTemplateAlgParams0(dataOffset1, dataCountPerLoopAixs1, interScratchOffset, tempAlgParamsInter1);
     399            0 :         CHK_RET(tempAlgInter.GenExtIns(tempFuncs, tempAlgParamsInter1, interLinks_, interQue_));
     400              :         //第一步做完后回到主流做尾同步
     401            0 :         CHK_RET(PostSyncQues(syncQueues_, 0));
     402              :         // 只有真正root节点的横纵坐标所在的卡,需要做第二步骤,担任过其中一个root节点的,只需要负责发就行了
     403            0 :         if ((static_cast<u32>(myRank_) != intraLocalRoot_) && (static_cast<u32>(myRank_) != interLocalRoot_)) {
     404            0 :             continue;
     405              :         }
     406              : 
     407              :         //第二步开始前同步
     408            0 :         CHK_RET(PreSyncQues(syncQueues_, 0));
     409            0 :         if (static_cast<u32>(myRank_) == intraLocalRoot_) {
     410              :             //数据0的server间的nhr算法
     411            0 :             GenTemplateAlgParams1(dataOffset0, dataCountPerLoopAixs0, interScratchOffset, tempAlgParamsInter0);
     412            0 :             CHK_RET(tempAlgInter.GenExtIns(tempFuncs, tempAlgParamsInter0, interLinks_, interQue_));
     413              :         }
     414            0 :         if (static_cast<u32>(myRank_) == interLocalRoot_) {
     415              :             //数据1的server内的mesh算法
     416            0 :             GenTemplateAlgParams1(dataOffset1,  dataCountPerLoopAixs1, intraScratchOffset,  tempAlgParamsIntra1);
     417            0 :             CHK_RET(tempAlgIntra.GenExtIns(tempFuncs, tempAlgParamsIntra1, intraLinks_, intraQue_));
     418              :         }
     419              :         //尾同步
     420            0 :         CHK_RET(PostSyncQues(syncQueues_, 0));
     421              :     }
     422            0 :     return HcclResult::HCCL_SUCCESS;
     423            0 : }
     424              : 
     425              : // 算法注册
     426              : INS_REGISTER_IMPL_BY_TWO_TEMPS(OpType::REDUCE, InsReduceParallelMesh1DNHR, InsReduceParallelExecutor, TopoMatchMeshNHR,
     427              :     InsTempReduceMesh1D, InsTempReduceNHR);
     428              : INS_REGISTER_IMPL_BY_TWO_TEMPS(OpType::REDUCE, InsReduceParallelMesh1DNHRPcie, InsReduceParallelExecutor,
     429              :     TopoMatchMeshNHRPcie, InsTempReduceMesh1D, InsTempReduceNHR);
     430              : #ifndef CCL_KERNEL_AICPU
     431              : INS_REGISTER_IMPL_BY_TWO_TEMPS(OpType::REDUCE, CcuReduceParallelMesh1DNHR, InsReduceParallelExecutor, TopoMatchMeshNHR,
     432              :     CcuTempReduceMeshMem2Mem1D, CcuTempReduceNHRMem2Mem1D);
     433              : #endif
     434              : }
        

Generated by: LCOV version 2.0-1