[Mlir-commits] [mlir] [mlir][tosa] Add missing check for mutiples of `tosa.tile` (PR #106337)
Longsheng Mou
llvmlistbot at llvm.org
Tue Aug 27 22:31:06 PDT 2024
https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/106337
This patch adds check for mutiples of `tosa.tile`. Each element of `mutiples` should be positive integer or -1. Fix #106167.
>From ec2166f6ec066a4df043bc7be6cc3987549fce43 Mon Sep 17 00:00:00 2001
From: Longsheng Mou <moulongsheng at huawei.com>
Date: Wed, 28 Aug 2024 13:24:00 +0800
Subject: [PATCH] [mlir][tosa] Add missing check for mutiples of `tosa.tile`
This patch adds check for mutiples of `tosa.tile`. Each element of
`mutiples` should be positive integer or -1.
---
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp | 4 ++++
mlir/test/Dialect/Tosa/invalid.mlir | 18 ++++++++++++++++++
2 files changed, 22 insertions(+)
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}}
More information about the Mlir-commits
mailing list