[flang-commits] [flang] [flang][cuda] Add interface for __saturatef (PR #153705)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Thu Aug 14 15:33:12 PDT 2025


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/153705

None

>From ff3823d44841bef4301e67109353329b72971c84 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 14 Aug 2025 15:32:47 -0700
Subject: [PATCH] [flang][cuda] Add interface for __saturatef

---
 flang/module/cudadevice.f90              | 7 +++++++
 flang/test/Lower/CUDA/cuda-libdevice.cuf | 9 +++++++++
 2 files changed, 16 insertions(+)

diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90
index a8b1d19a4c1ff..9adf611e9d0eb 100644
--- a/flang/module/cudadevice.f90
+++ b/flang/module/cudadevice.f90
@@ -325,6 +325,13 @@ attributes(device) real(8) function rsqrt(x) bind(c,name='__nv_rsqrt')
     end function
   end interface
 
+  interface saturate
+    attributes(device) real function __saturatef(r) bind(c, name='__nv_saturatef')
+      !dir$ ignore_tkr (d) r
+      real, value :: r
+    end function
+  end interface
+
   interface __sad
     attributes(device) integer function __sad(i,j,k) bind(c, name='__nv_sad')
       !dir$ ignore_tkr (d) i, (d) j, (d) k
diff --git a/flang/test/Lower/CUDA/cuda-libdevice.cuf b/flang/test/Lower/CUDA/cuda-libdevice.cuf
index 447e09cad747b..6d1ac411a603c 100644
--- a/flang/test/Lower/CUDA/cuda-libdevice.cuf
+++ b/flang/test/Lower/CUDA/cuda-libdevice.cuf
@@ -161,3 +161,12 @@ end subroutine
 ! CHECK: %{{.*}} = fir.call @__nv_double2ull_rn(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
 ! CHECK: %{{.*}} = fir.call @__nv_double2ull_ru(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
 ! CHECK: %{{.*}} = fir.call @__nv_double2ull_rz(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
+
+attributes(global) subroutine test_saturatef()
+  real :: res
+  real :: r
+  res = __saturatef(r)
+end subroutine
+
+! CHECK-LABEL: _QPtest_saturatef
+! CHECK: %{{.*}} = fir.call @__nv_saturatef(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f32) -> f32



More information about the flang-commits mailing list