-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dialects: Add lowering pass to convert snitch-runtime to external fun…
…c.funcs (#1085) This commit request does two things: * it introduces a lowering pass that lowers all snrt runtime operations, to a currently present to func.func, with an accompanying external function call for use with mlir-opt and clang -x ir. (interop tests with mlir-opt and clang are not included). * It slightly refactors snitch runtime with the recently introduced generics to reduce code size (1D and 2D DMA operations now have their own base classes for both regular and `wideptr` variants).
- Loading branch information
1 parent
1c22562
commit 98f75ff
Showing
5 changed files
with
260 additions
and
95 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
tests/filecheck/dialects/snitch_runtime/lower_snrt_to_func.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// RUN: xdsl-opt -p lower-snrt-to-func %s | filecheck %s | ||
"builtin.module"() ({ | ||
"func.func"() ({ | ||
// Runtime Info Getters | ||
%cluster_num = "snrt.cluster_num"() : () -> i32 | ||
// CHECK: %cluster_num = "func.call"() {"callee" = @snrt_cluster_num} : () -> i32 | ||
|
||
// Barriers | ||
"snrt.cluster_hw_barrier"() : () -> () | ||
// CHECK: "func.call"() {"callee" = @snrt_cluster_hw_barrier} : () -> () | ||
// DMA functions | ||
"snrt.dma_wait_all"() : () -> () | ||
// CHECK: "func.call"() {"callee" = @snrt_dma_wait_all} : () -> () | ||
|
||
%dst_64 = "arith.constant"() {"value" = 100 : i64} : () -> i64 | ||
%src_64 = "arith.constant"() {"value" = 0 : i64} : () -> i64 | ||
%size = "arith.constant"() {"value" = 100 : index} : () -> index | ||
%transfer_id = "snrt.dma_start_1d_wideptr"(%dst_64, %src_64, %size) : (i64, i64, index) -> i32 | ||
// CHECK: %transfer_id = "func.call"(%dst_64, %src_64, %size) {"callee" = @snrt_dma_start_1d_wideptr} : (i64, i64, index) -> i32 | ||
|
||
%dst_32 = "arith.constant"() {"value" = 100: i32} : () -> i32 | ||
%src_32 = "arith.constant"() {"value" = 0: i32} : () -> i32 | ||
%size_2 = "arith.constant"() {"value" = 100: index} : () -> index | ||
%transfer_id_2 = "snrt.dma_start_1d"(%dst_32, %src_32, %size_2) : (i32, i32, index) -> i32 | ||
// CHECK: %transfer_id_2 = "func.call"(%dst_32, %src_32, %size_2) {"callee" = @snrt_dma_start_1d} : (i32, i32, index) -> i32 | ||
%repeat = "arith.constant"() {"value" = 1: index} : () -> index | ||
%src_stride = "arith.constant"() {"value" = 1: index} : () -> index | ||
%dst_stride = "arith.constant"() {"value" = 1: index} : () -> index | ||
%transfer_id_3 = "snrt.dma_start_2d_wideptr"(%dst_64, %src_64, %dst_stride, %src_stride, %size_2, %repeat) : (i64, i64, index, index, index, index) -> i32 | ||
// CHECK: %transfer_id_3 = "func.call"(%dst_64, %src_64, %dst_stride, %src_stride, %size_2, %repeat) {"callee" = @snrt_dma_start_2d_wideptr} : (i64, i64, index, index, index, index) -> i32 | ||
%transfer_id_4 = "snrt.dma_start_2d"(%dst_32, %src_32, %dst_stride, %src_stride, %size_2, %repeat) : (i32, i32, index, index, index, index) -> i32 | ||
// CHECK: %transfer_id_4 = "func.call"(%dst_32, %src_32, %dst_stride, %src_stride, %size_2, %repeat) {"callee" = @snrt_dma_start_2d} : (i32, i32, index, index, index, index) -> i32 | ||
"func.return"() : () -> () | ||
}) {"sym_name" = "main", "function_type" = () -> (), "sym_visibility" = "private"} : () -> () | ||
// CHECK: func.func private @snrt_cluster_num() -> i32 | ||
// CHECK: func.func private @snrt_cluster_hw_barrier() -> () | ||
// CHECK: func.func private @snrt_dma_wait_all() -> () | ||
// CHECK: func.func private @snrt_dma_start_1d_wideptr(i64, i64, index) -> i32 | ||
// CHECK: func.func private @snrt_dma_start_1d(i32, i32, index) -> i32 | ||
// CHECK: func.func private @snrt_dma_start_2d_wideptr(i64, i64, index, index, index, index) -> i32 | ||
// CHECK: func.func private @snrt_dma_start_2d(i32, i32, index, index, index, index) -> i32 | ||
}) : () -> () |
60 changes: 31 additions & 29 deletions
60
tests/filecheck/dialects/snitch_runtime/snitch_runtime_ops.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,36 @@ | ||
// RUN: xdsl-opt %s | xdsl-opt --print-op-generic | filecheck %s | ||
"builtin.module"() ({ | ||
// Barriers | ||
"snrt.cluster_hw_barrier"() : () -> () | ||
// CHECK: "snrt.cluster_hw_barrier"() : () -> () | ||
"func.func"() ({ | ||
// Barriers | ||
"snrt.cluster_hw_barrier"() : () -> () | ||
// CHECK: "snrt.cluster_hw_barrier"() : () -> () | ||
|
||
// Runtime Info Getters | ||
%cluster_num = "snrt.cluster_num"() : () -> ui32 | ||
// CHECK: %{{.*}} = "snrt.cluster_num"() : () -> ui32 | ||
|
||
// DMA Operations | ||
%dst_64 = "arith.constant"() {"value" = 100 : ui64} : () -> ui64 | ||
%src_64 = "arith.constant"() {"value" = 0 : ui64} : () -> ui64 | ||
%size = "arith.constant"() {"value" = 100 : index} : () -> index | ||
%transfer_id = "snrt.dma_start_1d_wideptr"(%dst_64, %src_64, %size) : (ui64, ui64, index) -> ui32 | ||
// CHECK: %transfer_id = "snrt.dma_start_1d_wideptr"(%dst_64, %src_64, %size) : (ui64, ui64, index) -> ui32 | ||
%dst_32 = "arith.constant"() {"value" = 100: ui32} : () -> ui32 | ||
%src_32 = "arith.constant"() {"value" = 0: ui32} : () -> ui32 | ||
%size_2 = "arith.constant"() {"value" = 100: index} : () -> index | ||
%transfer_id_2 = "snrt.dma_start_1d"(%dst_32, %src_32, %size_2) : (ui32, ui32, index) -> ui32 | ||
// CHECK: %transfer_id_2 = "snrt.dma_start_1d"(%dst_32, %src_32, %size_2) : (ui32, ui32, index) -> ui32 | ||
"snrt.dma_wait"(%transfer_id) : (ui32) -> () | ||
// CHECK: "snrt.dma_wait"(%transfer_id) : (ui32) -> () | ||
%repeat = "arith.constant"() {"value" = 1: index} : () -> index | ||
%src_stride = "arith.constant"() {"value" = 1: index} : () -> index | ||
%dst_stride = "arith.constant"() {"value" = 1: index} : () -> index | ||
%transfer_id_3 = "snrt.dma_start_2d_wideptr"(%dst_64, %src_64, %dst_stride, %src_stride, %size, %repeat) : (ui64, ui64, index, index, index, index) -> ui32 | ||
// CHECK: transfer_id_3 = "snrt.dma_start_2d_wideptr"(%dst_64, %src_64, %dst_stride, %src_stride, %size, %repeat) : (ui64, ui64, index, index, index, index) -> ui32 | ||
%transfer_id_4 = "snrt.dma_start_2d"(%dst_32, %src_32, %dst_stride, %src_stride, %size_2, %repeat) : (ui32, ui32, index, index, index, index) -> ui32 | ||
// CHECK: transfer_id_4 = "snrt.dma_start_2d"(%dst_32, %src_32, %dst_stride, %src_stride, %size_2, %repeat) : (ui32, ui32, index, index, index, index) -> ui32 | ||
"snrt.dma_wait_all"() : () -> () | ||
// CHECK: "snrt.dma_wait_all"() : () -> () | ||
// Runtime Info Getters | ||
%cluster_num = "snrt.cluster_num"() : () -> i32 | ||
// CHECK: %{{.*}} = "snrt.cluster_num"() : () -> i32 | ||
|
||
// DMA Operations | ||
%dst_64 = "arith.constant"() {"value" = 100 : i64} : () -> i64 | ||
%src_64 = "arith.constant"() {"value" = 0 : i64} : () -> i64 | ||
%size = "arith.constant"() {"value" = 100 : index} : () -> index | ||
%transfer_id = "snrt.dma_start_1d_wideptr"(%dst_64, %src_64, %size) : (i64, i64, index) -> i32 | ||
// CHECK: %transfer_id = "snrt.dma_start_1d_wideptr"(%dst_64, %src_64, %size) : (i64, i64, index) -> i32 | ||
%dst_32 = "arith.constant"() {"value" = 100: i32} : () -> i32 | ||
%src_32 = "arith.constant"() {"value" = 0: i32} : () -> i32 | ||
%size_2 = "arith.constant"() {"value" = 100: index} : () -> index | ||
%transfer_id_2 = "snrt.dma_start_1d"(%dst_32, %src_32, %size_2) : (i32, i32, index) -> i32 | ||
// CHECK: %transfer_id_2 = "snrt.dma_start_1d"(%dst_32, %src_32, %size_2) : (i32, i32, index) -> i32 | ||
"snrt.dma_wait"(%transfer_id) : (i32) -> () | ||
// CHECK: "snrt.dma_wait"(%transfer_id) : (i32) -> () | ||
%repeat = "arith.constant"() {"value" = 1: index} : () -> index | ||
%src_stride = "arith.constant"() {"value" = 1: index} : () -> index | ||
%dst_stride = "arith.constant"() {"value" = 1: index} : () -> index | ||
%transfer_id_3 = "snrt.dma_start_2d_wideptr"(%dst_64, %src_64, %dst_stride, %src_stride, %size, %repeat) : (i64, i64, index, index, index, index) -> i32 | ||
// CHECK: transfer_id_3 = "snrt.dma_start_2d_wideptr"(%dst_64, %src_64, %dst_stride, %src_stride, %size, %repeat) : (i64, i64, index, index, index, index) -> i32 | ||
%transfer_id_4 = "snrt.dma_start_2d"(%dst_32, %src_32, %dst_stride, %src_stride, %size_2, %repeat) : (i32, i32, index, index, index, index) -> i32 | ||
// CHECK: transfer_id_4 = "snrt.dma_start_2d"(%dst_32, %src_32, %dst_stride, %src_stride, %size_2, %repeat) : (i32, i32, index, index, index, index) -> i32 | ||
"snrt.dma_wait_all"() : () -> () | ||
// CHECK: "snrt.dma_wait_all"() : () -> () | ||
"func.return"() : () -> () | ||
}) {"sym_name" = "main", "function_type" = () -> (), "sym_visibility" = "private"} : () -> () | ||
}) : () -> () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.