[Mlir-commits] [mlir] 2860b2c - [mlir] Add Acos, Asin, Atan, Sinh, Cosh, Pow to SPIRVGLSLOps

Lei Zhang llvmlistbot at llvm.org
Thu Sep 3 06:28:41 PDT 2020


Author: Ling, Liyang
Date: 2020-09-03T09:28:34-04:00
New Revision: 2860b2c14b42af1d6204af9a546edc7993680452

URL: https://github.com/llvm/llvm-project/commit/2860b2c14b42af1d6204af9a546edc7993680452
DIFF: https://github.com/llvm/llvm-project/commit/2860b2c14b42af1d6204af9a546edc7993680452.diff

LOG: [mlir] Add Acos, Asin, Atan, Sinh, Cosh, Pow to SPIRVGLSLOps

Reviewed By: mravishankar, antiagainst

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td
    mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir
    mlir/test/Dialect/SPIRV/glslops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td b/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td
index 6064cc304359..70534111b97f 100644
--- a/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td
@@ -265,6 +265,108 @@ def SPV_GLSLTanOp : SPV_GLSLUnaryArithmeticOp<"Tan", 15, SPV_Float16or32> {
 
 // -----
 
+def SPV_GLSLAsinOp : SPV_GLSLUnaryArithmeticOp<"Asin", 16, SPV_Float16or32> {
+  let summary = "Arc Sine of operand in radians";
+
+  let description = [{
+    The standard trigonometric arc sine of x radians.
+
+    Result is an angle, in radians, whose sine is x. The range of result values
+    is [-π / 2, π / 2]. Result is undefined if abs x > 1.
+
+    The operand x must be a scalar or vector whose component type is 16-bit or
+    32-bit floating-point.
+
+    Result Type and the type of x must be the same type. Results are computed
+    per component.
+    <!-- End of AutoGen section -->
+    ```
+    restricted-float-scalar-type ::=  `f16` | `f32`
+    restricted-float-scalar-vector-type ::=
+      restricted-float-scalar-type |
+      `vector<` integer-literal `x` restricted-float-scalar-type `>`
+    asin-op ::= ssa-id `=` `spv.GLSL.Asin` ssa-use `:`
+                restricted-float-scalar-vector-type
+    ```
+    #### Example:
+
+    ```mlir
+    %2 = spv.GLSL.Asin %0 : f32
+    %3 = spv.GLSL.Asin %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
+def SPV_GLSLAcosOp : SPV_GLSLUnaryArithmeticOp<"Acos", 17, SPV_Float16or32> {
+  let summary = "Arc Cosine of operand in radians";
+
+  let description = [{
+    The standard trigonometric arc cosine of x radians.
+
+    Result is an angle, in radians, whose cosine is x. The range of result
+    values is [0, π]. Result is undefined if abs x > 1.
+
+    The operand x must be a scalar or vector whose component type is 16-bit or
+    32-bit floating-point.
+
+    Result Type and the type of x must be the same type. Results are computed
+    per component.
+    <!-- End of AutoGen section -->
+    ```
+    restricted-float-scalar-type ::=  `f16` | `f32`
+    restricted-float-scalar-vector-type ::=
+      restricted-float-scalar-type |
+      `vector<` integer-literal `x` restricted-float-scalar-type `>`
+    acos-op ::= ssa-id `=` `spv.GLSL.Acos` ssa-use `:`
+                restricted-float-scalar-vector-type
+    ```
+    #### Example:
+
+    ```mlir
+    %2 = spv.GLSL.Acos %0 : f32
+    %3 = spv.GLSL.Acos %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
+def SPV_GLSLAtanOp : SPV_GLSLUnaryArithmeticOp<"Atan", 18, SPV_Float16or32> {
+  let summary = "Arc Tangent of operand in radians";
+
+  let description = [{
+    The standard trigonometric arc tangent of x radians.
+
+    Result is an angle, in radians, whose tangent is y_over_x. The range of
+    result values is [-π / 2, π / 2].
+
+    The operand x must be a scalar or vector whose component type is 16-bit or
+    32-bit floating-point.
+
+    Result Type and the type of x must be the same type. Results are computed
+    per component.
+    <!-- End of AutoGen section -->
+    ```
+    restricted-float-scalar-type ::=  `f16` | `f32`
+    restricted-float-scalar-vector-type ::=
+      restricted-float-scalar-type |
+      `vector<` integer-literal `x` restricted-float-scalar-type `>`
+    atan-op ::= ssa-id `=` `spv.GLSL.Atan` ssa-use `:`
+                restricted-float-scalar-vector-type
+    ```
+    #### Example:
+
+    ```mlir
+    %2 = spv.GLSL.Atan %0 : f32
+    %3 = spv.GLSL.Atan %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
 def SPV_GLSLExpOp : SPV_GLSLUnaryArithmeticOp<"Exp", 27, SPV_Float16or32> {
   let summary = "Exponentiation of Operand 1";
 
@@ -513,6 +615,40 @@ def SPV_GLSLSMinOp : SPV_GLSLBinaryArithmeticOp<"SMin", 39, SPV_Integer> {
 
 // -----
 
+def SPV_GLSLPowOp : SPV_GLSLBinaryArithmeticOp<"Pow", 26, SPV_Float16or32> {
+  let summary = "Return x raised to the y power of two operands";
+
+  let description = [{
+    Result is x raised to the y power; x^y.
+
+    Result is undefined if x = 0 and y ≤ 0.
+
+    The operand x and y must be a scalar or vector whose component type is
+    16-bit or 32-bit floating-point.
+
+    Result Type and the type of all operands must be the same type. Results are
+    computed per component.
+
+    <!-- End of AutoGen section -->
+    ```
+    restricted-float-scalar-type ::=  `f16` | `f32`
+    restricted-float-scalar-vector-type ::=
+      restricted-float-scalar-type |
+      `vector<` integer-literal `x` restricted-float-scalar-type `>`
+    pow-op ::= ssa-id `=` `spv.GLSL.Pow` ssa-use `:`
+               restricted-float-scalar-vector-type
+    ```
+    #### Example:
+
+    ```mlir
+    %2 = spv.GLSL.Pow %0, %1 : f32
+    %3 = spv.GLSL.Pow %0, %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
 def SPV_GLSLFSignOp : SPV_GLSLUnaryArithmeticOp<"FSign", 6, SPV_Float> {
   let summary = "Returns the sign of the operand";
 
@@ -602,6 +738,70 @@ def SPV_GLSLSqrtOp : SPV_GLSLUnaryArithmeticOp<"Sqrt", 31, SPV_Float> {
 
 // -----
 
+def SPV_GLSLSinhOp : SPV_GLSLUnaryArithmeticOp<"Sinh", 19, SPV_Float16or32> {
+  let summary = "Hyperbolic sine of operand in radians";
+
+  let description = [{
+    Hyperbolic sine of x radians.
+
+    The operand x must be a scalar or vector whose component type is 16-bit or
+    32-bit floating-point.
+
+    Result Type and the type of x must be the same type. Results are computed
+    per component.
+
+    <!-- End of AutoGen section -->
+    ```
+    restricted-float-scalar-type ::=  `f16` | `f32`
+    restricted-float-scalar-vector-type ::=
+      restricted-float-scalar-type |
+      `vector<` integer-literal `x` restricted-float-scalar-type `>`
+    sinh-op ::= ssa-id `=` `spv.GLSL.Sinh` ssa-use `:`
+                restricted-float-scalar-vector-type
+    ```
+    #### Example:
+
+    ```mlir
+    %2 = spv.GLSL.Sinh %0 : f32
+    %3 = spv.GLSL.Sinh %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
+def SPV_GLSLCoshOp : SPV_GLSLUnaryArithmeticOp<"Cosh", 20, SPV_Float16or32> {
+  let summary = "Hyperbolic cosine of operand in radians";
+
+  let description = [{
+    Hyperbolic cosine of x radians.
+
+    The operand x must be a scalar or vector whose component type is 16-bit or
+    32-bit floating-point.
+
+    Result Type and the type of x must be the same type. Results are computed
+    per component.
+
+    <!-- End of AutoGen section -->
+    ```
+    restricted-float-scalar-type ::=  `f16` | `f32`
+    restricted-float-scalar-vector-type ::=
+      restricted-float-scalar-type |
+      `vector<` integer-literal `x` restricted-float-scalar-type `>`
+    cosh-op ::= ssa-id `=` `spv.GLSL.Cosh` ssa-use `:`
+                restricted-float-scalar-vector-type
+    ```
+    #### Example:
+
+    ```mlir
+    %2 = spv.GLSL.Cosh %0 : f32
+    %3 = spv.GLSL.Cosh %1 : vector<3xf16>
+    ```
+  }];
+}
+
+// -----
+
 def SPV_GLSLTanhOp : SPV_GLSLUnaryArithmeticOp<"Tanh", 21, SPV_Float16or32> {
   let summary = "Hyperbolic tangent of operand in radians";
 

diff  --git a/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir b/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir
index b04195387f12..9909ef3698e1 100644
--- a/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir
@@ -14,6 +14,18 @@ spv.module Logical GLSL450 requires #spv.vce<v1.0, [Shader], []> {
     %4 = spv.GLSL.Sin %arg0 : f32
     // CHECK: {{%.*}} = spv.GLSL.Tan {{%.*}} : f32
     %5 = spv.GLSL.Tan %arg0 : f32
+    // CHECK: {{%.*}} = spv.GLSL.Acos {{%.*}} : f32
+    %6 = spv.GLSL.Acos %arg0 : f32
+    // CHECK: {{%.*}} = spv.GLSL.Asin {{%.*}} : f32
+    %7 = spv.GLSL.Asin %arg0 : f32
+    // CHECK: {{%.*}} = spv.GLSL.Atan {{%.*}} : f32
+    %8 = spv.GLSL.Atan %arg0 : f32
+    // CHECK: {{%.*}} = spv.GLSL.Sinh {{%.*}} : f32
+    %9 = spv.GLSL.Sinh %arg0 : f32
+    // CHECK: {{%.*}} = spv.GLSL.Cosh {{%.*}} : f32
+    %10 = spv.GLSL.Cosh %arg0 : f32
+    // CHECK: {{%.*}} = spv.GLSL.Pow {{%.*}} : f32
+    %11 = spv.GLSL.Pow %arg0, %arg1 : f32
     spv.Return
   }
 }

diff  --git a/mlir/test/Dialect/SPIRV/glslops.mlir b/mlir/test/Dialect/SPIRV/glslops.mlir
index 1e7b18ef71ff..a8df3710a1d8 100644
--- a/mlir/test/Dialect/SPIRV/glslops.mlir
+++ b/mlir/test/Dialect/SPIRV/glslops.mlir
@@ -155,3 +155,102 @@ func @tanvec(%arg0 : vector<3xf16>) -> () {
   %2 = spv.GLSL.Tan %arg0 : vector<3xf16>
   return
 }
+
+//===----------------------------------------------------------------------===//
+// spv.GLSL.Acos
+//===----------------------------------------------------------------------===//
+
+func @acos(%arg0 : f32) -> () {
+  // CHECK: spv.GLSL.Acos {{%.*}} : f32
+  %2 = spv.GLSL.Acos %arg0 : f32
+  return
+}
+
+func @acosvec(%arg0 : vector<3xf16>) -> () {
+  // CHECK: spv.GLSL.Acos {{%.*}} : vector<3xf16>
+  %2 = spv.GLSL.Acos %arg0 : vector<3xf16>
+  return
+}
+
+//===----------------------------------------------------------------------===//
+// spv.GLSL.Asin
+//===----------------------------------------------------------------------===//
+
+func @asin(%arg0 : f32) -> () {
+  // CHECK: spv.GLSL.Asin {{%.*}} : f32
+  %2 = spv.GLSL.Asin %arg0 : f32
+  return
+}
+
+func @asinvec(%arg0 : vector<3xf16>) -> () {
+  // CHECK: spv.GLSL.Asin {{%.*}} : vector<3xf16>
+  %2 = spv.GLSL.Asin %arg0 : vector<3xf16>
+  return
+}
+
+//===----------------------------------------------------------------------===//
+// spv.GLSL.Atan
+//===----------------------------------------------------------------------===//
+
+func @atan(%arg0 : f32) -> () {
+  // CHECK: spv.GLSL.Atan {{%.*}} : f32
+  %2 = spv.GLSL.Atan %arg0 : f32
+  return
+}
+
+func @atanvec(%arg0 : vector<3xf16>) -> () {
+  // CHECK: spv.GLSL.Atan {{%.*}} : vector<3xf16>
+  %2 = spv.GLSL.Atan %arg0 : vector<3xf16>
+  return
+}
+
+//===----------------------------------------------------------------------===//
+// spv.GLSL.Sinh
+//===----------------------------------------------------------------------===//
+
+func @sinh(%arg0 : f32) -> () {
+  // CHECK: spv.GLSL.Sinh {{%.*}} : f32
+  %2 = spv.GLSL.Sinh %arg0 : f32
+  return
+}
+
+func @sinhvec(%arg0 : vector<3xf16>) -> () {
+  // CHECK: spv.GLSL.Sinh {{%.*}} : vector<3xf16>
+  %2 = spv.GLSL.Sinh %arg0 : vector<3xf16>
+  return
+}
+
+//===----------------------------------------------------------------------===//
+// spv.GLSL.Cosh
+//===----------------------------------------------------------------------===//
+
+func @cosh(%arg0 : f32) -> () {
+  // CHECK: spv.GLSL.Cosh {{%.*}} : f32
+  %2 = spv.GLSL.Cosh %arg0 : f32
+  return
+}
+
+func @coshvec(%arg0 : vector<3xf16>) -> () {
+  // CHECK: spv.GLSL.Cosh {{%.*}} : vector<3xf16>
+  %2 = spv.GLSL.Cosh %arg0 : vector<3xf16>
+  return
+}
+
+//===----------------------------------------------------------------------===//
+// spv.GLSL.Pow
+//===----------------------------------------------------------------------===//
+
+func @pow(%arg0 : f32, %arg1 : f32) -> () {
+  // CHECK: spv.GLSL.Pow {{%.*}}, {{%.*}} : f32
+  %2 = spv.GLSL.Pow %arg0, %arg1 : f32
+  return
+}
+
+func @powvec(%arg0 : vector<3xf16>, %arg1 : vector<3xf16>) -> () {
+  // CHECK: spv.GLSL.Pow {{%.*}}, {{%.*}} : vector<3xf16>
+  %2 = spv.GLSL.Pow %arg0, %arg1 : vector<3xf16>
+  return
+}
+
+// -----
+


        


More information about the Mlir-commits mailing list