Skip to content

Commit 59cabe3

Browse files
authored
aiecc argument handling updates (#2141)
1 parent 4aa4e38 commit 59cabe3

4 files changed

Lines changed: 71 additions & 15 deletions

File tree

python/compiler/aiecc/cl_arguments.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def parse_args(args=None):
5858
parser.add_argument(
5959
"--no-xbridge",
6060
dest="xbridge",
61-
default=not aie_link_with_xchesscc,
61+
default=aie_link_with_xchesscc,
6262
action="store_false",
6363
help="Link using peano",
6464
)
@@ -86,7 +86,7 @@ def parse_args(args=None):
8686
parser.add_argument(
8787
"--no-xchesscc",
8888
dest="xchesscc",
89-
default=not aie_compile_with_xchesscc,
89+
default=aie_compile_with_xchesscc,
9090
action="store_false",
9191
help="Compile using peano",
9292
)
@@ -106,7 +106,7 @@ def parse_args(args=None):
106106
parser.add_argument(
107107
"--no-compile",
108108
dest="compile",
109-
default=aie_disable_compile,
109+
default=not aie_disable_compile,
110110
action="store_false",
111111
help="Disable compiling of AIE code",
112112
)
@@ -126,7 +126,7 @@ def parse_args(args=None):
126126
parser.add_argument(
127127
"--no-compile-host",
128128
dest="compile_host",
129-
default=host_disable_compile,
129+
default=not host_disable_compile,
130130
action="store_false",
131131
help="Disable compiling of the host program",
132132
)
@@ -140,7 +140,7 @@ def parse_args(args=None):
140140
parser.add_argument(
141141
"--no-link",
142142
dest="link",
143-
default=aie_disable_link,
143+
default=not aie_disable_link,
144144
action="store_false",
145145
help="Disable linking of AIE code",
146146
)
@@ -201,7 +201,7 @@ def parse_args(args=None):
201201
parser.add_argument(
202202
"--no-unified",
203203
dest="unified",
204-
default=not aie_unified_compile,
204+
default=aie_unified_compile,
205205
action="store_false",
206206
help="Compile cores independently in separate processes",
207207
)
@@ -247,7 +247,13 @@ def parse_args(args=None):
247247
default=False,
248248
action="store_const",
249249
const=True,
250-
help="Generate txn binary for configuration",
250+
help="Generate transaction binary mlir for configuration",
251+
)
252+
parser.add_argument(
253+
"--txn-name",
254+
dest="txn_name",
255+
default="transaction.mlir",
256+
help="Output filename for transaction binary mlir",
251257
)
252258
parser.add_argument(
253259
"--aie-generate-ctrlpkt",

python/compiler/aiecc/main.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def emit_design_kernel_json(
207207
}
208208

209209

210-
def emit_partition(mlir_module_str, pdi_name, kernel_id="0x901"):
210+
def emit_partition(mlir_module_str, kernel_id="0x901"):
211211
with Context(), Location.unknown():
212212
module = Module.parse(mlir_module_str)
213213
device = find_ops(
@@ -242,7 +242,7 @@ def emit_partition(mlir_module_str, pdi_name, kernel_id="0x901"):
242242
"PDIs": [
243243
{
244244
"uuid": str(pdi_uuid),
245-
"file_name": pdi_name,
245+
"file_name": "./design.pdi",
246246
"cdo_groups": [
247247
{
248248
"name": "DPU",
@@ -600,6 +600,10 @@ async def process_txn(self, module_str):
600600
self.prepend_tmp("txn.mlir"),
601601
self.opts.verbose,
602602
)
603+
tmp = self.prepend_tmp("txn.mlir")
604+
if opts.verbose:
605+
print(f"copy {tmp} to {opts.txn_name}")
606+
shutil.copy(tmp, opts.txn_name)
603607

604608
async def process_ctrlpkt(self, module_str):
605609
with Context(), Location.unknown():
@@ -616,7 +620,7 @@ async def process_pdi_gen(self):
616620

617621
await write_file_async(
618622
emit_design_bif(self.tmpdirname),
619-
self.prepend_tmp(opts.pdi_name + ".bif"),
623+
self.prepend_tmp("design.bif"),
620624
)
621625

622626
await self.do_call(
@@ -626,12 +630,17 @@ async def process_pdi_gen(self):
626630
"-arch",
627631
"versal",
628632
"-image",
629-
self.prepend_tmp(opts.pdi_name + ".bif"),
633+
self.prepend_tmp("design.bif"),
630634
"-o",
631-
self.prepend_tmp(opts.pdi_name),
635+
self.prepend_tmp('design.pdi'),
632636
"-w",
633637
],
634638
)
639+
if opts.pdi:
640+
tmp = self.prepend_tmp("design.pdi")
641+
if opts.verbose:
642+
print(f"copy {tmp} to {opts.pdi_name}")
643+
shutil.copy(tmp, opts.pdi_name)
635644

636645
# generate an xclbin. The inputs are self.mlir_module_str and the cdo
637646
# binaries from the process_cdo step.
@@ -658,7 +667,7 @@ async def process_xclbin_gen(self):
658667
processes.append(
659668
write_file_async(
660669
json.dumps(
661-
emit_partition(self.mlir_module_str, opts.pdi_name, opts.kernel_id),
670+
emit_partition(self.mlir_module_str, opts.kernel_id),
662671
indent=2,
663672
),
664673
self.prepend_tmp("aie_partition.json"),

test/aiecc/generate_pdi.mlir

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===- generate_pdi.mlir ---------------------------------------*- MLIR -*-===//
2+
//
3+
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
// (c) Copyright 2025 Advanced Micro Devices, Inc.
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
// REQUIRES: chess
12+
// REQUIRES: peano
13+
14+
// RUN: %python aiecc.py -v --xchesscc --xbridge --aie-generate-pdi --pdi-name=MlirAie0.pdi %s | FileCheck %s --check-prefix=XCHESSCC
15+
// RUN: %python aiecc.py -v --no-xchesscc --no-xbridge --aie-generate-pdi --pdi-name=MlirAie1.pdi %s | FileCheck %s --check-prefix=PEANO
16+
17+
// RUN: ls | grep MlirAie.pdi | FileCheck %s --check-prefix=CHECK-FILE
18+
19+
// XCHESSCC: bootgen
20+
// XCHESSCC: copy{{.*}} to MlirAie0.pdi
21+
// XCHESSCC-NOT: xclbinutil
22+
23+
// PEANO: bootgen
24+
// PEANO: copy{{.*}} to MlirAie1.pdi
25+
// PEANO-NOT: xclbinutil
26+
27+
// CHECK-FILE: MlirAie0.pdi
28+
// CHECK-FILE: MlirAie1.pdi
29+
30+
module {
31+
aie.device(npu1_4col) {
32+
%12 = aie.tile(1, 2)
33+
%buf = aie.buffer(%12) : memref<256xi32>
34+
%4 = aie.core(%12) {
35+
%0 = arith.constant 0 : i32
36+
%1 = arith.constant 0 : index
37+
memref.store %0, %buf[%1] : memref<256xi32>
38+
aie.end
39+
}
40+
}
41+
}

test/npu-xrt/add_one_two_txn/run.lit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
//
66
// RUN: clang %S/test.cpp -o test.exe -std=c++11 -Wall %xrt_flags -lrt -lstdc++ %test_utils_flags
77
// RUN: %python aiecc.py --xclbin-kernel-name=ADDONE --xclbin-kernel-id=0x901 --xclbin-instance-name=ADDONEINST --no-aiesim --aie-generate-xclbin --aie-generate-npu-insts --no-compile-host --xclbin-name=add_one.xclbin --npu-insts-name=add_one_insts.txt %S/aie1.mlir
8-
// RUN: %python aiecc.py --no-aiesim --aie-generate-txn --aie-generate-npu-insts --no-compile-host --npu-insts-name=add_two_insts.txt %S/aie2.mlir
9-
// RUN: aie-translate -aie-npu-to-binary -aie-output-binary=true -aie-sequence-name=configure aie2.mlir.prj/txn.mlir -o add_two_cfg.bin
8+
// RUN: %python aiecc.py --no-aiesim --aie-generate-txn --txn-name=transaction.mlir --aie-generate-npu-insts --no-compile-host --npu-insts-name=add_two_insts.txt %S/aie2.mlir
9+
// RUN: aie-translate -aie-npu-to-binary -aie-output-binary=true -aie-sequence-name=configure transaction.mlir -o add_two_cfg.bin
1010
// RUN: %run_on_npu ./test.exe -x add_one.xclbin -i add_one_insts.txt -c add_two_cfg.bin -j add_two_insts.txt

0 commit comments

Comments
 (0)