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 DISPATCHER_TASK_TYPES_H
12 : #define DISPATCHER_TASK_TYPES_H
13 :
14 : #include <memory>
15 : #include <mutex>
16 : #include <string>
17 : #include <map>
18 : #include <thread>
19 :
20 : #include <hccl/hccl_types.h>
21 : #include "hccl_common.h"
22 : #include "workflow_pub.h"
23 :
24 : namespace hccl {
25 : enum class TaskType {
26 : TASK_SDMA = 0,
27 : TASK_RDMA,
28 : TASK_REDUCE_INLINE,
29 : TASK_REDUCE_TBE,
30 : TASK_NOTIFY_RECORD,
31 : TASK_NOTIFY_WAIT,
32 : TASK_HOST,
33 : TASK_GRAPH_LAUNCH,
34 : TASK_BATCH_REPORT,
35 : TASK_FLIP
36 : };
37 :
38 : enum class SimpleTaskType { SDMA = 0, RDMA = 1, LOCAL = 2, RESERVED = 255 };
39 :
40 : enum class TaskRole { DST = 0, SRC = 1, RESERVED = 255 };
41 :
42 : enum class LinkType {
43 : LINK_ONCHIP = 0,
44 : LINK_HCCS = 1,
45 : LINK_PCIE = 2,
46 : LINK_ROCE = 3,
47 : LINK_SIO = 4,
48 : LINK_HCCS_SW = 5,
49 : LINK_STANDARD_ROCE = 6,
50 : LINK_UB = 7,
51 : LINK_RESERVED = 255
52 : };
53 :
54 : enum class RdmaType { RDMA_SEND_NOTIFY = 0, RDMA_SEND_PAYLOAD = 1, RDMA_TYPE_RESERVED = 255 };
55 :
56 : enum class ProfilerType { TASK_PROFILING = 0, TASK_EXCEPTION = 1, TASK_OVERFLOW, TASK_ALL, TASK_RESERVE };
57 :
58 : struct StepData {
59 : s32 streamID;
60 : s32 planeID; // bit[31..28] = 节点内8P-ring对应的物理环, bit[27..16] = rank_size, bit[15..0] = rank_id
61 : s32 stage;
62 : s32 step;
63 :
64 232 : StepData() : streamID(0), planeID(0), stage(0), step(-1) {}
65 : };
66 :
67 : struct TaskParaDMA {
68 : const void* src{nullptr};
69 : const void* dst{nullptr};
70 : std::size_t size{0};
71 : u64 notifyID{INVALID_U64};
72 : LinkType linkType{LinkType::LINK_ONCHIP};
73 : u32 remoteUserRank{INVALID_VALUE_RANKID};
74 : RdmaType rdmaType{RdmaType::RDMA_TYPE_RESERVED};
75 : u32 ctxId{INVALID_UINT}; // 子图 ctxId信息
76 54 : TaskParaDMA() {}
77 :
78 : TaskParaDMA(const void* inputSrc, const void* inputDst, std::size_t inputSize)
79 : : src(inputSrc),
80 : dst(inputDst),
81 : size(inputSize),
82 : notifyID(INVALID_U64),
83 : linkType(LinkType::LINK_ONCHIP),
84 : remoteUserRank(INVALID_VALUE_RANKID),
85 : rdmaType(RdmaType::RDMA_TYPE_RESERVED),
86 : ctxId(INVALID_UINT)
87 : {}
88 :
89 : TaskParaDMA(const void* inputSrc, const void* inputDst, std::size_t inputSize, u64 inputNotifyID)
90 : : src(inputSrc),
91 : dst(inputDst),
92 : size(inputSize),
93 : notifyID(inputNotifyID),
94 : linkType(LinkType::LINK_ONCHIP),
95 : remoteUserRank(INVALID_VALUE_RANKID),
96 : rdmaType(RdmaType::RDMA_TYPE_RESERVED),
97 : ctxId(INVALID_UINT)
98 : {}
99 :
100 0 : TaskParaDMA(
101 : const void* inputSrc, const void* inputDst, std::size_t inputSize, u64 inputNotifyID, LinkType inputLinkType,
102 : RdmaType inputRdmaType)
103 0 : : src(inputSrc),
104 0 : dst(inputDst),
105 0 : size(inputSize),
106 0 : notifyID(inputNotifyID),
107 0 : linkType(inputLinkType),
108 0 : remoteUserRank(static_cast<u32>(inputNotifyID >> 32)), // notifyID的高32位为对端usrrank
109 0 : rdmaType(inputRdmaType),
110 0 : ctxId(INVALID_UINT)
111 0 : {}
112 32 : TaskParaDMA(
113 : const void* inputSrc, const void* inputDst, std::size_t inputSize, LinkType inputLinkType,
114 : u32 remoteUserRank) // 无notifyID时需要传入remoteUserRank
115 32 : : src(inputSrc),
116 32 : dst(inputDst),
117 32 : size(inputSize),
118 32 : notifyID(INVALID_U64),
119 32 : linkType(inputLinkType),
120 32 : remoteUserRank(remoteUserRank),
121 32 : rdmaType(RdmaType::RDMA_TYPE_RESERVED),
122 32 : ctxId(INVALID_UINT)
123 32 : {}
124 4 : TaskParaDMA(
125 : const void* inputSrc, const void* inputDst, std::size_t inputSize, u64 inputNotifyID, LinkType inputLinkType,
126 : RdmaType inputRdmaType, u32 inputCtxId)
127 4 : : src(inputSrc),
128 4 : dst(inputDst),
129 4 : size(inputSize),
130 4 : notifyID(inputNotifyID),
131 4 : linkType(inputLinkType),
132 4 : remoteUserRank(static_cast<u32>(inputNotifyID >> 32)), // notifyID的高32位为对端usrrank
133 4 : rdmaType(inputRdmaType),
134 4 : ctxId(inputCtxId)
135 4 : {}
136 0 : TaskParaDMA(
137 : const void* inputSrc, const void* inputDst, std::size_t inputSize, LinkType inputLinkType, u32 remoteUserRank,
138 : RdmaType inputRdmaType, u32 inputCtxId)
139 0 : : src(inputSrc),
140 0 : dst(inputDst),
141 0 : size(inputSize),
142 0 : notifyID(INVALID_U64),
143 0 : linkType(inputLinkType),
144 0 : remoteUserRank(remoteUserRank),
145 0 : rdmaType(inputRdmaType),
146 0 : ctxId(inputCtxId)
147 0 : {}
148 : };
149 :
150 : struct TaskParaReduce {
151 : const void* src;
152 : const void* dst;
153 : std::size_t size;
154 :
155 : HcclReduceOp op;
156 : HcclDataType dataType;
157 : LinkType linkType;
158 : u32 remoteUserRank;
159 : u32 ctxId; // 子图 ctxId信息
160 33 : TaskParaReduce()
161 33 : : src(nullptr),
162 33 : dst(nullptr),
163 33 : size(0),
164 33 : op(HCCL_REDUCE_RESERVED),
165 33 : dataType(HCCL_DATA_TYPE_RESERVED),
166 33 : linkType(LinkType::LINK_ONCHIP),
167 33 : remoteUserRank(INVALID_UINT),
168 33 : ctxId(INVALID_UINT)
169 33 : {}
170 :
171 : TaskParaReduce(
172 : const void* inputSrc, const void* inputDst, std::size_t inputSize, HcclReduceOp inputOp,
173 : HcclDataType inputDataType)
174 : : src(inputSrc),
175 : dst(inputDst),
176 : size(inputSize),
177 : op(inputOp),
178 : dataType(inputDataType),
179 : linkType(LinkType::LINK_ONCHIP),
180 : remoteUserRank(INVALID_UINT),
181 : ctxId(INVALID_UINT)
182 : {}
183 :
184 0 : TaskParaReduce(
185 : const void* inputSrc, const void* inputDst, std::size_t inputSize, HcclReduceOp inputOp,
186 : HcclDataType inputDataType, LinkType inputLinkType)
187 0 : : src(inputSrc),
188 0 : dst(inputDst),
189 0 : size(inputSize),
190 0 : op(inputOp),
191 0 : dataType(inputDataType),
192 0 : linkType(inputLinkType),
193 0 : remoteUserRank(INVALID_UINT),
194 0 : ctxId(INVALID_UINT)
195 0 : {}
196 9 : TaskParaReduce(
197 : const void* inputSrc, const void* inputDst, std::size_t inputSize, HcclReduceOp inputOp,
198 : HcclDataType inputDataType, LinkType inputLinkType, u32 remoteUserRank)
199 9 : : src(inputSrc),
200 9 : dst(inputDst),
201 9 : size(inputSize),
202 9 : op(inputOp),
203 9 : dataType(inputDataType),
204 9 : linkType(inputLinkType),
205 9 : remoteUserRank(remoteUserRank),
206 9 : ctxId(INVALID_UINT)
207 9 : {}
208 0 : TaskParaReduce(
209 : const void* inputSrc, const void* inputDst, std::size_t inputSize, HcclReduceOp inputOp,
210 : HcclDataType inputDataType, LinkType inputLinkType, u32 remoteUserRank, u32 inputCtxId)
211 0 : : src(inputSrc),
212 0 : dst(inputDst),
213 0 : size(inputSize),
214 0 : op(inputOp),
215 0 : dataType(inputDataType),
216 0 : linkType(inputLinkType),
217 0 : remoteUserRank(remoteUserRank),
218 0 : ctxId(inputCtxId)
219 0 : {}
220 : };
221 :
222 : struct TaskParaNotify {
223 : u64 notifyID;
224 : s32 stage; // 用于标识stream间同步时所在的stage, 非用于stream同步的默认为-1
225 : u32 remoteUserRank;
226 : u32 ctxId; // 子图 ctxId信息
227 49 : TaskParaNotify() : notifyID(0), stage(INVALID_VALUE_STAGE), remoteUserRank(INVALID_UINT), ctxId(INVALID_UINT) {}
228 : explicit TaskParaNotify(u64 notifyIDInput)
229 : : notifyID(notifyIDInput),
230 : stage(INVALID_VALUE_STAGE),
231 : remoteUserRank(static_cast<u32>(notifyIDInput >> 32)), // 无remoteRank时,使用notify的高32位为remote rank
232 : ctxId(INVALID_UINT)
233 : {}
234 0 : TaskParaNotify(u64 notifyIDInput, s32 stageIn)
235 0 : : notifyID(notifyIDInput),
236 0 : stage(stageIn),
237 0 : remoteUserRank(static_cast<u32>(notifyIDInput >> 32)), // 无remoteRank时,使用notify的高32位为remote rank
238 0 : ctxId(INVALID_UINT)
239 0 : {}
240 6 : TaskParaNotify(u64 notifyIDInput, s32 stageIn, u32 remoteUserRank)
241 6 : : notifyID(notifyIDInput),
242 6 : stage(stageIn),
243 6 : remoteUserRank(remoteUserRank),
244 6 : ctxId(INVALID_UINT)
245 6 : {}
246 0 : TaskParaNotify(u64 notifyIDInput, s32 stageIn, u32 remoteUserRank, u32 ctxIdInput)
247 0 : : notifyID(notifyIDInput),
248 0 : stage(stageIn),
249 0 : remoteUserRank(remoteUserRank),
250 0 : ctxId(ctxIdInput)
251 0 : {}
252 : };
253 :
254 : struct TaskParaHost {
255 : u32 streamID;
256 : u32 taskID;
257 : u64 len;
258 : std::chrono::microseconds duration;
259 : std::string tag;
260 0 : TaskParaHost(u32 streamID, u32 taskID, u64 len, std::chrono::microseconds duration, std::string& tag)
261 0 : : streamID(streamID),
262 0 : taskID(taskID),
263 0 : len(len),
264 0 : duration(duration),
265 0 : tag(tag)
266 0 : {}
267 : };
268 :
269 : struct TaskParaGraphLaunch {
270 : u32 ctxNum{0};
271 : const void* descBuf{nullptr};
272 : size_t descBufLen{0};
273 : };
274 :
275 : // aicpu展开模式当前下到流上的所有task profiling信息
276 : struct AiCPUStreamTasks {
277 : s32 streamID;
278 : void* ctxPtr;
279 0 : AiCPUStreamTasks(u32 streamID, void* ctxPtr) : streamID(streamID), ctxPtr(ctxPtr) {}
280 : };
281 :
282 : // 发生翻转task profiling信息
283 : // 发生翻转的情况:1、重执行开始时;2、u16发生翻转task等于0时
284 : struct FlipTaskPara {
285 : s32 streamID;
286 : u16 taskID;
287 : u32 flipNum;
288 0 : FlipTaskPara(s32 streamID, u16 taskID, u16 flipNum) : streamID(streamID), taskID(taskID), flipNum(flipNum) {}
289 : };
290 :
291 : struct TaskPara {
292 : TaskType type{TaskType::TASK_NOTIFY_RECORD};
293 : ProfilerType profilerType{ProfilerType::TASK_ALL};
294 : void* stream{nullptr};
295 : bool isMainStream{false};
296 : u64 beginTime{0};
297 : bool isFftsDispatcher{false};
298 : union {
299 : struct TaskParaDMA dma;
300 : struct TaskParaReduce reduce;
301 : struct TaskParaNotify notify;
302 : struct TaskParaHost host;
303 : struct TaskParaGraphLaunch graphLaunch;
304 : struct AiCPUStreamTasks streamTasks;
305 : struct FlipTaskPara flipTask;
306 : };
307 :
308 38 : TaskPara()
309 38 : : type(TaskType::TASK_NOTIFY_RECORD),
310 38 : profilerType(ProfilerType::TASK_ALL),
311 38 : stream(nullptr),
312 38 : isMainStream(false),
313 38 : beginTime(0),
314 38 : isFftsDispatcher(false),
315 38 : dma()
316 38 : {}
317 :
318 9 : TaskPara(TaskType type, TaskParaReduce reduce)
319 9 : : type(type),
320 9 : profilerType(ProfilerType::TASK_ALL),
321 9 : stream(nullptr),
322 9 : isMainStream(false),
323 9 : beginTime(0),
324 9 : isFftsDispatcher(false),
325 9 : reduce(reduce)
326 9 : {}
327 :
328 0 : TaskPara(TaskType type, TaskParaNotify notify)
329 0 : : type(type),
330 0 : profilerType(ProfilerType::TASK_ALL),
331 0 : stream(nullptr),
332 0 : isMainStream(false),
333 0 : beginTime(0),
334 0 : isFftsDispatcher(false),
335 0 : notify(notify)
336 0 : {}
337 :
338 0 : TaskPara(TaskType type, TaskParaHost host)
339 0 : : type(type),
340 0 : profilerType(ProfilerType::TASK_ALL),
341 0 : stream(nullptr),
342 0 : isMainStream(false),
343 0 : beginTime(0),
344 0 : isFftsDispatcher(false),
345 0 : host(host)
346 0 : {}
347 :
348 : TaskPara(TaskType type, TaskParaGraphLaunch graphLaunch)
349 : : type(type),
350 : profilerType(ProfilerType::TASK_ALL),
351 : stream(nullptr),
352 : isMainStream(false),
353 : beginTime(0),
354 : isFftsDispatcher(false),
355 : graphLaunch(graphLaunch)
356 : {}
357 :
358 0 : TaskPara(TaskType type, AiCPUStreamTasks streamTasks)
359 0 : : type(type),
360 0 : profilerType(ProfilerType::TASK_ALL),
361 0 : stream(nullptr),
362 0 : isMainStream(false),
363 0 : beginTime(0),
364 0 : isFftsDispatcher(false),
365 0 : streamTasks(streamTasks)
366 0 : {}
367 :
368 0 : TaskPara(TaskType type, FlipTaskPara flipTask)
369 0 : : type(type),
370 0 : profilerType(ProfilerType::TASK_ALL),
371 0 : stream(nullptr),
372 0 : isMainStream(false),
373 0 : beginTime(0),
374 0 : isFftsDispatcher(false),
375 0 : flipTask(flipTask)
376 0 : {}
377 :
378 47 : ~TaskPara() {}
379 : };
380 :
381 : } // namespace hccl
382 :
383 : #endif /* DISPATCHER_TASK_TYPES_H */
|