[Mlir-commits] [mlir] d8fce78 - [mlir][spirv] math.erf OpenCL lowering
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Dec 8 11:00:35 PST 2021
Author: Butygin
Date: 2021-12-08T21:59:46+03:00
New Revision: d8fce785de8e5604ad359360c4f680d9013a5f48
URL: https://github.com/llvm/llvm-project/commit/d8fce785de8e5604ad359360c4f680d9013a5f48
DIFF: https://github.com/llvm/llvm-project/commit/d8fce785de8e5604ad359360c4f680d9013a5f48.diff
LOG: [mlir][spirv] math.erf OpenCL lowering
Differential Revision: https://reviews.llvm.org/D115335
Added:
Modified:
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVOCLOps.td
mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
mlir/test/Target/SPIRV/ocl-ops.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVOCLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVOCLOps.td
index ac773fd146c2c..330a1b99b7ef4 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVOCLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVOCLOps.td
@@ -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";
diff --git a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
index 95eca39d414aa..7e95d33e78dd8 100644
--- a/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
+++ b/mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
@@ -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>,
diff --git a/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir b/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
index 5bfd4e477c21c..7580f1f733c49 100644
--- a/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
+++ b/mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
@@ -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
}
diff --git a/mlir/test/Target/SPIRV/ocl-ops.mlir b/mlir/test/Target/SPIRV/ocl-ops.mlir
index c6c9af28f97d6..62360e0240820 100644
--- a/mlir/test/Target/SPIRV/ocl-ops.mlir
+++ b/mlir/test/Target/SPIRV/ocl-ops.mlir
@@ -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
}
More information about the Mlir-commits
mailing list