[PATCH] D73471: Fixed tanh lowering from Standard dialect to NVVM and ROCDL.
Julian Gross via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 27 06:31:15 PST 2020
dfki-jugr created this revision.
Herald added subscribers: llvm-commits, liufengdb, herhut, lucyrfox, mgester, arpith-jacob, csigg, antiagainst, shauheen, burmako, jpienaar, rriddle, mehdi_amini, jholewinski.
Herald added a reviewer: nicolasvasilache.
Herald added a project: LLVM.
The tanh lowering from Standard dialect to NVVM and ROCDL was not working.
The conversion pattern are inserted in the lowering files.
The test cases for the lowerings were added in the test files.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D73471
Files:
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
Index: mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
===================================================================
--- mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
+++ mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
@@ -83,6 +83,20 @@
// -----
+gpu.module @kernel_module {
+ // CHECK: llvm.func @_ocml_tanh_f32(!llvm.float) -> !llvm.float
+ // CHECK: llvm.func @_ocml_tanh_f64(!llvm.double) -> !llvm.double
+ // CHECK-LABEL: func @gpu_tanh
+ func @gpu_tanh(%arg_f32 : f32, %arg_f64 : f64) {
+ %result32 = std.tanh %arg_f32 : f32
+ // CHECK: llvm.call @_ocml_tanh_f32(%{{.*}}) : (!llvm.float) -> !llvm.float
+ %result64 = std.tanh %arg_f64 : f64
+ // CHECK: llvm.call @_ocml_tanh_f64(%{{.*}}) : (!llvm.double) -> !llvm.double
+ std.return
+ }
+}
+
+// -----
gpu.module @kernel_module {
// CHECK: llvm.func @_ocml_exp_f32(!llvm.float) -> !llvm.float
// CHECK: llvm.func @_ocml_exp_f64(!llvm.double) -> !llvm.double
Index: mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
===================================================================
--- mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
+++ mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
@@ -156,6 +156,20 @@
// -----
+gpu.module @test_module {
+ // CHECK: llvm.func @__nv_tanhf(!llvm.float) -> !llvm.float
+ // CHECK: llvm.func @__nv_tanh(!llvm.double) -> !llvm.double
+ // CHECK-LABEL: func @gpu_tanh
+ func @gpu_tanh(%arg_f32 : f32, %arg_f64 : f64) {
+ %result32 = std.tanh %arg_f32 : f32
+ // CHECK: llvm.call @__nv_tanhf(%{{.*}}) : (!llvm.float) -> !llvm.float
+ %result64 = std.tanh %arg_f64 : f64
+ // CHECK: llvm.call @__nv_tanh(%{{.*}}) : (!llvm.double) -> !llvm.double
+ std.return
+ }
+}
+
+// -----
gpu.module @test_module {
// CHECK: llvm.func @__nv_expf(!llvm.float) -> !llvm.float
// CHECK: llvm.func @__nv_exp(!llvm.double) -> !llvm.double
Index: mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
===================================================================
--- mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
+++ mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
@@ -58,6 +58,8 @@
"_ocml_cos_f64");
patterns.insert<OpToFuncCallLowering<ExpOp>>(converter, "_ocml_exp_f32",
"_ocml_exp_f64");
+ patterns.insert<OpToFuncCallLowering<TanhOp>>(converter, "_ocml_tanh_f32",
+ "_ocml_tanh_f64");
ConversionTarget target(getContext());
target.addLegalDialect<LLVM::LLVMDialect, ROCDL::ROCDLDialect>();
Index: mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
===================================================================
--- mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -746,6 +746,8 @@
"__nv_cos");
patterns.insert<OpToFuncCallLowering<ExpOp>>(converter, "__nv_expf",
"__nv_exp");
+ patterns.insert<OpToFuncCallLowering<TanhOp>>(converter, "__nv_tanhf",
+ "__nv_tanh");
}
std::unique_ptr<OpPassBase<gpu::GPUModuleOp>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73471.240556.patch
Type: text/x-patch
Size: 3291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200127/70a995b3/attachment.bin>
More information about the llvm-commits
mailing list