Skip to content

[mlir][tosa] Enable tosa-to-linalg allow-non-finites option by default - #239407

Merged
lhutton1 merged 1 commit into
llvm:mainfrom
lhutton1:enable-non-finites
Nov 16, 2026
Merged

lhutton1 merged 1 commit into
llvm:mainfrom
lhutton1:enable-non-finites

Conversation

@lhutton1

@lhutton1 lhutton1 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

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.

@llvmorg-github-actions

llvmorg-github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

@llvm/pr-subscribers-mlir-linalg
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-tosa

Author: Luke Hutton (lhutton1)

Changes

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.


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

3 Files Affected:

  • (modified) mlir/include/mlir/Conversion/Passes.td (+5-5)
  • (modified) mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-named.mlir (+3-3)
  • (modified) mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir (+2-2)
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<() -> ()>
 

@lhutton1

lhutton1 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@hariprasadravi

Copy link
Copy Markdown
Contributor

Reviewed and it looks good. It aligns with TOSA spec. Thanks for the change.

@sahas3 sahas3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

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
lhutton1 merged commit 806f953 into llvm:main Nov 16, 2026
10 checks passed
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]>
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.

3 participants