LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor - coll_comm_executor.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 1 1
Test Date: 2026-08-04 10:52:23 Functions: 50.0 % 2 1

            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              : #ifndef COLL_COMMON_EXECUTOR_H
      12              : #define COLL_COMMON_EXECUTOR_H
      13              : 
      14              : #include "coll_native_executor_base.h"
      15              : #include "coll_alg_exec_registry.h"
      16              : #include "profiler_base_pub.h"
      17              : #include "send_receive_pub.h"
      18              : #include "alg_template_register.h"
      19              : #include "alltoallv_staged_calculator_pub.h"
      20              : 
      21              : namespace hccl {
      22              : constexpr u32 NSLBDP_MIN_COUNT = 128; 
      23              : class CollCommExecutor : public CollNativeExecutorBase {
      24              : public:
      25              :     CollCommExecutor(const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher> &topoMatcher);
      26          179 :     ~CollCommExecutor() override = default;
      27              : 
      28              :     // CCL Op Share
      29              :     HcclResult MultiRingAllReduce(const std::string &tag, DeviceMem &inputMem, DeviceMem &outputMem,
      30              :                                     const u64 count, const HcclDataType dataType,
      31              :                                     const HcclReduceOp reductionOp,
      32              :                                     const std::vector<std::vector<Slice>> &multRingsSliceZero, Stream stream,
      33              :                                     s32 profStage, const u64 baseOffset = 0);
      34              :     HcclResult CollectMultiRingsUserMemSlices(u32 ringNum, const HcclDataType dataType,
      35              :         const HcomCollOpInfo *opInfo, const std::vector<std::vector<Slice>> &multRingsSliceZero,
      36              :         const std::vector<std::vector<u32>> &multiRingsOrder,
      37              :         const std::vector<std::vector<Slice>> &multRingsUserMemSlice,
      38              :         std::vector<std::vector<Slice>> &userMemSlicesOfMultiRings);
      39              :     HcclResult CollectMultiRingsRankOrder(u32 ringNum,
      40              :         const std::vector<std::vector<u32>> &multiRingsOrder,
      41              :         std::vector<std::vector<u32>> &rankOrders);
      42              :     u32 CalcOptimalIntraRingsize(u64 count, HcclDataType dataType, HcclCMDType opType);
      43              :     
      44              :     HcclResult MultiRingReduceScatter(const std::string &tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count,
      45              :         const HcclDataType dataType, const HcclReduceOp reductionOp,
      46              :         const std::vector<std::vector<Slice>> multRingsSliceZero, Stream stream,
      47              :         s32 profStage, const u64 baseOffset = 0, const HcomCollOpInfo *opInfo = nullptr,
      48              :         const std::vector<std::vector<Slice>> multRingsUserMemSlice = std::vector<std::vector<Slice>> (0),
      49              :         const CommPlane levelIndex = COMM_LEVEL0);
      50              : 
      51              :     HcclResult MultiRingReduceScatterConcurrent(const std::string &tag, DeviceMem inputMem,DeviceMem outputMem,
      52              :         const u64 count, const HcclDataType dataType, const HcclReduceOp reductionOp,
      53              :         const std::vector<std::pair<bool, std::vector<Slice>>> multRingsSliceZero, Stream stream,
      54              :         s32 profStage, const u64 baseOffset = 0, const HcomCollOpInfo *opInfo = nullptr,
      55              :         const std::vector<std::pair<bool, std::vector<Slice>>> multRingsUserMemSlice =
      56              :         std::vector<std::pair<bool, std::vector<Slice>>> (0));
      57              : 
      58              :     HcclResult Level1ReduceScatterConcurrent(DeviceMem inputMem, DeviceMem scratchMem,const u64 count,
      59              :         const HcclDataType dataType, const HcclReduceOp reductionOp, Stream stream, s32 profStage,
      60              :         std::vector<Slice> &level1DataSegsSlice, u32 syncTrans, u64 reduceAttr);
      61              : 
      62              :     HcclResult UpdateOffsetBasedOnStrideCount(const OpParam &param,
      63              :         std::vector<std::vector<Slice>> &multRingsUserMemSlice) const;
      64              : 
      65              :     HcclResult MultiRingAllGather(const std::string &tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count,
      66              :         const HcclDataType dataType,
      67              :         const std::vector<std::vector<Slice> > multRingsSliceZero, Stream stream,
      68              :         s32 profStage, const u64 baseOffset = 0, const HcomCollOpInfo *opInfo = nullptr,
      69              :         const std::vector<std::vector<Slice>> multRingsUserMemSlice = std::vector<std::vector<Slice>> (0),
      70              :         const CommPlane leveIndex = COMM_LEVEL0);
      71              : 
      72              :     HcclResult MultiRingAllGatherConcurrent(const std::string &tag, DeviceMem inputMem, DeviceMem outputMem,
      73              :         const u64 count, const HcclDataType dataType,
      74              :         const std::vector<std::pair<bool, std::vector<Slice>>> multRingsSliceZero, Stream stream,
      75              :         s32 profStage, const u64 baseOffset = 0, const HcomCollOpInfo *opInfo = nullptr,
      76              :         const std::vector<std::pair<bool, std::vector<Slice>>> multRingsUserMemSlice =
      77              :         std::vector<std::pair<bool, std::vector<Slice>>> (0));
      78              : 
      79              :     HcclResult Level1AllGatherConcurrent(DeviceMem inputMem, DeviceMem outputMem, const u64 count,
      80              :         const HcclDataType dataType, Stream stream, s32 profStage,
      81              :         std::vector<Slice> &level1DataSegsSlice, u32 syncTrans);
      82              : 
      83              :     HcclResult MultiRingMultiRootScatter(const std::string &tag, DeviceMem &inputMem, DeviceMem &outputMem,
      84              :         const u64 count, const HcclDataType dataType, const std::vector<std::vector<Slice>> &multRingsSliceZero,
      85              :         u32 root, Stream stream, const u64 baseOffset);
      86              : 
      87              :     HcclResult MultiStreamReduceScatterMesh(const std::string &tag, DeviceMem inputMem, DeviceMem outputMem,
      88              :                                                   const u64 count, const HcclDataType dataType,
      89              :                                                   const HcclReduceOp reductionOp,
      90              :                                                   const std::vector<std::vector<Slice>>& multStreamsSlice,
      91              :                                                   Stream stream,
      92              :                                                   const CommPlane commLevelIndex,
      93              :                                                   const u64 baseOffset = 0);
      94              : 
      95              :     HcclResult MultiRingGather(const std::string &tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count,
      96              :                                 const HcclDataType dataType, const std::vector<std::vector<Slice>> multRingsSliceZero,
      97              :                                 HcclReduceOp op, u32 root, Stream stream, s32 profStage);
      98              : 
      99              :     HcclResult MultiStreamReduceScatterMeshAtomic(const std::string &tag, DeviceMem &inputMem, DeviceMem &outputMem,
     100              :                                                   const u64 count, const HcclDataType dataType,
     101              :                                                   const HcclReduceOp reductionOp,
     102              :                                                   const std::vector<Slice> &dataSliceVct,
     103              :                                                   Stream &stream,
     104              :                                                   const CommPlane commLevelIndex,
     105              :                                                   const u64 baseOffset = 0, HcomCollOpInfo *opInfo = nullptr);
     106              :     HcclResult PrepareReduceScatterSliceData(u64 dataCount, u32 unitSize, u32 sliceNum, std::vector<Slice> &dataSlice);
     107              : 
     108              :     HcclResult MultiRingScatter(const std::string &tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count,
     109              :                                 const HcclDataType dataType, const std::vector<std::vector<Slice> > multRingsSliceZero,
     110              :                                 u32 root, Stream stream, const HcomCollOpInfo *opInfo, const u64 baseOffset = 0);
     111              :     std::vector<std::vector<u32>> GetRingsOrderByTopoType(u32 ranksSize, TopoType topoType, std::vector<u32> &nicList);
     112              :     HcclResult MutliSegSlicePrepare(const std::vector<Slice> &dataSegsSlice,
     113              :         std::vector<std::vector<Slice> >& mutliSegsSlices, u32 ringCount);
     114              :     HcclResult MutliSegSlicePrepareAvoidCceRewrite(const std::vector<Slice> &dataSegsSlice,
     115              :         std::vector<std::vector<Slice> >& mutliSegsSlices, u32 ringCount) const;
     116              :     void NicSendSizeCal(const std::vector<std::vector<Slice>> &mutliSegsSlices, u32 ringCount, u32 chunkSize,
     117              :         const std::vector<u32> &nicList, const std::string &tag);
     118              :     std::vector<std::vector<Slice> > PrepareMultiRingSlice(const std::vector<Slice> &dataSegsSlice,
     119              :         const std::string &tag, bool avoidCceRewrite = false, std::vector<u32> nicList = {0, 1, 2, 3, 4, 5, 6, 7}, CommPlane commLevelIndex = COMM_LEVEL0);
     120              :     // AnyPath特性使用
     121              :     std::vector<std::vector<u32>> GetRingsOrderForAnyPath(u32 ranksSize, TopoType topoType, std::vector<u32> &nicList);
     122              :     std::vector<std::vector<Slice> > AnyPathPrepareMultiRingSlice(const std::vector<Slice> &dataSegsSlice,
     123              :         const std::string &tag, bool avoidCceRewrite = false, std::vector<u32> nicList = {0, 1, 2, 3, 4, 5, 6, 7});
     124              : 
     125              :     bool Is2U2PInfer();
     126              :     bool Is910BSingleMesh();
     127              :     bool NeedCreateSingleMeshPlane(const bool isInlineReduce);
     128              :     bool SingleMeshInlineReduce(void *inputPtr, void *outputPtr, HcclDataType dataType, HcclReduceOp op);
     129              :     bool IsMultiMeshInlineReduce(void *inputPtr, void *outputPtr, HcclDataType dataType, HcclReduceOp op);
     130              : 
     131              :     u64 GetReduceAttr(DeviceMem &inputMem, DeviceMem &outputMem, HcclDataType dataType, HcclReduceOp op);
     132              :     HcclResult PrepareLevel1CommInfo(u32 &segmentIdx, u32 &commIndex, u64 &hdSize,
     133              :                                           const SubCommInfo &commInfo,
     134              :                                           const std::vector<std::vector<Slice> > &multRingsSliceZero,
     135              :                                           const std::string &tag);
     136              :     HcclResult GetAdjInfo(AlgResourceResponse& algRes, AdjInfo& adjInfo) override;
     137              : 
     138              : protected:
     139              :     virtual HcclResult GetSubStreamInfoOnOneRing(const u32 ringIndex,
     140              :                                          std::vector<Stream>                       &subStreamsInOneRing,
     141              :                                          std::vector<std::shared_ptr<LocalNotify>> &mainSignalsInOneRing,
     142              :                                          std::vector<std::shared_ptr<LocalNotify>> &subSignalsInOneRing);
     143              :     virtual u32 GetLevel0RingNum() const;
     144              :     HcclResult CalUserMemSlices(const HcclDataType dataType, const HcomCollOpInfo *opInfo,
     145              :                                 const std::vector<Slice> &singleRingSliceZero, u32 ringIndex,
     146              :                                 const std::vector<std::vector<u32>> &multiRingsOrder,
     147              :                                 std::vector<Slice>                  &userMemSlices);
     148              :     HcclResult GetRankOrder(const std::vector<std::vector<u32>> &multiRingsOrder, u32 ringIndex,
     149              :                             std::vector<u32> &rankOrder);
     150              :     HcclResult SetRingNics(const std::string &tag, const std::vector<std::vector<u32>> &ringNics);
     151              :     HcclResult GetRingNics(const std::string &tag, std::vector<std::vector<u32>> &ringNics);
     152              :     HcclResult SetNicSendSize(const std::string &tag, std::vector<u64> &sizeList);
     153              : 
     154              :     // 用于ZerocopyExecutor
     155              :     HcclResult CalcIntraServerDataSlicesDiscontinuous(const OpParam &param, const ExecMem &execMem,
     156              :         u32 level0RankSize, u32 level1RankSize, u32 level2RankSize, std::vector<Slice> &dataSegsSlice);
     157              :     HcclResult CalcIntraServerDataSlicesContinuous(const OpParam &param, const ExecMem &execMem,
     158              :         u32 level0RankSize, u32 level1RankSize, u32 level2RankSize, std::vector<Slice> &dataSegsSlice);
     159              :     void CalcLevel1DataSlices(u64 sliceSize, u32 level1RankSize, u32 level2RankSize, std::vector<Slice> &level1DataSegsSlice);
     160              :     HcclResult GetCommRankInfoNormal(u32 &level0Rank, u32 &level0RankSize,
     161              :         u32 &level1Rank, u32 &level1RankSize, u32 &level2Rank, u32 &level2RankSize, bool isAHCAlgo = false);
     162              : 
     163              :     // 用于ExchangeExecutor
     164              :     HcclResult CalExchangeRemoteRankForReduceScatter(u32 &remoteRankSend, u32 &remoteRankRecv);
     165              :     HcclResult GetTransportForExchange(u32 remoteUserRank, LINK &targetLink);
     166              :     bool IsLevel0Neighbor(u32 remoteRank, u32 level0RankSize);
     167              : 
     168              :     std::mutex ringNicListLock_;
     169              :     std::map<std::string, std::vector<std::vector<u32>>> ringNicList_;
     170              :     std::mutex nicSendSizeListLock_;
     171              :     std::map<std::string, std::vector<u64>> nicSendSizeList_;
     172              : };
     173              : } // namespace hccl
     174              : 
     175              : #endif /** __COLL_COMMON_EXECUTOR_H__ */
        

Generated by: LCOV version 2.0-1