Skip to content

Commit 0aa65a6

Browse files
authored
Add npu.load_pdi to aiex (#2147)
1 parent 49d1da6 commit 0aa65a6

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

include/aie/Dialect/AIEX/IR/AIEX.td

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,23 @@ def AIE_NpuWriteBdOp: AIEX_Op<"npu.writebd", []> {
953953
}];
954954
}
955955

956+
// NPU Load PDI operation
957+
def AIE_NpuLoadPdiOp: AIEX_Op<"npu.load_pdi", []> {
958+
let summary = "load pdi operator";
959+
let arguments = (
960+
ins I32Attr:$id,
961+
OptionalAttr<I32Attr>:$size,
962+
OptionalAttr<UI64Attr>:$address
963+
);
964+
let results = (outs );
965+
let assemblyFormat = [{ attr-dict }];
966+
let description = [{
967+
Load a PDI (Programmable Device Image) to configure the NPU.
968+
The PDI is identified by `id`. `address` and `size` are typically written at
969+
runtime by the driver or host program.
970+
}];
971+
}
972+
956973
def AIE_DMAConfigureTaskOp : AIEX_Op<"dma_configure_task", [HasParent<"RuntimeSequenceOp">, TileElement]>, Results<(outs Index:$result)> {
957974
let summary = "Concrete Instantiation of a Buffer Descriptor Chain as a Task on a Channel and Direction on a Tile";
958975
let description = [{

lib/Targets/AIETargetNPU.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ void appendMaskWrite32(std::vector<uint32_t> &instructions,
148148
words[6] = words.size() * sizeof(uint32_t); // Operation Size
149149
}
150150

151+
void appendLoadPdi(std::vector<uint32_t> &instructions, NpuLoadPdiOp op) {
152+
153+
auto words = reserveAndGetTail(instructions, 4);
154+
155+
// XAIE_IO_LOADPDI
156+
words[0] = XAIE_IO_LOADPDI;
157+
words[0] |= op.getId() << 16;
158+
std::optional<uint32_t> size = op.getSize();
159+
if (size)
160+
words[1] = *size;
161+
std::optional<uint64_t> address = op.getAddress();
162+
if (address) {
163+
words[2] = *address;
164+
words[3] = *address >> 32;
165+
}
166+
}
167+
151168
void appendAddressPatch(std::vector<uint32_t> &instructions,
152169
NpuAddressPatchOp op) {
153170

@@ -277,6 +294,10 @@ xilinx::AIE::AIETranslateNpuToBinary(ModuleOp module,
277294
count++;
278295
appendMaskWrite32(instructions, op);
279296
})
297+
.Case<NpuLoadPdiOp>([&](auto op) {
298+
count++;
299+
appendLoadPdi(instructions, op);
300+
})
280301
.Case<NpuAddressPatchOp>([&](auto op) {
281302
count++;
282303
appendAddressPatch(instructions, op);

test/Targets/NPU/npu_instgen.mlir

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ module {
1717
// TXN header 0.1
1818
// CHECK: 06030100
1919
// CHECK: 00000104
20-
// CHECK: 00000006
21-
// CHECK: 000000CC
20+
// CHECK: 00000007
21+
// CHECK: 000000DC
2222

2323
// CHECK: 00000000
2424
// CHECK: 00000000
@@ -79,6 +79,12 @@ module {
7979
// CHECK: 00030401
8080
// CHECK: 05010200
8181
aiex.npu.sync { column = 3 : i32, row = 4 : i32, direction = 1 : i32, channel = 5 : i32, column_num = 1 : i32, row_num = 2 : i32 }
82+
83+
// CHECK: 00020008
84+
// CHECK: 00000400
85+
// CHECK: 12345678
86+
// CHECK: 00000ABC
87+
aiex.npu.load_pdi { address = 0xabc12345678 : ui64, id = 2 : i32, size = 1024 : i32 }
8288
}
8389
}
8490
}

test/dialect/AIEX/roundtrip.mlir

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,19 @@ aie.device(npu1) {
6464
aiex.control_packet {address = 0xABCD : ui32, length = 3 : i32, opcode = 1 : i32, stream_id = 4 : i32}
6565
}
6666
}
67+
68+
// -----
69+
70+
// CHECK: aie.device
71+
// CHECK: aiex.npu.load_pdi {id = 4 : i32}
72+
// CHECK: aiex.npu.load_pdi {id = 7 : i32}
73+
// CHECK: aiex.npu.load_pdi {address = 2 : ui64, id = 1 : i32, size = 3 : i32}
74+
aie.device(npu1) {
75+
memref.global "private" constant @pdi_data : memref<8xi32> = dense<[-1, 1, 256, 1024, 41, 42, 43, 44]>
76+
aiex.runtime_sequence @pdi_loader(%arg0 : memref<?xi32>) {
77+
%0 = memref.get_global @pdi_data : memref<8xi32>
78+
aiex.npu.load_pdi {id = 4 : i32}
79+
aiex.npu.load_pdi {id = 7 : i32}
80+
aiex.npu.load_pdi {id = 1 : i32, address = 2 : ui64, size = 3 : i32}
81+
}
82+
}

0 commit comments

Comments
 (0)