31
31
import aie .compiler .aiecc .cl_arguments
32
32
import aie .compiler .aiecc .configure
33
33
from aie .dialects import aie as aiedialect
34
+ from aie .dialects import aiex as aiexdialect
34
35
from aie .ir import Context , Location , Module
35
36
from aie .passmanager import PassManager
36
37
@@ -614,7 +615,9 @@ async def process_txn(self, module_str):
614
615
print (f"copy { tmp } to { opts .txn_name } " )
615
616
shutil .copy (tmp , opts .txn_name )
616
617
617
- async def aiebu_asm (self , input_file , output_file , ctrl_packet_file = None ):
618
+ async def aiebu_asm (
619
+ self , input_file , output_file , ctrl_packet_file = None , ctrl_packet_idx = 0
620
+ ):
618
621
619
622
# find aiebu-asm binary
620
623
asm_bin = "aiebu-asm"
@@ -645,7 +648,7 @@ async def aiebu_asm(self, input_file, output_file, ctrl_packet_file=None):
645
648
exteral_buffers_json = {
646
649
"external_buffers" : {
647
650
"buffer_ctrl" : {
648
- "xrt_id" : 0 ,
651
+ "xrt_id" : ctrl_packet_idx ,
649
652
"logical_id" : - 1 ,
650
653
"size_in_bytes" : ctrl_packet_size ,
651
654
"ctrl_pkt_buffer" : 1 ,
@@ -665,43 +668,53 @@ async def aiebu_asm(self, input_file, output_file, ctrl_packet_file=None):
665
668
await self .do_call (None , args )
666
669
667
670
async def process_ctrlpkt (self , module_str ):
668
- with Context (), Location .unknown ():
669
- run_passes (
670
- "builtin.module(aie.device(convert-aie-to-control-packets{elf-dir="
671
- + self .tmpdirname
672
- + "}))" ,
673
- module_str ,
671
+ run_passes (
672
+ "builtin.module(aie.device(convert-aie-to-control-packets{elf-dir="
673
+ + self .tmpdirname
674
+ + "}))" ,
675
+ module_str ,
676
+ self .prepend_tmp ("ctrlpkt.mlir" ),
677
+ self .opts .verbose ,
678
+ )
679
+ await self .do_call (
680
+ None ,
681
+ [
682
+ "aie-translate" ,
683
+ "-aie-ctrlpkt-to-bin" ,
674
684
self .prepend_tmp ("ctrlpkt.mlir" ),
675
- self . opts . verbose ,
676
- )
677
- await self . do_call (
678
- None ,
679
- [
680
- "aie-translate" ,
681
- "- aie-ctrlpkt -to-bin " ,
682
- self . prepend_tmp ( "ctrlpkt.mlir" ) ,
683
- "-o" ,
684
- "ctrlpkt.bin" ,
685
- ],
686
- )
687
- ctrlpkt_mlir_str = await read_file_async ( self . prepend_tmp ( "ctrlpkt.mlir" ))
688
- run_passes (
689
- "builtin.module( aie.device(aie-ctrl-packet-to-dma,aie-dma-to-npu)) " ,
690
- ctrlpkt_mlir_str ,
685
+ "-o" ,
686
+ "ctrlpkt.bin" ,
687
+ ],
688
+ )
689
+ ctrlpkt_mlir_str = await read_file_async ( self . prepend_tmp ( "ctrlpkt.mlir" ))
690
+ run_passes (
691
+ "builtin.module(aie.device(aie-ctrl-packet-to-dma, aie-dma -to-npu)) " ,
692
+ ctrlpkt_mlir_str ,
693
+ self . prepend_tmp ( "ctrlpkt_dma_seq.mlir" ) ,
694
+ self . opts . verbose ,
695
+ )
696
+ await self . do_call (
697
+ None ,
698
+ [
699
+ "aie-translate " ,
700
+ "-aie-npu-to-binary" ,
691
701
self .prepend_tmp ("ctrlpkt_dma_seq.mlir" ),
692
- self .opts .verbose ,
693
- )
694
- await self .do_call (
695
- None ,
696
- [
697
- "aie-translate" ,
698
- "-aie-npu-to-binary" ,
699
- self .prepend_tmp ("ctrlpkt_dma_seq.mlir" ),
700
- "-o" ,
701
- opts .insts_name ,
702
- ],
702
+ "-o" ,
703
+ opts .insts_name ,
704
+ ],
705
+ )
706
+ ctrl_idx = 0
707
+ ctrl_seq_str = await read_file_async (self .prepend_tmp ("ctrlpkt_dma_seq.mlir" ))
708
+ with Context (), Location .unknown ():
709
+ dma_seq_module = Module .parse (ctrl_seq_str )
710
+ # walk through the dma sequence module to find runtime sequence
711
+ seqs = find_ops (
712
+ dma_seq_module .operation ,
713
+ lambda o : isinstance (o .operation .opview , aiexdialect .RuntimeSequenceOp ),
703
714
)
704
- await self .aiebu_asm (opts .insts_name , opts .elf_name , "ctrlpkt.bin" )
715
+ if seqs :
716
+ ctrl_idx = len (seqs [0 ].regions [0 ].blocks [0 ].arguments .types ) - 1
717
+ await self .aiebu_asm (opts .insts_name , opts .elf_name , "ctrlpkt.bin" , ctrl_idx )
705
718
706
719
async def process_elf (self , module_str ):
707
720
with Context (), Location .unknown ():
0 commit comments