Skip to content

Commit f8d8b4d

Browse files
committed
[MLIR][ROCDL] Add conversion of math.erfc to AMD GPU library calls
This patch adds a pattern to convert the math.erfc operation to AMD GPU library calls.
1 parent 4277c21 commit f8d8b4d

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

flang/test/Lower/OpenMP/math-amdgpu.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ subroutine omp_erf_f64(x, y)
9999
y = erf(x)
100100
end subroutine omp_erf_f64
101101

102+
subroutine omp_erfc_f32(x, y)
103+
!$omp declare target
104+
real :: x, y
105+
!CHECK: call float @__ocml_erfc_f32(float {{.*}})
106+
y = erfc(x)
107+
end subroutine omp_erfc_f32
108+
109+
subroutine omp_erfc_f64(x, y)
110+
!$omp declare target
111+
real(8) :: x, y
112+
!CHECK: call double @__ocml_erfc_f64(double {{.*}})
113+
y = erfc(x)
114+
end subroutine omp_erfc_f64
115+
102116
subroutine omp_exp_f32(x, y)
103117
!$omp declare target
104118
real :: x, y

mlir/lib/Conversion/MathToROCDL/MathToROCDL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ void mlir::populateMathToROCDLConversionPatterns(
113113
"__ocml_tan_f64", "__ocml_tan_f16");
114114
populateOpPatterns<math::ErfOp>(converter, patterns, "__ocml_erf_f32",
115115
"__ocml_erf_f64", "__ocml_erf_f16");
116+
populateOpPatterns<math::ErfcOp>(converter, patterns, "__ocml_erfc_f32",
117+
"__ocml_erfc_f64", "__ocml_erfc_f16");
116118
populateOpPatterns<math::FPowIOp>(converter, patterns, "__ocml_pown_f32",
117119
"__ocml_pown_f64", "__ocml_pown_f16");
118120
// Single arith pattern that needs a ROCDL call, probably not

mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,24 @@ module @test_module {
462462

463463
// -----
464464

465+
module @test_module {
466+
// CHECK: llvm.func @__ocml_erfc_f16(f16) -> f16
467+
// CHECK: llvm.func @__ocml_erfc_f32(f32) -> f32
468+
// CHECK: llvm.func @__ocml_erfc_f64(f64) -> f64
469+
// CHECK-LABEL: func @math_erfc
470+
func.func @math_erfc(%arg_f16 : f16, %arg_f32 : f32, %arg_f64 : f64) -> (f16, f32, f64) {
471+
%result16 = math.erfc %arg_f16 : f16
472+
// CHECK: llvm.call @__ocml_erfc_f16(%{{.*}}) : (f16) -> f16
473+
%result32 = math.erfc %arg_f32 : f32
474+
// CHECK: llvm.call @__ocml_erfc_f32(%{{.*}}) : (f32) -> f32
475+
%result64 = math.erfc %arg_f64 : f64
476+
// CHECK: llvm.call @__ocml_erfc_f64(%{{.*}}) : (f64) -> f64
477+
func.return %result16, %result32, %result64 : f16, f32, f64
478+
}
479+
}
480+
481+
// -----
482+
465483
module @test_module {
466484
// CHECK: llvm.func @__ocml_sin_f16(f16) -> f16
467485
// CHECK: llvm.func @__ocml_sin_f32(f32) -> f32

0 commit comments

Comments
 (0)