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<NVVM::NVVMDialect>();
// TODO: Remove once we support replacing non-root ops.
"__nv_rsqrt");
patterns.insert<OpToFuncCallLowering<SinOp>>(converter, "__nv_sinf",
"__nv_sin");
+ patterns.insert<OpToFuncCallLowering<SqrtOp>>(converter, "__nv_sqrtf",
+ "__nv_sqrt");
patterns.insert<OpToFuncCallLowering<TanhOp>>(converter, "__nv_tanhf",
"__nv_tanh");
}
// -----
+gpu.module @test_module {
+ // CHECK: llvm.func @__nv_sqrtf(!llvm.float) -> !llvm.float
+ // CHECK: llvm.func @__nv_sqrt(!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 @__nv_sqrtf(%{{.*}}) : (!llvm.float) -> !llvm.float
+ // CHECK-NEXT: llvm.fptrunc %{{.*}} : !llvm.float to !llvm.half
+ %result32 = std.sqrt %arg_f32 : f32
+ // CHECK: llvm.call @__nv_sqrtf(%{{.*}}) : (!llvm.float) -> !llvm.float
+ %result64 = std.sqrt %arg_f64 : f64
+ // CHECK: llvm.call @__nv_sqrt(%{{.*}}) : (!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"() ({