Skip to content

Commit 0591d59

Browse files
committed
Add command line device selection
1 parent 3cd0a8d commit 0591d59

File tree

7 files changed

+47
-25
lines changed

7 files changed

+47
-25
lines changed

include/aie-c/Translation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ MLIR_CAPI_EXPORTED MlirLogicalResult aieTranslateToCDODirect(
4040
bool xaieDebug, bool enableCores);
4141
MLIR_CAPI_EXPORTED MlirOperation aieTranslateBinaryToTxn(MlirContext ctx,
4242
MlirStringRef binary);
43-
MLIR_CAPI_EXPORTED MlirOperation
44-
aieTranslateBinaryToControlPackets(MlirContext ctx, MlirStringRef binary);
43+
MLIR_CAPI_EXPORTED MlirOperation aieTranslateBinaryToControlPackets(
44+
MlirContext ctx, MlirStringRef binary, int device);
4545

4646
struct AieRtControl {
4747
void *ptr;

include/aie/Conversion/AIEToConfiguration/AIEToConfiguration.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace xilinx::AIE {
1919

20+
enum class AIEDevice : uint32_t;
2021
class DeviceOp;
2122

2223
std::unique_ptr<mlir::OperationPass<xilinx::AIE::DeviceOp>>
@@ -29,9 +30,9 @@ std::optional<mlir::ModuleOp>
2930
convertTransactionBinaryToMLIR(mlir::MLIRContext *ctx,
3031
std::vector<uint8_t> &binary);
3132

32-
std::optional<mlir::ModuleOp>
33-
convertControlPacketBinaryToMLIR(mlir::MLIRContext *ctx,
34-
std::vector<uint8_t> &binary);
33+
std::optional<mlir::ModuleOp> convertControlPacketBinaryToMLIR(
34+
mlir::MLIRContext *ctx, std::vector<uint8_t> &binary,
35+
AIEDevice device = static_cast<AIEDevice>(4)); /* npu1 */
3536

3637
} // namespace xilinx::AIE
3738

lib/CAPI/Translation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ MlirOperation aieTranslateBinaryToTxn(MlirContext ctx, MlirStringRef binary) {
9595
}
9696

9797
MlirOperation aieTranslateBinaryToControlPackets(MlirContext ctx,
98-
MlirStringRef binary) {
98+
MlirStringRef binary,
99+
int device) {
99100
std::vector<uint8_t> binaryData(binary.data, binary.data + binary.length);
100-
auto mod = convertControlPacketBinaryToMLIR(unwrap(ctx), binaryData);
101+
auto mod = convertControlPacketBinaryToMLIR(unwrap(ctx), binaryData,
102+
static_cast<AIEDevice>(device));
101103
if (!mod)
102104
return wrap(ModuleOp().getOperation());
103105
return wrap(mod->getOperation());

lib/Conversion/AIEToConfiguration/AIEToConfiguration.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,8 @@ xilinx::AIE::convertTransactionBinaryToMLIR(mlir::MLIRContext *ctx,
863863
// new ModuleOp containing a DeviceOp containing a runtime sequence with the
864864
// control packet binary encoded as a sequence of aiex.control_packet
865865
// operations. On failure return std::nullopt.
866-
std::optional<mlir::ModuleOp>
867-
xilinx::AIE::convertControlPacketBinaryToMLIR(mlir::MLIRContext *ctx,
868-
std::vector<uint8_t> &binary) {
866+
std::optional<mlir::ModuleOp> xilinx::AIE::convertControlPacketBinaryToMLIR(
867+
mlir::MLIRContext *ctx, std::vector<uint8_t> &binary, AIEDevice device) {
869868

870869
// parse the binary
871870
auto maybeOps = parseControlPacket(binary);
@@ -882,13 +881,13 @@ xilinx::AIE::convertControlPacketBinaryToMLIR(mlir::MLIRContext *ctx,
882881
OpBuilder builder(module.getBodyRegion());
883882
builder.setInsertionPointToStart(module.getBody());
884883

885-
// Create aie.device - default to npu1_1col
886-
// Note: Control packets don't have device info in the binary format
887-
auto device = builder.create<DeviceOp>(loc, AIEDevice::npu1_1col,
888-
StringAttr::get(builder.getContext()));
889-
device.getRegion().emplaceBlock();
890-
DeviceOp::ensureTerminator(device.getBodyRegion(), builder, loc);
891-
builder.setInsertionPointToStart(device.getBody());
884+
// Create aie.device with specified device type
885+
auto deviceAttr = AIEDeviceAttr::get(ctx, device);
886+
auto deviceOp = builder.create<DeviceOp>(
887+
loc, deviceAttr, StringAttr::get(builder.getContext()));
888+
deviceOp.getRegion().emplaceBlock();
889+
DeviceOp::ensureTerminator(deviceOp.getBodyRegion(), builder, loc);
890+
builder.setInsertionPointToStart(deviceOp.getBody());
892891

893892
// Create tiles and set controller_id attributes based on packet info
894893
// Group operations by (pktType, pktId) to determine which tile they target
@@ -897,13 +896,13 @@ xilinx::AIE::convertControlPacketBinaryToMLIR(mlir::MLIRContext *ctx,
897896
auto key = std::make_pair(op.pktType, op.pktId);
898897
if (tileMap.find(key) == tileMap.end()) {
899898
// Extract col/row from address using target model
900-
const AIETargetModel &targetModel = device.getTargetModel();
899+
const AIETargetModel &targetModel = deviceOp.getTargetModel();
901900
uint32_t colInt = (op.address >> targetModel.getColumnShift()) & 0x1f;
902901
uint32_t rowInt = (op.address >> targetModel.getRowShift()) & 0x1f;
903902
tileMap[key] = std::make_pair(colInt, rowInt);
904903

905904
// Create tile and set controller_id attribute
906-
auto tile = TileOp::getOrCreate(builder, device, colInt, rowInt);
905+
auto tile = TileOp::getOrCreate(builder, deviceOp, colInt, rowInt);
907906
auto packetInfoAttr =
908907
AIE::PacketInfoAttr::get(builder.getContext(), op.pktType, op.pktId);
909908
tile->setAttr("controller_id", packetInfoAttr);

python/AIEMLIRModule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ NB_MODULE(_aie, m) {
135135

136136
m.def(
137137
"control_packets_binary_to_mlir",
138-
[](MlirContext ctx, nb::bytes bytes) {
138+
[](MlirContext ctx, nb::bytes bytes, int device) {
139139
MlirStringRef bin = {static_cast<const char *>(bytes.data()),
140140
bytes.size()};
141-
return aieTranslateBinaryToControlPackets(ctx, bin);
141+
return aieTranslateBinaryToControlPackets(ctx, bin, device);
142142
},
143-
"ctx"_a, "binary"_a);
143+
"ctx"_a, "binary"_a, "device"_a = 4); /* npu1 */
144144

145145
m.def(
146146
"translate_npu_to_binary",

python/compiler/pkt2mlir/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ The tool parses binary control packet files generated by `aie-translate --aie-ct
1212
## Usage
1313

1414
```bash
15-
pkt2mlir.py -f <binary-file>
15+
pkt2mlir.py -f <binary-file> [-d <device-type>]
1616
```
1717

1818
### Options
1919

2020
- `-f`, `-file FILE` : Input control packet binary file (required)
21+
- `-d`, `-device DEVICE` : Target AIE device type (default: npu1)
22+
- Supported devices: xcvc1902, xcve2302, xcve2802, npu1, npu1_1col, npu1_2col, npu1_3col, npu2, npu2_1col, npu2_2col, npu2_3col, npu2_4col, npu2_5col, npu2_6col, npu2_7col
2123
- `-h`, `--help` : Show help message and exit
2224

2325
## Examples
@@ -65,9 +67,17 @@ Translate back to MLIR:
6567
pkt2mlir.py -f control_packets.bin
6668
```
6769

70+
Or specify a different device type:
71+
72+
```bash
73+
pkt2mlir.py -f control_packets.bin -d npu1
74+
```
75+
76+
Output:
77+
6878
```mlir
6979
module {
70-
aie.device(npu1_1col) {
80+
aie.device(npu1) {
7181
%shim_noc_tile_0_0 = aie.tile(0, 0) {controller_id = #aie.packet_info<pkt_type = 2, pkt_id = 3>}
7282
7383
aiex.runtime_sequence @configure() {

python/compiler/pkt2mlir/main.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,24 @@ def main():
2424
required=True,
2525
help="Input control packet binary file",
2626
)
27+
parser.add_argument(
28+
"-device",
29+
"-d",
30+
type=str,
31+
default="npu1",
32+
help="Target AIE device type (default: npu1)",
33+
)
2734

2835
args = parser.parse_args()
2936

3037
# Read the data from the file
3138
data = args.file.read()
3239

40+
# Get the device enum value
41+
device_value = getattr(AIEDevice, args.device)
42+
3343
with Context() as ctx:
34-
module = control_packets_binary_to_mlir(ctx, data)
44+
module = control_packets_binary_to_mlir(ctx, data, device_value)
3545

3646
print(str(module))
3747

0 commit comments

Comments
 (0)