-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathAIEOps.td
More file actions
2238 lines (1928 loc) · 82.4 KB
/
AIEOps.td
File metadata and controls
2238 lines (1928 loc) · 82.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===- AIE.td ----------------------------------------------*- tablegen -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// (c) Copyright 2019 Xilinx Inc.
//
//===----------------------------------------------------------------------===//
#ifndef AIE_OPS
#define AIE_OPS
include "aie/Dialect/AIE/IR/AIE.td"
include "aie/Dialect/AIE/IR/AIEAttrs.td"
include "aie/Dialect/AIE/IR/AIEInterfaces.td"
include "aie/Dialect/AIE/IR/AIETypes.td"
include "mlir/Dialect/DLTI/DLTIBase.td"
include "mlir/IR/CommonAttrConstraints.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/CallInterfaces.td"
include "mlir/Interfaces/DataLayoutInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
class AIE_Op<string mnemonic, list<Trait> traits = []> :
Op<AIE_Dialect, mnemonic, traits>;
def AIE_DeviceOp: AIE_Op<"device", [
Symbol,
AIETarget,
HasParent<"mlir::ModuleOp">,
SymbolTable,
SingleBlockImplicitTerminator<"EndOp">,
IsolatedFromAbove,
DataLayoutOpInterface,
HasDefaultDLTIDataLayout
]> {
let summary = "Define an AIE design targetting a complete device";
let description = [{
This operation describes a design that executes on a particular AIEngine device.
It exists at the toplevel of a design; although currently it does not replace the
default toplevel module in MLIR, the intention is that this could be the case
in the future.
When using this operation, all resources in a physical device are available and
the design does not need to be concerned with other potential users of a physical
device. In addition, within an `aie.device` operation, tile addresses are absolute
coordinates and are not intended to describe a relocatable design. To describe
a portion of a device which may be relocatable, the intention would be to provide another
operation, for instance maybe `aie.segment`.
The design itself is described using a region of code contained by the device
operation.
Example:
```
aie.device(xcvc1902) {
%tile = aie.tile(1, 1)
%CORE = aie.core(%tile) { ... }
}
```
}];
let arguments = (
ins AIEDevice:$device,
DefaultValuedAttr<SymbolNameAttr, "getDefaultDeviceName()">:$sym_name
);
let regions = (region AnyRegion:$body_region);
let assemblyFormat = [{
`(` $device `)` ($sym_name^)? regions attr-dict
}];
let extraClassDeclaration = [{
const xilinx::AIE::AIETargetModel &getTargetModel();
static xilinx::AIE::DeviceOp getForSymbolInModule(mlir::ModuleOp module, llvm::StringRef symbol);
static xilinx::AIE::DeviceOp getForSymbolInModuleOrError(mlir::ModuleOp module, llvm::StringRef symbol);
static llvm::StringRef getDefaultDeviceName() { return "main"; }
}];
}
def AIE_TileOp: AIE_Op<"tile", [
Pure,
IsFlowEndPoint,
DeclareOpInterfaceMethods<OpAsmOpInterface, ["getAsmResultNames"]>,
DeclareOpInterfaceMethods<InferTypeOpInterface>
]>, Results<(outs Index:$result)> {
let arguments = (
ins ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$col,
ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$row,
OptionalAttr<StrAttr>:$allocation_scheme
);
let summary = "Declare an AIE tile";
let description = [{
This operation creates an AIE tile in the AIE array. We specify the column and the row of the tile.
Optionally, we can specify the memory allocation scheme for the tile (basic-sequential or bank-aware).
A tile encompasses core module (CoreOp), memory module (MemOp), stream switch (SwitchboxOp),
memory buffer (BufferOp), and lock (LockOp).
A tile is a logical abstraction. We use a tile to establish ownership of a hardware entity.
Note that row 0 of the Tile array is different from other rows, since it models the shim interface between
the AIE array proper and the PL. The South-West/Lower Right most core exists in Tile(0,1).
}];
let extraClassDeclaration = [{
size_t getNumSourceConnections(WireBundle bundle);
size_t getNumDestConnections(WireBundle bundle);
int colIndex() { return getCol(); }
int rowIndex() { return getRow(); }
TileID getTileID() { return {getCol(), getRow()}; }
bool isShimTile() { return getRow() == 0; }
bool isMemTile();
bool isShimNOCTile();
bool isShimPLTile();
bool isShimNOCorPLTile();
bool isInternalMemWest() { return ((rowIndex() % 2) == 0); };
MemOp getMemOp() {
auto users = getResult().getUsers();
for(auto user : users)
if(auto memOp = llvm::dyn_cast<MemOp>(*user))
return memOp;
return nullptr;
}
CoreOp getCoreOp() {
auto users = getResult().getUsers();
for(auto user : users)
if(auto coreOp = llvm::dyn_cast<CoreOp>(*user))
return coreOp;
return nullptr;
}
static AIE::TileOp getOrCreate(mlir::OpBuilder builder, AIE::DeviceOp device, int col, int row);
}];
let assemblyFormat = [{
`(` $col `,` $row `)` attr-dict
}];
let hasVerifier = 1;
let extraClassDefinition = [{
void $cppClass::getAsmResultNames(
function_ref<void(::mlir::Value, ::llvm::StringRef)> setNameFn) {
std::string tileName =
getOperationName().str().substr(getOperationName().find('.') + 1);
// Specialize the SSA value name according to the tile kind
if (isMemTile())
tileName = "mem_" + tileName;
else if (isShimNOCTile())
tileName = "shim_noc_" + tileName;
else if (isShimPLTile())
tileName = "shim_pl_" + tileName;
else if (isShimTile())
tileName = "shim_" + tileName;
setNameFn(getResult(), tileName + "_" +
std::to_string(getCol()) + "_" +
std::to_string(getRow()));
}
}];
let builders = [
OpBuilder<(ins "int32_t":$col, "int32_t":$row), [{
build($_builder, $_state, col, row, nullptr);
}]>,
OpBuilder<(ins "mlir::Type":$type, "int32_t":$col, "int32_t":$row), [{
build($_builder, $_state, type, col, row, nullptr);
}]>
];
}
def AIE_EndOp: AIE_Op<"end", [Terminator]> {
let summary = "end op";
let description = [{
A generic terminator operation for AIE ops' regions.
}];
let assemblyFormat = [{ attr-dict }];
}
def AIE_SwitchboxOp: AIE_Op<"switchbox", [
Interconnect,
SingleBlockImplicitTerminator<"EndOp">,
DeclareOpInterfaceMethods<InferTypeOpInterface>
]>, Results<(outs Index:$result)> {
let arguments = (ins Index:$tile);
let summary = "Declare a switch";
let description = [{
This operation represents the switchbox that is part of a tile. A switchbox is configured
by code in its region, representing various connections
Example:
```
%tile = aie.tile(1, 1)
aie.switchbox(%tile) {
aie.connect<"West" : 0, "Core" : 1>
}
```
}];
let regions = (region AnyRegion:$connections);
let assemblyFormat = [{ `(` $tile `)` regions attr-dict }];
let hasVerifier = 1;
let extraClassDeclaration = [{
TileOp getTileOp();
size_t getNumSourceConnections(WireBundle bundle);
size_t getNumDestConnections(WireBundle bundle);
void getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
::xilinx::AIE::TileElement::Trait<SwitchboxOp>::getAsmResultNames(setNameFn);
}
}];
}
def AIE_ShimSwitchboxOp: AIE_Op<"shim_switchbox", [
SingleBlockImplicitTerminator<"EndOp">,
DeclareOpInterfaceMethods<InferTypeOpInterface>
]>, Results<(outs Index)> {
let arguments = (ins AIEI32Attr:$col);
let summary = "Declare a switch in the PL shim";
let description = [{
A switch in the Shim.
AXI-Stream Master Ports AXI-Stream Slave Ports
6 Ports to North (Core Tile) 4 Ports from North (Core Tile)
4 Ports to West 4 Ports from West
4 Ports to East 4 Ports from East
6 Ports to South (DMA, NoC I/F, PL I/F) 8 Ports from South (DMA, NoC I/F, PL I/F)
2 Ports to FIFOs 2 Ports from FIFOs
1 Port for control packet for Shim register access
1 Port for response to access for Shim registers
1 Port for trace packet from Shim
}];
let regions = (region AnyRegion:$connections);
let assemblyFormat = [{ `(` $col `)` regions attr-dict }];
let hasVerifier = 1;
}
def AIE_ShimMuxOp: AIE_Op<"shim_mux", [
Interconnect, IsShimTile,
SingleBlockImplicitTerminator<"EndOp">,
DeclareOpInterfaceMethods<InferTypeOpInterface>
]>, Results<(outs Index)> {
let arguments = (
ins Index:$tile
);
let summary = "Declare a switch in the PL shim";
let description = [{
This operation represents the additional interconnect that is part of a shim interface tile.
Like the `aie.switchbox` operation, `aie.shim_mux` is configured
by code in its region, but can only contain connect operations
Example:
```
%tile = aie.tile(1, 1)
aie.shim_mux(%tile) {
aie.connect<"North" : 0, "DMA" : 1>
}
```
}];
let regions = (region AnyRegion:$connections);
let assemblyFormat = [{ `(` $tile `)` regions attr-dict }];
let hasVerifier = 1;
let extraClassDeclaration = [{
TileOp getTileOp();
size_t getNumSourceConnections(WireBundle bundle);
size_t getNumDestConnections(WireBundle bundle);
void getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
::xilinx::AIE::TileElement::Trait<ShimMuxOp>::getAsmResultNames(setNameFn);
}
}];
}
def AIE_ShimDMAOp: AIE_Op<"shim_dma", [
IsFlowEndPoint, TileElement, HasValidBDs,
HasValidDMAChannels, IsShimNOCTile,
DeclareOpInterfaceMethods<InferTypeOpInterface>
]>, Results<(outs Index)> {
let arguments = (
ins Index:$tile
);
let summary = "Declare a DMA in the PL shim";
let description = [{
This operation creates a DMA that belongs to a shim tile.
The region of a ShimDMAOp is used to setup the DMAs and Block Descriptors.
Example:
```
%buf = aie.external_buffer : memref<256xi64>
%lock1 = aie.lock(%t70, 1)
%dma = aie.shim_dma(%t70) {
aie.dma_start(MM2S, 0, ^bd0, ^end)
^bd0:
aie.use_lock(%lock1, Acquire, 1)
aie.dma_bd(%buf : memref<512 x i16>, 0, 512)
aie.use_lock(%lock1, Release, 0)
aie.next_bd ^bd0
^end:
aie.end
}
```
Create the shim_dma for tile `%t70` and setup one DMA channel and one Buffer Descriptor.
}];
let regions = (region AnyRegion:$body);
let assemblyFormat = [{ `(` $tile `)` regions attr-dict }];
let hasVerifier = 1;
let extraClassDeclaration = [{
TileOp getTileOp();
void getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
::xilinx::AIE::TileElement::Trait<ShimDMAOp>::getAsmResultNames(setNameFn);
}
}];
}
def AIE_CoreOp: AIE_Op<"core", [
IsFlowEndPoint, IsCoreTile, TileElement,
DeclareOpInterfaceMethods<InferTypeOpInterface>
]>, Results<(outs Index)> {
let arguments = (
ins Index:$tile,
DefaultValuedAttr<AIEI32Attr, "0x400">:$stack_size,
OptionalAttr<StrAttr>:$link_with,
OptionalAttr<StrAttr>:$elf_file,
OptionalAttr<BoolAttr>:$dynamic_objfifo_lowering
);
let summary = "Declare a core module";
let description = [{
This operation represents an AIEngine processor core belonging to a tile.
The region of a CoreOp contains code that gets run on the AIE core. This code will
typically be outlined into the LLVM dialect, eventually resulting in a binary file
for each core. The name of this file can be be specified using the `elf_file`
attribute.
If the `elf_file` attribute is present, no MLIR besides a terminator may be
present in the core; in that case, the binary file linked dictates what
will run in the core. The path specified should is relative to the MLIR
file.
This op has an optional `stackSize` attribute, to control the amount of memory (in bytes)
reserved for the stack. The default value is 1024. The stack (and other data allocations)
are always stored in the local core memory, to avoid conflicts with static data allocations
in other cores.
This op has an optional `dynamic_objfifo_lowering` attribute, to finely control whether the
objectfifos in this core should be lowered using the dynamic runtime lowering.
Examples:
```
%tile = aie.tile(1, 1)
%lock11_8 = aie.lock(%tile, 8)
aie.core(%tile) {
aie.use_lock(%lock11_8, "Acquire", 1)
aie.use_lock(%lock11_8, "Release", 0)
aie.end
}
```
```
%tile = aie.tile(3, 3)
aie.core(%tile) {
aie.end
} { stackSize = 2048 : i32, elf_file = "core_33.elf" }
```
}];
let regions = (region AnyRegion:$body);
let assemblyFormat = [{ `(` $tile `)` regions attr-dict }];
let hasVerifier = 1;
let extraClassDeclaration = [{
bool isMemWest() { return ((rowIndex() % 2) == 0); };
bool isEmpty();
TileOp getTileOp();
void getAsmResultNames(
llvm::function_ref<void(mlir::Value, llvm::StringRef)> setNameFn) {
::xilinx::AIE::TileElement::Trait<CoreOp>::getAsmResultNames(setNameFn);
}
}];
let builders = [
OpBuilder<(ins "mlir::Value":$tile), [{
build($_builder, $_state, $_builder.getIndexType(), tile);
}]>
];
}
def AIE_DebugOp: AIE_Op<"debug", []> {
let arguments = (
ins AnyType:$arg
);
let summary = "Capture a value for debugging";
let description = [{
Output the given value for debugging. This is primarily used for simulation.
}];
let assemblyFormat = [{ `(` $arg `:` type($arg) `)` attr-dict }];
}
def AIE_PLIOOp: AIE_Op<"plio", [
DeclareOpInterfaceMethods<InferTypeOpInterface>
]>, Results<(outs Index)> {
let arguments = (ins AIEI32Attr:$col);
let summary = "Declare an interface to the PL";
let description = [{
An interface to the PL.
}];
let assemblyFormat = [{ `(` $col `)` attr-dict }];
let extraClassDeclaration = [{
int colIndex() { return getCol(); }
}];
}
def AIE_ConnectOp: AIE_Op<"connect", [ParentOneOf<["SwitchboxOp", "ShimMuxOp"]> ]> {
let arguments = (
ins WireBundle:$source_bundle,
ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$source_channel,
WireBundle:$dest_bundle,
ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$dest_channel
);
let summary = "A circuit-switched connection inside a switchbox";
let description = [{
This operation represents a programmed circuit-switched connection in a stream switch.
It associates a source bundle and source channel with a destination bundle and a destination channel.
This operation must exist within an `aie.switchbox` or `aie.shim_switchbox` operation.
All of the `aie.connect` operations in a switchbox must have different destinations.
All of the `aie.connect` operations must also have a destination which is different from all
of the `aie.masterset` operations in the same switchbox.
Example:
```
%tile = aie.tile(1, 1)
aie.switchbox(%tile) {
aie.connect<"West" : 0, "Core" : 1>
}
```
}];
let assemblyFormat = [{
`<` $source_bundle `:` $source_channel `,` $dest_bundle `:` $dest_channel `>` attr-dict
}];
let extraClassDeclaration = [{
int sourceIndex() { return getSourceChannel(); }
int destIndex() { return getDestChannel(); }
Port sourcePort() { return {getSourceBundle(), sourceIndex()}; }
Port destPort() { return {getDestBundle(), destIndex()}; }
}];
}
def AIE_FlowOp: AIE_Op<"flow", []> {
let arguments = (
ins Index:$source,
WireBundle:$source_bundle,
ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$source_channel,
Index:$dest,
WireBundle:$dest_bundle,
ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$dest_channel
);
let summary = "A logical circuit-switched connection between cores";
let description = [{
The `aie.flow` operation represents a circuit switched connection between two endpoints, usually
`aie.tile` operations. During routing, this is replaced by `aie.connect` operations which represent
the programmed connections inside a switchbox, along with `aie.wire` operations which represent
physical connections between switchboxes and other components.
Example:
```
%00 = aie.tile(0, 0)
%11 = aie.tile(1, 1)
%01 = aie.tile(0, 1)
aie.flow(%00, "DMA" : 0, %11, "Core" : 1)
```
}];
let assemblyFormat = [{
`(` $source `,` $source_bundle `:` $source_channel `,` $dest `,` $dest_bundle `:` $dest_channel `)` attr-dict
}];
let extraClassDeclaration = [{
int sourceIndex() { return getSourceChannel(); }
int destIndex() { return getDestChannel(); }
}];
}
def AIE_AMSelOp: AIE_Op<"amsel", [
HasParent<"SwitchboxOp">,
DeclareOpInterfaceMethods<InferTypeOpInterface>
]>, Results<(outs Index)> {
let arguments = (
ins ConfinedAttr<AIEI8Attr, [IntMinValue<0>, IntMaxValue<5>]>:$arbiterID,
ConfinedAttr<AIEI8Attr, [IntMinValue<0>, IntMaxValue<3>]>:$msel
);
let summary = "Declare an arbiter of a switchbox with a master select value (arbiter + msel)";
let description = [{
A combination of arbiter ID and master select (msel) value.
This op is used as a pointer to select the arbiter for routing a packet-switched flow
Example:
```
%a0_0 = aie.amsel<5>(3)
%m1 = aie.masterset("East" : 0, %a0_0 )
aie.packet_rules("South" : 0) {
aie.rule(0x1F, 0x10, %a0_0)
}
```
This code associates arbiter 5 with msel=3. A packet-switched connection is made routing
traffic from the South:0 port to the East:0 port using this arbiter.
There are 6 arbiters per switchbox and 4 possible master select values.
See also [MasterSetOp](#aiemasterset-aiemastersetop),
[PacketRulesOp](#aiepacketrules-aiepacketrulesop), and
[PacketRuleOp](#aierule-aiepacketruleop) for more information.
}];
let assemblyFormat = [{
`<` $arbiterID `>` `(` $msel `)` attr-dict
}];
let extraClassDeclaration = [{
int arbiterIndex() { return getArbiterID(); }
int getMselValue() { return getMsel(); }
}];
let builders = [
OpBuilder<(ins "int":$arbiterID, "int":$msel),
[{
build($_builder, $_state, $_builder.getIndexType(),
$_builder.getI8IntegerAttr(arbiterID),
$_builder.getI8IntegerAttr(msel));
}]>
];
}
def AIE_MasterSetOp: AIE_Op<"masterset", [
HasParent<"SwitchboxOp">,
DeclareOpInterfaceMethods<InferTypeOpInterface>
]>, Results<(outs Index)> {
let arguments = (
ins WireBundle:$dest_bundle,
ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$dest_channel,
Variadic<Index>:$amsels,
OptionalAttr<BoolAttr>:$keep_pkt_header
);
let summary = "Packet switched input connection";
let description = [{
A packet switched connection inside a switchbox.
This operation specifies the configuration for a master port.
Example:
```
%a0_m2 = aie.amsel<0>(2)
aie.masterset("Core" : 0, %a0_m2)
```
The code will configure the master port <"Core" : 0> to use arbiter 0 with msel 2
(see AMSelOp for more details regarding AMSel)
In the current architecture, a master port can only be associated with one arbiter. However,
a master port can be activated by different msels from one arbiter
Example:
```
%a1_0 = aie.amsel<1>(0)
%a1_1 = aie.amsel<1>(1)
%a2_3 = aie.amsel<2>(3)
aie.masterset("West" : 2, %a1_0, %a2_3) // this is illegal, please don't do this
aie.masterset("West" : 3, %a1_0, %a1_1) // this is OK
```
}];
let assemblyFormat = [{
`(` $dest_bundle `:` $dest_channel `,` $amsels `)` attr-dict
}];
let extraClassDeclaration = [{
int destIndex() { return getDestChannel(); }
Port destPort() { return {getDestBundle(), destIndex()}; }
}];
}
def AIE_WireOp: AIE_Op<"wire", []> {
let arguments = (
ins Index:$source,
WireBundle:$source_bundle,
Index:$dest,
WireBundle:$dest_bundle
);
let summary = "A bundle of physical wires between components";
let description = [{
The `aie.wire` operation represents a physical set of connections between components in a Versal device.
Typically, these components are switches, represented by an `aie.switchbox` operation, and tiles,
represented by an [aie.tile](#aietile-aietileop) operation.
}];
let assemblyFormat = [{
`(` $source `:` $source_bundle `,` $dest `:` $dest_bundle `)` attr-dict
}];
}
def AIE_PacketRulesOp: AIE_Op<"packet_rules", [SingleBlockImplicitTerminator<"EndOp">]> {
let arguments = (
ins WireBundle:$source_bundle,
ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$source_channel
);
let regions = (region AnyRegion:$rules);
let summary = "Packet switched routing rules";
let description = [{
This operation defines packet-switched routing configuration for packets entering a switchbox.
It references a port of the containing switchbox, which must be unique among other packetRules
operations and [aie.connect]($aieconnect-aieconnectop) operations in the containing switchbox.
It contains a region of up to 4 [aie.rule](#aierule-aiepacketruleop) operations.
See [aie.rule](#aierule-aiepacketruleop) for an example.
}];
let assemblyFormat = [{ `(` $source_bundle `:` $source_channel `)` regions attr-dict }];
let hasVerifier = 1;
let extraClassDeclaration = [{
int sourceIndex() { return getSourceChannel(); }
Port sourcePort() { return {getSourceBundle(), sourceIndex()}; }
}];
}
def AIE_PacketRuleOp: AIE_Op<"rule", [HasParent<"PacketRulesOp">]> {
let arguments = (
ins AIEI8Attr:$mask,
AIEI8Attr:$value,
Index:$amsel
);
let summary = "Packet switched routing rule";
let description = [{
This operation defines a matching rule and a destination for packet-switched
connections in a switchbox. Routing is based on the ID field of packet arriving on the
matching port of the containing [aie.packetRules](#aiepacketrules-aiepacketrulesop).
The ID is first bitwise-AND'd with the mask and then checked for equality with the given ID.
It is routed to arbiter and master set associated with the first matching entry.
Example:
LUT ID | Mask | ID | Arbiter | Msel
--- | --- | --- | --- | ---
0 | 5'b11111 | 5'b00010 | 4 | 1
1 | 5'b11011 | 5'b00001 | 3 | 2
2 | | | |
3 | | | |
If a packet flow that has an ID of 2, it will be directed to the arbiter 4 with msel 1,
If a packet flow that has an ID of 1 or 5, it will be directed to the arbiter 3 with msel 2,
We encapsulate the configuration table as follows:
Example:
```
%a4_1 = aie.amsel<4>(1)
%a3_2 = aie.amsel<3>(2)
aie.packet_rules("Core" : 0) {
aie.rule(0x1F, 0x2, %a4_1)
aie.rule(0x1B, 0x1, %a3_2)
}
```
}];
let extraClassDeclaration = [{
int maskInt() { return getMask(); }
int valueInt() { return getValue(); }
}];
let assemblyFormat = [{
`(` $mask `,` $value `,` $amsel `)` attr-dict
}];
}
def AIE_PacketFlowOp: AIE_Op<"packet_flow", [SingleBlockImplicitTerminator<"EndOp">]> {
let summary = "Packet switched flow";
let description = [{
A logical packet-switched flow between tiles. During place and
route, this is replaced by MasterSets and PacketRules inside
switchboxes.
The optional attribute keep_pkt_header indicates whether each
data packet's packet header gets preserved at the flow's
destination. The optional attribute priority_route indicates
whether the packet flow is routed in priority over other flows,
so that they always get allocated with the same master, slave
ports, arbiters and master selects (msel).
Example:
```
%01 = aie.tile(0, 1)
aie.packet_flow(0x10) {
aie.packet_source<%01, "Core" : 0>
aie.packet_dest<%01, "Core" : 0>
}
```
}];
let arguments = (
ins AIEI8Attr:$ID,
OptionalAttr<BoolAttr>:$keep_pkt_header,
OptionalAttr<BoolAttr>:$priority_route
);
let regions = (region AnyRegion:$ports);
let assemblyFormat = [{ `(` $ID `)` regions attr-dict }];
let hasVerifier = 1;
let extraClassDeclaration = [{
int IDInt() { return getID(); }
}];
}
def AIE_PacketSourceOp: AIE_Op<"packet_source", [HasParent<"PacketFlowOp">]> {
let arguments = (
ins Index:$tile,
WireBundle:$bundle,
ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$channel
);
let summary = "A sourceport";
let description = [{
An object representing the destination of a packet-switched flow. This must exist
within an [aie.packet_flow](#aiepacketflow-aiepacketflowop) operation.
See [aie.packet_flow](#aiepacketflow-aiepacketflowop) for an example.
}];
let assemblyFormat = [{
`<` $tile `,` $bundle `:` $channel `>` attr-dict
}];
let extraClassDeclaration = [{
int channelIndex() { return getChannel(); }
Port port() { return {getBundle(), channelIndex()}; }
}];
}
def AIE_PacketDestOp: AIE_Op<"packet_dest", [HasParent<"PacketFlowOp">]> {
let arguments = (
ins Index:$tile,
WireBundle:$bundle,
ConfinedAttr<AIEI32Attr, [IntMinValue<0>]>:$channel
);
let summary = "A destination port";
let description = [{
A object representing the destination of a packet-switched flow. This must exist
within an [aie.packet_flow](#aiepacketflow-aiepacketflowop) operation. The destination
Must be unique within a design.
See [aie.packet_flow](#aiepacketflow-aiepacketflowop) for an example.
}];
let assemblyFormat = [{
`<` $tile `,` $bundle `:` $channel `>` attr-dict
}];
let extraClassDeclaration = [{
int channelIndex() { return getChannel(); }
Port port() { return {getBundle(), channelIndex()}; }
}];
}
def AIE_DMABDPACKETOp: AIE_Op<"dma_bd_packet", []> {
let summary = "Enable packet headers for a dma block descriptor";
let description = [{
This operation enables packet headers for a block descriptor for DMA operations. In particular, it specifies
the packet type (3-bits) and packet ID (5-bits).
This operation must be used in an MLIR block that lives inside a MemOp's region, and before aie.dma_bd.
The block descriptor specifies what lock to use and the buffer configuration.
Example:
```
// this defines a BD that uses lock %lck0 and buffer %buf0
^bd5:
aie.use_lock(%lck, "Acquire", 0)
aie.dma_bd_packet(0x4, 0xD)
aie.dma_bd(<$buf0 : memref<512xi32>, 0, 512>, 1)
aie.use_lock(%lck, "Release", 1)
br ^bd6 // point to the next Block, which is also a different Block Descriptor
```
}];
let arguments = (
ins AIEI32Attr:$packet_type,
AIEI32Attr:$packet_id
);
let assemblyFormat = [{
`(` $packet_type `,` $packet_id `)` attr-dict
}];
let extraClassDeclaration = [{
int getPacketID() { return getPacketId(); }
}];
}
def AIE_DMABDOp: AIE_Op<"dma_bd", []> {
let summary = "Declare a dma buffer descriptor op";
let description = [{
This operation describes a buffer descriptor for DMA operations. In particular, it specifies
what buffer to use, and optionally:
1. the offset into the buffer;
2. the transfer length;
3. the sizes and strides for n-d tensor addressing (described below);
4. the "bd_id" with which to associate the buffer descriptor (most often left empty);
5. the number of zeros to pad before and after every dimension of an n-d tensor (described below);
6. the burst length to use for the DMA operation. This option is only available for data movement between the host memory and Shim NOC tiles.
The default value of 0 is interpreted as the maximum available burst length in the architecture.
`offset`, `len`, `size`s and `stride`s are all denominated in element width; e.g., transferring the whole of
`memref<512xi32>` means `len == 512`, and also while transferring the whole of `memref<512xi16>`, `len == 512`.
The only caveat to this "everything-is-in-terms-of-element-width" rule is regarding the inner-most dimension's stride
(see [Important gotcha regarding strides](#important-gotcha-regarding-strides) below).
`dma_bd` ops must appear in their own BBs (basic blocks) and such BBs can (optionally) include `use_lock`
operations (specifying an "acquire" and a "release" lock; see the `use_lock` operation) and subsequent BDs in
a "chain" of BDs (using `next_bd` as a "jump" to the next BB which contains a `dma_bd`).
Example:
```
// this defines a BD that uses lock %lck0 and buffer %buf0
^bd5:
aie.use_lock(%lck, "Acquire", 0)
// transfer the first 32 elements of the memref
aie.dma_bd(<$buf0 : memref<128xi32>, 0, 32)
aie.use_lock(%lck, "Release", 1)
aie.next_bd ^bd6 // point to the next bb, which describes the next buffer descriptor
^bd6:
aie.use_lock(%lck, "Acquire", 1)
// transfer the last 32 elements of the memref
aie.dma_bd(<$buf1 : memref<128xi32>, 96, 32)
aie.use_lock(%lck, "Release", 0)
aie.next_bd ^end
...
// this defines a BD that does not use any lock
^bd8:
aie.dma_bd(<$buf2 : memref<64xi32>, 0, 64)
```
#### Background/context
A DMA channel in a Memory Module can process one buffer descriptor after another by chaining them.
There are 16 buffer descriptors per Core memory module and 48 buffer descriptors per Memtile memory module.
They are shared by four DMA channels (or 12).
#### DMA Data Layout Transformations on AIE-ML Devices
AIE-ML devices can apply data layout transformations at the buffer
descriptor level. These transformation are described by strides and sizes in up to three dimensions (four
dimensions on memtiles). Strides and sizes can be supplied to the `dma_bd`
through an optional argument, an array of "tuple-like" attributes `bd_dim_layout<size, stride>`.
The first element of this array gives the outer-most dimension's stride and
size, the last element of the array gives the inner-most dimension's stride and size.
We can model the access pattern strides and sizes generate by a series of
nested loops. In general, a set of strides and sizes like this...
```
[<size_2, stride_2>, <size_1, stride_1>, <size_0, stride_0>]
```
...translates to an access pattern that can be expressed like this:
```
int *buffer; // i32
for(int i = 0; i < size_2; i++)
for(int j = 0; j < size_1; j++)
for(int k = 0; k < size_0; k++)
// access/store element at/to buffer[ i * stride_2
// + j * stride_1
// + k * stride_0]
```
The following example shows an access pattern that corresponds to
alternating between even and odd elements of the buffer/stream every 8
elements:
```
aie.dma_bd(%buf : memref<128xi32>, 0, 128, [<8, 16>, <2, 1>, <8, 2>])
```
implies
```
for(int i = 0; i < 8 /*size_2*/; i++)
for(int j = 0; j < 2 /*size_1*/; j++)
for(int k = 0; k < 8 /*size_0*/; k++)
// access/store element at/to index (i * 16 /*stride_2*/ + j * 1 /*stride_1*/ + k * 2 /*stride_0*/)
```
#### Important gotcha regarding strides
All strides are expressed in multiples of the element width (just like `len` and `offset`)
**with the caveat that the inner-most dimension's stride must be 1**.
## DMA constant padding on AIE-ML Devices
AIE-ML devices can apply constant padding at the buffer descriptor level, described with pairs of padding
counts before and after a dimension, to all dimensions in the data layout transformations. The padding
counts can be supplied to the `dma_bd` through an optional argument, an array of "tuple-like" attributes
`bd_pad_layout<const_pad_before, const_pad_after>`, followed by an optional argument `const_val` (default
is 0). All counts are expressed in multiples of the element width.
}];
let arguments = (
ins AnyRankedOrUnrankedMemRef:$buffer,
// in multiples of element width (not bytes)
DefaultValuedAttr<AIEI32Attr, "0">:$offset,
// in multiples of element width (not bytes)
OptionalAttr<AIEI32Attr>:$len,
OptionalAttr<BDDimLayoutArrayAttr>:$dimensions,
OptionalAttr<BDPadLayoutArrayAttr>:$pad_dimensions,
DefaultValuedOptionalAttr<AIEI32Attr, "0">:$pad_value,
OptionalAttr<AIEI32Attr>:$bd_id,
OptionalAttr<PacketInfoAttr>:$packet,
DefaultValuedOptionalAttr<AIEI32Attr, "0">:$burst_length,
// should never be assigned by user...
OptionalAttr<AIEI32Attr>:$next_bd_id
);
let hasVerifier = 1;
let hasCustomAssemblyFormat = 1;
let extraClassDeclaration = [{
BufferOp getBufferOp();
int32_t getBufferElementTypeWidthInBytes() {
mlir::DataLayout dataLayout = mlir::DataLayout::closest(*this);
auto bufferType = llvm::cast<mlir::BaseMemRefType>(getBuffer().getType());
return dataLayout.getTypeSize(bufferType.getElementType());
}
uint32_t getLenInBytes() {
if (std::optional<uint32_t> len = getLen(); len.has_value())
return len.value() * getBufferElementTypeWidthInBytes();
auto memrefType = llvm::dyn_cast<mlir::MemRefType>(getBuffer().getType());
if (!memrefType)
return 0; // Unranked memref without explicit len
return memrefType.getNumElements() * getBufferElementTypeWidthInBytes();
}
int32_t getOffsetInBytes() { return getOffset() * getBufferElementTypeWidthInBytes(); }
}];
let hasVerifier = 1;
let builders = [
OpBuilder<(ins "mlir::Value":$buffer, "int":$offset, "int":$len), [{
$_state.addOperands(buffer);
$_state.addAttribute("offset", $_builder.getI32IntegerAttr(offset));
$_state.addAttribute("len", $_builder.getI32IntegerAttr(len));
}]>,
OpBuilder<(ins "mlir::Value":$buffer, "int":$offset, "int":$len, "BDDimLayoutArrayAttr":$dims), [{
$_state.addOperands(buffer);
$_state.addAttribute("offset", $_builder.getI32IntegerAttr(offset));
$_state.addAttribute("len", $_builder.getI32IntegerAttr(len));
$_state.addAttribute("dimensions", dims);
}]>,
OpBuilder<(ins "mlir::Value":$buffer, "int":$offset, "int":$len, "BDPadLayoutArrayAttr":$paddims), [{
$_state.addOperands(buffer);
$_state.addAttribute("offset", $_builder.getI32IntegerAttr(offset));
$_state.addAttribute("len", $_builder.getI32IntegerAttr(len));
$_state.addAttribute("pad_dimensions", paddims);
}]>,
OpBuilder<(ins "mlir::Value":$buffer, "int":$offset, "int":$len, "BDDimLayoutArrayAttr":$dims, "BDPadLayoutArrayAttr":$paddims), [{
$_state.addOperands(buffer);
$_state.addAttribute("offset", $_builder.getI32IntegerAttr(offset));
$_state.addAttribute("len", $_builder.getI32IntegerAttr(len));
$_state.addAttribute("dimensions", dims);
$_state.addAttribute("pad_dimensions", paddims);
}]>,
OpBuilder<(ins "mlir::Value":$buffer, "int":$offset, "int":$len, "PacketInfoAttr":$pkt), [{
$_state.addOperands(buffer);
$_state.addAttribute("offset", $_builder.getI32IntegerAttr(offset));
$_state.addAttribute("len", $_builder.getI32IntegerAttr(len));
$_state.addAttribute("packet", pkt);
}]>,
OpBuilder<(ins "mlir::Value":$buffer, "int":$offset, "int":$len, "BDDimLayoutArrayAttr":$dims, "PacketInfoAttr":$pkt), [{
$_state.addOperands(buffer);
$_state.addAttribute("offset", $_builder.getI32IntegerAttr(offset));
$_state.addAttribute("len", $_builder.getI32IntegerAttr(len));
$_state.addAttribute("dimensions", dims);
$_state.addAttribute("packet", pkt);
}]>,
OpBuilder<(ins "mlir::Value":$buffer, "int":$offset, "int":$len, "BDPadLayoutArrayAttr":$paddims, "PacketInfoAttr":$pkt), [{
$_state.addOperands(buffer);
$_state.addAttribute("offset", $_builder.getI32IntegerAttr(offset));
$_state.addAttribute("len", $_builder.getI32IntegerAttr(len));
$_state.addAttribute("pad_dimensions", paddims);
$_state.addAttribute("packet", pkt);