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(
30 : const std::string& tag, DeviceMem& inputMem, DeviceMem& outputMem, const u64 count, const HcclDataType dataType,
31 : const HcclReduceOp reductionOp, const std::vector<std::vector<Slice>>& multRingsSliceZero, Stream stream,
32 : s32 profStage, const u64 baseOffset = 0);
33 : HcclResult CollectMultiRingsUserMemSlices(
34 : u32 ringNum, const HcclDataType dataType, const HcomCollOpInfo* opInfo,
35 : const std::vector<std::vector<Slice>>& multRingsSliceZero, const std::vector<std::vector<u32>>& multiRingsOrder,
36 : const std::vector<std::vector<Slice>>& multRingsUserMemSlice,
37 : std::vector<std::vector<Slice>>& userMemSlicesOfMultiRings);
38 : HcclResult CollectMultiRingsRankOrder(
39 : u32 ringNum, const std::vector<std::vector<u32>>& multiRingsOrder, std::vector<std::vector<u32>>& rankOrders);
40 : u32 CalcOptimalIntraRingsize(u64 count, HcclDataType dataType, HcclCMDType opType);
41 :
42 : HcclResult MultiRingReduceScatter(
43 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
44 : const HcclReduceOp reductionOp, const std::vector<std::vector<Slice>> multRingsSliceZero, Stream stream,
45 : s32 profStage, const u64 baseOffset = 0, const HcomCollOpInfo* opInfo = nullptr,
46 : const std::vector<std::vector<Slice>> multRingsUserMemSlice = std::vector<std::vector<Slice>>(0),
47 : const CommPlane levelIndex = COMM_LEVEL0);
48 :
49 : HcclResult MultiRingReduceScatterConcurrent(
50 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
51 : const HcclReduceOp reductionOp, const std::vector<std::pair<bool, std::vector<Slice>>> multRingsSliceZero,
52 : Stream stream, s32 profStage, const u64 baseOffset = 0, const HcomCollOpInfo* opInfo = nullptr,
53 : const std::vector<std::pair<bool, std::vector<Slice>>> multRingsUserMemSlice
54 : = std::vector<std::pair<bool, std::vector<Slice>>>(0));
55 :
56 : HcclResult Level1ReduceScatterConcurrent(
57 : DeviceMem inputMem, DeviceMem scratchMem, const u64 count, const HcclDataType dataType,
58 : const HcclReduceOp reductionOp, Stream stream, s32 profStage, std::vector<Slice>& level1DataSegsSlice,
59 : u32 syncTrans, u64 reduceAttr);
60 :
61 : HcclResult
62 : UpdateOffsetBasedOnStrideCount(const OpParam& param, std::vector<std::vector<Slice>>& multRingsUserMemSlice) const;
63 :
64 : HcclResult MultiRingAllGather(
65 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
66 : const std::vector<std::vector<Slice>> multRingsSliceZero, Stream stream, s32 profStage,
67 : const u64 baseOffset = 0, const HcomCollOpInfo* opInfo = nullptr,
68 : const std::vector<std::vector<Slice>> multRingsUserMemSlice = std::vector<std::vector<Slice>>(0),
69 : const CommPlane leveIndex = COMM_LEVEL0);
70 :
71 : HcclResult MultiRingAllGatherConcurrent(
72 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
73 : const std::vector<std::pair<bool, std::vector<Slice>>> multRingsSliceZero, Stream stream, s32 profStage,
74 : const u64 baseOffset = 0, const HcomCollOpInfo* opInfo = nullptr,
75 : const std::vector<std::pair<bool, std::vector<Slice>>> multRingsUserMemSlice
76 : = std::vector<std::pair<bool, std::vector<Slice>>>(0));
77 :
78 : HcclResult Level1AllGatherConcurrent(
79 : DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType, Stream stream,
80 : s32 profStage, std::vector<Slice>& level1DataSegsSlice, u32 syncTrans);
81 :
82 : HcclResult MultiRingMultiRootScatter(
83 : const std::string& tag, DeviceMem& inputMem, DeviceMem& outputMem, const u64 count, const HcclDataType dataType,
84 : const std::vector<std::vector<Slice>>& multRingsSliceZero, u32 root, Stream stream, const u64 baseOffset);
85 :
86 : HcclResult MultiStreamReduceScatterMesh(
87 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
88 : const HcclReduceOp reductionOp, const std::vector<std::vector<Slice>>& multStreamsSlice, Stream stream,
89 : const CommPlane commLevelIndex, const u64 baseOffset = 0);
90 :
91 : HcclResult MultiRingGather(
92 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
93 : const std::vector<std::vector<Slice>> multRingsSliceZero, HcclReduceOp op, u32 root, Stream stream,
94 : s32 profStage);
95 :
96 : HcclResult MultiStreamReduceScatterMeshAtomic(
97 : const std::string& tag, DeviceMem& inputMem, DeviceMem& outputMem, const u64 count, const HcclDataType dataType,
98 : const HcclReduceOp reductionOp, const std::vector<Slice>& dataSliceVct, Stream& stream,
99 : const CommPlane commLevelIndex, const u64 baseOffset = 0, HcomCollOpInfo* opInfo = nullptr);
100 : HcclResult PrepareReduceScatterSliceData(u64 dataCount, u32 unitSize, u32 sliceNum, std::vector<Slice>& dataSlice);
101 :
102 : HcclResult MultiRingScatter(
103 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
104 : const std::vector<std::vector<Slice>> multRingsSliceZero, u32 root, Stream stream, const HcomCollOpInfo* opInfo,
105 : const u64 baseOffset = 0);
106 : std::vector<std::vector<u32>> GetRingsOrderByTopoType(u32 ranksSize, TopoType topoType, std::vector<u32>& nicList);
107 : HcclResult MutliSegSlicePrepare(
108 : const std::vector<Slice>& dataSegsSlice, std::vector<std::vector<Slice>>& mutliSegsSlices, u32 ringCount);
109 : HcclResult MutliSegSlicePrepareAvoidCceRewrite(
110 : const std::vector<Slice>& dataSegsSlice, std::vector<std::vector<Slice>>& mutliSegsSlices, u32 ringCount) const;
111 : void NicSendSizeCal(
112 : const std::vector<std::vector<Slice>>& mutliSegsSlices, u32 ringCount, u32 chunkSize,
113 : const std::vector<u32>& nicList, const std::string& tag);
114 : std::vector<std::vector<Slice>> PrepareMultiRingSlice(
115 : const std::vector<Slice>& dataSegsSlice, const std::string& tag, bool avoidCceRewrite = false,
116 : std::vector<u32> nicList = {0, 1, 2, 3, 4, 5, 6, 7}, CommPlane commLevelIndex = COMM_LEVEL0);
117 : // AnyPath特性使用
118 : std::vector<std::vector<u32>> GetRingsOrderForAnyPath(u32 ranksSize, TopoType topoType, std::vector<u32>& nicList);
119 : std::vector<std::vector<Slice>> AnyPathPrepareMultiRingSlice(
120 : const std::vector<Slice>& dataSegsSlice, const std::string& tag, bool avoidCceRewrite = false,
121 : std::vector<u32> nicList = {0, 1, 2, 3, 4, 5, 6, 7});
122 :
123 : bool Is2U2PInfer();
124 : bool Is910BSingleMesh();
125 : bool NeedCreateSingleMeshPlane(const bool isInlineReduce);
126 : bool SingleMeshInlineReduce(void* inputPtr, void* outputPtr, HcclDataType dataType, HcclReduceOp op);
127 : bool IsMultiMeshInlineReduce(void* inputPtr, void* outputPtr, HcclDataType dataType, HcclReduceOp op);
128 :
129 : u64 GetReduceAttr(DeviceMem& inputMem, DeviceMem& outputMem, HcclDataType dataType, HcclReduceOp op);
130 : HcclResult PrepareLevel1CommInfo(
131 : u32& segmentIdx, u32& commIndex, u64& hdSize, const SubCommInfo& commInfo,
132 : const std::vector<std::vector<Slice>>& multRingsSliceZero, const std::string& tag);
133 : HcclResult GetAdjInfo(AlgResourceResponse& algRes, AdjInfo& adjInfo) override;
134 :
135 : protected:
136 : virtual HcclResult GetSubStreamInfoOnOneRing(
137 : const u32 ringIndex, std::vector<Stream>& subStreamsInOneRing,
138 : std::vector<std::shared_ptr<LocalNotify>>& mainSignalsInOneRing,
139 : std::vector<std::shared_ptr<LocalNotify>>& subSignalsInOneRing);
140 : virtual u32 GetLevel0RingNum() const;
141 : HcclResult CalUserMemSlices(
142 : const HcclDataType dataType, const HcomCollOpInfo* opInfo, const std::vector<Slice>& singleRingSliceZero,
143 : u32 ringIndex, const std::vector<std::vector<u32>>& multiRingsOrder, std::vector<Slice>& userMemSlices);
144 : HcclResult
145 : GetRankOrder(const std::vector<std::vector<u32>>& multiRingsOrder, u32 ringIndex, std::vector<u32>& rankOrder);
146 : HcclResult SetRingNics(const std::string& tag, const std::vector<std::vector<u32>>& ringNics);
147 : HcclResult GetRingNics(const std::string& tag, std::vector<std::vector<u32>>& ringNics);
148 : HcclResult SetNicSendSize(const std::string& tag, std::vector<u64>& sizeList);
149 :
150 : // 用于ZerocopyExecutor
151 : HcclResult CalcIntraServerDataSlicesDiscontinuous(
152 : const OpParam& param, const ExecMem& execMem, u32 level0RankSize, u32 level1RankSize, u32 level2RankSize,
153 : std::vector<Slice>& dataSegsSlice);
154 : HcclResult CalcIntraServerDataSlicesContinuous(
155 : const OpParam& param, const ExecMem& execMem, u32 level0RankSize, u32 level1RankSize, u32 level2RankSize,
156 : std::vector<Slice>& dataSegsSlice);
157 : void CalcLevel1DataSlices(
158 : u64 sliceSize, u32 level1RankSize, u32 level2RankSize, std::vector<Slice>& level1DataSegsSlice);
159 : HcclResult GetCommRankInfoNormal(
160 : u32& level0Rank, u32& level0RankSize, u32& level1Rank, u32& level1RankSize, u32& level2Rank,
161 : 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__ */
|