Skip to content

Commit 548c4f3

Browse files
authored
Merge pull request #13 from amd/update-mlir-air-and-transform-scripts
Update mlir-air/aie and port annotation-based transform scripts
2 parents 918dc04 + a9aeca2 commit 548c4f3

14 files changed

Lines changed: 1020 additions & 1035 deletions

File tree

amd_triton_npu/backend/driver.py

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -228,38 +228,28 @@ def _get_transform_ir_string():
228228
elemwise_tiling_size_l1_n = 32
229229

230230
return f"""
231-
transform.with_pdl_patterns {{
232-
^bb0(%arg0: !pdl.operation):
233-
transform.sequence %arg0 : !pdl.operation failures(propagate) {{
234-
^bb1(%arg1: !pdl.operation):
235-
%mul = transform.structured.match ops{{["linalg.mul"]}} in %arg1 : (!pdl.operation) -> !pdl.operation
236-
transform.sequence %mul : !pdl.operation failures(propagate) {{
237-
^bb2(%arg2: !pdl.operation):
238-
%mul_1, %loop = transform.air.linalg_tile %arg2 [{elemwise_tiling_size_l1_m}, {elemwise_tiling_size_l1_n}]
239-
transform.air.linalg_promote %mul_1 {{"operands_to_promote"=[2], "memory_space"="L1"}}
240-
transform.air.linalg_promote %mul_1 {{"operands_to_promote"=[0,1], "memory_space"="L1"}}
241-
242-
}}
243-
%add = transform.structured.match ops{{["linalg.add"]}} in %arg1 : (!pdl.operation) -> !pdl.operation
244-
transform.sequence %add : !pdl.operation failures(propagate) {{
245-
^bb2(%arg2: !pdl.operation):
246-
%add_1, %loop = transform.air.linalg_tile %arg2 [{elemwise_tiling_size_l1_m}, {elemwise_tiling_size_l1_n}]
247-
transform.air.linalg_promote %add_1 {{"operands_to_promote"=[2], "memory_space"="L1"}}
248-
transform.air.linalg_promote %add_1 {{"operands_to_promote"=[0,1], "memory_space"="L1"}}
249-
250-
}}
251-
%matmul = transform.structured.match ops{{["linalg.matmul"]}} in %arg1 : (!pdl.operation) -> !pdl.operation
252-
transform.sequence %matmul : !pdl.operation failures(propagate) {{
253-
^bb2(%arg2: !pdl.operation):
254-
%fill = transform.structured.match ops{{["linalg.fill"]}} in %arg1 : (!pdl.operation) -> !pdl.operation
255-
%matmul_1, %loop = transform.air.linalg_tile %arg2 [{matmul_tiling_size_l1_m}, {matmul_tiling_size_l1_n}]
256-
%fill_1 = transform.air.fuse_into_containing_op %fill into %loop
257-
transform.air.linalg_promote %fill_1 {{"operands_to_promote"=[1], "memory_space"="L1"}}
258-
transform.air.linalg_promote %matmul_1 {{"operands_to_promote"=[2], "memory_space"="L1"}}
259-
%matmul_2, %reduction_loop = transform.air.linalg_tile %matmul_1 [0, 0, {matmul_tiling_size_l1_k}]
260-
transform.air.linalg_promote %matmul_2 {{"operands_to_promote"=[0,1], "memory_space"="L1"}}
261-
}}
262-
}}
231+
module attributes {{transform.with_named_sequence}} {{
232+
transform.named_sequence @__transform_main(%arg1: !transform.any_op {{transform.readonly}}) {{
233+
%mul = transform.structured.match ops{{["linalg.mul"]}} in %arg1 : (!transform.any_op) -> !transform.any_op
234+
%mul_1, %loop = transform.air.linalg_tile %mul [{elemwise_tiling_size_l1_m}, {elemwise_tiling_size_l1_n}]
235+
transform.air.linalg_promote %mul_1 {{"operands_to_promote"=[2], "memory_space"="L1"}}
236+
transform.air.linalg_promote %mul_1 {{"operands_to_promote"=[0,1], "memory_space"="L1"}}
237+
238+
%add = transform.structured.match ops{{["linalg.add"]}} in %arg1 : (!transform.any_op) -> !transform.any_op
239+
%add_1, %add_loop = transform.air.linalg_tile %add [{elemwise_tiling_size_l1_m}, {elemwise_tiling_size_l1_n}]
240+
transform.air.linalg_promote %add_1 {{"operands_to_promote"=[2], "memory_space"="L1"}}
241+
transform.air.linalg_promote %add_1 {{"operands_to_promote"=[0,1], "memory_space"="L1"}}
242+
243+
%matmul = transform.structured.match ops{{["linalg.matmul"]}} in %arg1 : (!transform.any_op) -> !transform.any_op
244+
%fill = transform.structured.match ops{{["linalg.fill"]}} in %arg1 : (!transform.any_op) -> !transform.any_op
245+
%matmul_1, %matmul_loop = transform.air.linalg_tile %matmul [{matmul_tiling_size_l1_m}, {matmul_tiling_size_l1_n}]
246+
%fill_1 = transform.air.fuse_into_containing_op %fill into %matmul_loop
247+
transform.air.linalg_promote %fill_1 {{"operands_to_promote"=[1], "memory_space"="L1"}}
248+
transform.air.linalg_promote %matmul_1 {{"operands_to_promote"=[2], "memory_space"="L1"}}
249+
%matmul_2, %reduction_loop = transform.air.linalg_tile %matmul_1 [0, 0, {matmul_tiling_size_l1_k}]
250+
transform.air.linalg_promote %matmul_2 {{"operands_to_promote"=[0,1], "memory_space"="L1"}}
251+
transform.yield
252+
}}
263253
}}
264254
"""
265255

0 commit comments

Comments
 (0)