[flang-commits] [flang] [flang][cuda] Add interfaces for __dsqrt_rn and __dsqrt_rz (PR #153624)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Thu Aug 14 14:48:45 PDT 2025
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/153624
>From 9171f1840979efcdc89499c5660bcaf4cd8a4d0f Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 14 Aug 2025 10:23:00 -0700
Subject: [PATCH] [flang][cuda] Add interfaces for __dsqrt_rn and __dsqrt_rz
---
flang/module/cudadevice.f90 | 14 ++++++++++++++
flang/test/Lower/CUDA/cuda-device-proc.cuf | 4 ----
flang/test/Lower/CUDA/cuda-libdevice.cuf | 15 +++++++++++++++
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90
index 4f3625a8b07af..767389430a923 100644
--- a/flang/module/cudadevice.f90
+++ b/flang/module/cudadevice.f90
@@ -716,6 +716,13 @@ attributes(device) real(8) function sinpi(x) bind(c,name='__nv_sinpi')
end function
end interface
+ interface __dsqrt_rn
+ attributes(device) double precision function __dsqrt_rn(x) bind(c, name='__nv_dsqrt_rn')
+ !dir$ ignore_tkr (d) x
+ double precision, value :: x
+ end function
+ end interface
+
interface __dsqrt_ru
attributes(device) double precision function __dsqrt_ru(x) bind(c, name='__nv_dsqrt_ru')
!dir$ ignore_tkr (d) x
@@ -723,6 +730,13 @@ attributes(device) real(8) function sinpi(x) bind(c,name='__nv_sinpi')
end function
end interface
+ interface __dsqrt_rz
+ attributes(device) double precision function __dsqrt_rz(x) bind(c, name='__nv_dsqrt_rz')
+ !dir$ ignore_tkr (d) x
+ double precision, value :: x
+ end function
+ end interface
+
interface __ddiv_rn
attributes(device) double precision function __ddiv_rn(x,y) bind(c, name='__nv_ddiv_rn')
!dir$ ignore_tkr (d) x, (d) y
diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf
index ab90dec790046..a6e8c69b2e52e 100644
--- a/flang/test/Lower/CUDA/cuda-device-proc.cuf
+++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf
@@ -82,8 +82,6 @@ attributes(global) subroutine devsub()
ai = __mul24(ai, ai)
ai = __umul24(ai, ai)
af = __powf(af, af)
- ad = __dsqrt_rd(ad)
- ad = __dsqrt_ru(ad)
ad = __ull2double_rd(al)
ad = __ull2double_rn(al)
ad = __ull2double_ru(al)
@@ -162,8 +160,6 @@ end
! CHECK: %{{.*}} = fir.call @__nv_mul24(%{{.*}}, %{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i32, i32) -> i32
! CHECK: %{{.*}} = fir.call @__nv_umul24(%{{.*}}, %{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i32, i32) -> i32
! CHECK: %{{.*}} = fir.call @__nv_powf(%{{.*}}, %{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f32, f32) -> f32
-! CHECK: %{{.*}} = fir.call @__nv_dsqrt_rd(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> f64
-! CHECK: %{{.*}} = fir.call @__nv_dsqrt_ru(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> f64
! CHECK: %{{.*}} = fir.call @__nv_ull2double_rd(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i64) -> f64
! CHECK: %{{.*}} = fir.call @__nv_ull2double_rn(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i64) -> f64
! CHECK: %{{.*}} = fir.call @__nv_ull2double_ru(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i64) -> f64
diff --git a/flang/test/Lower/CUDA/cuda-libdevice.cuf b/flang/test/Lower/CUDA/cuda-libdevice.cuf
index 10e4c2757d825..2f7fc53cd64df 100644
--- a/flang/test/Lower/CUDA/cuda-libdevice.cuf
+++ b/flang/test/Lower/CUDA/cuda-libdevice.cuf
@@ -19,3 +19,18 @@ end subroutine
! CHECK-LABEL: _QPtest_usad
! CHECK: %{{.*}} = fir.call @__nv_usad(%{{.*}}, %{{.*}}, %{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i32, i32, i32) -> i32
+
+attributes(global) subroutine test_dsqrt_rX()
+ double precision :: res
+ double precision :: p
+ res = __dsqrt_rd(p)
+ res = __dsqrt_rn(p)
+ res = __dsqrt_ru(p)
+ res = __dsqrt_rz(p)
+end subroutine
+
+! CHECK-LABEL: _QPtest_dsqrt_rx
+! CHECK: %{{.*}} = fir.call @__nv_dsqrt_rd(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> f64
+! CHECK: %{{.*}} = fir.call @__nv_dsqrt_rn(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> f64
+! CHECK: %{{.*}} = fir.call @__nv_dsqrt_ru(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> f64
+! CHECK: %{{.*}} = fir.call @__nv_dsqrt_rz(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> f64
More information about the flang-commits
mailing list