[mlir][spirv] math.erf OpenCL lowering

Differential Revision: https://reviews.llvm.org/D115335
This commit is contained in:
Butygin 2021-10-28 19:04:35 +03:00
parent 470c3d8ca3
commit d8fce785de
4 changed files with 42 additions and 5 deletions

View File

@ -86,8 +86,10 @@ class SPV_OCLBinaryArithmeticOp<string mnemonic, int opcode, Type type,
// -----
def SPV_OCLTanhOp : SPV_OCLUnaryArithmeticOp<"tanh", 63, SPV_Float> {
let summary = "Compute hyperbolic tangent of x radians.";
def SPV_OCLErfOp : SPV_OCLUnaryArithmeticOp<"erf", 18, SPV_Float> {
let summary = [{
Error function of x encountered in integrating the normal distribution.
}];
let description = [{
Result Type and x must be floating-point or vector(2,3,4,8,16) of
@ -101,15 +103,15 @@ def SPV_OCLTanhOp : SPV_OCLUnaryArithmeticOp<"tanh", 63, SPV_Float> {
```
float-scalar-vector-type ::= float-type |
`vector<` integer-literal `x` float-type `>`
tanh-op ::= ssa-id `=` `spv.OCL.tanh` ssa-use `:`
erf-op ::= ssa-id `=` `spv.OCL.erf` ssa-use `:`
float-scalar-vector-type
```mlir
#### Example:
```
%2 = spv.OCL.tanh %0 : f32
%3 = spv.OCL.tanh %1 : vector<3xf16>
%2 = spv.OCL.erf %0 : f32
%3 = spv.OCL.erf %1 : vector<3xf16>
```
}];
}
@ -423,6 +425,36 @@ def SPV_OCLSqrtOp : SPV_OCLUnaryArithmeticOp<"sqrt", 61, SPV_Float> {
// -----
def SPV_OCLTanhOp : SPV_OCLUnaryArithmeticOp<"tanh", 63, SPV_Float> {
let summary = "Compute hyperbolic tangent of x radians.";
let description = [{
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.
<!-- End of AutoGen section -->
```
float-scalar-vector-type ::= float-type |
`vector<` integer-literal `x` float-type `>`
tanh-op ::= ssa-id `=` `spv.OCL.tanh` ssa-use `:`
float-scalar-vector-type
```mlir
#### Example:
```
%2 = spv.OCL.tanh %0 : f32
%3 = spv.OCL.tanh %1 : vector<3xf16>
```
}];
}
// -----
def SPV_OCLSAbsOp : SPV_OCLUnaryArithmeticOp<"s_abs", 141, SPV_Integer> {
let summary = "Absolute value of operand";

View File

@ -84,6 +84,7 @@ void populateMathToSPIRVPatterns(SPIRVTypeConverter &typeConverter,
spirv::UnaryAndBinaryOpPattern<math::AbsOp, spirv::OCLFAbsOp>,
spirv::UnaryAndBinaryOpPattern<math::CeilOp, spirv::OCLCeilOp>,
spirv::UnaryAndBinaryOpPattern<math::CosOp, spirv::OCLCosOp>,
spirv::UnaryAndBinaryOpPattern<math::ErfOp, spirv::OCLErfOp>,
spirv::UnaryAndBinaryOpPattern<math::ExpOp, spirv::OCLExpOp>,
spirv::UnaryAndBinaryOpPattern<math::FloorOp, spirv::OCLFloorOp>,
spirv::UnaryAndBinaryOpPattern<math::LogOp, spirv::OCLLogOp>,

View File

@ -28,6 +28,8 @@ func @float32_unary_scalar(%arg0: f32) {
%9 = math.ceil %arg0 : f32
// CHECK: spv.OCL.floor %{{.*}}: f32
%10 = math.floor %arg0 : f32
// CHECK: spv.OCL.erf %{{.*}}: f32
%11 = math.erf %arg0 : f32
return
}

View File

@ -22,6 +22,8 @@ spv.module Physical64 OpenCL requires #spv.vce<v1.0, [Kernel, Addresses], []> {
%8 = spv.OCL.pow %arg0, %arg0 : f32
// CHECK: {{%.*}} = spv.OCL.rsqrt {{%.*}} : f32
%9 = spv.OCL.rsqrt %arg0 : f32
// CHECK: {{%.*}} = spv.OCL.erf {{%.*}} : f32
%10 = spv.OCL.erf %arg0 : f32
spv.Return
}