[Mlir-commits] [mlir] [mlir][tosa] Add missing check for mutiples of `tosa.tile` (PR #106337)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Aug 27 22:31:34 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Longsheng Mou (CoTinker)

<details>
<summary>Changes</summary>

This patch adds check for mutiples of `tosa.tile`. Each element of `mutiples` should be positive integer or -1. Fix #<!-- -->106167.

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


2 Files Affected:

- (modified) mlir/lib/Dialect/Tosa/IR/TosaOps.cpp (+4) 
- (modified) mlir/test/Dialect/Tosa/invalid.mlir (+18) 


``````````diff
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index c8e2b04eea0e22..267a875710ed71 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -930,6 +930,10 @@ LogicalResult tosa::TileOp::verify() {
     return emitOpError("expect 'multiples' array to have length ")
            << outputType.getRank() << " but got " << multiples.size() << ".";
 
+  if (llvm::any_of(multiples, [](int64_t v) { return v <= 0 && v != -1; }))
+    return emitOpError(
+        "expect element of 'multiples' to be positive integer or -1.");
+
   return success();
 }
 
diff --git a/mlir/test/Dialect/Tosa/invalid.mlir b/mlir/test/Dialect/Tosa/invalid.mlir
index 806ba22e1bbe8c..e72e154f952771 100644
--- a/mlir/test/Dialect/Tosa/invalid.mlir
+++ b/mlir/test/Dialect/Tosa/invalid.mlir
@@ -424,6 +424,24 @@ func.func @test_tile_invalid_multiples() {
 
 // -----
 
+func.func @test_tile_invalid_multiples_value() {
+  %0 = tensor.empty() : tensor<4x31xf32>
+  // expected-error at +1 {{'tosa.tile' op expect element of 'multiples' to be positive integer or -1.}}
+  %1 = tosa.tile %0 {multiples = array<i64: 2, -2>} : (tensor<4x31xf32>) -> tensor<4x31xf32>
+  return
+}
+
+// -----
+
+func.func @test_tile_io_rank_mismatch() {
+  %0 = tensor.empty() : tensor<4x31xf32>
+  // expected-error at +1 {{'tosa.tile' op expect same input and output tensor rank.}}
+  %1 = tosa.tile %0 {multiples = array<i64: 2, 2>} : (tensor<4x31xf32>) -> tensor<4x31x31xf32>
+  return
+}
+
+// -----
+
 // CHECK-LABEL: @test_invalid_constant_permutation
 func.func @test_invalid_constant_permutation() {
   // expected-error at +3 {{permutation must be within input bounds}}

``````````

</details>


https://github.com/llvm/llvm-project/pull/106337


More information about the Mlir-commits mailing list