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_INFO_V1_H
12 : #define CCU_ERROR_INFO_V1_H
13 : #include <cstdint>
14 : #include "enum_factory.h"
15 : #include "ccu_rep_type_v1.h"
16 : #include "ccu_error_info_v2.h"
17 :
18 : namespace hcomm {
19 : constexpr uint32_t MISSION_STATUS_MSG_LEN = 64;
20 : constexpr uint32_t WAIT_SIGNAL_CHANNEL_SIZE = 16;
21 : constexpr uint32_t BUF_REDUCE_ID_SIZE = 8;
22 :
23 214 : MAKE_ENUM(CcuErrorType, DEFAULT, MISSION, WAIT_SIGNAL, TRANS_MEM, BUF_TRANS_MEM, BUF_REDUCE, LOOP, LOOP_GROUP)
24 :
25 : struct CcuErrorInfo {
26 : // 根据不同的typeId解析不同的union类型
27 : CcuErrorType type;
28 :
29 : // 出异常的Rep类型
30 : CcuRep::CcuRepType repType;
31 :
32 : // CCU任务执行的DieId
33 : uint8_t dieId;
34 :
35 : // CCU任务执行的MissionId
36 : uint8_t missionId;
37 :
38 : // Error所在的指令Id
39 : uint16_t instrId;
40 :
41 : union {
42 : struct {
43 : char missionError[MISSION_STATUS_MSG_LEN];
44 : } mission;
45 :
46 : struct {
47 : uint16_t signalId;
48 : uint16_t signalMask;
49 : uint16_t signalValue;
50 : uint16_t paramId;
51 : uint64_t paramValue;
52 : uint16_t channelId[WAIT_SIGNAL_CHANNEL_SIZE];
53 : } waitSignal;
54 :
55 : struct {
56 : uint64_t locAddr;
57 : uint64_t locToken;
58 : uint64_t rmtAddr;
59 : uint64_t rmtToken;
60 : uint64_t len;
61 : uint16_t signalId;
62 : uint16_t signalMask;
63 : uint16_t channelId;
64 : uint16_t dataType;
65 : uint16_t opType;
66 : } transMem;
67 :
68 : struct {
69 : uint16_t bufId;
70 : uint16_t signalId;
71 : uint16_t signalMask;
72 : uint16_t channelId;
73 : uint64_t addr;
74 : uint64_t token;
75 : uint64_t len;
76 : } bufTransMem;
77 :
78 : struct {
79 : uint16_t bufIds[BUF_REDUCE_ID_SIZE];
80 : uint16_t count;
81 : uint16_t dataType;
82 : uint16_t outputDataType;
83 : uint16_t opType;
84 : uint16_t signalId;
85 : uint16_t signalMask;
86 : uint16_t xnIdLength;
87 : } bufReduce;
88 :
89 : struct {
90 : uint16_t startInstrId;
91 : uint16_t endInstrId;
92 : uint16_t loopEngineId;
93 : uint16_t loopCnt; // 该Loop需要循环执行的次数
94 : uint16_t loopCurrentCnt; // 该Loop已经循环次数
95 : uint32_t addrStride;
96 : } loop;
97 :
98 : struct {
99 : uint16_t startLoopInsId;
100 : uint16_t loopInsCnt;
101 : uint16_t expandOffset;
102 : uint16_t expandCnt;
103 : } loopGroup;
104 : } msg;
105 :
106 22 : void SetBaseInfo(CcuRep::CcuRepType ccuRepType, uint8_t ccuDieId, uint8_t ccuMissionId, uint16_t insId)
107 : {
108 22 : this->repType = ccuRepType;
109 22 : this->dieId = ccuDieId;
110 22 : this->missionId = ccuMissionId;
111 22 : this->instrId = insId;
112 22 : }
113 : };
114 :
115 : struct ErrorInfoBase {
116 : int32_t deviceId;
117 : uint8_t dieId;
118 : uint8_t missionId;
119 : uint16_t currentInsId;
120 : uint16_t status;
121 : };
122 :
123 : union LoopXm {
124 : uint64_t value;
125 : struct {
126 : uint64_t loopCnt : 13;
127 : uint64_t gsaStride : 32;
128 : uint64_t loopCtxId : 8;
129 : uint64_t reserved : 11;
130 : };
131 : };
132 :
133 : struct CcuLoopContext {
134 : union {
135 : uint16_t value;
136 : uint16_t timestamp;
137 : } part0;
138 :
139 : union {
140 : uint16_t value;
141 : uint16_t timestamp;
142 : } part1;
143 :
144 : union {
145 : uint16_t value;
146 : struct {
147 : uint16_t timestamp : 4;
148 : uint16_t ckeOffset : 10;
149 : uint16_t msOffset : 2;
150 : };
151 : } part2;
152 :
153 : union {
154 : uint16_t value;
155 : struct {
156 : uint16_t msOffset : 9;
157 : uint16_t addrOffset : 7;
158 : };
159 : } part3;
160 :
161 : union {
162 : uint16_t value;
163 : uint16_t addrOffset;
164 : } part4;
165 :
166 : union {
167 : uint16_t value;
168 : struct {
169 : uint16_t addrOffset : 9;
170 : uint16_t ckBit : 7;
171 : };
172 : } part5;
173 :
174 : union {
175 : uint16_t value;
176 : uint16_t ckBit;
177 : } part6;
178 :
179 : union {
180 : uint16_t value;
181 : struct {
182 : uint16_t ckBit : 9;
183 : uint16_t perfMode : 1;
184 : uint16_t waitLoopCkbitValue : 6;
185 : };
186 : } part7;
187 :
188 : union {
189 : uint16_t value;
190 : uint16_t waitLoopCkbitValue;
191 : } part8;
192 :
193 : union {
194 : uint16_t value;
195 : struct {
196 : uint16_t waitLoopCkbitValue : 10;
197 : uint16_t currentIns : 6; // Current_ins [5:0]
198 : };
199 : } part9;
200 :
201 : union {
202 : uint16_t value;
203 : struct {
204 : uint16_t currentIns : 10; // Current_ins [15:6]
205 : uint16_t addrStride : 6; // Addr_stride [5:0]
206 : };
207 : } part10;
208 :
209 : union {
210 : uint16_t value;
211 : uint16_t addrStride; // Addr_stride [21:6]
212 : } part11;
213 :
214 : union {
215 : uint16_t value;
216 : struct {
217 : uint16_t addrStride : 10; // Addr_stride [31:22]
218 : uint16_t denyCnt : 6;
219 : };
220 : } part12;
221 :
222 : union {
223 : uint16_t value;
224 : struct {
225 : uint16_t denyCnt : 4;
226 : uint16_t currentCnt : 12; // Current_cnt [11:0]
227 : };
228 : } part13;
229 :
230 : union {
231 : uint16_t value;
232 : struct {
233 : uint16_t currentCnt : 1; // Current_cnt [12]
234 : uint16_t totalCnt : 13;
235 : uint16_t endIns : 2;
236 : };
237 : } part14;
238 :
239 : union {
240 : uint16_t value;
241 : struct {
242 : uint16_t endIns : 14;
243 : uint16_t startIns : 2;
244 : };
245 : } part15;
246 :
247 : union {
248 : uint16_t value;
249 : struct {
250 : uint16_t startIns : 14;
251 : uint16_t missionId : 2;
252 : };
253 : } part16;
254 :
255 : union {
256 : uint16_t value;
257 : struct {
258 : uint16_t missionId : 2;
259 : uint16_t reserved : 14;
260 : };
261 : } part17;
262 :
263 : uint16_t reserved[14]; // part 18-31
264 :
265 1 : uint16_t GetCurrentIns() const
266 : {
267 1 : return (part10.currentIns << 6) | (part9.currentIns); // part10.currentIns为[15:6]位
268 : }
269 :
270 2 : uint16_t GetCurrentCnt() const
271 : {
272 2 : return (part14.currentCnt << 12) | (part13.currentCnt); // part14.currentCnt为第[12]位
273 : }
274 :
275 2 : uint32_t GetAddrStride() const
276 : {
277 2 : const uint32_t low = static_cast<uint32_t>(part10.addrStride);
278 2 : const uint32_t mid = static_cast<uint32_t>(part11.addrStride) << 6; // part11.addrStride为[21:6]位
279 2 : const uint32_t high = static_cast<uint32_t>(part12.addrStride) << 22; // part12.addrStride为[31:22]位
280 2 : return high | mid | low;
281 : }
282 : };
283 :
284 : struct CcuMissionContext {
285 : union {
286 : uint16_t value;
287 : uint16_t taskId;
288 : } part0;
289 :
290 : union {
291 : uint16_t value;
292 : uint16_t streamId;
293 : } part1;
294 :
295 : union {
296 : uint16_t value;
297 : struct {
298 : uint16_t taskKill : 1;
299 : uint16_t dieId : 2;
300 : uint16_t status : 13; // Status [12:0]
301 : };
302 : } part2;
303 :
304 : union {
305 : uint16_t value;
306 : struct {
307 : uint16_t status : 3; // Status [15:13]
308 : uint16_t counter : 8;
309 : uint16_t denyCnt : 5;
310 : };
311 : } part3;
312 :
313 : union {
314 : uint16_t value;
315 : struct {
316 : uint16_t denyCnt : 5;
317 : uint16_t currentIns : 11; // Current Ins [10:0]
318 : };
319 : } part4;
320 :
321 : union {
322 : uint16_t value;
323 : struct {
324 : uint16_t currentIns : 5; // Current Ins [15:11]
325 : uint16_t endIns : 11;
326 : };
327 : } part5;
328 :
329 : union {
330 : uint16_t value;
331 : struct {
332 : uint16_t endIns : 5;
333 : uint16_t startIns : 11;
334 : };
335 : } part6;
336 :
337 : union {
338 : uint16_t value;
339 : struct {
340 : uint16_t startIns : 5;
341 : uint16_t profileEn : 1;
342 : uint16_t missionVld : 1;
343 : uint16_t reserved : 9;
344 : };
345 : } part7;
346 :
347 : uint16_t reserved[24]; // part 8-31
348 :
349 1 : uint16_t GetStatus() const
350 : {
351 1 : return (part3.status << 13) | (part2.status); // part3.status为[15:13]位
352 : }
353 :
354 2 : uint16_t GetCurrentIns() const
355 : {
356 2 : return (part5.currentIns << 11) | (part4.currentIns); // part5.currentIns为[15:11]位
357 : }
358 :
359 2 : uint16_t GetStartIns() const
360 : {
361 2 : return (part7.startIns << 11) | (part6.startIns); // part7.startIns[15:11]位
362 : }
363 :
364 2 : uint16_t GetEndIns() const
365 : {
366 2 : return (part6.endIns << 11) | (part5.endIns); // part6.endIns[15:11]位
367 : }
368 : };
369 :
370 : union LoopGroupXn {
371 : uint64_t value;
372 : struct {
373 : uint64_t reservedLow : 41;
374 : uint64_t loopInsCnt : 7;
375 : uint64_t expandOffset : 7;
376 : uint64_t expandCnt : 7;
377 : uint64_t reservedHigh : 2;
378 : };
379 : };
380 :
381 : }; // namespace hcomm
382 :
383 : #endif // CCU_ERROR_INFO_V1_H
|