From 602f308d4fcc84d90d49fb708f757589bca68d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Clement=20=28=E3=83=90=E3=83=AC=E3=83=B3?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=B3=20=E3=82=AF=E3=83=AC=E3=83=A1?= =?UTF-8?q?=E3=83=B3=29?= Date: Thu, 14 Aug 2025 15:55:17 -0700 Subject: [PATCH] [flang][cuda] Add interface for __saturatef (#153705) --- 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 b5a92c63f19e..598d154eb3d8 100644 --- a/flang/module/cudadevice.f90 +++ b/flang/module/cudadevice.f90 @@ -325,6 +325,13 @@ implicit none 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 68fd443d39f5..ecce60599a35 100644 --- a/flang/test/Lower/CUDA/cuda-libdevice.cuf +++ b/flang/test/Lower/CUDA/cuda-libdevice.cuf @@ -162,6 +162,15 @@ end subroutine ! CHECK: %{{.*}} = fir.call @__nv_double2ull_ru(%{{.*}}) proc_attrs fastmath : (f64) -> i64 ! CHECK: %{{.*}} = fir.call @__nv_double2ull_rz(%{{.*}}) proc_attrs fastmath : (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 fastmath : (f32) -> f32 + attributes(global) subroutine test_float2ll_rX() integer(8) :: res real :: r