Skip to content

[mlir][tosa] Fix validation of dim op when reliant on datatype extension#180915

Merged
lhutton1 merged 1 commit into
llvm:mainfrom
lhutton1:fix-dim-op-validation
Feb 11, 2026
Merged

[mlir][tosa] Fix validation of dim op when reliant on datatype extension#180915
lhutton1 merged 1 commit into
llvm:mainfrom
lhutton1:fix-dim-op-validation

Conversation

@lhutton1
Copy link
Copy Markdown
Contributor

For example:

error: 'tosa.dim' op illegal: requires [bf16, shape] but not included in the profile compliance [shape]

    %0 = tosa.dim %arg0 {axis = 4 : i32} : (tensor<4x5x8x8x6x4xbf16>) -> !tosa.shape<1>

Here dim requires support to be declared for the BF16 and SHAPE extensions, but only SHAPE was specified in the op declaration.

…nsion

For example:
```
error: 'tosa.dim' op illegal: requires [bf16, shape] but not included in the profile compliance [shape]

    %0 = tosa.dim %arg0 {axis = 4 : i32} : (tensor<4x5x8x8x6x4xbf16>) -> !tosa.shape<1>
```
Here dim requires support to be declared for the BF16 and SHAPE extensions, but only SHAPE was specified
in the op declaration.

Change-Id: I5c986d6763904483c68da0e1c2aa9923947d2c3f
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Feb 11, 2026

@llvm/pr-subscribers-mlir-tosa

@llvm/pr-subscribers-mlir

Author: Luke Hutton (lhutton1)

Changes

For example:

error: 'tosa.dim' op illegal: requires [bf16, shape] but not included in the profile compliance [shape]

    %0 = tosa.dim %arg0 {axis = 4 : i32} : (tensor&lt;4x5x8x8x6x4xbf16&gt;) -&gt; !tosa.shape&lt;1&gt;

Here dim requires support to be declared for the BF16 and SHAPE extensions, but only SHAPE was specified in the op declaration.


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

2 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td (+5)
  • (modified) mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir (+10)
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
index cbcc2a017ac3a..25f7132fabea7 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
@@ -138,6 +138,11 @@ def Tosa_DimOp : Tosa_ShapeOp<"dim", [Pure]> {
 
   let results = (outs Tosa_Shape:$output);
 
+  list<Availability> availability = [
+    Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
+    Extension<[Tosa_EXT_SHAPE, Tosa_EXT_FP8E4M3, Tosa_EXT_FP8E5M2, Tosa_EXT_BF16, Tosa_EXT_MXFP, Tosa_EXT_INT64]>,
+  ];
+
   let hasVerifier = 1;
 
   let hasFolder = 1;
diff --git a/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir b/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
index 72269d21f3d98..fa03abcccacd8 100644
--- a/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
@@ -271,6 +271,14 @@ func.func @test_dim(%arg0: tensor<1x2x3x4xi32>) -> !tosa.shape<1> {
   return %0 : !tosa.shape<1>
 }
 
+// -----
+
+// CHECK-LABEL: test_dim_bf16
+func.func @test_dim_bf16(%0: tensor<6x4x6x9xbf16>) {
+  %1 = tosa.dim %0 {axis = 1 : i32} : (tensor<6x4x6x9xbf16>) -> !tosa.shape<1>
+  return
+}
+
 // -----
 // CHECK-LABEL: test_exp2_shape
 func.func @test_exp2_shape() -> !tosa.shape<4> {
@@ -308,6 +316,8 @@ func.func @test_conv2d_block_scaled(%arg0: tensor<1x4x4x64xf4E2M1FN>, %arg1: ten
   return %0 : tensor<1x4x4x8xf32>
 }
 
+// -----
+
 // CHECK-LABEL: test_assert_equal_shape
 func.func @test_assert_equal_shape() {
   %0 = tosa.const_shape {values = dense<[10, 15]> : tensor<2xindex>} : () -> !tosa.shape<2>

@IanTaylerLessa-arm
Copy link
Copy Markdown
Contributor

LGTM. Thank you for the quick fix!

@lhutton1 lhutton1 merged commit 3123d9c into llvm:main Feb 11, 2026
13 checks passed
@lhutton1 lhutton1 deleted the fix-dim-op-validation branch February 11, 2026 12:15
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