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