1818from pathlib import Path
1919
2020
21- def get_elementwise_mul_artifacts (
22- base_dir ,
23- device_type ,
24- size ,
25- tile_size = 2048 ,
26- num_columns = 4 ,
27- num_channels = 2 ,
28- prefix = "eltwise_mul_" ,
29- ):
30- file_name_base = f"{ prefix } { num_columns } c_{ num_channels } ch_{ size } _{ tile_size } t"
31-
32- mlir_artifact = PythonGeneratedMLIRArtifact .new (
33- f"{ file_name_base } .mlir" ,
34- import_path = base_dir / "example" / "elementwise_mul" / "eltwise_mul.py" ,
35- callback_fn = "my_eltwise_mul" ,
36- callback_args = [
37- device_type ,
38- size ,
39- num_columns ,
40- num_channels ,
41- tile_size ,
42- 0 ,
43- ],
44- )
45-
46- xclbin_artifact = XclbinArtifact .new (
47- f"{ file_name_base } .xclbin" ,
48- depends = [
49- mlir_artifact ,
50- KernelObjectArtifact .new (
51- f"mul.o" , depends = [SourceArtifact .new ("aie_kernels/generic/mul.cc" )]
52- ),
53- ],
54- )
55-
56- insts_artifact = InstsBinArtifact .new (
57- f"{ file_name_base } .bin" , depends = [mlir_artifact ]
58- )
59-
60- return xclbin_artifact , insts_artifact
61-
62-
6321class AIEElementwiseMul (AIEOperatorBase ):
6422 """AIE-accelerated element-wise multiplication"""
6523
66- def __init__ (self , size , num_columns = None , num_channels = None , tile_size = None ):
24+ def __init__ (
25+ self ,
26+ size ,
27+ num_columns = None ,
28+ num_channels = None ,
29+ tile_size = None ,
30+ trace_size = 0 ,
31+ do_set_up = True ,
32+ ):
6733 self .size = size
6834
6935 # Enforce ShimDMA limits for elementwise_mul (uses 2 inputs per core)
@@ -80,20 +46,54 @@ def __init__(self, size, num_columns=None, num_channels=None, tile_size=None):
8046 self .num_columns = num_columns
8147 self .num_channels = num_channels
8248 self .tile_size = tile_size
49+ self .trace_size = trace_size
50+ self .do_set_up = do_set_up
8351
8452 AIEOperatorBase .__init__ (self )
8553
54+ def get_artifacts (self , prefix = "eltwise_mul_" ):
55+ file_name_base = f"{ prefix } { self .num_columns } c_{ self .num_channels } ch_{ self .size } _{ self .tile_size } t"
56+
57+ mlir_artifact = PythonGeneratedMLIRArtifact .new (
58+ f"{ file_name_base } .mlir" ,
59+ import_path = self .base_dir
60+ / "example"
61+ / "elementwise_mul"
62+ / "eltwise_mul.py" ,
63+ callback_fn = "my_eltwise_mul" ,
64+ callback_args = [
65+ self .device_manager .device_type ,
66+ self .size ,
67+ self .num_columns ,
68+ self .num_channels ,
69+ self .tile_size ,
70+ self .trace_size ,
71+ ],
72+ )
73+
74+ xclbin_artifact = XclbinArtifact .new (
75+ f"{ file_name_base } .xclbin" ,
76+ depends = [
77+ mlir_artifact ,
78+ KernelObjectArtifact .new (
79+ f"mul.o" , depends = [SourceArtifact .new ("aie_kernels/generic/mul.cc" )]
80+ ),
81+ ],
82+ )
83+
84+ insts_artifact = InstsBinArtifact .new (
85+ f"{ file_name_base } .bin" , depends = [mlir_artifact ]
86+ )
87+
88+ return xclbin_artifact , insts_artifact
89+
8690 def set_up (self ):
91+ # If this operator is only used as a sub-operator in another operator that sets it up, we should skip the setup here as those artifacts and buffers may not be needed.
92+ if not self .do_set_up :
93+ return
94+
8795 # Compilation artifacts
88- xclbin_artifact , insts_artifact = get_elementwise_mul_artifacts (
89- self .base_dir ,
90- self .device_manager .device_type ,
91- self .size ,
92- self .tile_size ,
93- self .num_columns ,
94- self .num_channels ,
95- prefix = "" ,
96- )
96+ xclbin_artifact , insts_artifact = self .get_artifacts ()
9797
9898 # Override device_type in the mlir_artifact's callback_args if needed
9999 mlir_artifact = xclbin_artifact .depends [0 ]
0 commit comments