forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check tests for more tensor dialect ops. (iree-org#17726)
Partial follow-up to iree-org#17696 (comment). The `concat` tests exercises `__builtin_splat_i64` (incidentally, and the tests are mostly folded away if `util.optimization_barrier` is omitted). That PR addressed a bug in `__builtin_fill_i64`. To reliably test those builtins directly, we'll probably need to add other tests that start after stream. Docs: https://mlir.llvm.org/docs/Dialects/TensorOps/ --------- Signed-off-by: Scott Todd <[email protected]>
- Loading branch information
Showing
6 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
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
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
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,15 @@ | ||
func.func @collapse_shape_i32() { | ||
%1 = arith.constant dense<[[1, 2, 3, 4]]> : tensor<1x4xi32> | ||
%2 = util.optimization_barrier %1 : tensor<1x4xi32> | ||
%collapsed = tensor.collapse_shape %2 [[0, 1]] : tensor<1x4xi32> into tensor<4xi32> | ||
check.expect_eq_const(%collapsed, dense<[1,2,3,4]> : tensor<4xi32>) : tensor<4xi32> | ||
return | ||
} | ||
|
||
func.func @collapse_shape_i64() { | ||
%1 = arith.constant dense<[[1, 2, 3, 4]]> : tensor<1x4xi64> | ||
%2 = util.optimization_barrier %1 : tensor<1x4xi64> | ||
%collapsed = tensor.collapse_shape %2 [[0, 1]] : tensor<1x4xi64> into tensor<4xi64> | ||
check.expect_eq_const(%collapsed, dense<[1,2,3,4]> : tensor<4xi64>) : tensor<4xi64> | ||
return | ||
} |
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,59 @@ | ||
func.func @concat_i8_static_dim0() { | ||
%cst_1 = arith.constant dense<1> : tensor<1xi8> | ||
%cst_2 = arith.constant dense<2> : tensor<1xi8> | ||
%1 = util.optimization_barrier %cst_1 : tensor<1xi8> | ||
%2 = util.optimization_barrier %cst_2 : tensor<1xi8> | ||
%concat = tensor.concat dim(0) %1, %2 : (tensor<1xi8>, tensor<1xi8>) -> tensor<2xi8> | ||
check.expect_eq_const(%concat, dense<[1,2]> : tensor<2xi8>) : tensor<2xi8> | ||
return | ||
} | ||
|
||
func.func @concat_i16_static_dim0() { | ||
%cst_1 = arith.constant dense<1> : tensor<1xi16> | ||
%cst_2 = arith.constant dense<2> : tensor<1xi16> | ||
%1 = util.optimization_barrier %cst_1 : tensor<1xi16> | ||
%2 = util.optimization_barrier %cst_2 : tensor<1xi16> | ||
%concat = tensor.concat dim(0) %1, %2 : (tensor<1xi16>, tensor<1xi16>) -> tensor<2xi16> | ||
check.expect_eq_const(%concat, dense<[1,2]> : tensor<2xi16>) : tensor<2xi16> | ||
return | ||
} | ||
|
||
func.func @concat_i32_static_dim0() { | ||
%cst_1 = arith.constant dense<1> : tensor<1xi32> | ||
%cst_2 = arith.constant dense<2> : tensor<1xi32> | ||
%1 = util.optimization_barrier %cst_1 : tensor<1xi32> | ||
%2 = util.optimization_barrier %cst_2 : tensor<1xi32> | ||
%concat = tensor.concat dim(0) %1, %2 : (tensor<1xi32>, tensor<1xi32>) -> tensor<2xi32> | ||
check.expect_eq_const(%concat, dense<[1,2]> : tensor<2xi32>) : tensor<2xi32> | ||
return | ||
} | ||
|
||
func.func @concat_i64_static_dim0() { | ||
%cst_1 = arith.constant dense<1> : tensor<1xi64> | ||
%cst_2 = arith.constant dense<2> : tensor<1xi64> | ||
%1 = util.optimization_barrier %cst_1 : tensor<1xi64> | ||
%2 = util.optimization_barrier %cst_2 : tensor<1xi64> | ||
%concat = tensor.concat dim(0) %1, %2 : (tensor<1xi64>, tensor<1xi64>) -> tensor<2xi64> | ||
check.expect_eq_const(%concat, dense<[1,2]> : tensor<2xi64>) : tensor<2xi64> | ||
return | ||
} | ||
|
||
func.func @concat_f32_static_dim0() { | ||
%cst_1 = arith.constant dense<1.0> : tensor<1xf32> | ||
%cst_2 = arith.constant dense<2.0> : tensor<1xf32> | ||
%1 = util.optimization_barrier %cst_1 : tensor<1xf32> | ||
%2 = util.optimization_barrier %cst_2 : tensor<1xf32> | ||
%concat = tensor.concat dim(0) %1, %2 : (tensor<1xf32>, tensor<1xf32>) -> tensor<2xf32> | ||
check.expect_almost_eq_const(%concat, dense<[1.0,2.0]> : tensor<2xf32>) : tensor<2xf32> | ||
return | ||
} | ||
|
||
func.func @concat_i32_dim1() { | ||
%lhs = arith.constant dense<[[1,2,3],[-1,-2,-3]]> : tensor<2x3xi32> | ||
%rhs = arith.constant dense<[[4,5,6,7,8],[-4,-5,-6,-7,-8]]> : tensor<2x5xi32> | ||
%lhs_barrier = util.optimization_barrier %lhs : tensor<2x3xi32> | ||
%rhs_barrier = util.optimization_barrier %rhs : tensor<2x5xi32> | ||
%concat = tensor.concat dim(1) %lhs_barrier, %rhs_barrier : (tensor<2x3xi32>, tensor<2x5xi32>) -> tensor<2x8xi32> | ||
check.expect_eq_const(%concat, dense<[[1,2,3,4,5,6,7,8],[-1,-2,-3,-4,-5,-6,-7,-8]]> : tensor<2x8xi32>) : tensor<2x8xi32> | ||
return | ||
} |
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,15 @@ | ||
func.func @expand_shape_i32() { | ||
%1 = arith.constant dense<[1, 2, 3, 4]> : tensor<4xi32> | ||
%2 = util.optimization_barrier %1 : tensor<4xi32> | ||
%expanded = tensor.expand_shape %2 [[0, 1]] output_shape [1, 4] : tensor<4xi32> into tensor<1x4xi32> | ||
check.expect_eq_const(%expanded, dense<[[1,2,3,4]]> : tensor<1x4xi32>) : tensor<1x4xi32> | ||
return | ||
} | ||
|
||
func.func @expand_shape_i64() { | ||
%1 = arith.constant dense<[1, 2, 3, 4]> : tensor<4xi64> | ||
%2 = util.optimization_barrier %1 : tensor<4xi64> | ||
%expanded = tensor.expand_shape %2 [[0, 1]] output_shape [1, 4] : tensor<4xi64> into tensor<1x4xi64> | ||
check.expect_eq_const(%expanded, dense<[[1,2,3,4]]> : tensor<1x4xi64>) : tensor<1x4xi64> | ||
return | ||
} |
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