Skip to content

[mlir][tensor] Add tests to invalid.mlir (nfc) #112759

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

Conversation

banach-space
Copy link
Contributor

@banach-space banach-space commented Oct 17, 2024

Adds two test with invalid usage of tensor.extract_slice that were
missing. Also moves one other test for tensor.extract_slice, so that
all tests for this Op are clustered together.

Note, this PR merely documents the current behaviour. No new
functionality is added.

Adds two test with invalid usage of `tensor.extract_slice` that were
missing. Also moves one other test for `tensor.extract_slice`, so that
all tests for this Op are clustered together.
@llvmbot
Copy link
Member

llvmbot commented Oct 17, 2024

@llvm/pr-subscribers-mlir-tensor

Author: Andrzej Warzyński (banach-space)

Changes

Adds two test with invalid usage of tensor.extract_slice that were
missing. Also moves one other test for tensor.extract_slice, so that
all tests for this Op are clustered together.


Full diff: https://github.com/llvm/llvm-project/pull/112759.diff

1 Files Affected:

  • (modified) mlir/test/Dialect/Tensor/invalid.mlir (+29-8)
diff --git a/mlir/test/Dialect/Tensor/invalid.mlir b/mlir/test/Dialect/Tensor/invalid.mlir
index 84e6c59e403dde..a33ef0ba563154 100644
--- a/mlir/test/Dialect/Tensor/invalid.mlir
+++ b/mlir/test/Dialect/Tensor/invalid.mlir
@@ -213,6 +213,27 @@ func.func @extract_slice_wrong_result_rank(%t: tensor<?xf32>, %idx : index) {
   return
 }
 
+
+// -----
+
+func.func @extract_slice_size_and_output_dim_mismatch_static_size(%t: tensor<16xf32>) {
+  // expected-error @+1 {{expected type to be 'tensor<4xf32>' or a rank-reduced version. (size mismatch)}}
+  %0 = tensor.extract_slice %t[0][4][1]
+    : tensor<16xf32> to tensor<6xf32>
+
+  return
+}
+
+// -----
+
+func.func @extract_slice_size_and_output_dim_mismatch_dynamic_size(%t: tensor<?xf32>, %idx : index) {
+  // expected-error @+2 {{expected type to be 'tensor<?xf32>' or a rank-reduced version. (size mismatch)}}
+  %c4 = arith.constant 4 : index
+  %0 = tensor.extract_slice %t[0][%c4][1] : tensor<?xf32> to tensor<4xi8>
+
+  return
+}
+
 // -----
 
 func.func @extract_slice_wrong_static_type(%t: tensor<8x16x4xf32>, %idx : index) {
@@ -235,6 +256,14 @@ func.func @extract_slice_wrong_dynamic_type(%t: tensor<8x16x4xf32>, %idx : index
 
 // -----
 
+func.func @illegal_num_offsets(%arg0 : tensor<?x?x?xf32>, %arg1 : index, %arg2 : index) {
+  // expected-error@+1 {{expected 3 offset values}}
+  %0 = tensor.extract_slice %arg0[0, 0] [%arg1, %arg2] [1, 1] : tensor<?x?x?xf32> to tensor<?x?x?xf32>
+  return
+}
+
+// -----
+
 func.func @insert_slice_wrong_result_rank(%t1: tensor<?xf32>, %t2: tensor<?x?xf32>, %idx : index) {
   // expected-error @+1 {{expected rank to be smaller or equal to the other rank.}}
   %0 = tensor.insert_slice %t2 into %t1[0][4][1] : tensor<?x?xf32> into tensor<?xf32>
@@ -349,14 +378,6 @@ func.func @rank(%0: f32) {
 
 // -----
 
-func.func @illegal_num_offsets(%arg0 : tensor<?x?x?xf32>, %arg1 : index, %arg2 : index) {
-  // expected-error@+1 {{expected 3 offset values}}
-  %0 = tensor.extract_slice %arg0[0, 0] [%arg1, %arg2] [1, 1] : tensor<?x?x?xf32> to tensor<?x?x?xf32>
-  return
-}
-
-// -----
-
 func.func @illegal_num_offsets(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?x?x?xf32>,
     %arg2 : index, %arg3 : index) {
   // expected-error@+1 {{expected 3 offset values}}

@llvmbot
Copy link
Member

llvmbot commented Oct 17, 2024

@llvm/pr-subscribers-mlir

Author: Andrzej Warzyński (banach-space)

Changes

Adds two test with invalid usage of tensor.extract_slice that were
missing. Also moves one other test for tensor.extract_slice, so that
all tests for this Op are clustered together.


Full diff: https://github.com/llvm/llvm-project/pull/112759.diff

1 Files Affected:

  • (modified) mlir/test/Dialect/Tensor/invalid.mlir (+29-8)
diff --git a/mlir/test/Dialect/Tensor/invalid.mlir b/mlir/test/Dialect/Tensor/invalid.mlir
index 84e6c59e403dde..a33ef0ba563154 100644
--- a/mlir/test/Dialect/Tensor/invalid.mlir
+++ b/mlir/test/Dialect/Tensor/invalid.mlir
@@ -213,6 +213,27 @@ func.func @extract_slice_wrong_result_rank(%t: tensor<?xf32>, %idx : index) {
   return
 }
 
+
+// -----
+
+func.func @extract_slice_size_and_output_dim_mismatch_static_size(%t: tensor<16xf32>) {
+  // expected-error @+1 {{expected type to be 'tensor<4xf32>' or a rank-reduced version. (size mismatch)}}
+  %0 = tensor.extract_slice %t[0][4][1]
+    : tensor<16xf32> to tensor<6xf32>
+
+  return
+}
+
+// -----
+
+func.func @extract_slice_size_and_output_dim_mismatch_dynamic_size(%t: tensor<?xf32>, %idx : index) {
+  // expected-error @+2 {{expected type to be 'tensor<?xf32>' or a rank-reduced version. (size mismatch)}}
+  %c4 = arith.constant 4 : index
+  %0 = tensor.extract_slice %t[0][%c4][1] : tensor<?xf32> to tensor<4xi8>
+
+  return
+}
+
 // -----
 
 func.func @extract_slice_wrong_static_type(%t: tensor<8x16x4xf32>, %idx : index) {
@@ -235,6 +256,14 @@ func.func @extract_slice_wrong_dynamic_type(%t: tensor<8x16x4xf32>, %idx : index
 
 // -----
 
+func.func @illegal_num_offsets(%arg0 : tensor<?x?x?xf32>, %arg1 : index, %arg2 : index) {
+  // expected-error@+1 {{expected 3 offset values}}
+  %0 = tensor.extract_slice %arg0[0, 0] [%arg1, %arg2] [1, 1] : tensor<?x?x?xf32> to tensor<?x?x?xf32>
+  return
+}
+
+// -----
+
 func.func @insert_slice_wrong_result_rank(%t1: tensor<?xf32>, %t2: tensor<?x?xf32>, %idx : index) {
   // expected-error @+1 {{expected rank to be smaller or equal to the other rank.}}
   %0 = tensor.insert_slice %t2 into %t1[0][4][1] : tensor<?x?xf32> into tensor<?xf32>
@@ -349,14 +378,6 @@ func.func @rank(%0: f32) {
 
 // -----
 
-func.func @illegal_num_offsets(%arg0 : tensor<?x?x?xf32>, %arg1 : index, %arg2 : index) {
-  // expected-error@+1 {{expected 3 offset values}}
-  %0 = tensor.extract_slice %arg0[0, 0] [%arg1, %arg2] [1, 1] : tensor<?x?x?xf32> to tensor<?x?x?xf32>
-  return
-}
-
-// -----
-
 func.func @illegal_num_offsets(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?x?x?xf32>,
     %arg2 : index, %arg3 : index) {
   // expected-error@+1 {{expected 3 offset values}}

// expected-error @+1 {{expected type to be 'tensor<4xf32>' or a rank-reduced version. (size mismatch)}}
%0 = tensor.extract_slice %t[0][4][1]
: tensor<16xf32> to tensor<6xf32>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the empty line above return? I see pre-existing above had same. But these are not needed i suppose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's now fixed, thanks!

func.func @extract_slice_size_and_output_dim_mismatch_dynamic_size(%t: tensor<?xf32>, %idx : index) {
// expected-error @+2 {{expected type to be 'tensor<?xf32>' or a rank-reduced version. (size mismatch)}}
%c4 = arith.constant 4 : index
%0 = tensor.extract_slice %t[0][%c4][1] : tensor<?xf32> to tensor<4xi8>
Copy link
Contributor

@javedabsar1 javedabsar1 Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I think i am missing something here which maybe you need to explain just for my sake. Above is not rank-reduced case.%c4 is 4. Is it that the result type is still expected to be tensor<?x4> because value of '4' is not rolled into the extract_slice type deduction so to say.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this will clarify things a little bit:

Importantly, this PR merely documents the current behaviour. And, I might be sending more following the Discourse post :)

Please let me know if this is still unclear 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to ask, am kind of glad I asked actually because now is understand the problem. Thanks - "PR merely documents the current behaviour."

Copy link
Contributor

@javedabsar1 javedabsar1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@banach-space banach-space changed the title [mlir][tensor] Add tests to invalid.mlir [mlir][tensor] Add tests to invalid.mlir (nfc) Oct 18, 2024
@banach-space banach-space merged commit 1a871b2 into llvm:main Oct 18, 2024
8 checks passed
@banach-space banach-space deleted the andrzej/add_tensor_extract_slice_invalid_tests branch October 18, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants