[Mlir-commits] [mlir] 07cc771 - Lower math.expm1 to intrinsics in the GPUToNVVM and GPUToROCDL conversions.
Adrian Kuegel
llvmlistbot at llvm.org
Tue Feb 16 01:24:00 PST 2021
Author: Adrian Kuegel
Date: 2021-02-16T10:23:42+01:00
New Revision: 07cc77187a2fb558c5642f267a83b3621498f381
URL: https://github.com/llvm/llvm-project/commit/07cc77187a2fb558c5642f267a83b3621498f381
DIFF: https://github.com/llvm/llvm-project/commit/07cc77187a2fb558c5642f267a83b3621498f381.diff
LOG: Lower math.expm1 to intrinsics in the GPUToNVVM and GPUToROCDL conversions.
This adds the lowering for expm1 for GPU backends.
Differential Revision: https://reviews.llvm.org/D96756
Added:
Modified:
mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index 05b77dba8d11..3deec2242c5e 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -189,6 +189,8 @@ void mlir::populateGpuToNVVMConversionPatterns(
"__nv_cos");
patterns.insert<OpToFuncCallLowering<math::ExpOp>>(converter, "__nv_expf",
"__nv_exp");
+ patterns.insert<OpToFuncCallLowering<math::ExpM1Op>>(converter, "__nv_expm1f",
+ "__nv_expm1");
patterns.insert<OpToFuncCallLowering<FloorFOp>>(converter, "__nv_floorf",
"__nv_floor");
patterns.insert<OpToFuncCallLowering<math::LogOp>>(converter, "__nv_logf",
diff --git a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
index c29cfea2274d..d61c04702b5a 100644
--- a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
+++ b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
@@ -120,6 +120,8 @@ void mlir::populateGpuToROCDLConversionPatterns(
converter, "__ocml_cos_f32", "__ocml_cos_f64");
patterns.insert<OpToFuncCallLowering<math::ExpOp>>(
converter, "__ocml_exp_f32", "__ocml_exp_f64");
+ patterns.insert<OpToFuncCallLowering<math::ExpM1Op>>(
+ converter, "__ocml_expm1_f32", "__ocml_expm1_f64");
patterns.insert<OpToFuncCallLowering<FloorFOp>>(converter, "__ocml_floor_f32",
"__ocml_floor_f64");
patterns.insert<OpToFuncCallLowering<math::LogOp>>(
diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
index 1ade02e67a5b..1aaa4cd2399b 100644
--- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
+++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
@@ -411,6 +411,21 @@ gpu.module @test_module {
// -----
+gpu.module @test_module {
+ // CHECK: llvm.func @__nv_expm1f(f32) -> f32
+ // CHECK: llvm.func @__nv_expm1(f64) -> f64
+ // CHECK-LABEL: func @gpu_expm1
+ func @gpu_expm1(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
+ %result32 = math.expm1 %arg_f32 : f32
+ // CHECK: llvm.call @__nv_expm1f(%{{.*}}) : (f32) -> f32
+ %result64 = math.expm1 %arg_f64 : f64
+ // CHECK: llvm.call @__nv_expm1(%{{.*}}) : (f64) -> f64
+ std.return %result32, %result64 : f32, f64
+ }
+}
+
+// -----
+
gpu.module @test_module {
// CHECK: llvm.func @__nv_powf(f32, f32) -> f32
// CHECK: llvm.func @__nv_pow(f64, f64) -> f64
diff --git a/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir b/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
index 39ced31a7239..901e5ab4ed25 100644
--- a/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
+++ b/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
@@ -143,6 +143,7 @@ gpu.module @test_module {
}
// -----
+
gpu.module @test_module {
// CHECK: llvm.func @__ocml_exp_f32(f32) -> f32
// CHECK: llvm.func @__ocml_exp_f64(f64) -> f64
@@ -183,6 +184,23 @@ gpu.module @test_module {
// -----
+gpu.module @test_module {
+ // CHECK: llvm.func @__ocml_expm1_f32(f32) -> f32
+ // CHECK: llvm.func @__ocml_expm1_f64(f64) -> f64
+ // CHECK-LABEL: func @gpu_expm1
+ func @gpu_expm1(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
+ %expm1_f32 = math.expm1 %arg_f32 : f32
+ // CHECK: llvm.call @__ocml_expm1_f32(%{{.*}}) : (f32) -> f32
+ %result32 = math.expm1 %expm1_f32 : f32
+ // CHECK: llvm.call @__ocml_expm1_f32(%{{.*}}) : (f32) -> f32
+ %result64 = math.expm1 %arg_f64 : f64
+ // CHECK: llvm.call @__ocml_expm1_f64(%{{.*}}) : (f64) -> f64
+ std.return %result32, %result64 : f32, f64
+ }
+}
+
+// -----
+
gpu.module @test_module {
// CHECK: llvm.func @__ocml_log_f32(f32) -> f32
// CHECK: llvm.func @__ocml_log_f64(f64) -> f64
More information about the Mlir-commits
mailing list