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 HCCL_CCU_MICROCODE_H
12 : #define HCCL_CCU_MICROCODE_H
13 :
14 : #include <string>
15 : #include <cstdint>
16 :
17 : namespace Hccl {
18 : namespace CcuRep {
19 :
20 : constexpr uint16_t CCU_REDUCE_SUM = 0;
21 : constexpr uint16_t CCU_REDUCE_MAX = 1;
22 : constexpr uint16_t CCU_REDUCE_MIN = 2;
23 :
24 : constexpr uint16_t CCU_REDUCE_MIN_MS = 2;
25 : constexpr uint16_t CCU_REDUCE_MAX_MS = 8;
26 :
27 : constexpr uint64_t CCU_MS_SIZE = 4096;
28 : constexpr uint64_t CCU_MS_INTERLEAVE = 8;
29 : constexpr uint64_t CCU_MS_DEFAULT_LOOP_COUNT = 128;
30 :
31 : constexpr uint16_t CCU_LOAD_TO_XN_SEC_INFO = 1;
32 :
33 : #pragma pack(push, 1)
34 : // instr common header
35 : union CcuInstrHeader {
36 : struct {
37 : uint16_t code : 11;
38 : uint16_t type : 4;
39 : uint16_t reserved : 1;
40 : };
41 :
42 : uint16_t header;
43 : };
44 : #pragma pack(pop)
45 :
46 1188 : inline CcuInstrHeader InstrHeader(uint16_t type, uint16_t code)
47 : {
48 1188 : CcuInstrHeader header = {};
49 1188 : header.type = type;
50 1188 : header.code = code;
51 1188 : return header;
52 : }
53 :
54 : namespace CcuV1 {
55 :
56 : #pragma pack(push, 1)
57 : // load instruction
58 : struct CcuInstrLoadSqeArgsToGSA {
59 : uint16_t gsaId;
60 : uint16_t sqeArgsId;
61 : uint16_t reserved[13];
62 : };
63 :
64 : struct CcuInstrLoadSqeArgsToXn {
65 : uint16_t xnId;
66 : uint16_t sqeArgsId;
67 : uint16_t reserved[13];
68 : };
69 :
70 : struct CcuInstrLoadImdToGSA {
71 : uint16_t gsaId;
72 : uint64_t immediate;
73 : uint16_t reserved[10];
74 : };
75 :
76 : struct CcuInstrLoadImdToXn {
77 : uint16_t xnId;
78 : uint64_t immediate;
79 : uint16_t secFlag;
80 : uint16_t reserved[9];
81 : };
82 :
83 : struct CcuInstrLoadGSAXn {
84 : uint16_t gsAdId;
85 : uint16_t gsAmId;
86 : uint16_t xnId;
87 : uint16_t reserved[12];
88 : };
89 :
90 : struct CcuInstrLoadGSAGSA {
91 : uint16_t gsAdId;
92 : uint16_t gsAmId;
93 : uint16_t gsAnId;
94 : uint16_t reserved[12];
95 : };
96 :
97 : struct CcuInstrLoadXX {
98 : uint16_t xdId;
99 : uint16_t xmId;
100 : uint16_t xnId;
101 : uint16_t reserved[12];
102 : };
103 :
104 : // loop control instruction
105 : struct CcuInstrLoop {
106 : uint16_t startInstrId; // 开始指令地址Id
107 : uint16_t endInstrId; // 结束指令地址Id
108 : uint16_t xnId; // LoopCtxId[52:45], Offset[44:13], IterNum[12:0]
109 : uint16_t reserved[12];
110 : };
111 :
112 : struct CcuInstrLoopGroup {
113 : uint16_t startLoopInstrId; // 开始loop地址Id
114 : uint16_t xnId; // LoopNum[61:55], RepeatNum[54:48], NoRepeatNum[47:41]
115 : uint16_t xmId; // gsaOffset[52:21], MSOffset[20:10], ckeOffset[9:0]
116 : uint16_t highPerfModeEn : 1;
117 : uint16_t reserved1 : 15;
118 : uint16_t reserved[11];
119 : };
120 :
121 : struct CcuInstrSetCKE {
122 : uint16_t clearType : 1;
123 : uint16_t reserved1 : 15;
124 : uint16_t setCKEId;
125 : uint16_t setCKEMask;
126 : uint16_t waitCKEId;
127 : uint16_t waitCKEMask;
128 : uint16_t reserved[10];
129 : };
130 :
131 : struct CcuInstrClearCKE {
132 : uint16_t clearType : 1;
133 : uint16_t reserved1 : 15;
134 : uint16_t clearCKEId;
135 : uint16_t clearMask;
136 : uint16_t waitCKEId;
137 : uint16_t waitCKEMask;
138 : uint16_t reserved[10];
139 : };
140 :
141 : struct CcuInstrJmp {
142 : uint16_t dstInstrXnId;
143 : uint16_t conditionXnId;
144 : uint64_t expectData;
145 : };
146 :
147 : // data transfer instruction
148 : struct CcuInstrTransLocMemToLocMS {
149 : uint16_t locMSId;
150 : uint16_t locGSAId;
151 : uint16_t locXnId;
152 : uint16_t lengthXnId;
153 : uint16_t channelId;
154 : uint16_t reserved1[5];
155 : uint16_t clearType : 1;
156 : uint16_t lengthEn : 1;
157 : uint16_t reserved : 14;
158 : uint16_t setCKEId;
159 : uint16_t setCKEMask;
160 : uint16_t waitCKEId;
161 : uint16_t waitCKEMask;
162 : };
163 :
164 : struct CcuInstrTransRmtMemToLocMS {
165 : uint16_t locMSId;
166 : uint16_t rmtGSAId;
167 : uint16_t rmtXnId;
168 : uint16_t lengthXnId;
169 : uint16_t channelId;
170 : uint16_t reserved1[5];
171 : uint16_t clearType : 1;
172 : uint16_t lengthEn : 1;
173 : uint16_t reserved : 14;
174 : uint16_t setCKEId;
175 : uint16_t setCKEMask;
176 : uint16_t waitCKEId;
177 : uint16_t waitCKEMask;
178 : };
179 :
180 : struct CcuInstrTransLocMSToLocMem {
181 : uint16_t locGSAId;
182 : uint16_t locXnId;
183 : uint16_t locMSId;
184 : uint16_t lengthXnId;
185 : uint16_t channelId;
186 : uint16_t reserved1[5];
187 : uint16_t clearType : 1;
188 : uint16_t lengthEn : 1;
189 : uint16_t reserved : 14;
190 : uint16_t setCKEId;
191 : uint16_t setCKEMask;
192 : uint16_t waitCKEId;
193 : uint16_t waitCKEMask;
194 : };
195 :
196 : struct CcuInstrTransLocMSToRmtMem {
197 : uint16_t rmtGSAId;
198 : uint16_t rmtXnId;
199 : uint16_t locMSId;
200 : uint16_t lengthXnId;
201 : uint16_t channelId;
202 : uint16_t reserved1[5];
203 : uint16_t clearType : 1;
204 : uint16_t lengthEn : 1;
205 : uint16_t reserved : 14;
206 : uint16_t setCKEId;
207 : uint16_t setCKEMask;
208 : uint16_t waitCKEId;
209 : uint16_t waitCKEMask;
210 : };
211 :
212 : struct CcuInstrTransRmtMSToLocMem {
213 : uint16_t locGSAId;
214 : uint16_t locXnId;
215 : uint16_t rmtMSId;
216 : uint16_t lengthXnId;
217 : uint16_t channelId;
218 : uint16_t reserved1[5];
219 : uint16_t clearType : 1;
220 : uint16_t lengthEn : 1;
221 : uint16_t reserved : 14;
222 : uint16_t setCKEId;
223 : uint16_t setCKEMask;
224 : uint16_t waitCKEId;
225 : uint16_t waitCKEMask;
226 : };
227 :
228 : struct CcuInstrTransLocMSToLocMS {
229 : uint16_t dstMSId;
230 : uint16_t srcMSId;
231 : uint16_t lengthXnId;
232 : uint16_t channelId;
233 : uint16_t reserved1[6];
234 : uint16_t clearType : 1;
235 : uint16_t lengthEn : 1;
236 : uint16_t reserved : 14;
237 : uint16_t setCKEId;
238 : uint16_t setCKEMask;
239 : uint16_t waitCKEId;
240 : uint16_t waitCKEMask;
241 : };
242 :
243 : struct CcuInstrTransRmtMSToLocMS {
244 : uint16_t locMSId;
245 : uint16_t rmtMSId;
246 : uint16_t lengthXnId;
247 : uint16_t channelId;
248 : uint16_t reserved1[6];
249 : uint16_t clearType : 1;
250 : uint16_t lengthEn : 1;
251 : uint16_t reserved : 14;
252 : uint16_t setCKEId;
253 : uint16_t setCKEMask;
254 : uint16_t waitCKEId;
255 : uint16_t waitCKEMask;
256 : };
257 :
258 : struct CcuInstrTransLocMSToRmtMS {
259 : uint16_t rmtMSId;
260 : uint16_t locMSId;
261 : uint16_t lengthXnId;
262 : uint16_t channelId;
263 : uint16_t setRmtCKEId;
264 : uint16_t setRmtCKEMask;
265 : uint16_t reserved1[4];
266 : uint16_t clearType : 1;
267 : uint16_t lengthEn : 1;
268 : uint16_t reserved : 14;
269 : uint16_t setCKEId;
270 : uint16_t setCKEMask;
271 : uint16_t waitCKEId;
272 : uint16_t waitCKEMask;
273 : };
274 :
275 : struct CcuInstrTransRmtMemToLocMem {
276 : uint16_t locGSAId;
277 : uint16_t locXnId;
278 : uint16_t rmtGSAId;
279 : uint16_t rmtXnId;
280 : uint16_t lengthXnId;
281 : uint16_t channelId;
282 : uint16_t udfType : 8;
283 : uint16_t reduceDataType : 4;
284 : uint16_t reduceOpCode : 4;
285 : uint16_t reserved[3];
286 : uint16_t clearType : 1;
287 : uint16_t lengthEn : 1;
288 : uint16_t reduceEn : 1;
289 : uint16_t reserved1 : 13;
290 : uint16_t setCKEId;
291 : uint16_t setCKEMask;
292 : uint16_t waitCKEId;
293 : uint16_t waitCKEMask;
294 : };
295 :
296 : struct CcuInstrTransLocMemToRmtMem {
297 : uint16_t rmtGSAId;
298 : uint16_t rmtXnId;
299 : uint16_t locGSAId;
300 : uint16_t locXnId;
301 : uint16_t lengthXnId;
302 : uint16_t channelId;
303 : uint16_t udfType : 8;
304 : uint16_t reduceDataType : 4;
305 : uint16_t reduceOpCode : 4;
306 : uint16_t reserved[3];
307 : uint16_t clearType : 1;
308 : uint16_t lengthEn : 1;
309 : uint16_t reduceEn : 1;
310 : uint16_t reserved1 : 13;
311 : uint16_t setCKEId;
312 : uint16_t setCKEMask;
313 : uint16_t waitCKEId;
314 : uint16_t waitCKEMask;
315 : };
316 :
317 : struct CcuInstrTransLocMemToLocMem {
318 : uint16_t dstGSAId;
319 : uint16_t dstXnId;
320 : uint16_t srcGSAId;
321 : uint16_t srcXnId;
322 : uint16_t lengthXnId;
323 : uint16_t channelId;
324 : uint16_t reserved1[4];
325 : uint16_t clearType : 1;
326 : uint16_t lengthEn : 1;
327 : uint16_t reserved : 14;
328 : uint16_t setCKEId;
329 : uint16_t setCKEMask;
330 : uint16_t waitCKEId;
331 : uint16_t waitCKEMask;
332 : };
333 :
334 : struct CcuInstrSyncCKE {
335 : uint16_t rmtCKEId;
336 : uint16_t locCKEId;
337 : uint16_t locCKEMask;
338 : uint16_t channelId;
339 : uint16_t reserved[6];
340 : uint16_t clearType : 1;
341 : uint16_t reserved1 : 15;
342 : uint16_t setCKEId;
343 : uint16_t setCKEMask;
344 : uint16_t waitCKEId;
345 : uint16_t waitCKEMask;
346 : };
347 :
348 : struct CcuInstrSyncGSA {
349 : uint16_t rmtGSAId;
350 : uint16_t locGSAId;
351 : uint16_t reserved2;
352 : uint16_t channelId;
353 : uint16_t setRmtCKEId;
354 : uint16_t setRmtCKEMask;
355 : uint16_t reserved[4];
356 : uint16_t clearType : 1;
357 : uint16_t reserved1 : 15;
358 : uint16_t setCKEId;
359 : uint16_t setCKEMask;
360 : uint16_t waitCKEId;
361 : uint16_t waitCKEMask;
362 : };
363 :
364 : struct CcuInstrSyncXn {
365 : uint16_t rmtXnId;
366 : uint16_t locXnId;
367 : uint16_t reserved2;
368 : uint16_t channelId;
369 : uint16_t setRmtCKEId;
370 : uint16_t setRmtCKEMask;
371 : uint16_t reserved[4];
372 : uint16_t clearType : 1;
373 : uint16_t reserved1 : 15;
374 : uint16_t setCKEId;
375 : uint16_t setCKEMask;
376 : uint16_t waitCKEId;
377 : uint16_t waitCKEMask;
378 : };
379 :
380 : struct CcuInstrAdd {
381 : uint16_t msId[CCU_REDUCE_MAX_MS];
382 : uint16_t XnIdLength;
383 : uint16_t reserved;
384 : uint16_t clearType : 1;
385 : uint16_t count : 3;
386 : uint16_t castEn : 2;
387 : uint16_t reserved1 : 5;
388 : uint16_t dataType : 5;
389 : uint16_t setCKEId;
390 : uint16_t setCKEMask;
391 : uint16_t waitCKEId;
392 : uint16_t waitCKEMask;
393 : };
394 :
395 : struct CcuInstrMax {
396 : uint16_t msId[CCU_REDUCE_MAX_MS];
397 : uint16_t XnIdLength;
398 : uint16_t reserved;
399 : uint16_t clearType : 1;
400 : uint16_t count : 3;
401 : uint16_t reserved1 : 7;
402 : uint16_t dataType : 5;
403 : uint16_t setCKEId;
404 : uint16_t setCKEMask;
405 : uint16_t waitCKEId;
406 : uint16_t waitCKEMask;
407 : };
408 :
409 : struct CcuInstrMin {
410 : uint16_t msId[CCU_REDUCE_MAX_MS];
411 : uint16_t XnIdLength;
412 : uint16_t reserved;
413 : uint16_t clearType : 1;
414 : uint16_t count : 3;
415 : uint16_t reserved1 : 7;
416 : uint16_t dataType : 5;
417 : uint16_t setCKEId;
418 : uint16_t setCKEMask;
419 : uint16_t waitCKEId;
420 : uint16_t waitCKEMask;
421 : };
422 : #pragma pack(pop)
423 :
424 : union CcuMicroCodeV1 {
425 : CcuV1::CcuInstrLoadSqeArgsToGSA loadSqeArgsToGSA;
426 : CcuV1::CcuInstrLoadSqeArgsToXn loadSqeArgsToXn;
427 : CcuV1::CcuInstrLoadImdToGSA loadImdToGSA;
428 : CcuV1::CcuInstrLoadImdToXn loadImdToXn;
429 : CcuV1::CcuInstrLoadGSAXn loadGSAXn;
430 : CcuV1::CcuInstrLoadGSAGSA loadGSAGSA;
431 : CcuV1::CcuInstrLoadXX loadXX;
432 :
433 : CcuV1::CcuInstrLoop loop;
434 : CcuV1::CcuInstrLoopGroup loopGroup;
435 : CcuV1::CcuInstrSetCKE setCKE;
436 : CcuV1::CcuInstrClearCKE clearCKE;
437 : CcuV1::CcuInstrJmp jmp;
438 :
439 : CcuV1::CcuInstrTransLocMemToLocMS transLocMemToLocMS;
440 : CcuV1::CcuInstrTransRmtMemToLocMS transRmtMemToLocMS;
441 : CcuV1::CcuInstrTransLocMSToLocMem transLocMSToLocMem;
442 : CcuV1::CcuInstrTransLocMSToRmtMem transLocMSToRmtMem;
443 : CcuV1::CcuInstrTransRmtMSToLocMem transRmtMSToLocMem;
444 :
445 : CcuV1::CcuInstrTransLocMSToLocMS transLocMSToLocMS;
446 : CcuV1::CcuInstrTransRmtMSToLocMS transRmtMSToLocMS;
447 : CcuV1::CcuInstrTransLocMSToRmtMS transLocMSToRmtMS;
448 :
449 : CcuV1::CcuInstrTransRmtMemToLocMem transRmtMemToLocMem;
450 : CcuV1::CcuInstrTransLocMemToRmtMem transLocMemToRmtMem;
451 : CcuV1::CcuInstrTransLocMemToLocMem transLocMemToLocMem;
452 :
453 : CcuV1::CcuInstrSyncCKE syncCKE;
454 : CcuV1::CcuInstrSyncGSA syncGSA;
455 : CcuV1::CcuInstrSyncXn syncXn;
456 :
457 : CcuV1::CcuInstrAdd add;
458 : CcuV1::CcuInstrMax max;
459 : CcuV1::CcuInstrMin min;
460 : };
461 :
462 : }; // namespace CcuV1
463 :
464 : namespace CcuV2 {
465 :
466 : struct CacheConfig {
467 : uint16_t allocHint;
468 : uint16_t victimHint;
469 : };
470 :
471 : struct TransMemNotifyInfo {
472 : uint16_t xnId;
473 : uint16_t xntId;
474 : uint32_t value;
475 : };
476 :
477 : struct TransMemReduceInfo {
478 : uint16_t udfType;
479 : uint16_t reduceDataType;
480 : uint16_t reduceOpCode;
481 : };
482 :
483 : struct TransMemConfig {
484 : uint16_t dmaOpCode;
485 : uint16_t order;
486 : uint16_t fence;
487 : uint16_t cqe;
488 : uint16_t nf;
489 : uint16_t udfEnable;
490 : uint16_t splitMode;
491 : uint16_t se;
492 : uint16_t rmtJettyType;
493 : };
494 :
495 : #pragma pack(push, 1)
496 :
497 : // load instruction
498 : struct CcuInstrLoadSqeArgsToX {
499 : uint16_t xnId;
500 : uint16_t sqeArgsId;
501 : uint16_t reserved[11];
502 : uint16_t setCKEId;
503 : uint16_t setCKEMask;
504 : };
505 :
506 : struct CcuInstrLoadImdToX {
507 : uint16_t xnId;
508 : uint64_t immediate;
509 : uint16_t reserved[8];
510 : uint16_t setCKEId;
511 : uint16_t setCKEMask;
512 : };
513 :
514 : struct CcuInstrLoadStoreX {
515 : uint16_t xdId;
516 : uint16_t xsId;
517 : uint16_t xsoId;
518 : uint16_t xdoId;
519 : uint16_t oMode : 1;
520 : uint16_t reserved : 15;
521 : uint16_t reserved1[8];
522 : uint16_t setCKEId;
523 : uint16_t setCKEMask;
524 : };
525 :
526 : struct CcuInstrClearX {
527 : uint16_t xnId;
528 : uint16_t xmId;
529 : uint16_t reserved[11];
530 : uint16_t setCKEId;
531 : uint16_t setCKEMask;
532 : };
533 :
534 : struct CcuInstrNop {
535 : uint16_t reserved[15];
536 : };
537 :
538 : struct CcuInstrLoad {
539 : uint16_t xdId;
540 : uint16_t xsId;
541 : uint16_t xstId;
542 : uint16_t xlId;
543 : uint16_t reserved[6];
544 : uint16_t dstType : 4;
545 : uint16_t allocHint : 2;
546 : uint16_t victimHint : 2;
547 : uint16_t reserved1 : 8;
548 : uint16_t reserved2[2];
549 : uint16_t setCKEId;
550 : uint16_t setCKEMask;
551 : };
552 :
553 : struct CcuInstrStore {
554 : uint16_t xdId;
555 : uint16_t xdtId;
556 : uint16_t xsId;
557 : uint16_t xlId;
558 : uint16_t xhId;
559 : uint16_t reserved[5];
560 : uint16_t srcType : 4;
561 : uint16_t allocHint : 2;
562 : uint16_t victimHint : 2;
563 : uint16_t storeType : 1;
564 : uint16_t hscbType : 1;
565 : uint16_t hscbBroadCastDstType : 6;
566 : uint16_t reserved1[2];
567 : uint16_t setCKEId;
568 : uint16_t setCKEMask;
569 : };
570 :
571 : // 运算符复用相同的结构体
572 : // 左移右移:需要指定shiftType
573 : // A = B@C类算子,需要指定xd, xn, xm
574 : // 按位非,需要指定xd, xn
575 : // popcnt,需要指定xd, xn
576 : struct CcuInstrOperator {
577 : uint16_t xdId;
578 : uint16_t xnId;
579 : uint16_t xmId;
580 : uint16_t parMode : 1;
581 : uint16_t reserved : 15;
582 : uint16_t reserved1[6];
583 : uint16_t shiftType : 1;
584 : uint16_t reserved2 : 15;
585 : uint16_t reserved3[2];
586 : uint16_t setCKEId;
587 : uint16_t setCKEMask;
588 : };
589 :
590 : // loop control instruction
591 : struct CcuInstrLoop {
592 : uint16_t startInstrId; // 开始指令地址Id
593 : uint16_t endInstrId; // 结束指令地址Id
594 : uint16_t xmId; // IterNum[12:0]
595 : uint16_t xnId; // Offset[31:0]
596 : uint16_t xpId; // LoopCtxId[8:0]
597 : uint16_t wishCKEBit;
598 : uint16_t mode : 1;
599 : uint16_t reserved : 15;
600 : uint16_t reserved1[8];
601 : };
602 :
603 : struct CcuInstrLoopGroup {
604 : uint16_t startLoopInstrId; // 开始loop地址Id
605 : uint16_t xnId; // ExtendNum[22:16], RepeatLoopIndex[15:9], LoopNum[8:0]
606 : uint16_t xmId; // gsaOffset[52:21], MSOffset[20:10], ckeOffset[9:0]
607 : uint16_t xpId; // xnOffset[31:0]
608 : uint16_t reserved[11];
609 : };
610 :
611 : struct CcuInstrSetCKE {
612 : uint16_t clearType : 1;
613 : uint16_t reserved : 15;
614 : uint16_t setCKEId;
615 : uint16_t setCKEMask;
616 : uint16_t waitCKEId;
617 : uint16_t waitCKEMask;
618 : uint64_t userData;
619 : uint16_t reserved1[6];
620 : };
621 :
622 : struct CcuInstrClearCKE {
623 : uint16_t clearType : 1;
624 : uint16_t reserved : 15;
625 : uint16_t clearCKEId;
626 : uint16_t clearMask;
627 : uint16_t waitCKEId;
628 : uint16_t waitCKEMask;
629 : uint16_t reserved1[10];
630 : };
631 :
632 : struct CcuInstrJmp {
633 : uint16_t expectedXnId;
634 : uint16_t conditionXnId;
635 : uint16_t relTarInstrXnId;
636 : uint16_t conditionType : 4;
637 : uint16_t reserved : 12;
638 : uint16_t reserved1[11];
639 : };
640 :
641 : struct CcuInstrWait {
642 : uint16_t expectedXnId;
643 : uint16_t conditionXnId;
644 : uint16_t conditionType : 4;
645 : uint16_t reserved : 12;
646 : uint16_t reserved1[12];
647 : };
648 :
649 : struct CcuInstrFence {
650 : uint16_t reserved[15];
651 : };
652 :
653 : // data transfer instruction
654 : struct CcuInstrTransLocMemToLocMS {
655 : uint16_t msId;
656 : uint16_t xsId;
657 : uint16_t xstId;
658 : uint16_t xlId;
659 : uint16_t xoId;
660 : uint16_t allocHint : 2;
661 : uint16_t victimHint : 2;
662 : uint16_t reserved : 12;
663 : uint16_t reserved1[7];
664 : uint16_t setCKEId;
665 : uint16_t setCKEMask;
666 : };
667 :
668 : struct CcuInstrTransLocMSToLocMem {
669 : uint16_t xdId;
670 : uint16_t xdtId;
671 : uint16_t msId;
672 : uint16_t xlId;
673 : uint16_t xoId;
674 : uint16_t allocHint : 2;
675 : uint16_t victimHint : 2;
676 : uint16_t reserved : 12;
677 : uint16_t reserved1[7];
678 : uint16_t setCKEId;
679 : uint16_t setCKEMask;
680 : };
681 :
682 : struct CcuInstrTransLocMSToLocMS {
683 : uint16_t msdId;
684 : uint16_t mssId;
685 : uint16_t xlId;
686 : uint16_t xoId;
687 : uint16_t reserved[9];
688 : uint16_t setCKEId;
689 : uint16_t setCKEMask;
690 : };
691 :
692 : struct CcuInstrTransLocMemToLocMem {
693 : uint16_t xdId;
694 : uint16_t xdtId;
695 : uint16_t xsId;
696 : uint16_t xstId;
697 : uint16_t xlId;
698 : uint16_t usedMSId;
699 : uint16_t srcAllocHint : 2;
700 : uint16_t srcVictimHint : 2;
701 : uint16_t dstAllocHint : 2;
702 : uint16_t dstVictimHint : 2;
703 : uint16_t msNum : 8;
704 : uint16_t reserved1[6];
705 : uint16_t setCKEId;
706 : uint16_t setCKEMask;
707 : };
708 :
709 : struct CcuInstrTransMem {
710 : uint16_t xdId; // 存储目的内存地址
711 : uint16_t xdtId; // 存储目的内存Token
712 : uint16_t xsId; // 存储源内存地址
713 : uint16_t xstId; // 存储源内存Token
714 : uint16_t xlId; // 存储要搬运的数据长度
715 : uint16_t xcId; // 存储使用的channelId
716 : uint16_t xnId; // 存储notify/atomic的目的地址
717 : uint16_t xntId; // 存储notify/atomic的目的Token
718 : uint32_t value; // notify value, atomic store add value, immeidata data, 视不同的opCode确定, 只支持32bit
719 : uint16_t udfType : 8;
720 : uint16_t reduceDataType : 4;
721 : uint16_t reduceOpCode : 4;
722 : uint16_t dmaOpCode : 8; // wqe中的opcode,支持0x0: send,0x1: send with immediata,0x3: Write,0x5: Write
723 : // with Notify,0x6: Read,0x70: Write with atomic store add
724 : uint16_t order : 3;
725 : uint16_t fence : 1;
726 : uint16_t cqe : 1;
727 : uint16_t nf : 1; // No Fragment, 不允许分片
728 : uint16_t udfEnable : 1;
729 : uint16_t splitMode : 1;
730 : uint16_t se : 1; // Solicited Event,Responder基于se来判断生成CQE时是否产生Completion Event
731 : uint16_t rmtJettyType : 2; // 00: JFR, 01: Jetty,10: JettyGroup,11: reserved
732 : uint16_t reserved : 5;
733 : uint16_t targetHint : 8;
734 : uint16_t setCKEId;
735 : uint16_t setCKEMask;
736 : };
737 :
738 : // SyncWtX指令固定将一个指定Xn的信息同步,固定8B
739 : struct CcuInstrSyncWtX {
740 : uint16_t xdId; // 存储目的Xn寄存器的地址
741 : uint16_t xdtId; // 存储目的Xn寄存器Token
742 : uint16_t xsId; // 存储源Xn寄存器Id
743 : uint16_t xcId; // 存储使用的channelId
744 : uint16_t xnId; // 存储notify/atomic的目的地址
745 : uint16_t xntId; // 存储notify/atomic的目的Token
746 : uint32_t value; // notify value, 只支持32bit
747 : uint16_t notifyValid : 1;
748 : uint16_t parMode : 1;
749 : uint16_t reserved : 14;
750 : uint16_t reserved1[4];
751 : uint16_t setCKEId;
752 : uint16_t setCKEMask;
753 : };
754 :
755 : // SyncAtX指令以write with atomic store add发往对端,其中write的数据长度为0,本端Xn的值是写在atomic
756 : // value中进行发送
757 : struct CcuInstrSyncAtX {
758 : uint16_t xdId; // 存储目的Xn寄存器的地址
759 : uint16_t xdtId; // 存储目的Xn寄存器Token
760 : uint16_t xsId; // 存储源Xn寄存器Id
761 : uint16_t xcId; // 存储使用的channelId
762 : uint16_t reserved : 1;
763 : uint16_t parMode : 1;
764 : uint16_t reserved1 : 14;
765 : uint16_t reserved2[8];
766 : uint16_t setCKEId;
767 : uint16_t setCKEMask;
768 : };
769 :
770 : // reduce instruction
771 : // add: 配置castEn
772 : // max和min: castEn保持默认为0
773 : struct CcuInstrReduce {
774 : uint16_t msId[CCU_REDUCE_MAX_MS];
775 : uint16_t reserved[2];
776 : uint16_t clearType : 1;
777 : uint16_t count : 3;
778 : uint16_t castEn : 2;
779 : uint16_t reserved1 : 5;
780 : uint16_t dataType : 5;
781 : uint16_t reserved2[2];
782 : uint16_t setCKEId;
783 : uint16_t setCKEMask;
784 : };
785 :
786 : #pragma pack(pop)
787 :
788 : union CcuMicroCodeV2 {
789 : CcuV2::CcuInstrLoadSqeArgsToX loadSqeArgsToX;
790 : CcuV2::CcuInstrLoadImdToX loadImdToX;
791 : CcuV2::CcuInstrLoadStoreX loadStoreX;
792 : CcuV2::CcuInstrClearX clearX;
793 : CcuV2::CcuInstrNop nop;
794 : CcuV2::CcuInstrOperator operate;
795 : CcuV2::CcuInstrLoad load;
796 : CcuV2::CcuInstrStore store;
797 :
798 : CcuV2::CcuInstrLoop loop;
799 : CcuV2::CcuInstrLoopGroup loopGroup;
800 : CcuV2::CcuInstrSetCKE setCKE;
801 : CcuV2::CcuInstrClearCKE clearCKE;
802 : CcuV2::CcuInstrJmp jmp;
803 : CcuV2::CcuInstrWait wait;
804 : CcuV2::CcuInstrFence fence;
805 :
806 : CcuV2::CcuInstrTransLocMemToLocMS transLocMemToLocMS;
807 : CcuV2::CcuInstrTransLocMSToLocMem transLocMSToLocMem;
808 : CcuV2::CcuInstrTransLocMSToLocMS transLocMSToLocMS;
809 : CcuV2::CcuInstrTransLocMemToLocMem transLocMemToLocMem;
810 : CcuV2::CcuInstrTransMem transMem;
811 : CcuV2::CcuInstrSyncWtX syncWtX;
812 : CcuV2::CcuInstrSyncAtX syncAtX;
813 :
814 : CcuV2::CcuInstrReduce reduce;
815 : };
816 : }; // namespace CcuV2
817 :
818 : struct CcuInstr {
819 : CcuInstrHeader header;
820 : union {
821 : CcuV1::CcuMicroCodeV1 v1;
822 : CcuV2::CcuMicroCodeV2 v2;
823 : };
824 : };
825 :
826 : std::string ParseInstr(const CcuInstr* instr);
827 :
828 : void LoadSqeArgsToGSAInstr(CcuInstr* instr, uint16_t gsaId, uint16_t sqeArgsId);
829 : void LoadSqeArgsToXnInstr(CcuInstr* instr, uint16_t xnId, uint16_t sqeArgsId);
830 : void LoadImdToGSAInstr(CcuInstr* instr, uint16_t gsaId, uint64_t immediate);
831 : void LoadImdToXnInstr(CcuInstr* instr, uint16_t xnId, uint64_t immediate, uint16_t secFlag = 0);
832 : void LoadGSAXnInstr(CcuInstr* instr, uint16_t gsAdId, uint16_t gsAmId, uint16_t xnId);
833 : void LoadGSAGSAInstr(CcuInstr* instr, uint16_t gsAdId, uint16_t gsAmId, uint16_t gsAnId);
834 : void LoadXXInstr(CcuInstr* instr, uint16_t xdId, uint16_t xmId, uint16_t xnId);
835 :
836 : void LoopInstr(CcuInstr* instr, uint16_t startInstrId, uint16_t endInstrId, uint16_t xnId);
837 : void
838 : LoopGroupInstr(CcuInstr* instr, uint16_t startLoopInstrId, uint16_t xnId, uint16_t xmId, uint16_t highPerfModeEn);
839 : void JumpInstr(CcuInstr* instr, uint16_t dstInstrXnId, uint16_t conditionXnId, uint64_t expectData);
840 : void SetCKEInstr(
841 : CcuInstr* instr, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
842 : uint16_t clearType);
843 : void ClearCKEInstr(
844 : CcuInstr* instr, uint16_t clearCKEId, uint16_t clearMask, uint16_t waitCKEId, uint16_t waitCKEMask,
845 : uint16_t clearType);
846 :
847 : void TransLocMemToLocMSInstr(
848 : CcuInstr* instr, uint16_t locMSId, uint16_t locGSAId, uint16_t locXnId, uint16_t lengthXnId, uint16_t channelId,
849 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
850 : uint16_t lengthEn);
851 : void TransRmtMemToLocMSInstr(
852 : CcuInstr* instr, uint16_t locMSId, uint16_t rmtGSAId, uint16_t rmtXnId, uint16_t lengthXnId, uint16_t channelId,
853 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
854 : uint16_t lengthEn);
855 : void TransLocMSToLocMemInstr(
856 : CcuInstr* instr, uint16_t locGSAId, uint16_t locXnId, uint16_t locMSId, uint16_t lengthXnId, uint16_t channelId,
857 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
858 : uint16_t lengthEn);
859 : void TransLocMSToRmtMemInstr(
860 : CcuInstr* instr, uint16_t rmtGSAId, uint16_t rmtXnId, uint16_t locMSId, uint16_t lengthXnId, uint16_t channelId,
861 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
862 : uint16_t lengthEn);
863 : void TransRmtMSToLocMemInstr(
864 : CcuInstr* instr, uint16_t locGSAId, uint16_t locXnId, uint16_t rmtMSId, uint16_t lengthXnId, uint16_t channelId,
865 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType,
866 : uint16_t lengthEn);
867 :
868 : void TransLocMSToLocMSInstr(
869 : CcuInstr* instr, uint16_t dstMSId, uint16_t srcMSId, uint16_t lengthXnId, uint16_t channelId, uint16_t setCKEId,
870 : uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn);
871 : void TransRmtMSToLocMSInstr(
872 : CcuInstr* instr, uint16_t locMSId, uint16_t rmtMSId, uint16_t lengthXnId, uint16_t channelId, uint16_t setCKEId,
873 : uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn);
874 : void TransLocMSToRmtMSInstr(
875 : CcuInstr* instr, uint16_t rmtMSId, uint16_t locMSId, uint16_t lengthXnId, uint16_t channelId,
876 : uint16_t setRmtCKEId, uint16_t setRmtCKEMask, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId,
877 : uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn);
878 :
879 : void TransRmtMemToLocMemInstr(
880 : CcuInstr* instr, uint16_t locGSAId, uint16_t locXnId, uint16_t rmtGSAId, uint16_t rmtXnId, uint16_t lengthXnId,
881 : uint16_t channelId, uint16_t reduceDataType, uint16_t reduceOpCode, uint16_t setCKEId, uint16_t setCKEMask,
882 : uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn, uint16_t reduceEn);
883 : void TransLocMemToRmtMemInstr(
884 : CcuInstr* instr, uint16_t rmtGSAId, uint16_t rmtXnId, uint16_t locGSAId, uint16_t locXnId, uint16_t lengthXnId,
885 : uint16_t channelId, uint16_t reduceDataType, uint16_t reduceOpCode, uint16_t setCKEId, uint16_t setCKEMask,
886 : uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t lengthEn, uint16_t reduceEn);
887 : void TransLocMemToLocMemInstr(
888 : CcuInstr* instr, uint16_t dstGSAId, uint16_t dstXnId, uint16_t srcGSAId, uint16_t srcXnId, uint16_t lengthXnId,
889 : uint16_t channelId, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
890 : uint16_t clearType, uint16_t lengthEn);
891 :
892 : void SyncCKEInstr(
893 : CcuInstr* instr, uint16_t rmtCKEId, uint16_t locCKEId, uint16_t locCKEMask, uint16_t channelId,
894 : uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType);
895 : void SyncGSAInstr(
896 : CcuInstr* instr, uint16_t rmtGSAId, uint16_t locGSAId, uint16_t channelId, uint16_t setRmtCKEId,
897 : uint16_t setRmtCKEMask, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
898 : uint16_t clearType);
899 : void SyncXnInstr(
900 : CcuInstr* instr, uint16_t rmtXnId, uint16_t locXnId, uint16_t channelId, uint16_t setRmtCKEId,
901 : uint16_t setRmtCKEMask, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
902 : uint16_t clearType);
903 :
904 : void AddInstr(
905 : CcuInstr* instr, uint16_t* msId, uint16_t count, uint16_t castEn, uint16_t dataType, uint16_t setCKEId,
906 : uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t XnIdLength);
907 : void MaxInstr(
908 : CcuInstr* instr, uint16_t* msId, uint16_t count, uint16_t dataType, uint16_t setCKEId, uint16_t setCKEMask,
909 : uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t XnIdLength);
910 : void MinInstr(
911 : CcuInstr* instr, uint16_t* msId, uint16_t count, uint16_t dataType, uint16_t setCKEId, uint16_t setCKEMask,
912 : uint16_t waitCKEId, uint16_t waitCKEMask, uint16_t clearType, uint16_t XnIdLength);
913 :
914 : namespace CcuV2 {
915 : void Nop(CcuInstr* instr);
916 :
917 : void LoadSqeArgsToX(
918 : CcuInstr* instr, uint16_t xnId, uint16_t sqeArgsId, uint16_t setCKEId = 0, uint16_t setCKEMask = 0);
919 : void
920 : LoadImdToXn(CcuInstr* instr, uint16_t xnId, uint64_t immediate, uint16_t setCKEId = 0, uint16_t setCKEMask = 0);
921 : void LoadXFromMem(
922 : CcuInstr* instr, uint16_t dst, uint16_t src, uint16_t srcToken, uint16_t len,
923 : const CacheConfig& cacheConfig, uint16_t setCKEId, uint16_t setCKEMask);
924 : void StoreXToMem(
925 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t src, uint16_t len,
926 : const CacheConfig& cacheConfig, uint16_t setCKEId, uint16_t setCKEMask);
927 :
928 : void Assign(CcuInstr* instr, uint16_t result, uint16_t operand, uint16_t setCKEId = 0, uint16_t setCKEMask = 0);
929 :
930 : void
931 : Add(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
932 : uint16_t setCKEMask = 0);
933 : void AddI(
934 : CcuInstr* instr, uint16_t result, uint16_t operand, uint16_t imm, uint16_t setCKEId = 0,
935 : uint16_t setCKEMask = 0);
936 : void
937 : Mul(CcuInstr* instr, uint16_t result, uint16_t operand1, uint16_t operand2, uint16_t setCKEId = 0,
938 : uint16_t setCKEMask = 0);
939 : void MulI(
940 : CcuInstr* instr, uint16_t result, uint16_t operand, uint16_t imm, uint16_t setCKEId = 0,
941 : uint16_t setCKEMask = 0);
942 :
943 : void Loop(
944 : CcuInstr* instr, uint16_t startInstrId, uint16_t endInstrId, uint16_t iterNum, uint16_t offset,
945 : uint16_t contextId);
946 : void LoopGroup(
947 : CcuInstr* instr, uint16_t startLoopInstrId, uint16_t loopGroupConfig, uint16_t resOffset,
948 : uint16_t xnOffset);
949 : void Jump(
950 : CcuInstr* instr, uint16_t relTarInstrXnId, uint16_t conditionXnId, uint16_t expectedXnId,
951 : uint16_t conditionType);
952 :
953 : void SetCKE(
954 : CcuInstr* instr, uint16_t setCKEId, uint16_t setCKEMask, uint16_t waitCKEId, uint16_t waitCKEMask,
955 : uint16_t clearType);
956 : void ClearCKE(
957 : CcuInstr* instr, uint16_t clearCKEId, uint16_t clearMask, uint16_t waitCKEId, uint16_t waitCKEMask,
958 : uint16_t clearType);
959 :
960 : void TransLocMemToLocMS(
961 : CcuInstr* instr, uint16_t ms, uint16_t src, uint16_t srcToken, uint16_t len, uint16_t offset,
962 : uint16_t setCKEId, uint16_t setCKEMask, const CacheConfig& cacheConfig);
963 : void TransLocMSToLocMem(
964 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t ms, uint16_t len, uint16_t offset,
965 : uint16_t setCKEId, uint16_t setCKEMask, const CacheConfig& cacheConfig);
966 : void TransLocMemToLocMem(
967 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t src, uint16_t srcToken, uint16_t len,
968 : uint16_t usedMSId, uint16_t setCKEId, uint16_t setCKEMask, const CacheConfig& srcCacheConfig,
969 : const CacheConfig& dstcacheConfig);
970 : void TransMem(
971 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t src, uint16_t srcToken, uint16_t len,
972 : uint16_t channel, const TransMemNotifyInfo& notify, const TransMemReduceInfo& reduce,
973 : const TransMemConfig& config, uint16_t setCKEId, uint16_t setCKEMask);
974 : void SyncWtX(
975 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t xn, uint16_t channelId, uint16_t setCKEId,
976 : uint16_t setCKEMask);
977 : void SyncWtX(
978 : CcuInstr* instr, const TransMemNotifyInfo& notify, uint16_t channelId, uint16_t setCKEId,
979 : uint16_t setCKEMask);
980 : void SyncWtX(
981 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t xn, uint16_t channelId,
982 : const TransMemNotifyInfo& notify, uint16_t setCKEId, uint16_t setCKEMask);
983 : void SyncAtX(
984 : CcuInstr* instr, uint16_t dst, uint16_t dstToken, uint16_t mask, uint16_t channelId, uint16_t setCKEId,
985 : uint16_t setCKEMask);
986 : void ReduceAdd(
987 : CcuInstr* instr, uint16_t* ms, uint16_t count, uint16_t castEn, uint16_t dataType, uint16_t setCKEId,
988 : uint16_t setCKEMask);
989 : void ReduceMax(
990 : CcuInstr* instr, uint16_t* ms, uint16_t count, uint16_t dataType, uint16_t setCKEId, uint16_t setCKEMask);
991 : void ReduceMin(
992 : CcuInstr* instr, uint16_t* ms, uint16_t count, uint16_t dataType, uint16_t setCKEId, uint16_t setCKEMask);
993 : }; // namespace CcuV2
994 :
995 : }; // namespace CcuRep
996 : }; // namespace Hccl
997 :
998 : #endif // HCCL_CCU_MICROCODE_H
|