Skip to content

[mlir][nvvm] Add conversion for math.erfc #129329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

clementval
Copy link
Contributor

Add missing pattern to convert math.erfc operation to __nv_erfcf or __nv_erfc function call.

@llvmbot
Copy link
Member

llvmbot commented Feb 28, 2025

@llvm/pr-subscribers-mlir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Add missing pattern to convert math.erfc operation to __nv_erfcf or __nv_erfc function call.


Full diff: https://github.com/llvm/llvm-project/pull/129329.diff

2 Files Affected:

  • (modified) mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp (+2)
  • (modified) mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir (+13)
diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index 61b73f546b5da..159a6afd4a917 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -540,6 +540,8 @@ void mlir::populateLibDeviceConversionPatterns(
                                    "__nv_cosh");
   populateOpPatterns<math::ErfOp>(converter, patterns, benefit, "__nv_erff",
                                   "__nv_erf");
+  populateOpPatterns<math::ErfcOp>(converter, patterns, benefit, "__nv_erfcf",
+                                   "__nv_erfc");
   populateOpPatterns<math::ExpOp>(converter, patterns, benefit, "__nv_expf",
                                   "__nv_exp", "__nv_fast_expf");
   populateOpPatterns<math::Exp2Op>(converter, patterns, benefit, "__nv_exp2f",
diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
index 7b5b11ec02724..14594cd6badb1 100644
--- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
+++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
@@ -1095,3 +1095,16 @@ gpu.module @test_module_54 {
     return %0, %1, %2, %3, %4, %5 : i1, i1, i1, i1, i1, i1
   }
 }
+
+gpu.module @test_module_55 {
+  // CHECK: llvm.func @__nv_erfcf(f32) -> f32
+  // CHECK: llvm.func @__nv_erfc(f64) -> f64
+  // CHECK-LABEL: func @gpu_erf
+  func.func @gpu_erfc(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
+    %result32 = math.erfc %arg_f32 : f32
+    // CHECK: llvm.call @__nv_erfcf(%{{.*}}) : (f32) -> f32
+    %result64 = math.erfc %arg_f64 : f64
+    // CHECK: llvm.call @__nv_erfc(%{{.*}}) : (f64) -> f64
+    func.return %result32, %result64 : f32, f64
+  }
+}

@llvmbot
Copy link
Member

llvmbot commented Feb 28, 2025

@llvm/pr-subscribers-mlir-gpu

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Add missing pattern to convert math.erfc operation to __nv_erfcf or __nv_erfc function call.


Full diff: https://github.com/llvm/llvm-project/pull/129329.diff

2 Files Affected:

  • (modified) mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp (+2)
  • (modified) mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir (+13)
diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index 61b73f546b5da..159a6afd4a917 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -540,6 +540,8 @@ void mlir::populateLibDeviceConversionPatterns(
                                    "__nv_cosh");
   populateOpPatterns<math::ErfOp>(converter, patterns, benefit, "__nv_erff",
                                   "__nv_erf");
+  populateOpPatterns<math::ErfcOp>(converter, patterns, benefit, "__nv_erfcf",
+                                   "__nv_erfc");
   populateOpPatterns<math::ExpOp>(converter, patterns, benefit, "__nv_expf",
                                   "__nv_exp", "__nv_fast_expf");
   populateOpPatterns<math::Exp2Op>(converter, patterns, benefit, "__nv_exp2f",
diff --git a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
index 7b5b11ec02724..14594cd6badb1 100644
--- a/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
+++ b/mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
@@ -1095,3 +1095,16 @@ gpu.module @test_module_54 {
     return %0, %1, %2, %3, %4, %5 : i1, i1, i1, i1, i1, i1
   }
 }
+
+gpu.module @test_module_55 {
+  // CHECK: llvm.func @__nv_erfcf(f32) -> f32
+  // CHECK: llvm.func @__nv_erfc(f64) -> f64
+  // CHECK-LABEL: func @gpu_erf
+  func.func @gpu_erfc(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
+    %result32 = math.erfc %arg_f32 : f32
+    // CHECK: llvm.call @__nv_erfcf(%{{.*}}) : (f32) -> f32
+    %result64 = math.erfc %arg_f64 : f64
+    // CHECK: llvm.call @__nv_erfc(%{{.*}}) : (f64) -> f64
+    func.return %result32, %result64 : f32, f64
+  }
+}

@clementval clementval merged commit b3e05d5 into llvm:main Feb 28, 2025
14 checks passed
@clementval clementval deleted the mlir_nvvm_erfc branch February 28, 2025 22:51
asb added a commit that referenced this pull request Mar 12, 2025
… memset.pattern lowering

As noted during review of #129329.
frederik-h pushed a commit to frederik-h/llvm-project that referenced this pull request Mar 18, 2025
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
Add missing pattern to convert `math.erfc` operation to `__nv_erfcf` or
`__nv_erfc` function call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants