Skip to content

[mlir][Interfaces][NFC] Add TableGen test op for value bounds tests #88717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func.func @composed_affine_apply(%i1 : index) -> (index) {
%i2 = affine.apply affine_map<(d0) -> ((d0 floordiv 32) * 16)>(%i1)
%i3 = affine.apply affine_map<(d0) -> ((d0 floordiv 32) * 16 + 8)>(%i1)
%s = affine.apply affine_map<()[s0, s1] -> (s0 - s1)>()[%i2, %i3]
%reified = "test.reify_constant_bound"(%s) {type = "EQ"} : (index) -> (index)
%reified = "test.reify_bound"(%s) {type = "EQ", constant} : (index) -> (index)
return %reified : index
}

Expand Down
6 changes: 3 additions & 3 deletions mlir/test/Dialect/Affine/value-bounds-reification.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func.func @reify_slice_bound(%t: tensor<?x?xi32>, %idx: index, %ub: index, %f: f
%bound = "test.reify_bound"(%filled) {dim = 1, type = "UB"} : (tensor<1x?xi32>) -> (index)
"test.some_use"(%bound) : (index) -> ()

%bound_const = "test.reify_constant_bound"(%filled) {dim = 1, type = "UB"} : (tensor<1x?xi32>) -> (index)
%bound_const = "test.reify_bound"(%filled) {dim = 1, type = "UB", constant} : (tensor<1x?xi32>) -> (index)
"test.some_use"(%bound_const) : (index) -> ()
}
return
Expand Down Expand Up @@ -93,7 +93,7 @@ func.func @reify_slice_bound2(%lb0: index, %ub0: index, %step0: index,

// CHECK: %[[c129:.*]] = arith.constant 129 : index
// CHECK: "test.some_use"(%[[c129]])
%lb1_ub_const = "test.reify_constant_bound"(%lb1) {type = "UB"} : (index) -> (index)
%lb1_ub_const = "test.reify_bound"(%lb1) {type = "UB", constant} : (index) -> (index)
"test.some_use"(%lb1_ub_const) : (index) -> ()

scf.for %iv1 = %lb1 to %ub1 step %c32 {
Expand All @@ -116,7 +116,7 @@ func.func @reify_slice_bound2(%lb0: index, %ub0: index, %step0: index,

// CHECK: %[[c32:.*]] = arith.constant 32 : index
// CHECK: "test.some_use"(%[[c32]])
%matmul_ub_const = "test.reify_constant_bound"(%matmul) {dim = 1, type = "UB"} : (tensor<1x?xi32>) -> (index)
%matmul_ub_const = "test.reify_bound"(%matmul) {dim = 1, type = "UB", constant} : (tensor<1x?xi32>) -> (index)
"test.some_use"(%matmul_ub_const) : (index) -> ()
}
}
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Dialect/Tensor/value-bounds-op-interface-impl.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func.func @extract_slice_static(%t: tensor<?xf32>) -> index {
func.func @extract_slice_dynamic_constant(%t: tensor<?xf32>, %sz: index) -> index {
%0 = tensor.extract_slice %t[2][%sz][1] : tensor<?xf32> to tensor<?xf32>
// expected-error @below{{could not reify bound}}
%1 = "test.reify_constant_bound"(%0) {dim = 0} : (tensor<?xf32>) -> (index)
%1 = "test.reify_bound"(%0) {dim = 0, constant} : (tensor<?xf32>) -> (index)
return %1 : index
}

Expand All @@ -95,7 +95,7 @@ func.func @extract_slice_dynamic_constant(%t: tensor<?xf32>, %sz: index) -> inde
// CHECK: return %[[c5]]
func.func @extract_slice_static_constant(%t: tensor<?xf32>) -> index {
%0 = tensor.extract_slice %t[2][5][1] : tensor<?xf32> to tensor<5xf32>
%1 = "test.reify_constant_bound"(%0) {dim = 0} : (tensor<5xf32>) -> (index)
%1 = "test.reify_bound"(%0) {dim = 0, constant} : (tensor<5xf32>) -> (index)
return %1 : index
}

Expand Down
18 changes: 9 additions & 9 deletions mlir/test/Dialect/Vector/test-scalable-bounds.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func.func @fixed_size_loop_nest() {
%min_i = affine.min #map_dim_i(%i)[%c4_vscale]
scf.for %j = %c0 to %c16 step %c4_vscale {
%min_j = affine.min #map_dim_j(%j)[%c4_vscale]
%bound_i = "test.reify_scalable_bound"(%min_i) {type = "UB", vscale_min = 1, vscale_max = 16} : (index) -> index
%bound_j = "test.reify_scalable_bound"(%min_j) {type = "UB", vscale_min = 1, vscale_max = 16} : (index) -> index
%bound_i = "test.reify_bound"(%min_i) {type = "UB", vscale_min = 1, vscale_max = 16, scalable} : (index) -> index
%bound_j = "test.reify_bound"(%min_j) {type = "UB", vscale_min = 1, vscale_max = 16, scalable} : (index) -> index
"test.some_use"(%bound_i, %bound_j) : (index, index) -> ()
}
}
Expand Down Expand Up @@ -58,8 +58,8 @@ func.func @dynamic_size_loop_nest(%dim0: index, %dim1: index) {
%min_i = affine.min #map_dynamic_dim(%i)[%c4_vscale, %dim0]
scf.for %j = %c0 to %dim1 step %c4_vscale {
%min_j = affine.min #map_dynamic_dim(%j)[%c4_vscale, %dim1]
%bound_i = "test.reify_scalable_bound"(%min_i) {type = "UB", vscale_min = 1, vscale_max = 16} : (index) -> index
%bound_j = "test.reify_scalable_bound"(%min_j) {type = "UB", vscale_min = 1, vscale_max = 16} : (index) -> index
%bound_i = "test.reify_bound"(%min_i) {type = "UB", vscale_min = 1, vscale_max = 16, scalable} : (index) -> index
%bound_j = "test.reify_bound"(%min_j) {type = "UB", vscale_min = 1, vscale_max = 16, scalable} : (index) -> index
"test.some_use"(%bound_i, %bound_j) : (index, index) -> ()
}
}
Expand All @@ -80,7 +80,7 @@ func.func @add_to_vscale() {
%vscale = vector.vscale
%c8 = arith.constant 8 : index
%vscale_plus_c8 = arith.addi %vscale, %c8 : index
%bound = "test.reify_scalable_bound"(%vscale_plus_c8) {type = "EQ", vscale_min = 1, vscale_max = 16} : (index) -> index
%bound = "test.reify_bound"(%vscale_plus_c8) {type = "EQ", vscale_min = 1, vscale_max = 16, scalable} : (index) -> index
"test.some_use"(%bound) : (index) -> ()
return
}
Expand All @@ -94,7 +94,7 @@ func.func @add_to_vscale() {
// CHECK: "test.some_use"(%[[C2]]) : (index) -> ()
func.func @vscale_fixed_size() {
%vscale = vector.vscale
%bound = "test.reify_scalable_bound"(%vscale) {type = "EQ", vscale_min = 2, vscale_max = 2} : (index) -> index
%bound = "test.reify_bound"(%vscale) {type = "EQ", vscale_min = 2, vscale_max = 2, scalable} : (index) -> index
"test.some_use"(%bound) : (index) -> ()
return
}
Expand All @@ -107,7 +107,7 @@ func.func @unknown_bound(%a: index) {
%vscale = vector.vscale
%vscale_plus_a = arith.muli %vscale, %a : index
// expected-error @below{{could not reify bound}}
%bound = "test.reify_scalable_bound"(%vscale_plus_a) {type = "UB", vscale_min = 1, vscale_max = 16} : (index) -> index
%bound = "test.reify_bound"(%vscale_plus_a) {type = "UB", vscale_min = 1, vscale_max = 16, scalable} : (index) -> index
"test.some_use"(%bound) : (index) -> ()
return
}
Expand All @@ -134,7 +134,7 @@ func.func @duplicate_vscale_values() {
%c2_vscale = arith.muli %vscale_1, %c2 : index
%add = arith.addi %c2_vscale, %c4_vscale : index

%bound = "test.reify_scalable_bound"(%add) {type = "EQ", vscale_min = 1, vscale_max = 16} : (index) -> index
%bound = "test.reify_bound"(%add) {type = "EQ", vscale_min = 1, vscale_max = 16, scalable} : (index) -> index
"test.some_use"(%bound) : (index) -> ()
return
}
Expand All @@ -154,7 +154,7 @@ func.func @non_scalable_code() {
%c0 = arith.constant 0 : index
scf.for %i = %c0 to %c1024 step %c4 {
%min_i = affine.min #map_dim_i(%i)[%c4]
%bound_i = "test.reify_scalable_bound"(%min_i) {type = "UB", vscale_min = 1, vscale_max = 16} : (index) -> index
%bound_i = "test.reify_bound"(%min_i) {type = "UB", vscale_min = 1, vscale_max = 16, scalable} : (index) -> index
"test.some_use"(%bound_i) : (index) -> ()
}
return
Expand Down
8 changes: 8 additions & 0 deletions mlir/test/lib/Dialect/Affine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@ add_mlir_library(MLIRAffineTransformsTestPasses
MLIRSupport
MLIRMemRefDialect
MLIRTensorDialect
MLIRTestDialect
MLIRVectorUtils
)

target_include_directories(MLIRAffineTransformsTestPasses
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../Test
${CMAKE_CURRENT_BINARY_DIR}/../Test
)

Loading