[Mlir-commits] [mlir] [mlir][spirv] Add `CL.mix` op (PR #72800)
Ivan Butygin
llvmlistbot at llvm.org
Sun Nov 19 09:12:46 PST 2023
https://github.com/Hardcode84 created https://github.com/llvm/llvm-project/pull/72800
Also, script decided to rearrange bunch of ops inside td file, the only actual change is `SPIRV_CLMixOp`.
>From c0a46c2659a96929855bc2d7d58554b6cb48099c Mon Sep 17 00:00:00 2001
From: Ivan Butygin <ivan.butygin at gmail.com>
Date: Sun, 19 Nov 2023 18:09:58 +0100
Subject: [PATCH] [mlir][spirv] Add `CL.mix` op
Also, script decided to rearrange bunch of ops inside td file, the only actual change is `SPIRV_CLMixOp`.
---
.../mlir/Dialect/SPIRV/IR/SPIRVCLOps.td | 343 ++++++++++--------
mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir | 20 +
2 files changed, 207 insertions(+), 156 deletions(-)
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
index 66ed2db681196b1..026f59b2afd8e24 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
@@ -111,6 +111,37 @@ class SPIRV_CLTernaryArithmeticOp<string mnemonic, int opcode, Type type,
+// -----
+
+def SPIRV_CLMixOp : SPIRV_CLTernaryArithmeticOp<"mix", 99, SPIRV_Float> {
+ let summary = "Returns the linear blend of x & y implemented as: x + (y - x) * a";
+
+ let description = [{
+ Result Type, x, y and a must be floating-point or vector(2,3,4,8,16) of
+ floating-point values.
+
+ All of the operands, including the Result Type operand, must be of the
+ same type.
+
+ Note: This instruction can be implemented using contractions such as mad
+ or fma.
+
+ <!-- End of AutoGen section -->
+
+ ```
+ mix-op ::= ssa-id `=` `spirv.CL.mix` ssa-use, ssa-use, ssa-use `:`
+ float-scalar-vector-type
+ ```
+
+ #### Example:
+
+ ```mlir
+ %0 = spirv.CL.mix %a, %b, %c : f32
+ %1 = spirv.CL.mix %a, %b, %c : vector<3xf16>
+ ```
+ }];
+}
+
// -----
def SPIRV_CLCeilOp : SPIRV_CLUnaryArithmeticOp<"ceil", 12, SPIRV_Float> {
@@ -268,127 +299,127 @@ def SPIRV_CLFAbsOp : SPIRV_CLUnaryArithmeticOp<"fabs", 23, SPIRV_Float> {
// -----
-def SPIRV_CLFloorOp : SPIRV_CLUnaryArithmeticOp<"floor", 25, SPIRV_Float> {
- let summary = [{
- Round x to the integral value using the round to negative infinity
- rounding mode.
- }];
+def SPIRV_CLFMaxOp : SPIRV_CLBinaryArithmeticOp<"fmax", 27, SPIRV_Float> {
+ let summary = "Return maximum of two floating-point operands";
let description = [{
- Result Type and x must be floating-point or vector(2,3,4,8,16) of
- floating-point values.
+ Returns y if x < y, otherwise it returns x. If one argument is a NaN,
+ Fmax returns the other argument. If both arguments are NaNs, Fmax returns a NaN.
- All of the operands, including the Result Type operand, must be of the
- same type.
+ Result Type, x and y must be floating-point or vector(2,3,4,8,16)
+ of floating-point values.
- <!-- End of AutoGen section -->
+ All of the operands, including the Result Type operand,
+ must be of the same type.
+ <!-- End of AutoGen section -->
```
float-scalar-vector-type ::= float-type |
`vector<` integer-literal `x` float-type `>`
- floor-op ::= ssa-id `=` `spirv.CL.floor` ssa-use `:`
- float-scalar-vector-type
+ fmax-op ::= ssa-id `=` `spirv.CL.fmax` ssa-use `:`
+ float-scalar-vector-type
```
-
#### Example:
```mlir
- %2 = spirv.CL.floor %0 : f32
- %3 = spirv.CL.ceifloorl %1 : vector<3xf16>
+ %2 = spirv.CL.fmax %0, %1 : f32
+ %3 = spirv.CL.fmax %0, %1 : vector<3xf16>
```
}];
}
// -----
-def SPIRV_CLFmaOp : SPIRV_CLTernaryArithmeticOp<"fma", 26, SPIRV_Float> {
- let summary = [{
- Compute the correctly rounded floating-point representation of the sum
- of c with the infinitely precise product of a and b. Rounding of
- intermediate products shall not occur. Edge case results are per the
- IEEE 754-2008 standard.
- }];
+def SPIRV_CLFMinOp : SPIRV_CLBinaryArithmeticOp<"fmin", 28, SPIRV_Float> {
+ let summary = "Return minimum of two floating-point operands";
let description = [{
- Result Type, a, b and c must be floating-point or vector(2,3,4,8,16) of
- floating-point values.
+ Returns y if y < x, otherwise it returns x. If one argument is a NaN, Fmin returns the other argument.
+ If both arguments are NaNs, Fmin returns a NaN.
- All of the operands, including the Result Type operand, must be of the
- same type.
+ Result Type,x and y must be floating-point or vector(2,3,4,8,16) of floating-point values.
+
+ All of the operands, including the Result Type operand, must be of the same type.
- <!-- End of AutoGen section -->
+ <!-- End of AutoGen section -->
```
- fma-op ::= ssa-id `=` `spirv.CL.fma` ssa-use, ssa-use, ssa-use `:`
- float-scalar-vector-type
+ float-scalar-vector-type ::= float-type |
+ `vector<` integer-literal `x` float-type `>`
+ fmin-op ::= ssa-id `=` `spirv.CL.fmin` ssa-use `:`
+ float-scalar-vector-type
```
-
#### Example:
```mlir
- %0 = spirv.CL.fma %a, %b, %c : f32
- %1 = spirv.CL.fma %a, %b, %c : vector<3xf16>
+ %2 = spirv.CL.fmin %0, %1 : f32
+ %3 = spirv.CL.fmin %0, %1 : vector<3xf16>
```
}];
}
// -----
-def SPIRV_CLFMaxOp : SPIRV_CLBinaryArithmeticOp<"fmax", 27, SPIRV_Float> {
- let summary = "Return maximum of two floating-point operands";
+def SPIRV_CLFloorOp : SPIRV_CLUnaryArithmeticOp<"floor", 25, SPIRV_Float> {
+ let summary = [{
+ Round x to the integral value using the round to negative infinity
+ rounding mode.
+ }];
let description = [{
- Returns y if x < y, otherwise it returns x. If one argument is a NaN,
- Fmax returns the other argument. If both arguments are NaNs, Fmax returns a NaN.
-
- Result Type, x and y must be floating-point or vector(2,3,4,8,16)
- of floating-point values.
+ Result Type and x must be floating-point or vector(2,3,4,8,16) of
+ floating-point values.
- All of the operands, including the Result Type operand,
- must be of the same type.
+ All of the operands, including the Result Type operand, must be of the
+ same type.
<!-- End of AutoGen section -->
+
```
float-scalar-vector-type ::= float-type |
`vector<` integer-literal `x` float-type `>`
- fmax-op ::= ssa-id `=` `spirv.CL.fmax` ssa-use `:`
- float-scalar-vector-type
+ floor-op ::= ssa-id `=` `spirv.CL.floor` ssa-use `:`
+ float-scalar-vector-type
```
+
#### Example:
```mlir
- %2 = spirv.CL.fmax %0, %1 : f32
- %3 = spirv.CL.fmax %0, %1 : vector<3xf16>
+ %2 = spirv.CL.floor %0 : f32
+ %3 = spirv.CL.ceifloorl %1 : vector<3xf16>
```
}];
}
// -----
-def SPIRV_CLFMinOp : SPIRV_CLBinaryArithmeticOp<"fmin", 28, SPIRV_Float> {
- let summary = "Return minimum of two floating-point operands";
+def SPIRV_CLFmaOp : SPIRV_CLTernaryArithmeticOp<"fma", 26, SPIRV_Float> {
+ let summary = [{
+ Compute the correctly rounded floating-point representation of the sum
+ of c with the infinitely precise product of a and b. Rounding of
+ intermediate products shall not occur. Edge case results are per the
+ IEEE 754-2008 standard.
+ }];
let description = [{
- Returns y if y < x, otherwise it returns x. If one argument is a NaN, Fmin returns the other argument.
- If both arguments are NaNs, Fmin returns a NaN.
-
- Result Type,x and y must be floating-point or vector(2,3,4,8,16) of floating-point values.
-
- All of the operands, including the Result Type operand, must be of the same type.
+ Result Type, a, b and c must be floating-point or vector(2,3,4,8,16) of
+ floating-point values.
+ All of the operands, including the Result Type operand, must be of the
+ same type.
<!-- End of AutoGen section -->
+
```
- float-scalar-vector-type ::= float-type |
- `vector<` integer-literal `x` float-type `>`
- fmin-op ::= ssa-id `=` `spirv.CL.fmin` ssa-use `:`
- float-scalar-vector-type
+ fma-op ::= ssa-id `=` `spirv.CL.fma` ssa-use, ssa-use, ssa-use `:`
+ float-scalar-vector-type
```
+
#### Example:
```mlir
- %2 = spirv.CL.fmin %0, %1 : f32
- %3 = spirv.CL.fmin %0, %1 : vector<3xf16>
+ %0 = spirv.CL.fma %a, %b, %c : f32
+ %1 = spirv.CL.fma %a, %b, %c : vector<3xf16>
```
}];
}
@@ -456,10 +487,10 @@ def SPIRV_CLPowOp : SPIRV_CLBinaryArithmeticOp<"pow", 48, SPIRV_Float> {
// -----
-def SPIRV_CLRoundOp : SPIRV_CLUnaryArithmeticOp<"round", 55, SPIRV_Float> {
+def SPIRV_CLRintOp : SPIRV_CLUnaryArithmeticOp<"rint", 53, SPIRV_Float> {
let summary = [{
- Return the integral value nearest to x rounding halfway cases away from
- zero, regardless of the current rounding direction.
+ Round x to integral value (using round to nearest even rounding mode) in
+ floating-point format.
}];
let description = [{
@@ -474,24 +505,25 @@ def SPIRV_CLRoundOp : SPIRV_CLUnaryArithmeticOp<"round", 55, SPIRV_Float> {
```
float-scalar-vector-type ::= float-type |
`vector<` integer-literal `x` float-type `>`
- round-op ::= ssa-id `=` `spirv.CL.round` ssa-use `:`
+ rint-op ::= ssa-id `=` `spirv.CL.rint` ssa-use `:`
float-scalar-vector-type
```
+
#### Example:
```mlir
- %2 = spirv.CL.round %0 : f32
- %3 = spirv.CL.round %0 : vector<3xf16>
+ %0 = spirv.CL.rint %0 : f32
+ %1 = spirv.CL.rint %1 : vector<3xf16>
```
}];
}
// -----
-def SPIRV_CLRintOp : SPIRV_CLUnaryArithmeticOp<"rint", 53, SPIRV_Float> {
+def SPIRV_CLRoundOp : SPIRV_CLUnaryArithmeticOp<"round", 55, SPIRV_Float> {
let summary = [{
- Round x to integral value (using round to nearest even rounding mode) in
- floating-point format.
+ Return the integral value nearest to x rounding halfway cases away from
+ zero, regardless of the current rounding direction.
}];
let description = [{
@@ -506,15 +538,14 @@ def SPIRV_CLRintOp : SPIRV_CLUnaryArithmeticOp<"rint", 53, SPIRV_Float> {
```
float-scalar-vector-type ::= float-type |
`vector<` integer-literal `x` float-type `>`
- rint-op ::= ssa-id `=` `spirv.CL.rint` ssa-use `:`
+ round-op ::= ssa-id `=` `spirv.CL.round` ssa-use `:`
float-scalar-vector-type
```
-
#### Example:
```mlir
- %0 = spirv.CL.rint %0 : f32
- %1 = spirv.CL.rint %1 : vector<3xf16>
+ %2 = spirv.CL.round %0 : f32
+ %3 = spirv.CL.round %0 : vector<3xf16>
```
}];
}
@@ -551,6 +582,90 @@ def SPIRV_CLRsqrtOp : SPIRV_CLUnaryArithmeticOp<"rsqrt", 56, SPIRV_Float> {
// -----
+def SPIRV_CLSAbsOp : SPIRV_CLUnaryArithmeticOp<"s_abs", 141, SPIRV_Integer> {
+ let summary = "Absolute value of operand";
+
+ let description = [{
+ Returns |x|, where x is treated as signed integer.
+
+ Result Type and x must be integer or vector(2,3,4,8,16) of
+ integer values.
+
+ All of the operands, including the Result Type operand,
+ must be of the same type.
+
+ <!-- End of AutoGen section -->
+ ```
+ integer-scalar-vector-type ::= integer-type |
+ `vector<` integer-literal `x` integer-type `>`
+ abs-op ::= ssa-id `=` `spirv.CL.s_abs` ssa-use `:`
+ integer-scalar-vector-type
+ ```
+ #### Example:
+
+ ```mlir
+ %2 = spirv.CL.s_abs %0 : i32
+ %3 = spirv.CL.s_abs %1 : vector<3xi16>
+ ```
+ }];
+}
+
+// -----
+
+def SPIRV_CLSMaxOp : SPIRV_CLBinaryArithmeticOp<"s_max", 156, SPIRV_Integer> {
+ let summary = "Return maximum of two signed integer operands";
+
+ let description = [{
+ Returns y if x < y, otherwise it returns x, where x and y are treated as signed integers.
+
+ Result Type,x and y must be integer or vector(2,3,4,8,16) of integer values.
+
+ All of the operands, including the Result Type operand, must be of the same type.
+
+ <!-- End of AutoGen section -->
+ ```
+ integer-scalar-vector-type ::= integer-type |
+ `vector<` integer-literal `x` integer-type `>`
+ smax-op ::= ssa-id `=` `spirv.CL.s_max` ssa-use `:`
+ integer-scalar-vector-type
+ ```
+ #### Example:
+ ```mlir
+ %2 = spirv.CL.s_max %0, %1 : i32
+ %3 = spirv.CL.s_max %0, %1 : vector<3xi16>
+ ```
+ }];
+}
+
+// -----
+
+def SPIRV_CLSMinOp : SPIRV_CLBinaryArithmeticOp<"s_min", 158, SPIRV_Integer> {
+ let summary = "Return minimum of two signed integer operands";
+
+ let description = [{
+ Returns y if x < y, otherwise it returns x, where x and y are treated as signed integers.
+
+ Result Type,x and y must be integer or vector(2,3,4,8,16) of integer values.
+
+ All of the operands, including the Result Type operand, must be of the same type.
+
+ <!-- End of AutoGen section -->
+ ```
+ integer-scalar-vector-type ::= integer-type |
+ `vector<` integer-literal `x` integer-type `>`
+ smin-op ::= ssa-id `=` `spirv.CL.s_min` ssa-use `:`
+ integer-scalar-vector-type
+ ```
+ #### Example:
+ ```mlir
+ %2 = spirv.CL.s_min %0, %1 : i32
+ %3 = spirv.CL.s_min %0, %1 : vector<3xi16>
+ ```
+ }];
+}
+
+// -----
+
def SPIRV_CLSinOp : SPIRV_CLUnaryArithmeticOp<"sin", 57, SPIRV_Float> {
let summary = "Compute sine of x radians.";
@@ -641,63 +756,6 @@ def SPIRV_CLTanhOp : SPIRV_CLUnaryArithmeticOp<"tanh", 63, SPIRV_Float> {
// -----
-def SPIRV_CLSAbsOp : SPIRV_CLUnaryArithmeticOp<"s_abs", 141, SPIRV_Integer> {
- let summary = "Absolute value of operand";
-
- let description = [{
- Returns |x|, where x is treated as signed integer.
-
- Result Type and x must be integer or vector(2,3,4,8,16) of
- integer values.
-
- All of the operands, including the Result Type operand,
- must be of the same type.
-
- <!-- End of AutoGen section -->
- ```
- integer-scalar-vector-type ::= integer-type |
- `vector<` integer-literal `x` integer-type `>`
- abs-op ::= ssa-id `=` `spirv.CL.s_abs` ssa-use `:`
- integer-scalar-vector-type
- ```
- #### Example:
-
- ```mlir
- %2 = spirv.CL.s_abs %0 : i32
- %3 = spirv.CL.s_abs %1 : vector<3xi16>
- ```
- }];
-}
-
-// -----
-
-def SPIRV_CLSMaxOp : SPIRV_CLBinaryArithmeticOp<"s_max", 156, SPIRV_Integer> {
- let summary = "Return maximum of two signed integer operands";
-
- let description = [{
- Returns y if x < y, otherwise it returns x, where x and y are treated as signed integers.
-
- Result Type,x and y must be integer or vector(2,3,4,8,16) of integer values.
-
- All of the operands, including the Result Type operand, must be of the same type.
-
- <!-- End of AutoGen section -->
- ```
- integer-scalar-vector-type ::= integer-type |
- `vector<` integer-literal `x` integer-type `>`
- smax-op ::= ssa-id `=` `spirv.CL.s_max` ssa-use `:`
- integer-scalar-vector-type
- ```
- #### Example:
- ```mlir
- %2 = spirv.CL.s_max %0, %1 : i32
- %3 = spirv.CL.s_max %0, %1 : vector<3xi16>
- ```
- }];
-}
-
-// -----
-
def SPIRV_CLUMaxOp : SPIRV_CLBinaryArithmeticOp<"u_max", 157, SPIRV_Integer> {
let summary = "Return maximum of two unsigned integer operands";
@@ -725,33 +783,6 @@ def SPIRV_CLUMaxOp : SPIRV_CLBinaryArithmeticOp<"u_max", 157, SPIRV_Integer> {
// -----
-def SPIRV_CLSMinOp : SPIRV_CLBinaryArithmeticOp<"s_min", 158, SPIRV_Integer> {
- let summary = "Return minimum of two signed integer operands";
-
- let description = [{
- Returns y if x < y, otherwise it returns x, where x and y are treated as signed integers.
-
- Result Type,x and y must be integer or vector(2,3,4,8,16) of integer values.
-
- All of the operands, including the Result Type operand, must be of the same type.
-
- <!-- End of AutoGen section -->
- ```
- integer-scalar-vector-type ::= integer-type |
- `vector<` integer-literal `x` integer-type `>`
- smin-op ::= ssa-id `=` `spirv.CL.s_min` ssa-use `:`
- integer-scalar-vector-type
- ```
- #### Example:
- ```mlir
- %2 = spirv.CL.s_min %0, %1 : i32
- %3 = spirv.CL.s_min %0, %1 : vector<3xi16>
- ```
- }];
-}
-
-// -----
-
def SPIRV_CLUMinOp : SPIRV_CLBinaryArithmeticOp<"u_min", 159, SPIRV_Integer> {
let summary = "Return minimum of two unsigned integer operands";
diff --git a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
index 29a4a46136156a9..f4e3a83e39f2479 100644
--- a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
@@ -188,6 +188,26 @@ func.func @fma(%a : vector<3xf32>, %b : vector<3xf32>, %c : vector<3xf32>) -> ()
// -----
+//===----------------------------------------------------------------------===//
+// spirv.CL.mix
+//===----------------------------------------------------------------------===//
+
+func.func @mix(%a : f32, %b : f32, %c : f32) -> () {
+ // CHECK: spirv.CL.mix {{%[^,]*}}, {{%[^,]*}}, {{%[^,]*}} : f32
+ %2 = spirv.CL.mix %a, %b, %c : f32
+ return
+}
+
+// -----
+
+func.func @mix(%a : vector<3xf32>, %b : vector<3xf32>, %c : vector<3xf32>) -> () {
+ // CHECK: spirv.CL.mix {{%[^,]*}}, {{%[^,]*}}, {{%[^,]*}} : vector<3xf32>
+ %2 = spirv.CL.mix %a, %b, %c : vector<3xf32>
+ return
+}
+
+// -----
+
//===----------------------------------------------------------------------===//
// spirv.CL.{F|S|U}{Max|Min}
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list