[MLIR] Add atan and atan2 lowerings to CUDA intrinsics

Differential Revision: https://reviews.llvm.org/D93124
This commit is contained in:
Frederik Gossen 2020-12-11 17:54:53 +01:00
parent 5733167f54
commit 75d9a46090
2 changed files with 45 additions and 0 deletions

View File

@ -173,6 +173,10 @@ void mlir::populateGpuToNVVMConversionPatterns(
GPUFuncOpLowering<0>>(converter);
patterns.insert<OpToFuncCallLowering<AbsFOp>>(converter, "__nv_fabsf",
"__nv_fabs");
patterns.insert<OpToFuncCallLowering<AtanOp>>(converter, "__nv_atanf",
"__nv_atan");
patterns.insert<OpToFuncCallLowering<Atan2Op>>(converter, "__nv_atan2f",
"__nv_atan2");
patterns.insert<OpToFuncCallLowering<CeilFOp>>(converter, "__nv_ceilf",
"__nv_ceil");
patterns.insert<OpToFuncCallLowering<CosOp>>(converter, "__nv_cosf",

View File

@ -335,6 +335,47 @@ gpu.module @test_module {
// -----
gpu.module @test_module {
// CHECK: llvm.func @__nv_atanf(!llvm.float) -> !llvm.float
// CHECK: llvm.func @__nv_atan(!llvm.double) -> !llvm.double
// CHECK-LABEL: func @gpu_atan
func @gpu_atan(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64)
-> (f16, f32, f64) {
%result16 = std.atan %arg_f16 : f16
// CHECK: llvm.fpext %{{.*}} : !llvm.half to !llvm.float
// CHECK-NEXT: llvm.call @__nv_atanf(%{{.*}}) : (!llvm.float) -> !llvm.float
// CHECK-NEXT: llvm.fptrunc %{{.*}} : !llvm.float to !llvm.half
%result32 = std.atan %arg_f32 : f32
// CHECK: llvm.call @__nv_atanf(%{{.*}}) : (!llvm.float) -> !llvm.float
%result64 = std.atan %arg_f64 : f64
// CHECK: llvm.call @__nv_atan(%{{.*}}) : (!llvm.double) -> !llvm.double
std.return %result16, %result32, %result64 : f16, f32, f64
}
}
// -----
gpu.module @test_module {
// CHECK: llvm.func @__nv_atan2f(!llvm.float, !llvm.float) -> !llvm.float
// CHECK: llvm.func @__nv_atan2(!llvm.double, !llvm.double) -> !llvm.double
// CHECK-LABEL: func @gpu_atan2
func @gpu_atan2(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64)
-> (f16, f32, f64) {
%result16 = std.atan2 %arg_f16, %arg_f16 : f16
// CHECK: llvm.fpext %{{.*}} : !llvm.half to !llvm.float
// CHECK: llvm.fpext %{{.*}} : !llvm.half to !llvm.float
// CHECK-NEXT: llvm.call @__nv_atan2f(%{{.*}}) : (!llvm.float, !llvm.float) -> !llvm.float
// CHECK-NEXT: llvm.fptrunc %{{.*}} : !llvm.float to !llvm.half
%result32 = std.atan2 %arg_f32, %arg_f32 : f32
// CHECK: llvm.call @__nv_atan2f(%{{.*}}) : (!llvm.float, !llvm.float) -> !llvm.float
%result64 = std.atan2 %arg_f64, %arg_f64 : f64
// CHECK: llvm.call @__nv_atan2(%{{.*}}) : (!llvm.double, !llvm.double) -> !llvm.double
std.return %result16, %result32, %result64 : f16, f32, f64
}
}
// -----
// Test that we handled properly operation with SymbolTable other than module op
gpu.module @test_module {
"test.symbol_scope"() ({