[Mlir-commits] [mlir] [mlir][spirv] Add Activation operators to TOSA Extended Instruction S… (PR #178620)
Davide Grohmann
llvmlistbot at llvm.org
Thu Jan 29 03:10:19 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>
+ %3 = spirv.Tosa.Clamp min_val = -1.19339396E+38 : f32, max_val = 2.38255944E+38 : f32, nan_mode = <Ignore>, %arg0 : !spirv.arm.tensor<18x5x17x6xf32> -> !spirv.arm.tensor<18x5x17x6xf32>
+ ```
+ }];
+
+ let arguments = (ins
+ SPIRV_TosaNumericalAttr: $min_val,
+ SPIRV_TosaNumericalAttr: $max_val,
+ SPIRV_TosaExtNaNPropagationModeAttr: $nan_mode,
+ SPIRV_TosaNumerical_TensorArm: $input
+ );
+
+ let results = (outs
+ SPIRV_TosaNumerical_TensorArm: $output
+ );
+
+ let assemblyFormat = [{
+ `min_val` `=` $min_val `,`
+ `max_val` `=` $max_val `,`
+ `nan_mode` `=` $nan_mode `,`
+ $input
+ attr-dict `:` type(operands) `->` type(results)
+ }];
+
+ let extraClassDeclaration = extraBaseClassDeclaration#[{
+ ::mlir::spirv::TensorArmType getInputType() {
+ return cast<::mlir::spirv::TensorArmType>(getInput().getType());
+ }
+ }];
+}
+
+
+def SPIRV_TosaErfOp : SPIRV_TosaOpWithResult<"Erf", 11, [Pure,
+ AllTypesMatch<["input", "output"]>]> {
+ let summary = "Computes Gauss Error Function of input.";
+
+ let description = [{
+ Gauss Error Function: $ erf(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2} dt $
+ For quantized integer data types, the table operator should be used instead
----------------
davidegrohmann wrote:
I have no strong opinions, I can remove the comment if preferred.
I add it there as a tip that this op supports only floating-point and for integers the Table operator should be use instead.
https://github.com/llvm/llvm-project/pull/178620
More information about the Mlir-commits
mailing list