[Mlir-commits] [mlir] [mlir][gpu] Add support for lowering math.erf to __nv_erf (PR #79848)

David Majnemer llvmlistbot at llvm.org
Mon Jan 29 09:24:16 PST 2024


https://github.com/majnemer updated https://github.com/llvm/llvm-project/pull/79848

>From c7aecf77dff3f845d823195e9294f0a264f1152e Mon Sep 17 00:00:00 2001
From: David Majnemer <david.majnemer at gmail.com>
Date: Mon, 29 Jan 2024 15:18:31 +0000
Subject: [PATCH 1/2] [mlir][gpu] Add support for lowering math.erf to __nv_erf

---
 mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index a7ac2332961ae21..d6a5d8cd74d5f20 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -367,6 +367,7 @@ void mlir::populateGpuToNVVMConversionPatterns(LLVMTypeConverter &converter,
   populateOpPatterns<math::CeilOp>(converter, patterns, "__nv_ceilf",
                                    "__nv_ceil");
   populateOpPatterns<math::CosOp>(converter, patterns, "__nv_cosf", "__nv_cos");
+  populateOpPatterns<math::ErfOp>(converter, patterns, "__nv_erff", "__nv_erf");
   populateOpPatterns<math::ExpOp>(converter, patterns, "__nv_expf", "__nv_exp");
   populateOpPatterns<math::Exp2Op>(converter, patterns, "__nv_exp2f",
                                    "__nv_exp2");

>From 1d5a185ffd11b1742c9917d140361f949a4faf4a Mon Sep 17 00:00:00 2001
From: David Majnemer <david.majnemer at gmail.com>
Date: Mon, 29 Jan 2024 17:23:39 +0000
Subject: [PATCH 2/2] amend! [mlir][gpu] Add support for lowering math.erf to
 __nv_erf

[mlir][gpu] Add support for lowering math.erf to __nv_erf
---
 mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
index 66630d33d118e6e..dd3b6c2080aa21b 100644
--- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
+++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
@@ -627,6 +627,19 @@ gpu.module @test_module_31 {
   }
 }
 
+gpu.module @test_module_32 {
+  // CHECK: llvm.func @__nv_erff(f32) -> f32
+  // CHECK: llvm.func @__nv_erf(f64) -> f64
+  // CHECK-LABEL: func @gpu_erf
+  func.func @gpu_erf(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
+    %result32 = math.erf %arg_f32 : f32
+    // CHECK: llvm.call @__nv_erff(%{{.*}}) : (f32) -> f32
+    %result64 = math.erf %arg_f64 : f64
+    // CHECK: llvm.call @__nv_erf(%{{.*}}) : (f64) -> f64
+    func.return %result32, %result64 : f32, f64
+  }
+}
+
 gpu.module @gpumodule {
 // CHECK-LABEL: func @kernel_with_block_size()
 // CHECK: attributes {gpu.kernel, gpu.known_block_size = array<i32: 128, 1, 1>, nvvm.kernel, nvvm.maxntid = array<i32: 128, 1, 1>} 



More information about the Mlir-commits mailing list