Skip to content

Commit c8568f0

Browse files
authored
[mlir][tosa] Add missing check for mutiples of tosa.tile (#106337)
This patch adds check for mutiples of `tosa.tile`. The `multiples` in `tosa.tile` indicates how many times the tensor should be replicated along each dimension. Zero and negative values are invalid, except for -1, which represents a dynamic value. Therefore, each element of `mutiples` should be positive integer or -1. Fix #106167.
1 parent 833ce5d commit c8568f0

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mlir/lib/Dialect/Tosa/IR/TosaOps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,10 @@ LogicalResult tosa::TileOp::verify() {
930930
return emitOpError("expect 'multiples' array to have length ")
931931
<< outputType.getRank() << " but got " << multiples.size() << ".";
932932

933+
if (llvm::any_of(multiples, [](int64_t v) { return v <= 0 && v != -1; }))
934+
return emitOpError(
935+
"expect element of 'multiples' to be positive integer or -1.");
936+
933937
return success();
934938
}
935939

mlir/test/Dialect/Tosa/invalid.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,24 @@ func.func @test_tile_invalid_multiples() {
424424

425425
// -----
426426

427+
func.func @test_tile_invalid_multiples_value() {
428+
%0 = tensor.empty() : tensor<4x31xf32>
429+
// expected-error@+1 {{'tosa.tile' op expect element of 'multiples' to be positive integer or -1.}}
430+
%1 = tosa.tile %0 {multiples = array<i64: 2, -2>} : (tensor<4x31xf32>) -> tensor<4x31xf32>
431+
return
432+
}
433+
434+
// -----
435+
436+
func.func @test_tile_io_rank_mismatch() {
437+
%0 = tensor.empty() : tensor<4x31xf32>
438+
// expected-error@+1 {{'tosa.tile' op expect same input and output tensor rank.}}
439+
%1 = tosa.tile %0 {multiples = array<i64: 2, 2>} : (tensor<4x31xf32>) -> tensor<4x31x31xf32>
440+
return
441+
}
442+
443+
// -----
444+
427445
// CHECK-LABEL: @test_invalid_constant_permutation
428446
func.func @test_invalid_constant_permutation() {
429447
// expected-error@+3 {{permutation must be within input bounds}}

0 commit comments

Comments
 (0)