[llvm-branch-commits] [mlir] ada4c7a - Add rsqrt lowering from standard to ROCDL.

Adrian Kuegel via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Dec 11 04:30:10 PST 2020


Author: Adrian Kuegel
Date: 2020-12-11T13:18:57+01:00
New Revision: ada4c7a351710f05a02c84f5643de925aa4dedfc

URL: https://github.com/llvm/llvm-project/commit/ada4c7a351710f05a02c84f5643de925aa4dedfc
DIFF: https://github.com/llvm/llvm-project/commit/ada4c7a351710f05a02c84f5643de925aa4dedfc.diff

LOG: Add rsqrt lowering from standard to ROCDL.

Add a lowering for rsqrt from standard dialect to ROCDL.

Differential Revision: https://reviews.llvm.org/D93011

Added: 
    

Modified: 
    mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
    mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
index 4d81e2cc1f78..e8c8a1fc3eb9 100644
--- a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
+++ b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
@@ -113,6 +113,8 @@ void mlir::populateGpuToROCDLConversionPatterns(
                                                  "__ocml_log10_f64");
   patterns.insert<OpToFuncCallLowering<Log2Op>>(converter, "__ocml_log2_f32",
                                                 "__ocml_log2_f64");
+  patterns.insert<OpToFuncCallLowering<RsqrtOp>>(converter, "__ocml_rsqrt_f32",
+                                                 "__ocml_rsqrt_f64");
   patterns.insert<OpToFuncCallLowering<SinOp>>(converter, "__ocml_sin_f32",
                                                "__ocml_sin_f64");
   patterns.insert<OpToFuncCallLowering<SqrtOp>>(converter, "__ocml_sqrt_f32",

diff  --git a/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir b/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
index 759d2f2d2d70..acc3826cacce 100644
--- a/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
+++ b/mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
@@ -228,6 +228,26 @@ gpu.module @test_module {
 
 // -----
 
+gpu.module @test_module {
+  // CHECK: llvm.func @__ocml_rsqrt_f32(!llvm.float) -> !llvm.float
+  // CHECK: llvm.func @__ocml_rsqrt_f64(!llvm.double) -> !llvm.double
+  // CHECK-LABEL: func @gpu_rsqrt
+  func @gpu_rsqrt(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64)
+      -> (f16, f32, f64) {
+    %result16 = std.rsqrt %arg_f16 : f16
+    // CHECK: llvm.fpext %{{.*}} : !llvm.half to !llvm.float
+    // CHECK-NEXT: llvm.call @__ocml_rsqrt_f32(%{{.*}}) : (!llvm.float) -> !llvm.float
+    // CHECK-NEXT: llvm.fptrunc %{{.*}} : !llvm.float to !llvm.half
+    %result32 = std.rsqrt %arg_f32 : f32
+    // CHECK: llvm.call @__ocml_rsqrt_f32(%{{.*}}) : (!llvm.float) -> !llvm.float
+    %result64 = std.rsqrt %arg_f64 : f64
+    // CHECK: llvm.call @__ocml_rsqrt_f64(%{{.*}}) : (!llvm.double) -> !llvm.double
+    std.return %result16, %result32, %result64 : f16, f32, f64
+  }
+}
+
+// -----
+
 gpu.module @test_module {
   // CHECK: llvm.func @__ocml_sqrt_f32(!llvm.float) -> !llvm.float
   // CHECK: llvm.func @__ocml_sqrt_f64(!llvm.double) -> !llvm.double


        


More information about the llvm-branch-commits mailing list