[Mlir-commits] [mlir] [mlir][spirv] Add Activation operators to TOSA Extended Instruction S… (PR #178620)

Jakub Kuderski llvmlistbot at llvm.org
Thu Jan 29 05:08:28 PST 2026


================
@@ -694,4 +694,182 @@ def SPIRV_TosaTransposeConv2DOp : SPIRV_TosaOpWithResult<"TransposeConv2D", 9, [
 }
 
 
+def SPIRV_TosaClampOp : SPIRV_TosaOpWithResult<"Clamp", 10, [Pure,
+  AllTypesMatch<["input", "output"]>,
+  AllElementTypesMatch<["input", "output", "min_val", "max_val"]>]> {
+  let summary = "Computes Clamp(min, max).";
+
+  let description = [{
+    Clamp to an arbitrary minimum and maximum value.
+    Maximum and minimum values are specified as values in the range of the
+    input type.
+    No zero point subtraction is done to the values, thus to clamp to the zero
+    point value, the zero point itself should be supplied as the minimum value.
+
+    References:
+      * https://github.khronos.org/SPIRV-Registry/extended/TOSA.001000.1.html#_clamp
+      * https://www.mlplatform.org/tosa/tosa_spec_1_0_1.html#_clamp
+
+    #### Example:
+    ```mlir
+    %3 = spirv.Tosa.Clamp min_val = -102 : i8, max_val = -100 : i8, nan_mode = <Propagate>, %arg0 : !spirv.arm.tensor<27x44x55xi8> -> !spirv.arm.tensor<27x44x55xi8>
----------------
kuhar wrote:

If input and output types match, we can omit the `-> result` type. If you want to keep it consistent across ops, that's also fine.

https://github.com/llvm/llvm-project/pull/178620


More information about the Mlir-commits mailing list