Commit 664d2f5b authored by Julian Gross's avatar Julian Gross
Browse files

Add tanh lowering from Standard dialect to NVVM and ROCDL.

Summary:
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.

Reviewers: nicolasvasilache, ftynse, herhut

Reviewed By: ftynse, herhut

Subscribers: merge_guards_bot, ftynse, jholewinski, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, herhut, liufengdb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73471
parent 92600c2e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -746,6 +746,8 @@ void mlir::populateGpuToNVVMConversionPatterns(
                                               "__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>>
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ public:
                                                 "_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>();
+14 −0
Original line number Diff line number Diff line
@@ -156,6 +156,20 @@ gpu.module @test_module {

// -----

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
+14 −0
Original line number Diff line number Diff line
@@ -83,6 +83,20 @@ gpu.module @kernel_module {

// -----

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