Skip to content
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

[TOSA] Don't run validation pass on non TOSA operations #120205

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

lhutton1
Copy link
Contributor

This commit ensures the validation pass is not run on operations from other dialects. In doing so, operations from other dialects that, for example, use types not supported by TOSA don't result in an error.

@llvmbot
Copy link
Member

llvmbot commented Dec 17, 2024

@llvm/pr-subscribers-mlir-tosa

@llvm/pr-subscribers-mlir

Author: Luke Hutton (lhutton1)

Changes

This commit ensures the validation pass is not run on operations from other dialects. In doing so, operations from other dialects that, for example, use types not supported by TOSA don't result in an error.


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

2 Files Affected:

  • (modified) mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp (+3)
  • (modified) mlir/test/Dialect/Tosa/invalid.mlir (+10-2)
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
index 893cedefc1ebde..62bbeead4d4a7b 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
@@ -543,6 +543,9 @@ bool TosaValidation::isValidElementType(Type type) {
 void TosaValidation::runOnOperation() {
   configLevelAndProfile();
   getOperation().walk([&](Operation *op) {
+    if (!op->getDialect() || op->getDialect()->getNamespace() != TosaDialect::getDialectNamespace())
+      return;
+
     for (Value operand : op->getOperands()) {
       auto elementTy = getElementTypeOrSelf(operand);
       if (!isValidElementType(elementTy)) {
diff --git a/mlir/test/Dialect/Tosa/invalid.mlir b/mlir/test/Dialect/Tosa/invalid.mlir
index 79bb7fce5755ef..cca50b25d14d6b 100644
--- a/mlir/test/Dialect/Tosa/invalid.mlir
+++ b/mlir/test/Dialect/Tosa/invalid.mlir
@@ -625,7 +625,6 @@ func.func @test_mul_invalid_shift(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x1
 func.func @test_unsupported_int64_data_type(%arg0: tensor<1x13x13x5xf32>) -> tensor<1x13x13xi64> {
   // expected-error@+1 {{'tosa.argmax' op is not profile-aligned: element type 'i64' is not legal}}
   %0 = tosa.argmax %arg0 {axis = 3 : i32} : (tensor<1x13x13x5xf32>) -> tensor<1x13x13xi64>
-  // expected-error@+1 {{'func.return' op is not profile-aligned: element type 'i64' is not legal}}
   return %0 : tensor<1x13x13xi64>
 }
 
@@ -879,4 +878,13 @@ func.func @test_mismatch_in_out_shape_logical_not(%arg0: tensor<1x21x3xi1>) -> t
   // expected-error@+1 {{'tosa.logical_not' op requires the same shape for all operands and results}}
   %0 = tosa.logical_not %arg0 : (tensor<1x21x3xi1>) -> tensor<13x21x3xi1>
   return %0 : tensor<13x21x3xi1>
-}
\ No newline at end of file
+}
+
+// -----
+
+// Check validate pass doesn't run on non TOSA ops
+func.func @test_non_tosa_ops() {
+  %0 = arith.constant 6 : index
+  %2 = tensor.empty(%0) : tensor<?x27xi64>
+  return
+}

Copy link

github-actions bot commented Dec 17, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

This commit ensures the validation pass is not run on operations
from other dialects. In doing so, operations from other dialects
that, for example, use types not supported by TOSA don't result
in an error.

Change-Id: If1efde2036f2d3e13b8c8588fea6344922453c2b
Signed-off-by: Luke Hutton <luke.hutton@arm.com>
@lhutton1 lhutton1 force-pushed the validate-pass-only-tosa-ops branch from be33e63 to cb055ae Compare December 17, 2024 10:09
@lhutton1
Copy link
Contributor Author

@lhutton1 lhutton1 merged commit e4351f2 into llvm:main Dec 19, 2024
8 checks passed
lhutton1 added a commit to lhutton1/llvm-project that referenced this pull request Dec 23, 2024
After a suggestion in llvm#120205, this commit adjusts a dialect check
that runs per op to be more efficient.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
Change-Id: I137ec8e1fd73dc2de0b211e1ff38cb128e99a671
lhutton1 added a commit to lhutton1/llvm-project that referenced this pull request Dec 23, 2024
After a suggestion in llvm#120205, this commit adjusts a dialect check
that runs per op to be more efficient.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
Change-Id: I137ec8e1fd73dc2de0b211e1ff38cb128e99a671
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.

5 participants