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] Make validation pass isValidElementType check more strict #119671

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

lhutton1
Copy link
Contributor

The validation pass is used to check alignment of the IR against the TOSA specification. This commit updates the isValidElement check to more strictly align with the specifications supported element types.

The validation pass is used to check alignment of the IR against the
TOSA specification. This commit updates the `isValidElement` check to
more strictly align with the specifications supported element types.

Signed-off-by: Luke Hutton <luke.hutton@arm.com>
Change-Id: I1261220f8bebb7d64d04d00b5c656383f8329b5e
@llvmbot
Copy link
Member

llvmbot commented Dec 12, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-tosa

Author: Luke Hutton (lhutton1)

Changes

The validation pass is used to check alignment of the IR against the TOSA specification. This commit updates the isValidElement check to more strictly align with the specifications supported element types.


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

2 Files Affected:

  • (modified) mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp (+3-16)
  • (modified) mlir/test/Dialect/Tosa/level_check.mlir (+8)
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
index 93e8cac6b84e9c..893cedefc1ebde 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
@@ -524,18 +524,8 @@ bool TosaValidation::isValidElementType(Type type) {
     if (!isEnabledProfile(TosaProfileEnum::MainInference))
       return false;
     return type.isF32() || type.isF16() || type.isBF16();
-  }
-  if (auto intTy = dyn_cast<IntegerType>(type)) {
-    if (intTy.isUnsigned()) {
-      switch (intTy.getWidth()) {
-      case 8:
-      case 16:
-        return true;
-      default:
-        return false;
-      }
-    } else {
-      // Signless - treated as signed.
+  } else if (auto intTy = dyn_cast<IntegerType>(type)) {
+    if (intTy.isSignless()) {
       switch (intTy.getWidth()) {
       case 1:
       case 4:
@@ -544,13 +534,10 @@ bool TosaValidation::isValidElementType(Type type) {
       case 32:
       case 48:
         return true;
-      default:
-        return false;
       }
     }
-    return false;
   }
-  return true;
+  return false;
 }
 
 void TosaValidation::runOnOperation() {
diff --git a/mlir/test/Dialect/Tosa/level_check.mlir b/mlir/test/Dialect/Tosa/level_check.mlir
index e851019362958f..529a16ca48c7eb 100644
--- a/mlir/test/Dialect/Tosa/level_check.mlir
+++ b/mlir/test/Dialect/Tosa/level_check.mlir
@@ -143,6 +143,14 @@ func.func @test_const_f64(%arg0 : tensor<1xf64>) {
 
 // -----
 
+func.func @test_const_ui8(%arg0 : tensor<1xui8>) {
+  // expected-error@+1 {{'tosa.const' op is not profile-aligned: element type 'ui8' is not legal}}
+  %0 = "tosa.const"() {value = dense<0> : tensor<1xui8>} : () -> tensor<1xui8>
+  return
+}
+
+// -----
+
 func.func @test_avgpool2d_kernel_y(%arg0: tensor<1x32x32x8xf32>) -> tensor<1x32x32x8xf32> {
   // expected-error@+1 {{'tosa.avg_pool2d' op failed level check: kernel <= MAX_KERNEL}}
   %0 = "tosa.avg_pool2d"(%arg0) {kernel = array<i64: 8193, 1>, pad = array<i64: 4, 4, 4, 4>, stride = array<i64: 1, 1>, acc_type = f32} :

@lhutton1 lhutton1 changed the title [TOSA] Make validation pass isValidElement check more strict [TOSA] Make validation pass isValidElementType check more strict Dec 12, 2024
Copy link
Contributor

@GeorgeARM GeorgeARM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
I recall that rescale could return u8 back but this is already fixed from what I see.

@GeorgeARM GeorgeARM merged commit 9472c5f into llvm:main Dec 12, 2024
11 checks passed
@MaheshRavishankar
Copy link
Contributor

This seems to fail on IndexType. Is that explicit.

(Found as an error while integrate it into downstream iree-org/iree#19479 )

MaheshRavishankar added a commit to iree-org/llvm-project that referenced this pull request Dec 12, 2024
MaheshRavishankar added a commit to iree-org/iree that referenced this pull request Dec 12, 2024
Carrying the following reverts

- llvm/llvm-project#116470
- llvm/llvm-project#117424
- llvm/llvm-project#119671

First two are carry over from previous integrate. It is being fixed in
#19451 . The last one is a new
failure.

---------

Signed-off-by: MaheshRavishankar <mahesh.ravishankar@gmail.com>
MaheshRavishankar added a commit to iree-org/llvm-project that referenced this pull request Dec 12, 2024
@lhutton1
Copy link
Contributor Author

lhutton1 commented Dec 13, 2024

Thanks for reporting and for the revert @MaheshRavishankar, apologies I'm only just taking a look now.

I took a look at the failures and noticed that the validation pass is being run over mixed dialect IR. Currently the pass seems to run over all operators regardless of the dialect, including operators from arith/tensor/linalg that use the index type which would be considered illegal in tosa. I suspect we'll need to ensure only tosa operators are checked by this pass - I'll work on a patch for this, then resubmit this change

raikonenfnu pushed a commit to iree-org/llvm-project that referenced this pull request Dec 16, 2024
raikonenfnu added a commit to iree-org/iree that referenced this pull request Dec 17, 2024
Update LLVM to llvm/llvm-project@3f136f7
(#19479)
Carrying the following reverts

- llvm/llvm-project#116470
- llvm/llvm-project#117424
- llvm/llvm-project#119671
- llvm/llvm-project#119970

First two are carry over from previous-previous integrate. It is being
fixed in
#19451 . The last one is a from the
previous integrate.
The last one is a new error being tracked in
#19498

---------

Signed-off-by: Stanley Winata <stanley.winata@amd.com>
raikonenfnu pushed a commit to iree-org/llvm-project that referenced this pull request Dec 17, 2024
raikonenfnu added a commit to raikonenfnu/iree that referenced this pull request Dec 17, 2024
Update LLVM to llvm/llvm-project@b07e7b76c5d532a6 (llvm/llvm-project#120002)
Carrying the following reverts

- llvm/llvm-project#116470
- llvm/llvm-project#117424
- llvm/llvm-project#119671
- llvm/llvm-project#119970

First two are carry over from previous-previous integrate. It is being fixed in
iree-org#19451 . The last one is a from the previous integrate.
The last one is a new error being tracked in iree-org#19498

Signed-off-by: Stanley Winata <stanley.winata@amd.com>
raikonenfnu added a commit to raikonenfnu/iree that referenced this pull request Dec 17, 2024
Update LLVM to llvm/llvm-project@b07e7b76c5d532a6 (llvm/llvm-project#120002)
Carrying the following reverts

- llvm/llvm-project#116470
- llvm/llvm-project#117424
- llvm/llvm-project#119671
- llvm/llvm-project#119970

First two are carry over from previous-previous integrate. It is being fixed in
iree-org#19451 . The last one is a from the previous integrate.
The last one is a new error being tracked in iree-org#19498

Signed-off-by: Stanley Winata <stanley.winata@amd.com>
MaheshRavishankar added a commit to iree-org/llvm-project that referenced this pull request Dec 17, 2024
raikonenfnu pushed a commit to iree-org/llvm-project that referenced this pull request Dec 18, 2024
raikonenfnu pushed a commit to iree-org/llvm-project that referenced this pull request Dec 20, 2024
raikonenfnu added a commit to raikonenfnu/iree that referenced this pull request Dec 20, 2024
Changes in C++ mostly handle changes done in llvm/llvm-project@4b56345 that combines SCFTilingResult and SCFReductionTilingResult.

This PR also carries the following reverts

- llvm/llvm-project#119671
- llvm/llvm-project#119970

The first one is a from the previous integrate. The last one is a new error being tracked in iree-org#19498.

Signed-off-by: Stanley Winata <stanley.winata@amd.com>
raikonenfnu added a commit to raikonenfnu/iree that referenced this pull request Dec 20, 2024
Changes in C++ mostly handle changes done in llvm/llvm-project@4b56345 that combines SCFTilingResult and SCFReductionTilingResult.

This PR also carries the following reverts

- llvm/llvm-project#119671
- llvm/llvm-project#119970

The first one is a from the previous integrate. The last one is a new error being tracked in iree-org#19498.

Signed-off-by: Stanley Winata <stanley.winata@amd.com>
@lhutton1
Copy link
Contributor Author

I thought this commit had been reverted in LLVM, but it seems I was mistaken and it was reverted in the IREE fork instead. I'm unsure of the official process here, but I wanted to give a quick update. Since #120205 was merged, my hope is that the failures in IREE have been fixed - please let me know if that's not the case so I can investigate further

@MaheshRavishankar
Copy link
Contributor

I thought this commit had been reverted in LLVM, but it seems I was mistaken and it was reverted in the IREE fork instead. I'm unsure of the official process here, but I wanted to give a quick update. Since #120205 was merged, my hope is that the failures in IREE have been fixed - please let me know if that's not the case so I can investigate further

Thanks @lhutton1 . @raikonenfnu if you get around to another integrate of LLVM into IREE could you please try dropping the revert in IREEs LLVM fork

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.

4 participants