[Mlir-commits] [mlir] [mlir][spirv] Add 6 Element Binary operators to TOSA Ext Inst Set (PR #179627)
Jakub Kuderski
llvmlistbot at llvm.org
Tue Feb 10 07:01:46 PST 2026
================
@@ -863,4 +876,229 @@ def SPIRV_TosaTanhOp : SPIRV_TosaOpWithResult<"Tanh", 13, [Pure,
}
+def SPIRV_TosaAddOp : SPIRV_TosaElementwiseBinaryOp<"Add", 14, [Pure,
+ AllElementTypesMatch<["input1", "input2", "output"]>,
+ AllRanksMatch<["input1", "input2"]>]> {
+ let summary = "Addition operator.";
+
+ let description = [{
+ Elementwise Addition of input1 and input2. Axis of size 1 will be broadcast,
+ as necessary. Rank of input tensors must match.
+
+ References:
+ * https://github.khronos.org/SPIRV-Registry/extended/TOSA.001000.1.html#_add
+ * https://www.mlplatform.org/tosa/tosa_spec_1_0_1.html#_add
+
+ #### Example:
+ ```mlir
+ %0 = spirv.Tosa.Add %arg0, %arg1 : !spirv.arm.tensor<4x7x3x10xi32>, !spirv.arm.tensor<4x7x3x1xi32> -> !spirv.arm.tensor<4x7x3x10xi32>
+ %0 = spirv.Tosa.Add %arg0, %arg1 : !spirv.arm.tensor<26x37x18xf16>, !spirv.arm.tensor<1x37x18xf16> -> !spirv.arm.tensor<26x37x18xf16>
+ ```
+ }];
+
+ let arguments = (ins
+ SPIRV_TosaNumerical_TensorArm: $input1,
+ SPIRV_TosaNumerical_TensorArm: $input2
+ );
+
+ let results = (outs
+ SPIRV_TosaNumerical_TensorArm: $output
+ );
+
+ let assemblyFormat = [{
+ $input1 `,`
+ $input2
+ attr-dict `:` type(operands) `->` type(results)
+ }];
+}
+
+
+def SPIRV_TosaArithmeticRightShiftOp : SPIRV_TosaElementwiseBinaryOp<"ArithmeticRightShift", 15, [Pure,
+ AllElementTypesMatch<["input1", "input2", "output"]>,
+ AllRanksMatch<["input1", "input2"]>]> {
+ let summary = "Arithmetic Right Shift.";
+
+ let description = [{
+ Elementwise Arithmetic Right Shift of input1 by the amount specified in
+ input2. Axis of size 1 will be broadcast, as necessary. Rank of input tensors
+ must match.
+
+ References:
+ * https://github.khronos.org/SPIRV-Registry/extended/TOSA.001000.1.html#_arithmetic_right_shift
+ * https://www.mlplatform.org/tosa/tosa_spec_1_0_1.html#_arithmetic_right_shift
+
+ #### Example:
+ ```mlir
+ %1 = spirv.Tosa.ArithmeticRightShift round = true, %arg0, %arg1 : !spirv.arm.tensor<1x47x22xi16>, !spirv.arm.tensor<49x47x22xi16> -> !spirv.arm.tensor<49x47x22xi16>
+ ```
+ }];
+
+ let arguments = (ins
+ SPIRV_BoolConstAttr: $round,
+ SPIRV_TosaInteger_TensorArm: $input1,
+ SPIRV_TosaInteger_TensorArm: $input2
+ );
+
+ let results = (outs
+ SPIRV_TosaInteger_TensorArm: $output
+ );
+
+ let assemblyFormat = [{
+ `round` `=` $round `,`
+ $input1 `,`
+ $input2
----------------
kuhar wrote:
```suggestion
$input1 `,` $input2
```
https://github.com/llvm/llvm-project/pull/179627
More information about the Mlir-commits
mailing list