[flang-commits] [flang] [flang][cuda] Add bind name for __float2half_rn and __half2float (PR #153298)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Wed Aug 13 13:50:26 PDT 2025


https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/153298

>From 83caa586b05569f9ddf211a1e8f7197d92bc1a5a Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 12 Aug 2025 14:21:36 -0700
Subject: [PATCH 1/2] [flang][cuda] Add bind name for __float2half_rn and
 __half2float

---
 flang/test/Lower/CUDA/cuda-device-proc.cuf | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf
index f9ec0c773fe80..dc2ffbe89f1e0 100644
--- a/flang/test/Lower/CUDA/cuda-device-proc.cuf
+++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf
@@ -5,6 +5,7 @@
 attributes(global) subroutine devsub()
   implicit none
   integer :: ret
+  real(2) :: r2
   real(4) :: af
   real(8) :: ad
   integer(4) :: ai
@@ -83,6 +84,8 @@ attributes(global) subroutine devsub()
   af = __powf(af, af)
   ad = __dsqrt_rd(ad)
   ad = __dsqrt_ru(ad)
+  r2 = __float2half_rn(af)
+  af = __half2float(r2)
 end
 
 ! CHECK-LABEL: func.func @_QPdevsub() attributes {cuf.proc_attr = #cuf.cuda_proc<global>}

>From 9a2a588c74c965ba8e6feebc864816cfebd74c02 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Wed, 13 Aug 2025 13:50:10 -0700
Subject: [PATCH 2/2] Add missing checks

---
 flang/test/Lower/CUDA/cuda-device-proc.cuf | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf
index dc2ffbe89f1e0..7957e8b5b0be0 100644
--- a/flang/test/Lower/CUDA/cuda-device-proc.cuf
+++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf
@@ -156,6 +156,8 @@ end
 ! 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_float2half_rn(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f32) -> f16
+! CHECK: %{{.*}} = fir.call @__nv_half2float(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f16) -> f32
 
 subroutine host1()
   integer, device :: a(32)



More information about the flang-commits mailing list