Repository navigation
[mlir][tosa] Enable tosa-to-linalg allow-non-finites option by default - #239407
Merged
Merged
Conversation
|
@llvm/pr-subscribers-mlir-linalg @llvm/pr-subscribers-mlir-tosa Author: Luke Hutton (lhutton1) ChangesThe TOSA specification seeds reduce_min/max and max_pool with non-finite values. This commit enables the 3 Files Affected:
diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td
index 14f2158b312968..35ad3d0448a35c 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -1463,10 +1463,10 @@ def TosaToLinalg
"bool", /*default=*/"false",
"Always perform the reduce constant optimization">,
Option<"allowNonFinites", "allow-non-finites", "bool",
- /*default=*/"false",
+ /*default=*/"true",
"When enabled, float min/max reductions are seeded with the "
"infinite identity mandated by the TOSA specification. When "
- "disabled (default), the largest finite value is used instead. "
+ "disabled, the largest finite value is used instead. "
"This controls only compiler-generated identity values; NaN "
"results required by nan_mode are unaffected.">
];
@@ -1489,10 +1489,10 @@ def TosaToLinalgNamed
"bool", /*default=*/"false",
"Prefer generating linalg.conv_2d_nhwc_hwcf over linalg.conv_2d_nhwc_fhwc">,
Option<"allowNonFinites", "allow-non-finites", "bool",
- /*default=*/"false",
+ /*default=*/"true",
"When enabled, float max pooling is seeded with the infinite "
- "identity mandated by the TOSA specification. When disabled "
- "(default), the largest finite value is used instead. This "
+ "identity mandated by the TOSA specification. When disabled, "
+ "the largest finite value is used instead. This "
"controls only compiler-generated identity values; NaN results "
"required by nan_mode are unaffected.">
];
diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-named.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-named.mlir
index 22caf9d409eacc..0bee7d8bb551b7 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-named.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-named.mlir
@@ -1,7 +1,7 @@
-// RUN: mlir-opt --verify-each --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named))" %s -verify-diagnostics -o -| FileCheck %s --check-prefixes=CHECK,FINITE
+// RUN: mlir-opt --verify-each --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named))" %s -verify-diagnostics -o -| FileCheck %s --check-prefixes=CHECK,NONFINITE
// RUN: mlir-opt --verify-each --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named{prefer-conv2d-kernel-layout-hwcf=true}))" %s -verify-diagnostics -o -| FileCheck --check-prefix="HWCF" %s
// RUN: mlir-opt --verify-each --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named,cse))" %s -verify-diagnostics -o -| FileCheck --check-prefix="CHECK-CSE" %s
-// RUN: mlir-opt --verify-each --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named{allow-non-finites=true}))" %s -verify-diagnostics -o -| FileCheck %s --check-prefixes=CHECK,NONFINITE
+// RUN: mlir-opt --verify-each --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named{allow-non-finites=false}))" %s -verify-diagnostics -o -| FileCheck %s --check-prefixes=CHECK,FINITE
// CHECK-LABEL: @matmul
func.func @matmul(%arg0: tensor<2x5x3xf32>, %arg1: tensor<2x3x6xf32>) -> (tensor<2x5x6xf32>) {
@@ -1016,7 +1016,7 @@ func.func @max_pool_all_dynamic(%arg0: tensor<?x?x?x?xf32>) -> tensor<?x?x?x?xf3
// CHECK-CSE: %[[CHANNEL:.+]] = tensor.dim %arg0, %[[C3]] : tensor<?x?x?x?xf32>
// Pad the input
- // CHECK-CSE: %[[FLOAT_MIN:.+]] = arith.constant -3.40282347E+38 : f32
+ // CHECK-CSE: %[[FLOAT_MIN:.+]] = arith.constant 0xFF800000 : f32
// CHECK-CSE: %[[PADDED:.+]] = tensor.pad %arg0 low[0, 0, 2, 0] high[0, 0, 2, 0] {
// CHECK-CSE: tensor.yield %[[FLOAT_MIN]] : f32
diff --git a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
index d1c39ea86658ad..fae5662167a166 100644
--- a/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
+++ b/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
@@ -1,5 +1,5 @@
-// RUN: mlir-opt --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" %s -verify-diagnostics -o -| FileCheck %s --check-prefixes=CHECK,FINITE
-// RUN: mlir-opt --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg{allow-non-finites=true}))" %s -verify-diagnostics -o -| FileCheck %s --check-prefixes=CHECK,NONFINITE
+// RUN: mlir-opt --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" %s -verify-diagnostics -o -| FileCheck %s --check-prefixes=CHECK,NONFINITE
+// RUN: mlir-opt --split-input-file -pass-pipeline="builtin.module(func.func(tosa-to-linalg{allow-non-finites=false}))" %s -verify-diagnostics -o -| FileCheck %s --check-prefixes=CHECK,FINITE
// CHECK: #[[$MAP0:.*]] = affine_map<() -> ()>
|
Contributor
Author
Contributor
|
Reviewed and it looks good. It aligns with TOSA spec. Thanks for the change. |
The TOSA specification seeds reduce_min/max and max_pool with non-finite values. This commit enables the `allow-non-finites` option by default to align the default tosa-to-linalg lowering with the TOSA specification. Change-Id: I069e993224065763931df16e24dd050652f47120
lhutton1
force-pushed
the
enable-non-finites
branch
from
November 16, 2026 10:08
c543870 to
ff7b5ad
Compare
mbknust
added a commit
to iree-org/iree
that referenced
this pull request
Nov 17, 2026
The following fix needs to be kept: - [mlir][VectorToGPU] Reconsider cached slices after rejected candidates We also needed to fold slices of empty tensors before scf.forall canonicalization would tie them to `shared_outs`, due to changes introduced in: - llvm/llvm-project#241838 A GPU lit test had to be adjusted to account for that as well. The TOSA allowNonFinities option had to be explicitly set back to false, to not break WebGPU. The default was changed in upstream MLIR: - llvm/llvm-project#239407 The bump also exposed pre-existing UB, fixed by replacing std::abs with llvm::AbsoluteValue. Assisted-by: Codex Signed-off-by: Maksymilian B. Knust <[email protected]>
mbknust
added a commit
to iree-org/iree
that referenced
this pull request
Nov 17, 2026
The following fix needs to be kept: - [mlir][VectorToGPU] Reconsider cached slices after rejected candidates We also needed to fold slices of empty tensors before scf.forall canonicalization would tie them to `shared_outs`, due to changes introduced in: - llvm/llvm-project#241838 A GPU lit test had to be adjusted to account for that as well. The TOSA allowNonFinities option had to be explicitly set back to false, to not break WebGPU. The default was changed in upstream MLIR: - llvm/llvm-project#239407 The bump also exposed pre-existing UB, fixed by replacing std::abs with llvm::AbsoluteValue. Assisted-by: Codex Signed-off-by: Maksymilian B. Knust <[email protected]>
AGindinson
pushed a commit
to iree-org/iree
that referenced
this pull request
Nov 18, 2026
The following fix needs to be kept: - [[mlir][VectorToGPU] Reconsider cached slices after rejected candidates](iree-org/llvm-project@143db48) We also needed to fold slices of empty tensors before `scf.forall` canonicalization would tie them to `shared_outs`, due to changes introduced in: - llvm/llvm-project#241838 A GPU lit test had to be adjusted to account for that as well. The TOSA `allowNonFinities` option had to be explicitly set back to false, to not break WebGPU. The default was changed in upstream MLIR: - llvm/llvm-project#239407 - related: #11321 The bump also exposed pre-existing UB, fixed by replacing `std::abs` with `llvm::AbsoluteValue`. Assisted-by: Codex Signed-off-by: Maksymilian B. Knust <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The TOSA specification seeds reduce_min/max and max_pool with non-finite values. This commit enables the
allow-non-finitesoption by default to align the default tosa-to-linalg lowering with the TOSA specification.