[Mlir-commits] [mlir] 2ea5e7b - [mlir] SPIR-V: add sin, cos, log, sqrt OCL ops

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Oct 18 10:50:22 PDT 2021


Author: Caitlyn Cano
Date: 2021-10-18T20:48:59+03:00
New Revision: 2ea5e7ba570a96df88516d749c8030013824e021

URL: https://github.com/llvm/llvm-project/commit/2ea5e7ba570a96df88516d749c8030013824e021
DIFF: https://github.com/llvm/llvm-project/commit/2ea5e7ba570a96df88516d749c8030013824e021.diff

LOG: [mlir] SPIR-V: add sin, cos, log, sqrt OCL ops

Differential Revision: https://reviews.llvm.org/D111884

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/SPIRV/IR/SPIRVOCLOps.td
    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 fda4a0ce3c6ef..ecbe2b63356dd 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVOCLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVOCLOps.td
@@ -78,6 +78,36 @@ class SPV_OCLBinaryArithmeticOp<string mnemonic, int opcode, Type type,
 
 // -----
 
+def SPV_OCLCosOp : SPV_OCLUnaryArithmeticOp<"cos", 14, SPV_Float> {
+  let summary = "Compute the cosine 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 `>`
+    abs-op ::= ssa-id `=` `spv.OCL.cos` ssa-use `:`
+               float-scalar-vector-type
+    ```mlir
+
+    #### Example:
+
+    ```
+    %2 = spv.OCL.cos %0 : f32
+    %3 = spv.OCL.cos %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
 def SPV_OCLExpOp : SPV_OCLUnaryArithmeticOp<"exp", 19, SPV_Float> {
   let summary = "Exponentiation of Operand 1";
 
@@ -138,6 +168,96 @@ def SPV_OCLFAbsOp : SPV_OCLUnaryArithmeticOp<"fabs", 23, SPV_Float> {
 
 // -----
 
+def SPV_OCLLogOp : SPV_OCLUnaryArithmeticOp<"log", 37, SPV_Float> {
+  let summary = "Compute the natural logarithm of x.";
+
+  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 `>`
+    abs-op ::= ssa-id `=` `spv.OCL.log` ssa-use `:`
+               float-scalar-vector-type
+    ```mlir
+
+    #### Example:
+
+    ```
+    %2 = spv.OCL.log %0 : f32
+    %3 = spv.OCL.log %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
+def SPV_OCLSinOp : SPV_OCLUnaryArithmeticOp<"sin", 57, SPV_Float> {
+  let summary = "Compute sine 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 `>`
+    abs-op ::= ssa-id `=` `spv.OCL.sin` ssa-use `:`
+               float-scalar-vector-type
+    ```mlir
+
+    #### Example:
+
+    ```
+    %2 = spv.OCL.sin %0 : f32
+    %3 = spv.OCL.sin %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
+def SPV_OCLSqrtOp : SPV_OCLUnaryArithmeticOp<"sqrt", 61, SPV_Float> {
+  let summary = "Compute square root of x.";
+
+  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 `>`
+    abs-op ::= ssa-id `=` `spv.OCL.sqrt` ssa-use `:`
+               float-scalar-vector-type
+    ```mlir
+
+    #### Example:
+
+    ```
+    %2 = spv.OCL.sqrt %0 : f32
+    %3 = spv.OCL.sqrt %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
 def SPV_OCLSAbsOp : SPV_OCLUnaryArithmeticOp<"s_abs", 141, SPV_Integer> {
   let summary = "Absolute value of operand";
 

diff  --git a/mlir/test/Target/SPIRV/ocl-ops.mlir b/mlir/test/Target/SPIRV/ocl-ops.mlir
index 2fd0476ad3612..37ab7d90e2bc5 100644
--- a/mlir/test/Target/SPIRV/ocl-ops.mlir
+++ b/mlir/test/Target/SPIRV/ocl-ops.mlir
@@ -6,6 +6,14 @@ spv.module Physical64 OpenCL requires #spv.vce<v1.0, [Kernel, Addresses], []> {
     %0 = spv.OCL.exp %arg0 : f32
     // CHECK: {{%.*}} = spv.OCL.fabs {{%.*}} : f32
     %1 = spv.OCL.fabs %arg0 : f32
+    // CHECK: {{%.*}} = spv.OCL.sin {{%.*}} : f32
+    %2 = spv.OCL.sin %arg0 : f32
+    // CHECK: {{%.*}} = spv.OCL.cos {{%.*}} : f32
+    %3 = spv.OCL.cos %arg0 : f32
+    // CHECK: {{%.*}} = spv.OCL.log {{%.*}} : f32
+    %4 = spv.OCL.log %arg0 : f32
+    // CHECK: {{%.*}} = spv.OCL.sqrt {{%.*}} : f32
+    %5 = spv.OCL.sqrt %arg0 : f32
     spv.Return
   }
 


        


More information about the Mlir-commits mailing list