[Mlir-commits] [mlir] eef8e79 - [mlir][tosa] Add log2_ceil/log2_floor/exp2_shape ops (#175057)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jan 9 13:33:51 PST 2026
Author: Yuvaraj Venkatesh
Date: 2026-01-09T21:33:47Z
New Revision: eef8e79e3a1c3f65f61ee42ccdbca8edb4fa32c6
URL: https://github.com/llvm/llvm-project/commit/eef8e79e3a1c3f65f61ee42ccdbca8edb4fa32c6
DIFF: https://github.com/llvm/llvm-project/commit/eef8e79e3a1c3f65f61ee42ccdbca8edb4fa32c6.diff
LOG: [mlir][tosa] Add log2_ceil/log2_floor/exp2_shape ops (#175057)
This commit introduces new ext-shape operations,
- LOG2_CEIL_SHAPE
- LOG2_FLOOR_SHAPE
- EXP2_SHAPE
These additions include the operator definitions, same-rank
verification, and level checks during validation.
---------
Co-authored-by: Luke Hutton <luke.hutton at arm.com>
Added:
Modified:
mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
mlir/test/Dialect/Tosa/level_check.mlir
mlir/test/Dialect/Tosa/ops.mlir
mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
index be5789c1be7bf..d8597151714c3 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaShapeOps.td
@@ -175,6 +175,57 @@ def Tosa_DivFloorShapeOp : Tosa_ElementwiseShapeOp<"div_floor_shape", [Pure]> {
let results = (outs Tosa_Shape:$output);
}
+//===----------------------------------------------------------------------===//
+// Operator: Exp2Shape
+//===----------------------------------------------------------------------===//
+def Tosa_Exp2ShapeOp : Tosa_ElementwiseShapeOp<"exp2_shape", [Pure]> {
+ let summary = "Elementwise base-2 exponential of shapes.";
+
+ let description = [{
+ Computation of raising two to the power of each element in input.
+ }];
+
+ let arguments = (ins
+ Tosa_Shape:$input
+ );
+
+ let results = (outs Tosa_Shape:$output);
+}
+
+//===----------------------------------------------------------------------===//
+// Operator: Log2CeilShape
+//===----------------------------------------------------------------------===//
+def Tosa_Log2CeilShapeOp : Tosa_ElementwiseShapeOp<"log2_ceil_shape", [Pure]> {
+ let summary = "Elementwise ceil base-2 logarithm of shapes.";
+
+ let description = [{
+ Computation of the base two logarithm of each element in input. Result is rounded up.
+ }];
+
+ let arguments = (ins
+ Tosa_Shape:$input
+ );
+
+ let results = (outs Tosa_Shape:$output);
+}
+
+//===----------------------------------------------------------------------===//
+// Operator: Log2FloorShape
+//===----------------------------------------------------------------------===//
+def Tosa_Log2FloorShapeOp : Tosa_ElementwiseShapeOp<"log2_floor_shape", [Pure]> {
+ let summary = "Elementwise floor base-2 logarithm of shapes.";
+
+ let description = [{
+ Computation of the base two logarithm of each element in input. Result is rounded down.
+ }];
+
+ let arguments = (ins
+ Tosa_Shape:$input
+ );
+
+ let results = (outs Tosa_Shape:$output);
+}
+
//===----------------------------------------------------------------------===//
// Operator: MaxShape
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
index 46c8c32324313..08c702bd2f29f 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaProfileCompliance.cpp
@@ -329,6 +329,9 @@ LogicalResult ProfileInfoDepot::populatationDispatch(Operation *op) {
POPULATE_PROFILE_INFO_SKIP(ConstShape)
POPULATE_PROFILE_INFO_SKIP(DivCeilShape)
POPULATE_PROFILE_INFO_SKIP(DivFloorShape)
+ POPULATE_PROFILE_INFO_SKIP(Exp2Shape)
+ POPULATE_PROFILE_INFO_SKIP(Log2CeilShape)
+ POPULATE_PROFILE_INFO_SKIP(Log2FloorShape)
POPULATE_PROFILE_INFO_SKIP(MaxShape)
POPULATE_PROFILE_INFO_SKIP(MinShape)
POPULATE_PROFILE_INFO_SKIP(ModShape)
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
index dc2c90bbf1199..a900aef04f753 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
@@ -708,6 +708,9 @@ LogicalResult TosaValidation::levelCheckRanksAndSizes(Operation *op) {
CHECK_RANKS(ConcatShape);
CHECK_RANKS(DivCeilShape);
CHECK_RANKS(DivFloorShape);
+ CHECK_RANKS(Exp2Shape);
+ CHECK_RANKS(Log2CeilShape);
+ CHECK_RANKS(Log2FloorShape);
CHECK_RANKS(MaxShape);
CHECK_RANKS(MinShape);
CHECK_RANKS(ModShape);
diff --git a/mlir/test/Dialect/Tosa/level_check.mlir b/mlir/test/Dialect/Tosa/level_check.mlir
index 5e681c1ef75c8..d874ab6d23a50 100644
--- a/mlir/test/Dialect/Tosa/level_check.mlir
+++ b/mlir/test/Dialect/Tosa/level_check.mlir
@@ -1691,7 +1691,6 @@ func.func @test_dim(%arg0: tensor<1x2x3x4x5x6x7x8xi32>) -> !tosa.shape<1> {
return %0 : !tosa.shape<1>
}
-
// -----
func.func @test_concat_shape_invalid_list_size() {
@@ -1722,6 +1721,33 @@ func.func @test_concat_shape_invalid_list_size() {
// -----
+func.func @test_exp2_shape_invalid_rank() -> !tosa.shape<7> {
+ %0 = tosa.const_shape {values = dense<[1, 2, 3, 4, 5, 6, 7]> : tensor<7xindex>} : () -> !tosa.shape<7>
+ // expected-error at +1 {{'tosa.exp2_shape' op failed shape type level check: '!tosa.shape<7>' exceeds MAX_RANK}}
+ %1 = tosa.exp2_shape %0 : (!tosa.shape<7>) -> !tosa.shape<7>
+ return %1 : !tosa.shape<7>
+}
+
+// -----
+
+func.func @test_log2_floor_shape_invalid_rank() -> !tosa.shape<7> {
+ %0 = tosa.const_shape {values = dense<[1, 2, 3, 4, 5, 6, 7]> : tensor<7xindex>} : () -> !tosa.shape<7>
+ // expected-error at +1 {{'tosa.log2_floor_shape' op failed shape type level check: '!tosa.shape<7>' exceeds MAX_RANK}}
+ %1 = tosa.log2_floor_shape %0 : (!tosa.shape<7>) -> !tosa.shape<7>
+ return %1 : !tosa.shape<7>
+}
+
+// -----
+
+func.func @test_log2_ceil_shape_invalid_rank() -> !tosa.shape<7> {
+ %0 = tosa.const_shape {values = dense<[1, 2, 3, 4, 5, 6, 7]> : tensor<7xindex>} : () -> !tosa.shape<7>
+ // expected-error at +1 {{'tosa.log2_ceil_shape' op failed shape type level check: '!tosa.shape<7>' exceeds MAX_RANK}}
+ %1 = tosa.log2_ceil_shape %0 : (!tosa.shape<7>) -> !tosa.shape<7>
+ return %1 : !tosa.shape<7>
+}
+
+// -----
+
func.func @test_mod_shape_invalid_rank() -> !tosa.shape<9> {
%a = tosa.const_shape {values = dense<[1, 2, 3, 4, 5, 6, 7, 8, 9]> : tensor<9xindex>} : () -> !tosa.shape<9>
%b = tosa.const_shape {values = dense<[1, 2, 3, 4, 5, 6, 7, 8, 9]> : tensor<9xindex>} : () -> !tosa.shape<9>
diff --git a/mlir/test/Dialect/Tosa/ops.mlir b/mlir/test/Dialect/Tosa/ops.mlir
index 8d7d703e2f450..5d6384ca34cac 100644
--- a/mlir/test/Dialect/Tosa/ops.mlir
+++ b/mlir/test/Dialect/Tosa/ops.mlir
@@ -1481,6 +1481,30 @@ func.func @test_slice_shape_dynamic(%arg0: tensor<1xi32>, %arg1: tensor<1xi32>)
return %3 : !tosa.shape<3>
}
+// -----
+// CHECK-LABEL: test_exp2_shape
+func.func @test_exp2_shape() -> !tosa.shape<4> {
+ %a = tosa.const_shape {values = dense<[5, 7, 10, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %b = tosa.exp2_shape %a : (!tosa.shape<4>) -> !tosa.shape<4>
+ return %b : !tosa.shape<4>
+}
+
+// -----
+// CHECK-LABEL: test_log2_ceil_shape
+func.func @test_log2_ceil_shape() -> !tosa.shape<4> {
+ %a = tosa.const_shape {values = dense<[5, 7, 10, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %b = tosa.log2_ceil_shape %a : (!tosa.shape<4>) -> !tosa.shape<4>
+ return %b : !tosa.shape<4>
+}
+
+// -----
+// CHECK-LABEL: test_log2_floor_shape
+func.func @test_log2_floor_shape() -> !tosa.shape<4> {
+ %a = tosa.const_shape {values = dense<[5, 7, 10, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %b = tosa.log2_floor_shape %a : (!tosa.shape<4>) -> !tosa.shape<4>
+ return %b : !tosa.shape<4>
+}
+
// -----
// CHECK-LABEL: test_max_shape
func.func @test_max_shape() -> !tosa.shape<4> {
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 1b2403c60fbbd..d11c2b512b273 100644
--- a/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
@@ -167,6 +167,22 @@ func.func @test_dim(%arg0: tensor<1x2x3x4xi32>) -> !tosa.shape<1> {
return %0 : !tosa.shape<1>
}
+// -----
+// CHECK-LABEL: test_exp2_shape
+func.func @test_exp2_shape() -> !tosa.shape<4> {
+ %a = tosa.const_shape {values = dense<[5, 7, 10, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %b = tosa.exp2_shape %a : (!tosa.shape<4>) -> !tosa.shape<4>
+ return %b : !tosa.shape<4>
+}
+
+// -----
+// CHECK-LABEL: test_log2_ceil_shape
+func.func @test_log2_ceil_shape() -> !tosa.shape<4> {
+ %a = tosa.const_shape {values = dense<[5, 7, 10, 1]> : tensor<4xindex>} : () -> !tosa.shape<4>
+ %b = tosa.log2_ceil_shape %a : (!tosa.shape<4>) -> !tosa.shape<4>
+ return %b : !tosa.shape<4>
+}
+
// -----
// CHECK-LABEL: test_mod_shape
More information about the Mlir-commits
mailing list