[Mlir-commits] [mlir] 9f58181 - Add Expm1 op to the math dialect.

Adrian Kuegel llvmlistbot at llvm.org
Mon Feb 15 23:34:22 PST 2021


Author: Adrian Kuegel
Date: 2021-02-16T08:33:37+01:00
New Revision: 9f581815ae4d5df7453f0b3bea845c0ba508c91e

URL: https://github.com/llvm/llvm-project/commit/9f581815ae4d5df7453f0b3bea845c0ba508c91e
DIFF: https://github.com/llvm/llvm-project/commit/9f581815ae4d5df7453f0b3bea845c0ba508c91e.diff

LOG: Add Expm1 op to the math dialect.

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Math/IR/MathOps.td
    mlir/test/Dialect/Math/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Math/IR/MathOps.td b/mlir/include/mlir/Dialect/Math/IR/MathOps.td
index a33fa13ac2cb..0ac5c0e05706 100644
--- a/mlir/include/mlir/Dialect/Math/IR/MathOps.td
+++ b/mlir/include/mlir/Dialect/Math/IR/MathOps.td
@@ -244,6 +244,40 @@ def Exp2Op : FloatUnaryOp<"exp2"> {
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// ExpM1Op
+//===----------------------------------------------------------------------===//
+
+def ExpM1Op : FloatUnaryOp<"expm1"> {
+  let summary = "base-e exponential of the specified value minus 1";
+  let description = [{
+    Syntax:
+
+    ```
+    operation ::= ssa-id `=` `math.expm1` ssa-use `:` type
+    ```
+
+    expm1(x) := exp(x) - 1
+
+    The `expm1` operation 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 natural exponential minus 1.
+    %a = math.expm1 %b : f64
+
+    // SIMD vector element-wise natural exponential minus 1.
+    %f = math.expm1 %g : vector<4xf32>
+
+    // Tensor element-wise natural exponential minus 1.
+    %x = math.expm1 %y : tensor<4x?xf8>
+    ```
+  }];
+}
+
 //===----------------------------------------------------------------------===//
 // LogOp
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/test/Dialect/Math/ops.mlir b/mlir/test/Dialect/Math/ops.mlir
index cfdf0bf76228..186fcff050e9 100644
--- a/mlir/test/Dialect/Math/ops.mlir
+++ b/mlir/test/Dialect/Math/ops.mlir
@@ -74,6 +74,18 @@ func @exp2(%f: f32, %v: vector<4xf32>, %t: tensor<4x4x?xf32>) {
   return
 }
 
+// CHECK-LABEL: func @expm1(
+// CHECK-SAME:            %[[F:.*]]: f32, %[[V:.*]]: vector<4xf32>, %[[T:.*]]: tensor<4x4x?xf32>)
+func @expm1(%f: f32, %v: vector<4xf32>, %t: tensor<4x4x?xf32>) {
+  // CHECK: %{{.*}} = math.expm1 %[[F]] : f32
+  %0 = math.expm1 %f : f32
+  // CHECK: %{{.*}} = math.expm1 %[[V]] : vector<4xf32>
+  %1 = math.expm1 %v : vector<4xf32>
+  // CHECK: %{{.*}} = math.expm1 %[[T]] : tensor<4x4x?xf32>
+  %2 = math.expm1 %t : tensor<4x4x?xf32>
+  return
+}
+
 // CHECK-LABEL: func @log(
 // CHECK-SAME:            %[[F:.*]]: f32, %[[V:.*]]: vector<4xf32>, %[[T:.*]]: tensor<4x4x?xf32>)
 func @log(%f: f32, %v: vector<4xf32>, %t: tensor<4x4x?xf32>) {


        


More information about the Mlir-commits mailing list