Add sqrt lowering from standard to ROCDL

Add a lowering for sqrt from standard dialect to ROCDL.

Differential Revision: https://reviews.llvm.org/D92921
This commit is contained in:
Adrian Kuegel 2020-12-09 10:41:33 +01:00
parent 5bb28fa0f5
commit 09f717b929
2 changed files with 23 additions and 1 deletions

View File

@ -72,7 +72,7 @@ struct LowerGpuOpsToROCDLOpsPass
target.addIllegalDialect<gpu::GPUDialect>();
target.addIllegalOp<LLVM::CosOp, LLVM::ExpOp, LLVM::FAbsOp, LLVM::FCeilOp,
LLVM::FFloorOp, LLVM::LogOp, LLVM::Log10Op,
LLVM::Log2Op, LLVM::SinOp>();
LLVM::Log2Op, LLVM::SinOp, LLVM::SqrtOp>();
target.addIllegalOp<FuncOp>();
target.addLegalDialect<ROCDL::ROCDLDialect>();
// TODO: Remove once we support replacing non-root ops.
@ -115,6 +115,8 @@ void mlir::populateGpuToROCDLConversionPatterns(
"__ocml_log2_f64");
patterns.insert<OpToFuncCallLowering<SinOp>>(converter, "__ocml_sin_f32",
"__ocml_sin_f64");
patterns.insert<OpToFuncCallLowering<SqrtOp>>(converter, "__ocml_sqrt_f32",
"__ocml_sqrt_f64");
patterns.insert<OpToFuncCallLowering<TanhOp>>(converter, "__ocml_tanh_f32",
"__ocml_tanh_f64");
}

View File

@ -228,6 +228,26 @@ gpu.module @test_module {
// -----
gpu.module @test_module {
// CHECK: llvm.func @__ocml_sqrt_f32(!llvm.float) -> !llvm.float
// CHECK: llvm.func @__ocml_sqrt_f64(!llvm.double) -> !llvm.double
// CHECK-LABEL: func @gpu_sqrt
func @gpu_sqrt(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64)
-> (f16, f32, f64) {
%result16 = std.sqrt %arg_f16 : f16
// CHECK: llvm.fpext %{{.*}} : !llvm.half to !llvm.float
// CHECK-NEXT: llvm.call @__ocml_sqrt_f32(%{{.*}}) : (!llvm.float) -> !llvm.float
// CHECK-NEXT: llvm.fptrunc %{{.*}} : !llvm.float to !llvm.half
%result32 = std.sqrt %arg_f32 : f32
// CHECK: llvm.call @__ocml_sqrt_f32(%{{.*}}) : (!llvm.float) -> !llvm.float
%result64 = std.sqrt %arg_f64 : f64
// CHECK: llvm.call @__ocml_sqrt_f64(%{{.*}}) : (!llvm.double) -> !llvm.double
std.return %result16, %result32, %result64 : f16, f32, f64
}
}
// -----
gpu.module @test_module {
// CHECK: llvm.func @__ocml_tanh_f32(!llvm.float) -> !llvm.float
// CHECK: llvm.func @__ocml_tanh_f64(!llvm.double) -> !llvm.double