LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/base/alg_template - alg_template_base.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 38.6 % 459 177
Test Date: 2026-08-17 10:19:35 Functions: 39.5 % 81 32

            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 "sal_pub.h"
      12              : #include "alg_template_base.h"
      13              : 
      14              : namespace hccl {
      15          232 : ExecutorBase::ExecutorBase(const HcclDispatcher dispatcher)
      16          232 :     : dispatcher_(dispatcher),
      17          232 :       slices_(slicesDummy_),
      18          232 :       count_(0),
      19          232 :       dataBytes_(0),
      20          232 :       dataType_(HCCL_DATA_TYPE_RESERVED),
      21          232 :       reductionOp_(HCCL_REDUCE_RESERVED),
      22          232 :       root_(INVALID_VALUE_RANKID),
      23          232 :       baseOffset_(0),
      24          232 :       barrierSwitchOn_(true)
      25          232 : {}
      26              : 
      27          232 : ExecutorBase::~ExecutorBase() { slices_.clear(); }
      28              : 
      29            1 : HcclResult ExecutorBase::Prepare(PrepareData& param) { return HCCL_E_PARA; }
      30              : 
      31              : // prepare函数给需要进行集合通信操作进行参数赋值
      32          113 : HcclResult ExecutorBase::Prepare(
      33              :     DeviceMem& inputMem, DeviceMem& outputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType,
      34              :     const Stream& stream, const HcclReduceOp reductionOp, const u32 root, const std::vector<Slice>& slices,
      35              :     const u64 baseOffset, std::vector<u32> nicRankList, const bool disableDMAReduce)
      36              : {
      37              :     // 部分集合通信操作允许input_mem/output_mem为空
      38              : 
      39              :     /* * 参数保存 */
      40          113 :     inputMem_ = inputMem;
      41          113 :     outputMem_ = outputMem;
      42          113 :     scratchMem_ = scratchMem;
      43          113 :     stream_ = stream;
      44          113 :     count_ = count;
      45          113 :     dataType_ = dataType;
      46          113 :     dataBytes_ = count * DataUnitSize(dataType);
      47          113 :     reductionOp_ = reductionOp;
      48          113 :     HCCL_DEBUG("[ExecutorBase][Prepare]count is %lu, reductionOp is %d", count_, reductionOp_);
      49          113 :     root_ = root;
      50          113 :     disableDMAReduce_ = disableDMAReduce;
      51          113 :     HCCL_DEBUG("ExecutorBase prepare start");
      52              : 
      53              :     /* 相对用户基地址偏移 */
      54          113 :     baseOffset_ = baseOffset;
      55              : 
      56          113 :     if (slices.size() > 0) {
      57           37 :         slices_.resize(slices.size());
      58           37 :         slices_ = slices;
      59              :     }
      60              : 
      61          113 :     nicRankList_.assign(nicRankList.begin(), nicRankList.end());
      62              :     // 不带入该参数,代表数据均分,直接用count赋值
      63          113 :     HCCL_DEBUG("ExecutorBase prepare end");
      64          113 :     return HCCL_SUCCESS;
      65              : }
      66              : 
      67            0 : HcclResult ExecutorBase::Prepare(
      68              :     DeviceMem& inputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType, const Stream& stream,
      69              :     const HcclReduceOp reductionOp, const u32 root, const std::vector<Slice>& slices, const u64 baseOffset,
      70              :     std::vector<u32> nicRankList, const bool disableDMAReduce)
      71              : {
      72              :     // 部分集合通信操作允许input_mem/output_mem为空
      73            0 :     CHK_PTR_NULL(stream.ptr());
      74              : 
      75            0 :     HCCL_DEBUG("ExecutorBase prepare start");
      76              : 
      77              :     /* * 参数保存 */
      78            0 :     inputMem_ = inputMem;
      79            0 :     outputMem_ = inputMem;
      80            0 :     scratchMem_ = scratchMem;
      81            0 :     stream_ = stream;
      82            0 :     count_ = count;
      83            0 :     dataType_ = dataType;
      84            0 :     dataBytes_ = count * DataUnitSize(dataType);
      85            0 :     reductionOp_ = reductionOp;
      86            0 :     root_ = root;
      87            0 :     disableDMAReduce_ = disableDMAReduce;
      88              : 
      89              :     /* 相对用户基地址偏移 */
      90            0 :     baseOffset_ = baseOffset;
      91              : 
      92            0 :     if (slices.size() > 0) {
      93            0 :         slices_.resize(slices.size());
      94            0 :         slices_ = slices;
      95              :     }
      96              : 
      97            0 :     nicRankList_.assign(nicRankList.begin(), nicRankList.end());
      98              :     // 不带入该参数,代表数据均分,直接用count赋值
      99            0 :     HCCL_DEBUG("ExecutorBase prepare end");
     100            0 :     return HCCL_SUCCESS;
     101              : }
     102              : 
     103           66 : HcclResult ExecutorBase::Prepare(
     104              :     DeviceMem& inputMem, DeviceMem& outputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType,
     105              :     const Stream& stream, const std::vector<std::vector<Slice>>& multRingsSlices, const HcclReduceOp reductionOp,
     106              :     const u32 root, const u64 baseOffset, const bool disableDMAReduce)
     107              : {
     108              :     // 部分集合通信操作允许input_mem/output_mem为空
     109              : 
     110           66 :     HCCL_DEBUG("AlignedDoubleRing prepare start");
     111              : 
     112              :     /* * 参数保存 */
     113           66 :     inputMem_ = inputMem;
     114           66 :     outputMem_ = outputMem;
     115           66 :     scratchMem_ = scratchMem;
     116           66 :     stream_ = stream;
     117           66 :     count_ = count;
     118           66 :     dataType_ = dataType;
     119           66 :     dataBytes_ = count * DataUnitSize(dataType);
     120           66 :     reductionOp_ = reductionOp;
     121           66 :     root_ = root;
     122           66 :     disableDMAReduce_ = disableDMAReduce;
     123              : 
     124              :     /* 相对用户基地址偏移 */
     125           66 :     baseOffset_ = baseOffset;
     126           66 :     multRingsSlices_.resize(multRingsSlices.size());
     127          198 :     for (u32 ringIndex = 0; ringIndex < multRingsSlices.size(); ringIndex++) {
     128          132 :         if (multRingsSlices[ringIndex].size() > 0) {
     129          132 :             multRingsSlices_[ringIndex].resize(multRingsSlices[ringIndex].size());
     130          132 :             multRingsSlices_[ringIndex] = multRingsSlices[ringIndex];
     131              :         }
     132              :     }
     133              : 
     134           66 :     HCCL_DEBUG("AlignedDoubleRing prepare end");
     135           66 :     return HCCL_SUCCESS;
     136              : }
     137              : 
     138              : /* 1个参数 */
     139              : // AllGatherNHR, ScatterNHR
     140            0 : HcclResult ExecutorBase::Prepare(bool needSaveRankMap) { return HCCL_E_PARA; }
     141              : 
     142              : // GatherStar
     143            0 : HcclResult ExecutorBase::Prepare(u32 userRank) { return HCCL_E_PARA; }
     144              : 
     145              : // AHC 扩展参数
     146            0 : HcclResult ExecutorBase::Prepare(AHCExtendPreparePara& extendParam) { return HCCL_E_PARA; }
     147              : 
     148              : /* 2个参数 */
     149              : // ReduceScatterNB, ReduceScatterNHRV1, ReduceScatterRing, ReduceScatterRecursiveHalvingDoubling
     150            1 : HcclResult ExecutorBase::Prepare(u64 reduceAttrBitMap, HcomCollOpInfo* opInfo) { return HCCL_E_PARA; }
     151              : 
     152              : // ReduceScatterNHR
     153            1 : HcclResult ExecutorBase::Prepare(u64 reduceAttrBitMap, bool needMerge) { return HCCL_E_PARA; }
     154              : 
     155              : // ReduceScatterMeshMixSingleStream, ReduceScatterMesh
     156            1 : HcclResult ExecutorBase::Prepare(u64 reduceAttrBitMap, u32 streamIndex) { return HCCL_E_PARA; }
     157              : 
     158              : // ScatterMesh
     159            0 : HcclResult ExecutorBase::Prepare(u32 interRank, u32 interRankSize) { return HCCL_E_PARA; }
     160              : 
     161              : /* 3个参数 */
     162              : // for AllGatherHalvingDoubling based on intput_scratch_Mem_nicRankList Prepare
     163              : // and should be called soon template AllGatherHalvingDoubling created
     164            0 : HcclResult ExecutorBase::Prepare(u32 blockSize, UserMemType hdInputMemType, UserMemType hdOutputMemType)
     165              : {
     166            0 :     return HCCL_E_PARA;
     167              : }
     168              : 
     169              : /* 4个参数 */
     170              : // ScatterRingDirect
     171            0 : HcclResult ExecutorBase::Prepare(
     172              :     HcomCollOpInfo* opInfo, const u32 userRank, const std::vector<u32>& ringsOrders,
     173              :     const std::vector<Slice>& userMemInputSlices)
     174              : {
     175            0 :     return HCCL_E_PARA;
     176              : }
     177              : 
     178              : HcclResult
     179            0 : ExecutorBase::Prepare(HcomCollOpInfo* opInfo, u32 userRank, const std::vector<Slice>& userMemOutputSlices, bool isSdma)
     180              : {
     181            0 :     return HCCL_E_PARA;
     182              : }
     183              : 
     184              : /* 5个参数 */
     185              : // AHC 5个参数,带扩展参数
     186            0 : HcclResult ExecutorBase::Prepare(
     187              :     u64 totalCount, const std::vector<std::vector<std::vector<u32>>>& subGroups,
     188              :     std::map<AHCConcOpType, TemplateType>& ahcAlgOption, bool extendFlag, AHCExtendPreparePara extendPara)
     189              : {
     190            0 :     return HCCL_E_PARA;
     191              : }
     192              : 
     193              : /* 6个参数 */
     194              : // AlltoAllVStagedPairwise
     195            1 : HcclResult ExecutorBase::Prepare(
     196              :     DeviceMem& sendMem, DeviceMem& recvMem, StageAlltoAllVAddrInfo& sendAddrInfo, StageAlltoAllVAddrInfo& recvAddrInfo,
     197              :     bool isAlltoAllZCopyMode, Stream& mainStream)
     198              : {
     199            1 :     return HCCL_E_PARA;
     200              : }
     201              : 
     202              : /* 7个参数 */
     203            0 : HcclResult ExecutorBase::Prepare(
     204              :     u64 reduceAttrBitMap, std::vector<Stream>& meshStreams, std::vector<std::shared_ptr<LocalNotify>>& meshSignal,
     205              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux, u32 userRank, HcomCollOpInfo* opInfo, bool aicpu)
     206              : {
     207            0 :     return HCCL_E_PARA;
     208              : }
     209              : 
     210              : // AlltoAllVPairWise
     211            1 : HcclResult ExecutorBase::Prepare(
     212              :     AlltoAllVBufferInfo& sendBuffer, AlltoAllVBufferInfo& recvBuffer, bool isAlltoAllZCopyMode, const Stream& stream,
     213              :     HcclWorkflowMode workMode, std::map<u32, std::vector<u64>>& rankSendDisplsMap,
     214              :     std::map<u32, std::vector<u64>>& rankRecvDisplsMap)
     215              : {
     216            1 :     return HCCL_E_PARA;
     217              : }
     218              : 
     219              : // AlignedAllGatherDoubleRing
     220            0 : HcclResult ExecutorBase::Prepare(
     221              :     HcomCollOpInfo* opInfo, const u32 userRank, std::vector<Stream>& subStreams,
     222              :     std::vector<std::shared_ptr<LocalNotify>>& mainSignals, std::vector<std::shared_ptr<LocalNotify>>& subSignals,
     223              :     const std::vector<std::vector<u32>>& ringsOrders,
     224              :     const std::vector<std::vector<Slice>>& userMemOutputSlicesOfDoubleRing)
     225              : {
     226            0 :     return HCCL_E_PARA;
     227              : }
     228              : 
     229              : // AllGatherMeshAtomic, AllgatherMeshDirect, AllGatherMesh, AllgatherMeshMix GatherMesh
     230            0 : HcclResult ExecutorBase::Prepare(
     231              :     std::vector<Stream>& meshStreams, std::vector<std::shared_ptr<LocalNotify>>& meshSignal,
     232              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux, u32 userRank, HcomCollOpInfo* opInfo, u32 interRank,
     233              :     u32 interRankSize)
     234              : {
     235            0 :     return HCCL_E_PARA;
     236              : }
     237              : 
     238              : /* 8个参数 */
     239            0 : HcclResult ExecutorBase::Prepare(
     240              :     u64 reduceAttrBitMap, std::vector<Stream>& meshStreams, std::vector<std::shared_ptr<LocalNotify>>& meshSignal,
     241              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux, u32 interRank, u32 interRankSize, u32 userRank,
     242              :     HcomCollOpInfo* opInfo)
     243              : {
     244            0 :     return HCCL_E_PARA;
     245              : }
     246              : 
     247              : // AlltoAllVStagedPairwise
     248            1 : HcclResult ExecutorBase::Prepare(
     249              :     DeviceMem& sendMem, DeviceMem& recvMem, DeviceMem& scratchInputMem, DeviceMem& scratchOutputMem,
     250              :     StageAlltoAllVAddrInfo& sendAddrInfo, StageAlltoAllVAddrInfo& recvAddrInfo, bool isAlltoAllZCopyMode,
     251              :     Stream& mainStream)
     252              : {
     253            1 :     return HCCL_E_PARA;
     254              : }
     255              : 
     256              : // AllGatherRingConcurrentDirect ScatterRingConcurrentDirect
     257            0 : HcclResult ExecutorBase::Prepare(
     258              :     HcomCollOpInfo* opInfo, const u32 userRank, std::vector<Stream>& subStreams,
     259              :     const std::vector<std::shared_ptr<LocalNotify>>& mainSignals,
     260              :     const std::vector<std::shared_ptr<LocalNotify>>& subSignals, const std::vector<u32>& ringsOrder,
     261              :     const std::vector<Slice>& userMemSlices, bool isSdma)
     262              : {
     263            0 :     return HCCL_E_PARA;
     264              : }
     265              : 
     266              : /* 9个参数 */
     267              : // catterDoubleRingDirect
     268            0 : HcclResult ExecutorBase::Prepare(
     269              :     HcomCollOpInfo* opInfo, const u32 userRank, const u32 subRingRank, std::vector<Stream>& subStreams,
     270              :     const std::vector<std::shared_ptr<LocalNotify>>& mainSignals,
     271              :     const std::vector<std::shared_ptr<LocalNotify>>& subSignals, const std::vector<std::vector<u32>>& ringsOrders,
     272              :     const std::vector<std::vector<Slice>>& multiRingSlices, const std::vector<std::vector<Slice>>& userMemInputSlices)
     273              : {
     274            0 :     return HCCL_E_PARA;
     275              : }
     276              : 
     277              : // ReduceScatterRingConcurrentDirect
     278            1 : HcclResult ExecutorBase::Prepare(
     279              :     const u64 reduceAttrBitMap, const HcomCollOpInfo* opInfo, const u32 userRank, std::vector<Stream>& subStreams,
     280              :     const std::vector<std::shared_ptr<LocalNotify>>& mainSignals,
     281              :     const std::vector<std::shared_ptr<LocalNotify>>& subSignals, const std::vector<u32>& ringsOrder,
     282              :     const std::vector<Slice>& userMemInputSlices, bool isSdma)
     283              : {
     284            1 :     return HCCL_E_PARA;
     285              : }
     286              : 
     287              : // AlltoAllVPairWise
     288            1 : HcclResult ExecutorBase::Prepare(
     289              :     AlltoAllVBufferInfo& sendBuffer, AlltoAllVBufferInfo& recvBuffer, DeviceMem& scratchInputMem,
     290              :     DeviceMem& scratchOutputMem, bool isAlltoAllZCopyMode, const Stream& stream, HcclWorkflowMode workMode,
     291              :     std::map<u32, std::vector<u64>>& rankSendDisplsMap, std::map<u32, std::vector<u64>>& rankRecvDisplsMap)
     292              : {
     293            1 :     return HCCL_E_PARA;
     294              : }
     295              : 
     296              : /* 10个参数 */
     297            0 : HcclResult ExecutorBase::Prepare(
     298              :     const HcomCollOpInfo* opInfo, DeviceMem& cclBufferA, DeviceMem& cclBufferB, const u64 count,
     299              :     const SubCommInfo& level1CommInfo, const SubCommInfo& level0CommInfo, Stream& mainStream,
     300              :     std::vector<Stream>& subStream, std::vector<std::shared_ptr<LocalNotify>>& notifyMain,
     301              :     std::vector<std::shared_ptr<LocalNotify>>& notifySub)
     302              : {
     303            0 :     return HCCL_E_PARA;
     304              : }
     305              : 
     306              : // AlltoallPipelineMeshPairwiseCCLEnough, AlltoallPipelineMeshPairwisePingPong
     307            0 : HcclResult ExecutorBase::Prepare(
     308              :     u32 userRank, A2aPipelineMemory A2aPipelineMemory, const SubCommInfo& level0CommInfo,
     309              :     const SubCommInfo& level1CommInfo, Stream& mainStream, std::vector<Stream>& subStream,
     310              :     std::vector<std::shared_ptr<LocalNotify>>& notifyMain, std::vector<std::shared_ptr<LocalNotify>>& notifySub,
     311              :     std::vector<SendRecvInfo>& allMeshAggregationSendRecvInfo, HcclWorkflowMode workMode)
     312              : {
     313            0 :     return HCCL_E_PARA;
     314              : }
     315              : 
     316              : // AlltoAllVStagedMesh
     317            1 : HcclResult ExecutorBase::Prepare(
     318              :     DeviceMem& sendMem, DeviceMem& recvMem, StageAlltoAllVAddrInfo& sendAddrInfo, StageAlltoAllVAddrInfo& recvAddrInfo,
     319              :     bool isAlltoAllZCopyMode, u32 userRank, Stream& mainStream, std::vector<Stream>& subStreams,
     320              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignalMainToSub,
     321              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignalSubToMain)
     322              : {
     323            1 :     return HCCL_E_PARA;
     324              : }
     325              : 
     326              : // ReduceScatterPlantLocalReduceCombine
     327            0 : HcclResult ExecutorBase::Prepare(
     328              :     DeviceMem& cclInMem, DeviceMem& outputMem, const Stream& stream, std::vector<Stream>& subStreams,
     329              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignal, std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux,
     330              :     MemBlockInfo& memBlockInfo, const HcclReduceOp reductionOp, const HcclDataType dataType, bool isUseCclIn,
     331              :     bool isLevel0LastRank, bool isNeedSpaceBorrow)
     332              : {
     333              :     (void)isUseCclIn;
     334              :     (void)memBlockInfo;
     335              :     (void)isLevel0LastRank;
     336              :     (void)isNeedSpaceBorrow;
     337            0 :     return HCCL_E_PARA;
     338              : }
     339              : 
     340              : /* 11个参数 */
     341              : // Prepare for AllGatherPipeline
     342            0 : HcclResult ExecutorBase::Prepare(
     343              :     HcomCollOpInfo* opInfo, u32 userRank, u64& count, DeviceMem& cclBufferPartOne, DeviceMem& cclBufferPartTwo,
     344              :     SubCommInfo& level0CommInfo, SubCommInfo& level1CommInfo, Stream& mainStream, std::vector<Stream>& subStream,
     345              :     std::vector<std::shared_ptr<LocalNotify>>& notifyMain, std::vector<std::shared_ptr<LocalNotify>>& notifySub)
     346              : {
     347            0 :     return HCCL_E_PARA;
     348              : }
     349              : 
     350              : // Prepare for AllGatherUnifiedMarch
     351            0 : HcclResult ExecutorBase::Prepare(
     352              :     const Stream& mainStream, SubCommInfo& level0CommInfo, DeviceMem& userInput, DeviceMem& userOutput,
     353              :     DeviceMem& usrInMem, DeviceMem& usrOutMem, u64 blockDataByte, std::vector<Stream>& subStreams,
     354              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignalMainToSub,
     355              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignalSubToMain,
     356              :     const std::vector<std::vector<Slice>>& multRingsUserMemSlice, const u64 baseOffset)
     357              : {
     358            0 :     return HCCL_E_PARA;
     359              : }
     360              : 
     361              : // Prepare for ReduceScatterPlantLocalReduce
     362            0 : HcclResult ExecutorBase::Prepare(
     363              :     void* inputMemPtr, DeviceMem& cclInMem, DeviceMem& outputMem, const Stream& stream, std::vector<Stream>& subStreams,
     364              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignal, std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux,
     365              :     GroupSlicesInfo& grouSlicesInfo, const HcclReduceOp reductionOp, u32 all2allOffset, const HcclDataType dataType,
     366              :     bool isNeedSpaceBorrow, bool reverseMemUsage, bool isA3CrossNode)
     367              : {
     368              :     (void)inputMemPtr;
     369              :     (void)all2allOffset;
     370              :     (void)grouSlicesInfo;
     371              :     (void)isNeedSpaceBorrow;
     372            0 :     return HCCL_E_PARA;
     373              : }
     374              : 
     375              : // Prepare for ReduceScatterVPipeline
     376            0 : HcclResult ExecutorBase::Prepare(
     377              :     HcomCollOpInfo* opInfo, DeviceMem& cclBuffer, const u64 bufferSize, const std::vector<Slice>& slices,
     378              :     const SubCommInfo& level0CommInfo, const SubCommInfo& level1CommInfo, Stream& mainStream,
     379              :     std::vector<Stream>& subStream, std::vector<std::shared_ptr<LocalNotify>>& notifyMain,
     380              :     std::vector<std::shared_ptr<LocalNotify>>& notifySub, u64 reduceAttrBitMap)
     381              : {
     382            0 :     return HCCL_E_PARA;
     383              : }
     384              : 
     385            0 : HcclResult ExecutorBase::Prepare(
     386              :     const u32 userRank, const A2aPipelineMemory& a2aPipelineMemory, const SubCommInfo& level0CommInfo,
     387              :     const SubCommInfo& level1CommInfo, const Stream& mainStream, std::vector<Stream>& subStream,
     388              :     std::vector<std::shared_ptr<LocalNotify>>& notifyMain, std::vector<std::shared_ptr<LocalNotify>>& notifySub,
     389              :     std::vector<SendRecvInfo>& sendRecvInfoList, const HcclDataType dataType, const HcclWorkflowMode workMode)
     390              : {
     391              :     (void)a2aPipelineMemory;
     392              :     (void)sendRecvInfoList;
     393            0 :     return HCCL_E_PARA;
     394              : }
     395              : 
     396              : /* 12个参数 */
     397              : // AlltoAllVFor310P
     398            1 : HcclResult ExecutorBase::Prepare(
     399              :     DeviceMem& userInput, DeviceMem& userOutput, DeviceMem& cclInMem, DeviceMem& cclOutMem,
     400              :     const std::vector<std::shared_ptr<LocalNotify>>& signalMainToSub,
     401              :     const std::vector<std::shared_ptr<LocalNotify>>& signalSubToMain, Stream& mainStream,
     402              :     std::vector<Stream>& subStreams, const std::vector<LINK>& links, u32 userRank, u32 userRankSize,
     403              :     std::vector<SendRecvInfo>& allMeshAggregationSendRecvInfo)
     404              : {
     405            1 :     return HCCL_E_PARA;
     406              : }
     407              : 
     408              : // AlltoAllVStagedMesh
     409            1 : HcclResult ExecutorBase::Prepare(
     410              :     DeviceMem& sendMem, DeviceMem& recvMem, DeviceMem& scratchInputMem, DeviceMem& scratchOutputMem,
     411              :     StageAlltoAllVAddrInfo& sendAddrInfo, StageAlltoAllVAddrInfo& recvAddrInfo, bool isAlltoAllZCopyMode, u32 userRank,
     412              :     Stream& mainStream, std::vector<Stream>& subStreams, std::vector<std::shared_ptr<LocalNotify>>& meshSignalMainToSub,
     413              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignalSubToMain)
     414              : {
     415            1 :     return HCCL_E_PARA;
     416              : }
     417              : 
     418              : // ReduceScatterPipeline
     419            1 : HcclResult ExecutorBase::Prepare(
     420              :     HcomCollOpInfo* opInfo, DeviceMem& cclBuffer, const u64 count, const u64 bufferSize, const u64 offset,
     421              :     const SubCommInfo& level0CommInfo, const SubCommInfo& level1CommInfo, Stream& mainStream,
     422              :     std::vector<Stream>& subStream, std::vector<std::shared_ptr<LocalNotify>>& notifyMain,
     423              :     std::vector<std::shared_ptr<LocalNotify>>& notifySub, u64 reduceAttrBitMap)
     424              : {
     425            1 :     return HCCL_E_PARA;
     426              : }
     427              : 
     428              : // BroadcastStar
     429            1 : HcclResult ExecutorBase::Prepare(
     430              :     DeviceMem& inputMem, DeviceMem& outputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType,
     431              :     const Stream& stream, const HcclReduceOp reductionOp, const u32 root, const std::vector<Slice>& slices,
     432              :     const u64 baseOffset, std::vector<u32> nicRankList, u32 userRank)
     433              : {
     434            1 :     return HCCL_E_PARA;
     435              : }
     436              : 
     437              : // Prepare for AllGatherVPipeline
     438            0 : HcclResult ExecutorBase::Prepare(
     439              :     HcomCollOpInfo* opInfo, u32 userRank, u64& count, DeviceMem& cclBufferPartOne, DeviceMem& cclBufferPartTwo,
     440              :     SubCommInfo& level0CommInfo, SubCommInfo& level1CommInfo, Stream& mainStream, std::vector<Stream>& subStream,
     441              :     std::vector<std::shared_ptr<LocalNotify>>& notifyMain, std::vector<std::shared_ptr<LocalNotify>>& notifySub,
     442              :     std::vector<Slice>& userOutSlice)
     443              : {
     444              :     (void)userOutSlice;
     445            0 :     return HCCL_E_PARA;
     446              : }
     447              : 
     448              : /* 13个参数 */
     449              : // BroadcastHD
     450            1 : HcclResult ExecutorBase::Prepare(
     451              :     DeviceMem& inputMem, DeviceMem& outputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType,
     452              :     const Stream& stream, const HcclReduceOp reductionOp, const u32 root, std::vector<Stream>& meshStreams,
     453              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignal,
     454              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux, u32 interRank, const HcomCollOpInfo* opInfo)
     455              : {
     456            1 :     return HCCL_E_PARA;
     457              : }
     458              : 
     459              : /* 14个参数 */
     460              : // ReduceScatterUnifiedMarch
     461            1 : HcclResult ExecutorBase::Prepare(
     462              :     Stream& mainStream, SubCommInfo& level0CommInfo, DeviceMem& userInput, DeviceMem& userOutput, DeviceMem& usrInMem,
     463              :     DeviceMem& scratchMem, u64 totalCount, std::vector<Stream>& subStreams,
     464              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignalMainToSub,
     465              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignalSubToMain, const HcclDataType dataType,
     466              :     const HcclReduceOp reductionOp, const std::vector<std::vector<Slice>>& multRingsUserMemSlice, u64 reduceAttrBitMap)
     467              : {
     468            1 :     return HCCL_E_PARA;
     469              : }
     470              : 
     471              : // ReduceScatterHalvingDoubling
     472            1 : HcclResult ExecutorBase::Prepare(
     473              :     DeviceMem& inputMem, DeviceMem& outputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType,
     474              :     const Stream& stream, const HcclReduceOp reductionOp, const u32 root, const std::vector<Slice>& slices,
     475              :     const u64 baseOffset, const u32 blockSize, const u64 reduceAttrBitMap, const UserMemType hdInputMemType,
     476              :     const UserMemType hdOutputMemType)
     477              : {
     478            1 :     return HCCL_E_PARA;
     479              : }
     480              : 
     481              : /* 15个参数 */
     482              : // AlltoAllVMeshReadOnly
     483            0 : HcclResult ExecutorBase::Prepare(
     484              :     DeviceMem& userInput, DeviceMem& userOutput, DeviceMem& scratchPingMem, DeviceMem& scratchPongMem,
     485              :     StageAlltoAllVAddrInfo& sendAddrInfo, StageAlltoAllVAddrInfo& recvAddrInfo, HcclWorkflowMode workMode,
     486              :     Stream& mainStream, std::vector<Stream>& subStreams,
     487              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignalMainToSub,
     488              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignalSubToMain, u32 userRank, u32 intraRankSize,
     489              :     const std::vector<LINK>& links, std::vector<SendRecvInfo>& allMeshAggregationSendRecvInfo)
     490              : {
     491            0 :     return HCCL_E_PARA;
     492              : }
     493              : 
     494              : /* 16个参数 */
     495              : // ReduceScatterHDStage, ReduceScatterLocalReduce, ReduceScatterMeshAtomic, ReduceScatterMeshDirect
     496            1 : HcclResult ExecutorBase::Prepare(
     497              :     DeviceMem& inputMem, DeviceMem& outputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType,
     498              :     const Stream& stream, const HcclReduceOp reductionOp, const u32 root, const std::vector<Slice>& slices,
     499              :     const u64 baseOffset, const u64 reduceAttrBitMap, std::vector<Stream>& meshStreams,
     500              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignal, std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux,
     501              :     u32 userRank, const HcomCollOpInfo* opInfo)
     502              : {
     503            1 :     return HCCL_E_PARA;
     504              : }
     505              : 
     506              : /* 17个参数 */
     507              : // ReduceScatterMeshMix
     508            1 : HcclResult ExecutorBase::Prepare(
     509              :     DeviceMem& inputMem, DeviceMem& outputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType,
     510              :     const Stream& stream, const HcclReduceOp reductionOp, const u32 root, const std::vector<Slice>& slices,
     511              :     const u64 baseOffset, const u64 reduceAttrBitMap, std::vector<Stream>& meshStreams,
     512              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignal,
     513              :     const std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux, u32 interRank, u32 interRankSize,
     514              :     HcomCollOpInfo* opInfo)
     515              : {
     516            1 :     return HCCL_E_PARA;
     517              : }
     518              : 
     519              : /* 19个参数 */
     520              : // AlignedReduceScatterDoubleRing, AlignedReduceScatter, DoubleRingWithSerialLocalCopy
     521            1 : HcclResult ExecutorBase::Prepare(
     522              :     DeviceMem& inputMem, DeviceMem& outputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType,
     523              :     const Stream& stream, const std::vector<std::vector<Slice>>& multRingsSlices, const HcclReduceOp reductionOp,
     524              :     const u32 root, const u64 baseOffset, const bool disableDMAReduce, const u64 reduceAttrBitMap,
     525              :     const HcomCollOpInfo* opInfo, const u32 userRank, std::vector<Stream>& subStreams,
     526              :     const std::vector<std::shared_ptr<LocalNotify>>& mainSignals,
     527              :     const std::vector<std::shared_ptr<LocalNotify>>& subSignals, const std::vector<std::vector<u32>>& ringsOrders,
     528              :     const std::vector<std::vector<Slice>>& userMemInputSlicesOfDoubleRing)
     529              : {
     530            1 :     return HCCL_E_PARA;
     531              : }
     532              : 
     533              : // ReduceScatterHccsSio
     534            0 : HcclResult ExecutorBase::Prepare(
     535              :     DeviceMem& inputMem, DeviceMem& outputMem, DeviceMem& scratchMem, const u64 count, const HcclDataType dataType,
     536              :     const Stream& stream, const HcclReduceOp reductionOp, const u32 root, const u64 baseOffset,
     537              :     const u64 reduceAttrBitMap, std::vector<Stream>& meshStreams, std::vector<std::shared_ptr<LocalNotify>>& meshSignal,
     538              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux, u32 userRank, SubCommInfo subCommInfoHccs,
     539              :     SubCommInfo subCommInfoSio, HcomCollOpInfo* opInfo)
     540              : {
     541            0 :     return HCCL_E_PARA;
     542              : }
     543              : 
     544              : // AllGatherHccsSio
     545            0 : HcclResult ExecutorBase::Prepare(
     546              :     SubCommInfo& outerCommInfoHccs, SubCommInfo& outerCommInfoSio, DeviceMem& usrInMem, DeviceMem& usrOutMem,
     547              :     u64 totalCount, const HcclDataType dataType, const Stream& mainStream, std::vector<Stream>& meshStreams,
     548              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignal, std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux,
     549              :     u32 userRank, HcomCollOpInfo* opInfo)
     550              : {
     551            0 :     return HCCL_E_PARA;
     552              : }
     553              : 
     554              : // ReduceScatterDeterPipeline
     555            0 : HcclResult ExecutorBase::Prepare(
     556              :     HcomCollOpInfo* opInfo, DeviceMem& buffer, const u64 count, const u64 offset, const std::vector<Slice>& slices,
     557              :     const SubCommInfo& level0CommInfo, const SubCommInfo& level1CommInfo, Stream& mainStream,
     558              :     std::vector<Stream>& subStream, std::vector<std::shared_ptr<LocalNotify>>& notifyMain,
     559              :     std::vector<std::shared_ptr<LocalNotify>>& notifySub)
     560              : {
     561            0 :     return HCCL_E_PARA;
     562              : }
     563              : 
     564              : // AllReduceDeterPipeline
     565            0 : HcclResult ExecutorBase::Prepare(
     566              :     HcomCollOpInfo* opInfo, DeviceMem& inBuffer, DeviceMem& outBuffer, const u64 count,
     567              :     const std::vector<Slice>& slices, const SubCommInfo& level0CommInfo, const SubCommInfo& level1CommInfo,
     568              :     Stream& mainStream, std::vector<Stream>& subStream, std::vector<std::shared_ptr<LocalNotify>>& notifyMain,
     569              :     std::vector<std::shared_ptr<LocalNotify>>& notifySub)
     570              : {
     571            0 :     return HCCL_E_PARA;
     572              : }
     573              : 
     574          146 : HcclResult ExecutorBase::RegisterProfiler(s32 planeId, s32 stage, s32 step, const Stream& stream)
     575              : {
     576          146 :     profilerInput_.streamID = stream.id();
     577          146 :     profilerInput_.planeID = planeId;
     578          146 :     profilerInput_.stage = stage;
     579          146 :     profilerInput_.step = step;
     580          146 :     return HCCL_SUCCESS;
     581              : }
     582              : 
     583            0 : HcclResult ExecutorBase::RunAsync() { return HCCL_SUCCESS; }
     584              : 
     585              : HcclResult
     586            0 : ExecutorBase::RunAsync(const u32 rank, const u32 rankSize, const std::vector<std::shared_ptr<Transport>>& links)
     587              : {
     588              :     (void)rank;
     589              :     (void)rankSize;
     590              :     (void)links;
     591            0 :     return HCCL_SUCCESS;
     592              : }
     593              : 
     594            0 : HcclResult ExecutorBase::RunAsyncStaged(
     595              :     const u32 rank, const u32 rankSize, const std::vector<std::shared_ptr<Transport>>& links, RunStage stage)
     596              : {
     597              :     (void)rank;
     598              :     (void)rankSize;
     599              :     (void)links;
     600              :     (void)stage;
     601            0 :     return HCCL_SUCCESS;
     602              : }
     603              : 
     604            0 : void ExecutorBase::CalcBinaryBlockParams(
     605              :     u32 rank, u32 rankSize, u32& stepsInBlock, u32& lowerBlockSize, u32& myBlockSize, u32& rankInMyBlock,
     606              :     u32& myBlockOffset, u32& higherBlockSize)
     607              : {
     608            0 :     u32 offset = rankSize;
     609            0 :     u32 blockSize = 1;
     610              : 
     611            0 :     u32 currentBlockSize = 0;
     612            0 :     u32 preBlockSize = 0;
     613            0 :     while (offset != 0) {
     614            0 :         if ((rankSize & blockSize) != 0) {
     615            0 :             preBlockSize = currentBlockSize;
     616            0 :             currentBlockSize = blockSize;
     617            0 :             if (blockSize == 0) {
     618            0 :                 HCCL_ERROR("[Calc][BinaryBlockParams]calculate_binary_block_paras: blockSize[%u] is zero", blockSize);
     619            0 :                 break;
     620              :             }
     621            0 :             offset -= blockSize;
     622            0 :             if (myBlockSize != 0) {
     623            0 :                 higherBlockSize = currentBlockSize;
     624            0 :                 break;
     625              :             }
     626            0 :             if (offset <= rank) {
     627            0 :                 myBlockOffset = offset;
     628            0 :                 myBlockSize = currentBlockSize;
     629            0 :                 lowerBlockSize = preBlockSize;
     630              :             }
     631              :         }
     632            0 :         blockSize <<= 1;
     633              :     }
     634            0 :     stepsInBlock = SalLog2(myBlockSize);
     635            0 :     if (myBlockSize != 0) {
     636            0 :         rankInMyBlock = rank % myBlockSize;
     637              :     }
     638            0 : }
     639            6 : std::vector<bool> ExecutorBase::CalcLinksRelation(
     640              :     const u32 rank, const u32 rankSize, const u32 rootRank, HalvingDoublingType algorithmType)
     641              : {
     642            6 :     HCCL_INFO(
     643              :         "Calculate links relation: Rank[%u], RankSize[%u], RootRank[%u], HDType[%d]", rank, rankSize, rootRank,
     644              :         algorithmType);
     645            6 :     std::vector<bool> linkRelation(rankSize, false);
     646              : 
     647              :     HcclResult ret;
     648            6 :     switch (algorithmType) {
     649            6 :         case HalvingDoublingType::RECURSIVE_HALVING_DOUBLING:
     650            6 :             CalcRecursiveHalvingDobuleLinkReleation(rank, rankSize, rootRank, linkRelation);
     651            6 :             break;
     652            0 :         case HalvingDoublingType::BINARY_BLOCK_HALVING_DOUBLING:
     653              :         default:
     654            0 :             ret = CalcBinaryBlockHalvingDoubleLinkReleation(rank, rankSize, linkRelation);
     655            0 :             if (ret == HCCL_E_PARA) {
     656            0 :                 HCCL_ERROR(
     657              :                     "[Calc][LinksRelation]errNo[0x%016llx] Calculation binary block parameter error",
     658              :                     HCCL_ERROR_CODE(HCCL_E_PARA));
     659            0 :                 for (u32 i = 0; i < rankSize; i++) {
     660            0 :                     linkRelation[i] = false;
     661              :                 }
     662            0 :                 return linkRelation;
     663              :             }
     664            0 :             break;
     665              :     }
     666              : 
     667              :     // 打印建链关系
     668            6 :     std::string strLinkRelation;
     669            6 :     u32 index = 0;
     670           18 :     for (auto link : linkRelation) {
     671           12 :         if (link) {
     672            6 :             strLinkRelation.append(std::to_string(index));
     673              :         }
     674           12 :         if (index < linkRelation.size() - 1) {
     675            6 :             strLinkRelation.append(", ");
     676              :         }
     677           12 :         index++;
     678              :     }
     679            6 :     HCCL_DEBUG("Rank[%u] has link to these Ranks: %s", rank, strLinkRelation.c_str());
     680              : 
     681            6 :     return linkRelation;
     682            0 : }
     683              : 
     684              : // 将数据均分,最小单位是128
     685           16 : HcclResult ExecutorBase::PrepareSliceData(
     686              :     u64 dataCount, u32 unitSize, u32 sliceNum, u64 piplineOffset, std::vector<Slice>& dataSlice)
     687              : {
     688           16 :     Slice temp;
     689           16 :     u64 totalSize = dataCount * unitSize;
     690           16 :     dataSlice.clear();
     691           16 :     dataSlice.reserve(sliceNum);
     692           16 :     CHK_PRT_RET((sliceNum == 0), HCCL_ERROR("[Prepare][SliceData]data slice prepare, sliceNum is 0"), HCCL_E_PARA);
     693           16 :     u64 tempPerSlice = (totalSize + sliceNum - 1) / sliceNum; /* 1是为了向上取整 */
     694           16 :     u64 sizePerSlice = RoundUpWithDivisor(tempPerSlice, HCCL_MIN_SLICE_ALIGN);
     695           16 :     HCCL_DEBUG(
     696              :         "total_size:%llu sliceNum:%u temp_per_ring:%llu size_per_ring:%llu", totalSize, sliceNum, tempPerSlice,
     697              :         sizePerSlice);
     698           16 :     u64 residueSize = totalSize;
     699           16 :     u32 i = 0;
     700           56 :     while (residueSize > 0) {
     701           40 :         u64 sliceSize = sizePerSlice < residueSize ? sizePerSlice : residueSize;
     702           40 :         temp.size = sliceSize;
     703           40 :         temp.offset = totalSize - residueSize + piplineOffset;
     704           40 :         i++;
     705           40 :         CHK_PRT_RET(
     706              :             (sliceSize <= 0), HCCL_ERROR("[Prepare][SliceData]data_slice_prepare sliceSize[%llu]", sliceSize),
     707              :             HCCL_E_PARA);
     708           40 :         residueSize -= sliceSize;
     709           40 :         dataSlice.push_back(temp);
     710              :     }
     711           16 :     while (i < sliceNum) {
     712            0 :         temp.size = 0;
     713            0 :         temp.offset = totalSize + piplineOffset;
     714            0 :         i++;
     715            0 :         dataSlice.push_back(temp);
     716              :     }
     717           16 :     return HCCL_SUCCESS;
     718              : }
     719              : 
     720              : // 数据切分到每个stream上,最小单位是128
     721            0 : HcclResult ExecutorBase::PrepareSliceMeshStreams(
     722              :     const std::vector<Slice>& rankSegsSlice, u32 streamCount, std::vector<std::vector<Slice>>& mutliStreamsSlices)
     723              : {
     724            0 :     std::vector<u64> rankStreamSize;
     725            0 :     std::vector<u64> rankResidueSize;
     726            0 :     rankStreamSize.reserve(rankSegsSlice.size());
     727            0 :     rankResidueSize.reserve(rankSegsSlice.size());
     728            0 :     mutliStreamsSlices.clear();
     729            0 :     mutliStreamsSlices.reserve(streamCount);
     730            0 :     if (streamCount == 0) {
     731            0 :         HCCL_ERROR("[Prepare][SliceMeshStreams]data slice mesh prepare, streamCount is 0");
     732            0 :         return HCCL_E_PARA;
     733              :     }
     734            0 :     for (u32 rankId = 0; rankId < rankSegsSlice.size(); rankId++) {
     735            0 :         u64 rankDataSize = rankSegsSlice[rankId].size;
     736            0 :         u64 sizePerStream = (rankDataSize + streamCount - 1) / streamCount;
     737            0 :         u64 sizeAlgin = ExecutorBase::RoundUpWithDivisor(sizePerStream, HCCL_MIN_SLICE_ALIGN);
     738            0 :         rankStreamSize.push_back(sizeAlgin);
     739            0 :         rankResidueSize.push_back(rankDataSize);
     740              :     }
     741              : 
     742            0 :     for (u32 streamIndex = 0; streamIndex < streamCount; streamIndex++) {
     743            0 :         std::vector<Slice> singleStreamSlices;
     744            0 :         singleStreamSlices.reserve(rankSegsSlice.size());
     745            0 :         for (u32 rankId = 0; rankId < rankSegsSlice.size(); rankId++) {
     746            0 :             Slice rankSliceTemp;
     747            0 :             u64 rankDataResidue = rankResidueSize[rankId];
     748            0 :             u64 singleStreamSize = 0;
     749            0 :             if (rankDataResidue > 0) {
     750            0 :                 singleStreamSize = rankStreamSize[rankId] < rankDataResidue ? rankStreamSize[rankId] : rankDataResidue;
     751            0 :                 rankSliceTemp.offset = rankSegsSlice[rankId].offset + rankSegsSlice[rankId].size - rankDataResidue;
     752            0 :                 rankSliceTemp.size = singleStreamSize;
     753            0 :                 rankResidueSize[rankId] -= singleStreamSize;
     754              :             } else {
     755            0 :                 rankSliceTemp.offset = rankSegsSlice[rankId].offset;
     756            0 :                 rankSliceTemp.size = 0;
     757              :             }
     758            0 :             singleStreamSlices.push_back(rankSliceTemp);
     759              :         }
     760            0 :         mutliStreamsSlices.push_back(singleStreamSlices);
     761            0 :     }
     762            0 :     return HCCL_SUCCESS;
     763            0 : }
     764              : 
     765              : HcclResult
     766            0 : ExecutorBase::CalcBinaryBlockHalvingDoubleLinkReleation(u32 rank, u32 rankSize, std::vector<bool>& linkRelation)
     767              : {
     768            0 :     u32 stepsInBlock = 0;
     769            0 :     u32 myBlockSize = 0;
     770            0 :     u32 rankInMyBlock = INVALID_VALUE_RANKID;
     771            0 :     u32 myBlockOffset = 0;
     772            0 :     u32 higherBlockSize = 0;
     773            0 :     u32 lowerBlockSize = 0;
     774            0 :     CalcBinaryBlockParams(
     775              :         rank, rankSize, stepsInBlock, lowerBlockSize, myBlockSize, rankInMyBlock, myBlockOffset, higherBlockSize);
     776            0 :     if (lowerBlockSize == 0) {
     777            0 :         HCCL_ERROR("[Calc][BinaryBlockHalvingDoubleLinkReleation]lowerBlockSize size is zero.");
     778            0 :         return HCCL_E_PARA;
     779              :     }
     780            0 :     for (u32 i = 0; i < rankSize; i++) {
     781            0 :         linkRelation[i] = false;
     782              :     }
     783            0 :     u32 dstRankBitmask = 1;
     784            0 :     for (u32 i = 0; i < stepsInBlock; i++) {
     785            0 :         u32 dstRankBitmaskTemp = dstRankBitmask;
     786            0 :         u32 dstRank = rank ^ dstRankBitmaskTemp;
     787            0 :         linkRelation[dstRank] = true;
     788            0 :         dstRankBitmask <<= 1;
     789              :     }
     790            0 :     if (lowerBlockSize != 0) {
     791            0 :         u32 divBlockSize = myBlockSize / lowerBlockSize;
     792            0 :         u32 dstRank = myBlockOffset + myBlockSize + rankInMyBlock / divBlockSize;
     793            0 :         linkRelation[dstRank] = true;
     794              :     }
     795            0 :     if (higherBlockSize != 0) {
     796            0 :         u32 segments = higherBlockSize / myBlockSize; // 和高阶block的rank数差n倍,那么本rank就要向高阶的n个rank发送
     797            0 :         u32 dstRank = (myBlockOffset - higherBlockSize) + rankInMyBlock * segments;
     798            0 :         for (u32 i = 0; i < segments; i++) {
     799            0 :             linkRelation[dstRank] = true;
     800            0 :             dstRank++;
     801              :         }
     802              :     }
     803            0 :     return HCCL_SUCCESS;
     804              : }
     805              : 
     806              : //  用于recursive halving doubling
     807            6 : void ExecutorBase::CalcLinkInBlock(u32 blockSize, u32 rankInBlock, std::list<u32>& linkRankIndexInBlock)
     808              : {
     809            6 :     u32 blockSizeHalving = blockSize / 2; //  每个循环除2计算当前block的折半rank数
     810            6 :     u32 rankInTempBlock = rankInBlock;
     811           12 :     while (blockSizeHalving >= 1) {
     812            6 :         if (rankInTempBlock < blockSizeHalving) {
     813            6 :             linkRankIndexInBlock.push_back(rankInBlock + blockSizeHalving);
     814              :         } else {
     815            0 :             linkRankIndexInBlock.push_back(rankInBlock - blockSizeHalving);
     816            0 :             rankInTempBlock -= blockSizeHalving;
     817              :         }
     818            6 :         blockSizeHalving = blockSizeHalving / 2; //  每个循环除2计算当前block的折半rank数
     819              :     }
     820            6 : }
     821              : 
     822              : //  用于recursive halving doubling
     823            6 : void ExecutorBase::CalcLinkBetweenParts(
     824              :     u32 part1Size, std::list<u32>& linkRankIndexInBlock, std::list<u32>& linkRankIndex, bool oddRank)
     825              : {
     826           12 :     for (auto it : linkRankIndexInBlock) {
     827            6 :         if (it < (part1Size / 2)) { //  属于part1,除2计算part1中的rank范围
     828            0 :             if (oddRank) {
     829            0 :                 linkRankIndex.push_back(it * 2 + 1); //  乘2加1得到part1中奇数rank
     830              :             } else {
     831            0 :                 linkRankIndex.push_back(it * 2); //  乘2得到part1中偶数rank
     832              :             }
     833              :         } else {
     834            6 :             linkRankIndex.push_back(part1Size / 2 + it); //  不属于part1,除2得到part1中rank范围
     835              :         }
     836              :     }
     837            6 : }
     838              : 
     839              : //  用于recursive halving doubling
     840            6 : void ExecutorBase::CalcRecursiveHalvingDobuleLinkReleation(
     841              :     u32 rank, u32 rankSize, u32 rootRank, std::vector<bool>& linkRelation)
     842              : {
     843            6 :     u32 exponent = 0;
     844              : 
     845            6 :     if (rootRank == INVALID_VALUE_RANKID) { // all reduce 走这个分支
     846            6 :         rootRank = 0;
     847              :     }
     848              : 
     849            6 :     u32 base = 1;
     850           18 :     while ((base << exponent) <= rankSize) {
     851           12 :         exponent++;
     852              :     }
     853            6 :     if (exponent > 0) {
     854            6 :         exponent--;
     855              :     }
     856            6 :     u32 blockSize = base << exponent;
     857            6 :     u32 part1Size = (rankSize - blockSize) * 2; // part1的大小为总rankSize减去blockSize再乘2
     858              : 
     859              :     //  情况1、情况3的建链方式
     860            6 :     if (rootRank >= part1Size || rootRank % 2 == 0) { // 除2判断是否为偶数
     861            6 :         CalcRecursiveHdLinkRelationForFirstScene(rank, part1Size, blockSize, linkRelation);
     862              :     } else { //  情况2的建链方式,rootRank<part1Size && 1==rootRank%2
     863            0 :         CalcRecursiveHdLinkRelationForSecondScene(rank, part1Size, blockSize, linkRelation);
     864              :     }
     865            6 : }
     866              : 
     867            6 : void ExecutorBase::CalcRecursiveHdLinkRelationForFirstScene(
     868              :     u32 rank, u32 part1Size, u32 blockSize, std::vector<bool>& linkRelation)
     869              : {
     870            6 :     if (rank < part1Size && rank % 2 == 0) { // 除2判断是否为偶数
     871            0 :         std::list<u32> linkRankIndex;
     872            0 :         std::list<u32> linkRankIndexInBlock;
     873            0 :         u32 rankInBlock = rank / 2; // 除2计算block内的rank号
     874            0 :         CalcLinkInBlock(blockSize, rankInBlock, linkRankIndexInBlock);
     875            0 :         CalcLinkBetweenParts(part1Size, linkRankIndexInBlock, linkRankIndex, false);
     876            0 :         linkRankIndex.push_back(rank + 1); // 加1得到旁边的那个rank
     877            0 :         for (auto it : linkRankIndex) {
     878            0 :             linkRelation[it] = true;
     879              :         }
     880            6 :     } else if (rank < part1Size && rank % 2 == 1) { // 除2判断是否为奇数
     881            0 :         if ((rank > 0) && (rank - 1 < linkRelation.size())) {
     882            0 :             linkRelation[rank - 1] = true; //  只有旁边的那个rank
     883              :         }
     884              :     } else { //  rank大于等于part1Size
     885            6 :         std::list<u32> linkRankIndexInBlock;
     886            6 :         u32 rankInBlock = rank - part1Size / 2; // 除2计算part1在block内的rank范围
     887            6 :         std::list<u32> linkRankIndex;
     888            6 :         CalcLinkInBlock(blockSize, rankInBlock, linkRankIndexInBlock);
     889            6 :         CalcLinkBetweenParts(part1Size, linkRankIndexInBlock, linkRankIndex, false);
     890           12 :         for (auto it : linkRankIndex) {
     891            6 :             linkRelation[it] = true;
     892              :         }
     893            6 :     }
     894            6 : }
     895              : 
     896            0 : void ExecutorBase::CalcRecursiveHdLinkRelationForSecondScene(
     897              :     u32 rank, u32 part1Size, u32 blockSize, std::vector<bool>& linkRelation)
     898              : {
     899            0 :     if (rank < part1Size && rank % 2 == 1) { // 除2判断是否为奇数
     900            0 :         std::list<u32> linkRankIndex;
     901            0 :         std::list<u32> linkRankIndexInBlock;
     902            0 :         u32 rankInBlock = (rank - 1) / 2; // 减1再除2计算在block内的rank
     903            0 :         CalcLinkInBlock(blockSize, rankInBlock, linkRankIndexInBlock);
     904            0 :         CalcLinkBetweenParts(part1Size, linkRankIndexInBlock, linkRankIndex, true);
     905            0 :         linkRankIndex.push_back(rank - 1); // 减1得到旁边的那个rank
     906            0 :         for (auto it : linkRankIndex) {
     907            0 :             linkRelation[it] = true;
     908              :         }
     909            0 :     } else if (rank < part1Size && rank % 2 == 0) { // 除2判断是否为偶数
     910            0 :         if (rank + 1 < linkRelation.size()) {
     911            0 :             linkRelation[rank + 1] = true; //  只有旁边的那个rank
     912              :         }
     913              :     } else { //  rank大于等于part1Size
     914            0 :         std::list<u32> linkRankIndexInBlock;
     915            0 :         u32 rankInBlock = rank - part1Size / 2; // 除2计算part1在block内的rank范围
     916            0 :         std::list<u32> linkRankIndex;
     917            0 :         CalcLinkInBlock(blockSize, rankInBlock, linkRankIndexInBlock);
     918            0 :         CalcLinkBetweenParts(part1Size, linkRankIndexInBlock, linkRankIndex, true);
     919            0 :         for (auto it : linkRankIndex) {
     920            0 :             linkRelation[it] = true;
     921              :         }
     922            0 :     }
     923            0 : }
     924              : 
     925              : HcclResult
     926            0 : ExecutorBase::ExecuteBarrier(const std::shared_ptr<Transport>& preLink, const std::shared_ptr<Transport>& aftLink)
     927              : {
     928            0 :     return ExecuteBarrier(preLink, aftLink, stream_);
     929              : }
     930              : 
     931            0 : HcclResult ExecutorBase::ExecuteBarrier(
     932              :     const std::shared_ptr<Transport>& preLink, const std::shared_ptr<Transport>& aftLink, Stream& stream)
     933              : {
     934              :     // 同步与preLink保证数据收发已结束
     935            0 :     CHK_RET(preLink->TxAck(stream));
     936              : 
     937            0 :     CHK_RET(aftLink->RxAck(stream));
     938              : 
     939              :     // 同步与aftLink保证数据收发已结束
     940            0 :     CHK_RET(aftLink->TxDataSignal(stream));
     941              : 
     942            0 :     CHK_RET(preLink->RxDataSignal(stream));
     943              : 
     944            0 :     return HCCL_SUCCESS;
     945              : }
     946              : 
     947            0 : HcclResult ExecutorBase::ExecuteBarrier(std::shared_ptr<Transport> link, Stream& stream)
     948              : {
     949            0 :     CHK_RET(link->TxAck(stream));
     950              : 
     951            0 :     CHK_RET(link->RxAck(stream));
     952              : 
     953            0 :     CHK_RET(link->TxDataSignal(stream));
     954              : 
     955            0 :     CHK_RET(link->RxDataSignal(stream));
     956              : 
     957            0 :     return HCCL_SUCCESS;
     958              : }
     959              : 
     960            0 : HcclResult ExecutorBase::ExecuteBarrier(
     961              :     const std::shared_ptr<Transport>& preLink, const std::shared_ptr<Transport>& aftLink, u32 notifyIdx)
     962              : {
     963            0 :     return ExecuteBarrier(preLink, aftLink, notifyIdx, stream_);
     964              : }
     965              : 
     966            0 : HcclResult ExecutorBase::ExecuteBarrier(
     967              :     const std::shared_ptr<Transport>& preLink, const std::shared_ptr<Transport>& aftLink, u32 notifyIdx, Stream& stream)
     968              : {
     969              :     // 同步与aftLink保证数据收发已结束
     970            0 :     CHK_RET(aftLink->Post(notifyIdx, stream));
     971              : 
     972            0 :     CHK_RET(preLink->Wait(notifyIdx, stream));
     973              : 
     974            0 :     return HCCL_SUCCESS;
     975              : }
     976              : 
     977            0 : HcclResult ExecutorBase::Sum(const std::vector<Slice>& inputSlices, u32 start, u32 num, u64& sizeOut)
     978              : {
     979            0 :     u64 totalSize = 0;
     980              :     // 判断不是<=因为访问vector前会先进行num--
     981            0 :     CHK_PRT_RET(
     982              :         inputSlices.size() < start + num,
     983              :         HCCL_ERROR(
     984              :             "[ExecutorBase][Sum]recursive Halving Doubling sum "
     985              :             "error.para: size[%llu], start[%u], num[%u]",
     986              :             inputSlices.size(), start, num),
     987              :         HCCL_E_PARA);
     988            0 :     while (num > 0) {
     989            0 :         num--;
     990            0 :         totalSize += inputSlices[start + num].size;
     991              :     }
     992            0 :     sizeOut = totalSize;
     993            0 :     return HCCL_SUCCESS;
     994              : }
     995            0 : HcclResult ExecutorBase::ExecuteRxSync(
     996              :     std::shared_ptr<Transport> link, UserMemType srcMemType, u64 srcOffset, void* dst, u64 len, Stream& stream) const
     997              : {
     998            0 :     HcclResult ret = link->TxAsync(srcMemType, srcOffset, dst, 0, stream);
     999            0 :     CHK_PRT_RET(
    1000              :         ret != HCCL_SUCCESS,
    1001              :         HCCL_ERROR(
    1002              :             "[ExecutorBase][ExecuteRxSync]ExecuteRxSync: tx async size[%llu] "
    1003              :             "failed",
    1004              :             len),
    1005              :         ret);
    1006            0 :     ret = link->RxAsync(srcMemType, srcOffset, dst, len, stream);
    1007            0 :     CHK_PRT_RET(
    1008              :         ret != HCCL_SUCCESS,
    1009              :         HCCL_ERROR(
    1010              :             "[ExecutorBase][ExecuteRxSync]ExecuteRxSync: rx async with rcvMem[%p] "
    1011              :             "offset[%llu] size[%llu] failed",
    1012              :             dst, srcOffset, len),
    1013              :         ret);
    1014            0 :     ret = link->DataReceivedAck(stream);
    1015            0 :     CHK_PRT_RET(
    1016              :         ret != HCCL_SUCCESS, HCCL_ERROR("[ExecutorBase][ExecuteRxSync]ExecuteRxSync: data received ack failed"), ret);
    1017            0 :     return HCCL_SUCCESS;
    1018              : }
    1019            0 : HcclResult ExecutorBase::ExecuteTxSync(
    1020              :     std::shared_ptr<Transport> link, UserMemType dstMemType, u64 dstOffset, void* src, u64 len, Stream& stream) const
    1021              : {
    1022            0 :     HcclResult ret = link->TxAsync(dstMemType, dstOffset, src, len, stream);
    1023            0 :     CHK_PRT_RET(
    1024              :         ret != HCCL_SUCCESS,
    1025              :         HCCL_ERROR(
    1026              :             "[ExecutorBase][ExecuteTxSync]ExecuteTxSync: tx async sendMem[%p] "
    1027              :             "offset[%llu] size[%llu] failed",
    1028              :             src, dstOffset, len),
    1029              :         ret);
    1030              :     // 接收应答
    1031            0 :     ret = link->RxAsync(dstMemType, dstOffset, src, 0, stream);
    1032            0 :     CHK_PRT_RET(
    1033              :         ret != HCCL_SUCCESS,
    1034              :         HCCL_ERROR(
    1035              :             "[ExecutorBase][ExecuteTxSync]ExecuteTxSync: rx async size[%llu] "
    1036              :             "failed",
    1037              :             len),
    1038              :         ret);
    1039            0 :     ret = link->DataReceivedAck(stream);
    1040            0 :     CHK_PRT_RET(
    1041              :         ret != HCCL_SUCCESS, HCCL_ERROR("[ExecutorBase][ExecuteTxSync]ExecuteTxSync: data received ack failed"), ret);
    1042            0 :     return HCCL_SUCCESS;
    1043              : }
    1044              : 
    1045              : HcclResult
    1046            0 : ExecutorBase::PrepareRunAsync(const u32 rank, const u32 rankSize, const std::vector<std::shared_ptr<Transport>>& links)
    1047              : {
    1048              :     (void)rank;
    1049              :     (void)rankSize;
    1050              :     (void)links;
    1051            0 :     return HCCL_SUCCESS;
    1052              : }
    1053              : 
    1054              : HcclResult
    1055           42 : ExecutorBase::ExecEmptyTask(DeviceMem& inputMem, DeviceMem& outputMem, Stream& stream, const HcclDispatcher dispatcher)
    1056              : {
    1057           42 :     DeviceMem emptySrcMem = DeviceMem::create(inputMem.ptr(), 0);
    1058           42 :     DeviceMem emptyDstMem = DeviceMem::create(outputMem.ptr(), 0);
    1059           42 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher, emptyDstMem, emptySrcMem, stream));
    1060           42 :     return HCCL_SUCCESS;
    1061           42 : }
    1062              : 
    1063              : HcclResult
    1064            0 : ExecutorBase::CheckConcurrentDirectParameters(const u32 rank, const u32 rankSize, const std::vector<LINK>& links)
    1065              : {
    1066              :     // 判断stream, dispatcher是否为空
    1067            0 :     CHK_SMART_PTR_NULL(dispatcher_);
    1068            0 :     CHK_PTR_NULL(stream_.ptr());
    1069              : 
    1070              :     // inputMem_ == outputMem_ 是允许的, 因为ring的时候收的slice和发的slice不是同一片
    1071              :     // reduce scatter用inputMem_,allgather用outputMem_
    1072            0 :     if (!outputMem_ || !inputMem_) {
    1073            0 :         HCCL_ERROR("[ExecutorBase] rank[%u] run_async inputmem or outputmem is null", rank);
    1074            0 :         return HCCL_E_PTR;
    1075              :     }
    1076            0 :     HCCL_INFO(
    1077              :         "ExecutorBase run: rank[%u] ranksize[%u] inputMem[%p] outputMem[%p] count[%llu]", rank, rankSize,
    1078              :         inputMem_.ptr(), outputMem_.ptr(), count_);
    1079              : 
    1080              :     // 判断links数量是否正确
    1081            0 :     CHK_PRT_RET(
    1082              :         links.size() < rankSize,
    1083              :         HCCL_ERROR(
    1084              :             "[ExecutorBase] rank[%u] link size[%u] is less than "
    1085              :             "rank size[%u]",
    1086              :             rank, links.size(), rankSize),
    1087              :         HCCL_E_PARA);
    1088              : 
    1089              :     // 校验DataUnitSize
    1090            0 :     if (DataUnitSize(dataType_) == 0) {
    1091            0 :         HCCL_ERROR("[ExecutorBase] rank[%u] unit data size is zero", rank);
    1092            0 :         return HCCL_E_INTERNAL;
    1093              :     }
    1094              : 
    1095            0 :     HCCL_INFO("ExecutorBase finished to CheckParameters");
    1096            0 :     return HCCL_SUCCESS;
    1097              : }
    1098              : 
    1099              : HcclResult
    1100            0 : ExecutorBase::GetNslbAdjInfo(const u32 rank, const u32 rankSize, const std::vector<LINK>& links, AdjInfo& nslbAdjInfo)
    1101              : {
    1102              :     (void)rank;
    1103              :     (void)rankSize;
    1104              :     (void)nslbAdjInfo;
    1105            0 :     return HCCL_SUCCESS;
    1106              : }
    1107              : 
    1108              : HcclResult
    1109            0 : ExecutorBase::GetHcclOffsetDstRanksMap(std::unordered_map<uint64_t, std::vector<uint32_t>>& hcclOffsetDstRanksMap) const
    1110              : {
    1111              :     UNUSED_PARAM(hcclOffsetDstRanksMap);
    1112            0 :     HCCL_ERROR("[ExecutorBase][GetHcclOffsetDstRanksMap] not supported for current template!");
    1113            0 :     return HCCL_E_NOT_SUPPORT;
    1114              : }
    1115              : 
    1116              : } // namespace hccl
        

Generated by: LCOV version 2.0-1