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
101 : PrepareReduceScatterSliceData(u64 dataCount, u32 unitSize, u32 sliceNum, std::vector<Slice>& dataSlice) const;
102 :
103 : HcclResult MultiRingScatter(
104 : const std::string& tag, DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
105 : const std::vector<std::vector<Slice>> multRingsSliceZero, u32 root, Stream stream, const HcomCollOpInfo* opInfo,
106 : const u64 baseOffset = 0);
107 : std::vector<std::vector<u32>>
108 : GetRingsOrderByTopoType(u32 ranksSize, TopoType topoType, std::vector<u32>& nicList) const;
109 : HcclResult MutliSegSlicePrepare(
110 : const std::vector<Slice>& dataSegsSlice, std::vector<std::vector<Slice>>& mutliSegsSlices, u32 ringCount) const;
111 : HcclResult MutliSegSlicePrepareAvoidCceRewrite(
112 : const std::vector<Slice>& dataSegsSlice, std::vector<std::vector<Slice>>& mutliSegsSlices, u32 ringCount) const;
113 : void NicSendSizeCal(
114 : const std::vector<std::vector<Slice>>& mutliSegsSlices, u32 ringCount, u32 chunkSize,
115 : const std::vector<u32>& nicList, const std::string& tag);
116 : std::vector<std::vector<Slice>> PrepareMultiRingSlice(
117 : const std::vector<Slice>& dataSegsSlice, const std::string& tag, bool avoidCceRewrite = false,
118 : std::vector<u32> nicList = {0, 1, 2, 3, 4, 5, 6, 7}, CommPlane commLevelIndex = COMM_LEVEL0);
119 : // AnyPath特性使用
120 : std::vector<std::vector<u32>>
121 : GetRingsOrderForAnyPath(u32 ranksSize, TopoType topoType, std::vector<u32>& nicList) const;
122 : std::vector<std::vector<Slice>> AnyPathPrepareMultiRingSlice(
123 : const std::vector<Slice>& dataSegsSlice, const std::string& tag, bool avoidCceRewrite = false,
124 : std::vector<u32> nicList = {0, 1, 2, 3, 4, 5, 6, 7});
125 :
126 : bool Is2U2PInfer();
127 : bool Is910BSingleMesh();
128 : bool NeedCreateSingleMeshPlane(const bool isInlineReduce);
129 : bool SingleMeshInlineReduce(void* inputPtr, void* outputPtr, HcclDataType dataType, HcclReduceOp op);
130 : bool IsMultiMeshInlineReduce(void* inputPtr, void* outputPtr, HcclDataType dataType, HcclReduceOp op);
131 :
132 : u64 GetReduceAttr(DeviceMem& inputMem, DeviceMem& outputMem, HcclDataType dataType, HcclReduceOp op);
133 : HcclResult PrepareLevel1CommInfo(
134 : u32& segmentIdx, u32& commIndex, u64& hdSize, const SubCommInfo& commInfo,
135 : const std::vector<std::vector<Slice>>& multRingsSliceZero, const std::string& tag);
136 : HcclResult GetAdjInfo(AlgResourceResponse& algRes, AdjInfo& adjInfo) override;
137 :
138 : protected:
139 : virtual HcclResult GetSubStreamInfoOnOneRing(
140 : const u32 ringIndex, 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(
145 : const HcclDataType dataType, const HcomCollOpInfo* opInfo, const std::vector<Slice>& singleRingSliceZero,
146 : u32 ringIndex, const std::vector<std::vector<u32>>& multiRingsOrder, std::vector<Slice>& userMemSlices);
147 : HcclResult GetRankOrder(
148 : const std::vector<std::vector<u32>>& multiRingsOrder, u32 ringIndex, std::vector<u32>& rankOrder) const;
149 : HcclResult SetRingNics(const std::string& tag, const std::vector<std::vector<u32>>& ringNics);
150 : HcclResult GetRingNics(const std::string& tag, std::vector<std::vector<u32>>& ringNics);
151 : HcclResult SetNicSendSize(const std::string& tag, std::vector<u64>& sizeList);
152 :
153 : // 用于ZerocopyExecutor
154 : HcclResult CalcIntraServerDataSlicesDiscontinuous(
155 : const OpParam& param, const ExecMem& execMem, u32 level0RankSize, u32 level1RankSize, u32 level2RankSize,
156 : std::vector<Slice>& dataSegsSlice);
157 : HcclResult CalcIntraServerDataSlicesContinuous(
158 : const OpParam& param, const ExecMem& execMem, u32 level0RankSize, u32 level1RankSize, u32 level2RankSize,
159 : std::vector<Slice>& dataSegsSlice) const;
160 : void CalcLevel1DataSlices(
161 : u64 sliceSize, u32 level1RankSize, u32 level2RankSize, std::vector<Slice>& level1DataSegsSlice) const;
162 : HcclResult GetCommRankInfoNormal(
163 : u32& level0Rank, u32& level0RankSize, u32& level1Rank, u32& level1RankSize, u32& level2Rank,
164 : u32& level2RankSize, bool isAHCAlgo = false);
165 :
166 : // 用于ExchangeExecutor
167 : HcclResult CalExchangeRemoteRankForReduceScatter(u32& remoteRankSend, u32& remoteRankRecv);
168 : HcclResult GetTransportForExchange(u32 remoteUserRank, LINK& targetLink);
169 : bool IsLevel0Neighbor(u32 remoteRank, u32 level0RankSize);
170 :
171 : std::mutex ringNicListLock_;
172 : std::map<std::string, std::vector<std::vector<u32>>> ringNicList_;
173 : std::mutex nicSendSizeListLock_;
174 : std::map<std::string, std::vector<u64>> nicSendSizeList_;
175 : };
176 : } // namespace hccl
177 :
178 : #endif /** __COLL_COMMON_EXECUTOR_H__ */
|