From 9c1c825b724928130a4e73a24d12943de1fd0581 Mon Sep 17 00:00:00 2001 From: natashaknk Date: Fri, 7 Feb 2020 16:35:36 -0500 Subject: [PATCH] [mlir][spirv] Adding sin op in the GLSL extension Differential Revision: https://reviews.llvm.org/D74151 --- mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td | 32 ++++++++++++++++++++++ .../test/Dialect/SPIRV/Serialization/glsl-ops.mlir | 4 +++ mlir/test/Dialect/SPIRV/glslops.mlir | 32 ++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td b/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td index b3324df..faf114c 100644 --- a/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td +++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVGLSLOps.td @@ -200,6 +200,38 @@ def SPV_GLSLCosOp : SPV_GLSLUnaryArithmeticOp<"Cos", 14, SPV_Float16or32> { // ----- +def SPV_GLSLSinOp : SPV_GLSLUnaryArithmeticOp<"Sin", 13, SPV_Float16or32> { + let summary = "Sine of operand in radians"; + + let description = [{ + The standard trigonometric 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. + + ### Custom assembly format + ``` + restricted-float-scalar-type ::= `f16` | `f32` + restricted-float-scalar-vector-type ::= + restricted-float-scalar-type | + `vector<` integer-literal `x` restricted-float-scalar-type `>` + sin-op ::= ssa-id `=` `spv.GLSL.Sin` ssa-use `:` + restricted-float-scalar-vector-type + ``` + For example: + + ``` + %2 = spv.GLSL.Sin %0 : f32 + %3 = spv.GLSL.Sin %1 : vector<3xf16> + ``` + }]; +} + +// ----- + def SPV_GLSLExpOp : SPV_GLSLUnaryArithmeticOp<"Exp", 27, SPV_Float16or32> { let summary = "Exponentiation of Operand 1"; diff --git a/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir b/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir index 2ebe188..d2582a9 100644 --- a/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir +++ b/mlir/test/Dialect/SPIRV/Serialization/glsl-ops.mlir @@ -8,6 +8,10 @@ spv.module "Logical" "GLSL450" { %1 = spv.GLSL.FMax %arg0, %arg1 : f32 // CHECK: {{%.*}} = spv.GLSL.Sqrt {{%.*}} : f32 %2 = spv.GLSL.Sqrt %arg0 : f32 + // CHECK: {{%.*}} = spv.GLSL.Cos {{%.*}} : f32 + %3 = spv.GLSL.Cos %arg0 : f32 + // CHECK: {{%.*}} = spv.GLSL.Sin {{%.*}} : f32 + %4 = spv.GLSL.Sin %arg0 : f32 spv.Return } } diff --git a/mlir/test/Dialect/SPIRV/glslops.mlir b/mlir/test/Dialect/SPIRV/glslops.mlir index e3a3ca5..8e06df3 100644 --- a/mlir/test/Dialect/SPIRV/glslops.mlir +++ b/mlir/test/Dialect/SPIRV/glslops.mlir @@ -107,3 +107,35 @@ func @sqrtvec(%arg0 : vector<3xf16>) -> () { %2 = spv.GLSL.Sqrt %arg0 : vector<3xf16> return } + +//===----------------------------------------------------------------------===// +// spv.GLSL.Cos +//===----------------------------------------------------------------------===// + +func @cos(%arg0 : f32) -> () { + // CHECK: spv.GLSL.Cos {{%.*}} : f32 + %2 = spv.GLSL.Cos %arg0 : f32 + return +} + +func @cosvec(%arg0 : vector<3xf16>) -> () { + // CHECK: spv.GLSL.Cos {{%.*}} : vector<3xf16> + %2 = spv.GLSL.Cos %arg0 : vector<3xf16> + return +} + +//===----------------------------------------------------------------------===// +// spv.GLSL.Sin +//===----------------------------------------------------------------------===// + +func @sin(%arg0 : f32) -> () { + // CHECK: spv.GLSL.Sin {{%.*}} : f32 + %2 = spv.GLSL.Sin %arg0 : f32 + return +} + +func @sinvec(%arg0 : vector<3xf16>) -> () { + // CHECK: spv.GLSL.Sin {{%.*}} : vector<3xf16> + %2 = spv.GLSL.Sin %arg0 : vector<3xf16> + return +} -- 2.7.4