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 CCU_ERROR_HANDLER_H
12 : #define CCU_ERROR_HANDLER_H
13 :
14 : #include <vector>
15 : #include "hccl_types.h"
16 : #include "task_param.h"
17 : #include "ccu_error_info.h"
18 : #include "ccu_rep_base.h"
19 : #include "ccu_rep_context.h"
20 :
21 : namespace Hccl {
22 :
23 : struct CcuMissionContext {
24 : union {
25 : uint16_t value;
26 : uint16_t taskId;
27 : } part0;
28 :
29 : union {
30 : uint16_t value;
31 : uint16_t streamId;
32 : } part1;
33 :
34 : union {
35 : uint16_t value;
36 : struct {
37 : uint16_t taskKill : 1;
38 : uint16_t dieId : 2;
39 : uint16_t status : 13; // Status [12:0]
40 : };
41 : } part2;
42 :
43 : union {
44 : uint16_t value;
45 : struct {
46 : uint16_t status : 3; // Status [15:13]
47 : uint16_t counter : 8;
48 : uint16_t denyCnt : 5;
49 : };
50 : } part3;
51 :
52 : union {
53 : uint16_t value;
54 : struct {
55 : uint16_t denyCnt : 5;
56 : uint16_t currentIns : 11; // Current Ins [10:0]
57 : };
58 : } part4;
59 :
60 : union {
61 : uint16_t value;
62 : struct {
63 : uint16_t currentIns : 5; // Current Ins [15:11]
64 : uint16_t endIns : 11;
65 : };
66 : } part5;
67 :
68 : union {
69 : uint16_t value;
70 : struct {
71 : uint16_t endIns : 5;
72 : uint16_t startIns : 11;
73 : };
74 : } part6;
75 :
76 : union {
77 : uint16_t value;
78 : struct {
79 : uint16_t startIns : 5;
80 : uint16_t profileEn : 1;
81 : uint16_t missionVld : 1;
82 : uint16_t reserved : 9;
83 : };
84 : } part7;
85 :
86 : uint16_t reserved[24]; // part 8-31
87 :
88 770 : uint16_t GetStatus() const
89 : {
90 770 : return (part3.status << 13) | (part2.status); // part3.status为[15:13]位
91 : }
92 :
93 2 : uint16_t GetCurrentIns() const
94 : {
95 2 : return (part5.currentIns << 11) | (part4.currentIns); // part5.currentIns为[15:11]位
96 : }
97 :
98 0 : uint16_t GetStartIns() const
99 : {
100 0 : return (part7.startIns << 11) | (part6.startIns); // part7.startIns[15:11]位
101 : }
102 :
103 0 : uint16_t GetEndIns() const
104 : {
105 0 : return (part6.endIns << 11) | (part5.endIns); // part6.endIns[15:11]位
106 : }
107 : };
108 :
109 : struct CcuLoopContext {
110 : union {
111 : uint16_t value;
112 : uint16_t timestamp;
113 : } part0;
114 :
115 : union {
116 : uint16_t value;
117 : uint16_t timestamp;
118 : } part1;
119 :
120 : union {
121 : uint16_t value;
122 : struct {
123 : uint16_t timestamp : 4;
124 : uint16_t ckeOffset : 10;
125 : uint16_t msOffset : 2;
126 : };
127 : } part2;
128 :
129 : union {
130 : uint16_t value;
131 : struct {
132 : uint16_t msOffset : 9;
133 : uint16_t addrOffset : 7;
134 : };
135 : } part3;
136 :
137 : union {
138 : uint16_t value;
139 : uint16_t addrOffset;
140 : } part4;
141 :
142 : union {
143 : uint16_t value;
144 : struct {
145 : uint16_t addrOffset : 9;
146 : uint16_t ckBit : 7;
147 : };
148 : } part5;
149 :
150 : union {
151 : uint16_t value;
152 : uint16_t ckBit;
153 : } part6;
154 :
155 : union {
156 : uint16_t value;
157 : struct {
158 : uint16_t ckBit : 9;
159 : uint16_t perfMode : 1;
160 : uint16_t waitLoopCkbitValue : 6;
161 : };
162 : } part7;
163 :
164 : union {
165 : uint16_t value;
166 : uint16_t waitLoopCkbitValue;
167 : } part8;
168 :
169 : union {
170 : uint16_t value;
171 : struct {
172 : uint16_t waitLoopCkbitValue : 10;
173 : uint16_t currentIns : 6; // Current_ins [5:0]
174 : };
175 : } part9;
176 :
177 : union {
178 : uint16_t value;
179 : struct {
180 : uint16_t currentIns : 10; // Current_ins [15:6]
181 : uint16_t addrStride : 6; // Addr_stride [5:0]
182 : };
183 : } part10;
184 :
185 : union {
186 : uint16_t value;
187 : uint16_t addrStride; // Addr_stride [21:6]
188 : } part11;
189 :
190 : union {
191 : uint16_t value;
192 : struct {
193 : uint16_t addrStride : 10; // Addr_stride [31:22]
194 : uint16_t denyCnt : 6;
195 : };
196 : } part12;
197 :
198 : union {
199 : uint16_t value;
200 : struct {
201 : uint16_t denyCnt : 4;
202 : uint16_t currentCnt : 12; // Current_cnt [11:0]
203 : };
204 : } part13;
205 :
206 : union {
207 : uint16_t value;
208 : struct {
209 : uint16_t currentCnt : 1; // Current_cnt [12]
210 : uint16_t totalCnt : 13;
211 : uint16_t endIns : 2;
212 : };
213 : } part14;
214 :
215 : union {
216 : uint16_t value;
217 : struct {
218 : uint16_t endIns : 14;
219 : uint16_t startIns : 2;
220 : };
221 : } part15;
222 :
223 : union {
224 : uint16_t value;
225 : struct {
226 : uint16_t startIns : 14;
227 : uint16_t missionId : 2;
228 : };
229 : } part16;
230 :
231 : union {
232 : uint16_t value;
233 : struct {
234 : uint16_t missionId : 2;
235 : uint16_t reserved : 14;
236 : };
237 : } part17;
238 :
239 : uint16_t reserved[14]; // part 18-31
240 :
241 2 : uint16_t GetCurrentIns() const
242 : {
243 2 : return (part10.currentIns << 6) | (part9.currentIns); // part10.currentIns为[15:6]位
244 : }
245 :
246 4 : uint16_t GetCurrentCnt() const
247 : {
248 4 : return (part14.currentCnt << 12) | (part13.currentCnt); // part14.currentCnt为第[12]位
249 : }
250 :
251 4 : uint32_t GetAddrStride() const
252 : {
253 4 : const uint32_t low = static_cast<uint32_t>(part10.addrStride);
254 4 : const uint32_t mid = static_cast<uint32_t>(part11.addrStride) << 6; // part11.addrStride为[21:6]位
255 4 : const uint32_t high = static_cast<uint32_t>(part12.addrStride) << 22; // part12.addrStride为[31:22]位
256 4 : return high | mid | low;
257 : }
258 : };
259 :
260 : union LoopXm {
261 : uint64_t value;
262 : struct {
263 : uint64_t loopCnt : 13;
264 : uint64_t gsaStride : 32;
265 : uint64_t loopCtxId : 8;
266 : uint64_t reserved : 11;
267 : };
268 : };
269 :
270 : union LoopGroupXn {
271 : uint64_t value;
272 : struct {
273 : uint64_t reservedLow : 41;
274 : uint64_t loopInsCnt : 7;
275 : uint64_t expandOffset : 7;
276 : uint64_t expandCnt : 7;
277 : uint64_t reservedHigh : 2;
278 : };
279 : };
280 :
281 : union LoopGroupXm {
282 : uint64_t value;
283 : struct {
284 : uint64_t ckOffset : 10;
285 : uint64_t msOffset : 11;
286 : uint64_t gsaOffset : 32;
287 : uint64_t reserved : 11;
288 : };
289 : };
290 :
291 : struct ErrorInfoBase {
292 : int32_t deviceId;
293 : uint8_t dieId;
294 : uint8_t missionId;
295 : uint16_t currentInsId;
296 : uint16_t status;
297 : };
298 :
299 : class CcuErrorHandler {
300 : public:
301 : CcuErrorHandler() = delete;
302 : CcuErrorHandler(const CcuErrorHandler&) = delete;
303 : void operator=(const CcuErrorHandler&) = delete;
304 :
305 : static void GetCcuErrorMsg(
306 : int32_t deviceId, uint16_t missionStatus, const ParaCcu& ccuTaskParam, const std::string& groupRankContent,
307 : std::vector<CcuErrorInfo>& errorInfo);
308 : static void GetCcuJettys(int32_t deviceId, const ParaCcu& ccuTaskParam, std::vector<CcuJetty*> ccuJettys);
309 : static CcuMissionContext GetCcuMissionContext(int32_t deviceId, uint32_t dieId, uint32_t missionId);
310 :
311 : private:
312 : static void GenStatusInfo(
313 : const ErrorInfoBase& baseInfo, const std::string& groupRankContent, std::vector<CcuErrorInfo>& errorInfo);
314 :
315 : // LoopGroup
316 : static void GenErrorInfoLoopGroup(
317 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase, CcuRep::CcuRepContext& ctx,
318 : std::vector<CcuErrorInfo>& errorInfo);
319 : // Loop
320 : static void
321 : GenErrorInfoLoop(const ErrorInfoBase& baseInfo, CcuRep::CcuRepContext& ctx, std::vector<CcuErrorInfo>& errorInfo);
322 :
323 : static void GenErrorInfoByRepType(
324 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
325 : std::vector<CcuErrorInfo>& errorInfo);
326 : // Default
327 : static void GenErrorInfoDefault(
328 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
329 : std::vector<CcuErrorInfo>& errorInfo);
330 : // WaitSignal
331 : static void GenErrorInfoLocPostSem(
332 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
333 : std::vector<CcuErrorInfo>& errorInfo);
334 : static void GenErrorInfoLocWaitSem(
335 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
336 : std::vector<CcuErrorInfo>& errorInfo);
337 : static void GenErrorInfoRemPostSem(
338 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
339 : std::vector<CcuErrorInfo>& errorInfo);
340 : static void GenErrorInfoRemWaitSem(
341 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
342 : std::vector<CcuErrorInfo>& errorInfo);
343 : static void GenErrorInfoRemPostVar(
344 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
345 : std::vector<CcuErrorInfo>& errorInfo);
346 : static void GenErrorInfoRemWaitGroup(
347 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
348 : std::vector<CcuErrorInfo>& errorInfo);
349 : static void GenErrorInfoPostSharedVar(
350 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
351 : std::vector<CcuErrorInfo>& errorInfo);
352 : static void GenErrorInfoPostSharedSem(
353 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
354 : std::vector<CcuErrorInfo>& errorInfo);
355 : // TransMem
356 : static void GenErrorInfoRead(
357 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
358 : std::vector<CcuErrorInfo>& errorInfo);
359 : static void GenErrorInfoWrite(
360 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
361 : std::vector<CcuErrorInfo>& errorInfo);
362 : static void GenErrorInfoLocalCpy(
363 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
364 : std::vector<CcuErrorInfo>& errorInfo);
365 : static void GenErrorInfoLocalReduce(
366 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
367 : std::vector<CcuErrorInfo>& errorInfo);
368 : // BufTransMem
369 : static void GenErrorInfoBufRead(
370 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
371 : std::vector<CcuErrorInfo>& errorInfo);
372 : static void GenErrorInfoBufWrite(
373 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
374 : std::vector<CcuErrorInfo>& errorInfo);
375 : static void GenErrorInfoBufLocRead(
376 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
377 : std::vector<CcuErrorInfo>& errorInfo);
378 : static void GenErrorInfoBufLocWrite(
379 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
380 : std::vector<CcuErrorInfo>& errorInfo);
381 : // BufReduce
382 : static void GenErrorInfoBufReduce(
383 : const ErrorInfoBase& baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase,
384 : std::vector<CcuErrorInfo>& errorInfo);
385 :
386 : static CcuLoopContext GetCcuLoopContext(int32_t deviceId, uint32_t dieId, uint32_t loopCtxId);
387 : static uint64_t GetCcuXnValue(int32_t deviceId, uint32_t dieId, uint32_t xnId);
388 : static uint64_t GetCcuGSAValue(int32_t deviceId, uint32_t dieId, uint32_t gsaId);
389 : static uint16_t GetCcuCKEValue(int32_t deviceId, uint32_t dieId, uint32_t ckeId);
390 : };
391 :
392 : } // namespace Hccl
393 : #endif // CCU_ERROR_HANDLER_H
|