Skip to content

Commit 1a871b2

Browse files
authored
[mlir][tensor] Add tests to invalid.mlir (nfc) (#112759)
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.
1 parent 332ac18 commit 1a871b2

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

mlir/test/Dialect/Tensor/invalid.mlir

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ func.func @tensor.reshape_num_elements_mismatch(
200200
func.func @extract_slice_wrong_result_rank(%t: tensor<?xf32>, %idx : index) {
201201
// expected-error @+1 {{expected rank to be smaller or equal to the other rank.}}
202202
%0 = tensor.extract_slice %t[0][4][1] : tensor<?xf32> to tensor<?x?xf32>
203-
204203
return
205204
}
206205

@@ -209,7 +208,25 @@ func.func @extract_slice_wrong_result_rank(%t: tensor<?xf32>, %idx : index) {
209208
func.func @extract_slice_wrong_result_rank(%t: tensor<?xf32>, %idx : index) {
210209
// expected-error @+1 {{expected element type to be 'f32'}}
211210
%0 = tensor.extract_slice %t[0][4][1] : tensor<?xf32> to tensor<4xi8>
211+
return
212+
}
213+
214+
215+
// -----
216+
217+
func.func @extract_slice_size_and_output_dim_mismatch_static_size(%t: tensor<16xf32>) {
218+
// expected-error @+1 {{expected type to be 'tensor<4xf32>' or a rank-reduced version. (size mismatch)}}
219+
%0 = tensor.extract_slice %t[0][4][1]
220+
: tensor<16xf32> to tensor<6xf32>
221+
return
222+
}
223+
224+
// -----
212225

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

@@ -219,7 +236,6 @@ func.func @extract_slice_wrong_static_type(%t: tensor<8x16x4xf32>, %idx : index)
219236
// expected-error @+1 {{expected type to be 'tensor<?x4x4xf32>' or a rank-reduced version. (size mismatch)}}
220237
%0 = tensor.extract_slice %t[0, 0, 0][%idx, 4, 4][1, 1, 1]
221238
: tensor<8x16x4xf32> to tensor<4x4x4xf32>
222-
223239
return
224240
}
225241

@@ -229,7 +245,14 @@ func.func @extract_slice_wrong_dynamic_type(%t: tensor<8x16x4xf32>, %idx : index
229245
// expected-error @+1 {{expected type to be 'tensor<4x4x4xf32>' or a rank-reduced version. (size mismatch)}}
230246
%0 = tensor.extract_slice %t[0, 2, 0][4, 4, 4][1, 1, 1]
231247
: tensor<8x16x4xf32> to tensor<?x4x4xf32>
248+
return
249+
}
232250

251+
// -----
252+
253+
func.func @illegal_num_offsets(%arg0 : tensor<?x?x?xf32>, %arg1 : index, %arg2 : index) {
254+
// expected-error@+1 {{expected 3 offset values}}
255+
%0 = tensor.extract_slice %arg0[0, 0] [%arg1, %arg2] [1, 1] : tensor<?x?x?xf32> to tensor<?x?x?xf32>
233256
return
234257
}
235258

@@ -349,14 +372,6 @@ func.func @rank(%0: f32) {
349372

350373
// -----
351374

352-
func.func @illegal_num_offsets(%arg0 : tensor<?x?x?xf32>, %arg1 : index, %arg2 : index) {
353-
// expected-error@+1 {{expected 3 offset values}}
354-
%0 = tensor.extract_slice %arg0[0, 0] [%arg1, %arg2] [1, 1] : tensor<?x?x?xf32> to tensor<?x?x?xf32>
355-
return
356-
}
357-
358-
// -----
359-
360375
func.func @illegal_num_offsets(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?x?x?xf32>,
361376
%arg2 : index, %arg3 : index) {
362377
// expected-error@+1 {{expected 3 offset values}}

0 commit comments

Comments
 (0)