Skip to content

Commit 6183515

Browse files
authored
[mlir][spirv] Add more CL math ops (llvm#72995)
tan atan atanh sinh cosh asin asinh acos acosh atan2
1 parent f85e7ab commit 6183515

File tree

2 files changed

+483
-10
lines changed

2 files changed

+483
-10
lines changed

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td

Lines changed: 323 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,223 @@ class SPIRV_CLTernaryArithmeticOp<string mnemonic, int opcode, Type type,
113113

114114
// -----
115115

116-
def SPIRV_CLMixOp : SPIRV_CLTernaryArithmeticOp<"mix", 99, SPIRV_Float> {
117-
let summary = "Returns the linear blend of x & y implemented as: x + (y - x) * a";
116+
def SPIRV_CLAtan2Op : SPIRV_CLBinaryArithmeticOp<"atan2", 7, SPIRV_Float > {
117+
let summary = "Compute the arc tangent of y / x.";
118118

119119
let description = [{
120-
Result Type, x, y and a must be floating-point or vector(2,3,4,8,16) of
120+
Result is an angle in radians.
121+
122+
Result Type, y and x must be floating-point or vector(2,3,4,8,16) of
121123
floating-point values.
122124

123125
All of the operands, including the Result Type operand, must be of the
124126
same type.
125127

126-
Note: This instruction can be implemented using contractions such as mad
127-
or fma.
128+
<!-- End of AutoGen section -->
129+
130+
```
131+
float-scalar-vector-type ::= float-type |
132+
`vector<` integer-literal `x` float-type `>`
133+
atan2-op ::= ssa-id `=` `spirv.CL.atan2` ssa-use `:`
134+
float-scalar-vector-type
135+
```
136+
#### Example:
137+
138+
```mlir
139+
%2 = spirv.CL.atan2 %0, %1 : f32
140+
%3 = spirv.CL.atan2 %0, %1 : vector<4xf16>
141+
```
142+
}];
143+
}
144+
145+
// -----
146+
147+
def SPIRV_CLAcosOp : SPIRV_CLUnaryArithmeticOp<"acos", 0, SPIRV_Float > {
148+
let summary = "Compute the arc cosine of x.";
149+
150+
let description = [{
151+
Result is an angle in radians.
152+
153+
Result Type and x must be floating-point or vector(2,3,4,8,16) of
154+
floating-point values.
155+
156+
All of the operands, including the Result Type operand, must be of the
157+
same type.
128158

129159
<!-- End of AutoGen section -->
130160

131161
```
132-
mix-op ::= ssa-id `=` `spirv.CL.mix` ssa-use, ssa-use, ssa-use `:`
133-
float-scalar-vector-type
162+
float-scalar-vector-type ::= float-type |
163+
`vector<` integer-literal `x` float-type `>`
164+
acos-op ::= ssa-id `=` `spirv.CL.acos` ssa-use `:`
165+
float-scalar-vector-type
134166
```
135167

136168
#### Example:
137169

138170
```mlir
139-
%0 = spirv.CL.mix %a, %b, %c : f32
140-
%1 = spirv.CL.mix %a, %b, %c : vector<3xf16>
171+
%2 = spirv.CL.acos %0 : f32
172+
%3 = spirv.CL.acos %1 : vector<4xf16>
173+
```
174+
}];
175+
}
176+
177+
// -----
178+
179+
def SPIRV_CLAcoshOp : SPIRV_CLUnaryArithmeticOp<"acosh", 1, SPIRV_Float > {
180+
let summary = "Compute the inverse hyperbolic cosine of x .";
181+
182+
let description = [{
183+
Result is an angle in radians.
184+
185+
Result Type and x must be floating-point or vector(2,3,4,8,16) of
186+
floating-point values.
187+
188+
All of the operands, including the Result Type operand, must be of the
189+
same type.
190+
191+
<!-- End of AutoGen section -->
192+
193+
```
194+
float-scalar-vector-type ::= float-type |
195+
`vector<` integer-literal `x` float-type `>`
196+
acosh-op ::= ssa-id `=` `spirv.CL.acosh` ssa-use `:`
197+
float-scalar-vector-type
198+
```
199+
200+
#### Example:
201+
202+
```mlir
203+
%2 = spirv.CL.acosh %0 : f32
204+
%3 = spirv.CL.acosh %1 : vector<4xf16>
205+
```
206+
}];
207+
}
208+
209+
// -----
210+
211+
def SPIRV_CLAsinOp : SPIRV_CLUnaryArithmeticOp<"asin", 3, SPIRV_Float > {
212+
let summary = "Compute the arc sine of x.";
213+
214+
let description = [{
215+
Result is an angle in radians.
216+
217+
Result Type and x must be floating-point or vector(2,3,4,8,16) of
218+
floating-point values.
219+
220+
All of the operands, including the Result Type operand, must be of the
221+
same type.
222+
223+
<!-- End of AutoGen section -->
224+
225+
```
226+
float-scalar-vector-type ::= float-type |
227+
`vector<` integer-literal `x` float-type `>`
228+
asin-op ::= ssa-id `=` `spirv.CL.asin` ssa-use `:`
229+
float-scalar-vector-type
230+
```
231+
232+
#### Example:
233+
234+
```mlir
235+
%2 = spirv.CL.asin %0 : f32
236+
%3 = spirv.CL.asin %1 : vector<4xf16>
237+
```
238+
}];
239+
}
240+
241+
// -----
242+
243+
def SPIRV_CLAsinhOp : SPIRV_CLUnaryArithmeticOp<"asinh", 4, SPIRV_Float > {
244+
let summary = "Compute the inverse hyperbolic sine of x.";
245+
246+
let description = [{
247+
Result is an angle in radians.
248+
249+
Result Type and x must be floating-point or vector(2,3,4,8,16) of
250+
floating-point values.
251+
252+
All of the operands, including the Result Type operand, must be of the
253+
same type.
254+
255+
<!-- End of AutoGen section -->
256+
257+
```
258+
float-scalar-vector-type ::= float-type |
259+
`vector<` integer-literal `x` float-type `>`
260+
asinh-op ::= ssa-id `=` `spirv.CL.asinh` ssa-use `:`
261+
float-scalar-vector-type
262+
```
263+
264+
#### Example:
265+
266+
```mlir
267+
%2 = spirv.CL.asinh %0 : f32
268+
%3 = spirv.CL.asinh %1 : vector<4xf16>
269+
```
270+
}];
271+
}
272+
273+
// -----
274+
275+
def SPIRV_CLAtanOp : SPIRV_CLUnaryArithmeticOp<"atan", 6, SPIRV_Float > {
276+
let summary = "Compute the arc tangent of x.";
277+
278+
let description = [{
279+
Result is an angle in radians.
280+
281+
Result Type and x must be floating-point or vector(2,3,4,8,16) of
282+
floating-point values.
283+
284+
All of the operands, including the Result Type operand, must be of the
285+
same type.
286+
287+
<!-- End of AutoGen section -->
288+
289+
```
290+
float-scalar-vector-type ::= float-type |
291+
`vector<` integer-literal `x` float-type `>`
292+
atan-op ::= ssa-id `=` `spirv.CL.atan` ssa-use `:`
293+
float-scalar-vector-type
294+
```
295+
296+
#### Example:
297+
298+
```mlir
299+
%2 = spirv.CL.atan %0 : f32
300+
%3 = spirv.CL.atan %1 : vector<4xf16>
301+
```
302+
}];
303+
}
304+
305+
// -----
306+
307+
def SPIRV_CLAtanhOp : SPIRV_CLUnaryArithmeticOp<"atanh", 8, SPIRV_Float > {
308+
let summary = "Compute the hyperbolic arc tangent of x.";
309+
310+
let description = [{
311+
Result is an angle in radians.
312+
313+
Result Type and x must be floating-point or vector(2,3,4,8,16) of
314+
floating-point values.
315+
316+
All of the operands, including the Result Type operand, must be of the
317+
same type.
318+
319+
<!-- End of AutoGen section -->
320+
321+
```
322+
float-scalar-vector-type ::= float-type |
323+
`vector<` integer-literal `x` float-type `>`
324+
atanh-op ::= ssa-id `=` `spirv.CL.atanh` ssa-use `:`
325+
float-scalar-vector-type
326+
```
327+
328+
#### Example:
329+
330+
```mlir
331+
%2 = spirv.CL.atanh %0 : f32
332+
%3 = spirv.CL.atanh %1 : vector<4xf16>
141333
```
142334
}];
143335
}
@@ -207,6 +399,36 @@ def SPIRV_CLCosOp : SPIRV_CLUnaryArithmeticOp<"cos", 14, SPIRV_Float> {
207399

208400
// -----
209401

402+
def SPIRV_CLCoshOp : SPIRV_CLUnaryArithmeticOp<"cosh", 15, SPIRV_Float > {
403+
let summary = "Compute the hyperbolic cosine of x radians.";
404+
405+
let description = [{
406+
Result Type and x must be floating-point or vector(2,3,4,8,16) of
407+
floating-point values.
408+
409+
All of the operands, including the Result Type operand, must be of the
410+
same type.
411+
412+
<!-- End of AutoGen section -->
413+
414+
```
415+
float-scalar-vector-type ::= float-type |
416+
`vector<` integer-literal `x` float-type `>`
417+
cosh-op ::= ssa-id `=` `spirv.CL.cosh` ssa-use `:`
418+
float-scalar-vector-type
419+
```
420+
421+
#### Example:
422+
423+
```mlir
424+
%2 = spirv.CL.cosh %0 : f32
425+
%3 = spirv.CL.cosh %1 : vector<4xf16>
426+
```
427+
}];
428+
}
429+
430+
// -----
431+
210432
def SPIRV_CLErfOp : SPIRV_CLUnaryArithmeticOp<"erf", 18, SPIRV_Float> {
211433
let summary = [{
212434
Error function of x encountered in integrating the normal distribution.
@@ -386,7 +608,7 @@ def SPIRV_CLFloorOp : SPIRV_CLUnaryArithmeticOp<"floor", 25, SPIRV_Float> {
386608

387609
```mlir
388610
%2 = spirv.CL.floor %0 : f32
389-
%3 = spirv.CL.ceifloorl %1 : vector<3xf16>
611+
%3 = spirv.CL.floor %1 : vector<3xf16>
390612
```
391613
}];
392614
}
@@ -456,6 +678,37 @@ def SPIRV_CLLogOp : SPIRV_CLUnaryArithmeticOp<"log", 37, SPIRV_Float> {
456678

457679
// -----
458680

681+
def SPIRV_CLMixOp : SPIRV_CLTernaryArithmeticOp<"mix", 99, SPIRV_Float> {
682+
let summary = "Returns the linear blend of x & y implemented as: x + (y - x) * a";
683+
684+
let description = [{
685+
Result Type, x, y and a must be floating-point or vector(2,3,4,8,16) of
686+
floating-point values.
687+
688+
All of the operands, including the Result Type operand, must be of the
689+
same type.
690+
691+
Note: This instruction can be implemented using contractions such as mad
692+
or fma.
693+
694+
<!-- End of AutoGen section -->
695+
696+
```
697+
mix-op ::= ssa-id `=` `spirv.CL.mix` ssa-use, ssa-use, ssa-use `:`
698+
float-scalar-vector-type
699+
```
700+
701+
#### Example:
702+
703+
```mlir
704+
%0 = spirv.CL.mix %a, %b, %c : f32
705+
%1 = spirv.CL.mix %a, %b, %c : vector<3xf16>
706+
```
707+
}];
708+
}
709+
710+
// -----
711+
459712
def SPIRV_CLPowOp : SPIRV_CLBinaryArithmeticOp<"pow", 48, SPIRV_Float> {
460713
let summary = "Compute x to the power y.";
461714

@@ -696,6 +949,36 @@ def SPIRV_CLSinOp : SPIRV_CLUnaryArithmeticOp<"sin", 57, SPIRV_Float> {
696949

697950
// -----
698951

952+
def SPIRV_CLSinhOp : SPIRV_CLUnaryArithmeticOp<"sinh", 59, SPIRV_Float > {
953+
let summary = "Compute hyperbolic sine of x radians.";
954+
955+
let description = [{
956+
Result Type and x must be floating-point or vector(2,3,4,8,16) of
957+
floating-point values.
958+
959+
All of the operands, including the Result Type operand, must be of the
960+
same type.
961+
962+
<!-- End of AutoGen section -->
963+
964+
```
965+
float-scalar-vector-type ::= float-type |
966+
`vector<` integer-literal `x` float-type `>`
967+
sinh-op ::= ssa-id `=` `spirv.CL.sinh` ssa-use `:`
968+
float-scalar-vector-type
969+
```
970+
971+
#### Example:
972+
973+
```mlir
974+
%2 = spirv.CL.sinh %0 : f32
975+
%3 = spirv.CL.sinh %1 : vector<4xf16>
976+
```
977+
}];
978+
}
979+
980+
// -----
981+
699982
def SPIRV_CLSqrtOp : SPIRV_CLUnaryArithmeticOp<"sqrt", 61, SPIRV_Float> {
700983
let summary = "Compute square root of x.";
701984

@@ -726,6 +1009,36 @@ def SPIRV_CLSqrtOp : SPIRV_CLUnaryArithmeticOp<"sqrt", 61, SPIRV_Float> {
7261009

7271010
// -----
7281011

1012+
def SPIRV_CLTanOp : SPIRV_CLUnaryArithmeticOp<"tan", 62, SPIRV_Float > {
1013+
let summary = "Compute tangent of x radians.";
1014+
1015+
let description = [{
1016+
Result Type and x must be floating-point or vector(2,3,4,8,16) of
1017+
floating-point values.
1018+
1019+
All of the operands, including the Result Type operand, must be of the
1020+
same type.
1021+
1022+
<!-- End of AutoGen section -->
1023+
1024+
```
1025+
float-scalar-vector-type ::= float-type |
1026+
`vector<` integer-literal `x` float-type `>`
1027+
tan-op ::= ssa-id `=` `spirv.CL.tan` ssa-use `:`
1028+
float-scalar-vector-type
1029+
```
1030+
1031+
#### Example:
1032+
1033+
```mlir
1034+
%2 = spirv.CL.tan %0 : f32
1035+
%3 = spirv.CL.tan %1 : vector<4xf16>
1036+
```
1037+
}];
1038+
}
1039+
1040+
// -----
1041+
7291042
def SPIRV_CLTanhOp : SPIRV_CLUnaryArithmeticOp<"tanh", 63, SPIRV_Float> {
7301043
let summary = "Compute hyperbolic tangent of x radians.";
7311044

0 commit comments

Comments
 (0)