[Mlir-commits] [mlir] 43b89ec - [mlir] Add sine operation to Standard dialect.
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Apr 30 22:16:16 PDT 2020
Author: MaheshRavishankar
Date: 2020-04-30T22:15:42-07:00
New Revision: 43b89ecdb9a7528b8697ec596cd15057e6875896
URL: https://github.com/llvm/llvm-project/commit/43b89ecdb9a7528b8697ec596cd15057e6875896
DIFF: https://github.com/llvm/llvm-project/commit/43b89ecdb9a7528b8697ec596cd15057e6875896.diff
LOG: [mlir] Add sine operation to Standard dialect.
Also add lowering of sine operation to SPIR-V dialect.
Differential Revision: https://reviews.llvm.org/D79102
Added:
Modified:
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
mlir/test/IR/core-ops.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
index 1f1658f9695f..2d7ca0f48fdb 100644
--- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
+++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
@@ -1238,6 +1238,36 @@ def CosOp : FloatUnaryOp<"cos"> {
}];
}
+def SinOp : FloatUnaryOp<"sin"> {
+ let summary = "sine of the specified value";
+ let description = [{
+ Syntax:
+
+ ```
+ operation ::= ssa-id `=` `std.sin` ssa-use `:` type
+ ```
+
+ The `sin` operation computes the sine of a given value. It takes one
+ operand and returns one result of the same type. This type may be a float
+ scalar type, a vector whose element type is float, or a tensor of floats.
+ It has no standard attributes.
+
+ Example:
+
+ ```mlir
+ // Scalar sine value.
+ %a = sin %b : f64
+
+ // SIMD vector element-wise sine value.
+ %f = sin %g : vector<4xf32>
+
+ // Tensor element-wise sine value.
+ %x = sin %y : tensor<4x?xf8>
+ ```
+ }];
+}
+
+
//===----------------------------------------------------------------------===//
// DeallocOp
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp b/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
index eb0421d2fae6..3120f45d7992 100644
--- a/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
+++ b/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRV.cpp
@@ -757,6 +757,7 @@ void populateStandardToSPIRVPatterns(MLIRContext *context,
UnaryAndBinaryOpPattern<SignedRemIOp, spirv::SRemOp>,
UnaryAndBinaryOpPattern<SignedShiftRightOp,
spirv::ShiftRightArithmeticOp>,
+ UnaryAndBinaryOpPattern<SinOp, spirv::GLSLSinOp>,
UnaryAndBinaryOpPattern<SqrtOp, spirv::GLSLSqrtOp>,
UnaryAndBinaryOpPattern<SubFOp, spirv::FSubOp>,
UnaryAndBinaryOpPattern<SubIOp, spirv::ISubOp>,
diff --git a/mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir b/mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
index d2ede0c8024e..41cc7c60ca59 100644
--- a/mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
+++ b/mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
@@ -52,6 +52,8 @@ func @float32_unary_scalar(%arg0: f32) {
%7 = sqrt %arg0 : f32
// CHECK: spv.GLSL.Tanh %{{.*}}: f32
%8 = tanh %arg0 : f32
+ // CHECK: spv.GLSL.Sin %{{.*}}: f32
+ %9 = sin %arg0 : f32
return
}
diff --git a/mlir/test/IR/core-ops.mlir b/mlir/test/IR/core-ops.mlir
index d0a27ec68468..69ba75ab481f 100644
--- a/mlir/test/IR/core-ops.mlir
+++ b/mlir/test/IR/core-ops.mlir
@@ -515,6 +515,18 @@ func @standard_instrs(tensor<4x4x?xf32>, f32, i32, index, i64, f16) {
// CHECK: %{{[0-9]+}} = rsqrt %arg1 : f32
%145 = rsqrt %f : f32
+ // CHECK: %{{[0-9]+}} = sin %arg1 : f32
+ %146 = "std.sin"(%f) : (f32) -> f32
+
+ // CHECK: %{{[0-9]+}} = sin %arg1 : f32
+ %147 = sin %f : f32
+
+ // CHECK: %{{[0-9]+}} = sin %cst_8 : vector<4xf32>
+ %148 = sin %vcf32 : vector<4xf32>
+
+ // CHECK: %{{[0-9]+}} = sin %arg0 : tensor<4x4x?xf32>
+ %149 = sin %t : tensor<4x4x?xf32>
+
return
}
More information about the Mlir-commits
mailing list