[flang-commits] [flang] df808df - [flang][cuda] Add bind(c) interfaces for __fadd_rd and __fadd_ru (#122535)

via flang-commits flang-commits at lists.llvm.org
Fri Jan 10 19:15:06 PST 2025


Author: Valentin Clement (バレンタイン クレメン)
Date: 2025-01-10T19:15:02-08:00
New Revision: df808df8f73e30d288e4dfdef5e527bc392f3bce

URL: https://github.com/llvm/llvm-project/commit/df808df8f73e30d288e4dfdef5e527bc392f3bce
DIFF: https://github.com/llvm/llvm-project/commit/df808df8f73e30d288e4dfdef5e527bc392f3bce.diff

LOG: [flang][cuda] Add bind(c) interfaces for __fadd_rd and __fadd_ru (#122535)

Function like `__fadd_rd ` and `__fadd_ru ` need to be converted to the
cuda equivalent.

Added: 
    flang/test/Lower/CUDA/cuda-intrinsic.cuf

Modified: 
    flang/module/cudadevice.f90

Removed: 
    


################################################################################
diff  --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90
index 1402bd4e150419..e06c706538fe63 100644
--- a/flang/module/cudadevice.f90
+++ b/flang/module/cudadevice.f90
@@ -71,4 +71,20 @@ attributes(device) subroutine threadfence_system()
   end interface
   public :: threadfence_system
 
+  interface
+    attributes(device) function __fadd_rd(x, y) bind(c, name='__nv_fadd_rd')
+      real, intent(in) :: x, y
+      real :: __fadd_rd
+    end function
+  end interface
+  public :: __fadd_rd
+
+  interface
+    attributes(device) function __fadd_ru(x, y) bind(c, name='__nv_fadd_ru')
+      real, intent(in) :: x, y
+      real :: __fadd_ru
+    end function
+  end interface
+  public :: __fadd_ru
+
 end module

diff  --git a/flang/test/Lower/CUDA/cuda-intrinsic.cuf b/flang/test/Lower/CUDA/cuda-intrinsic.cuf
new file mode 100644
index 00000000000000..9723afc532387f
--- /dev/null
+++ b/flang/test/Lower/CUDA/cuda-intrinsic.cuf
@@ -0,0 +1,17 @@
+! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
+
+module mod1
+  type int
+    real :: inf, sup 
+  end type int
+contains
+  attributes(global) subroutine fadd(c, a, b)
+    type (int) :: c, a, b
+    c%inf = __fadd_rd(a%inf, b%inf)
+    c%sup = __fadd_ru(a%sup, b%sup)
+  end subroutine
+end
+
+! CHECK-LABEL: func.func @_QMmod1Pfadd
+! CHECK: fir.call @__nv_fadd_rd
+! CHECK: fir.call @__nv_fadd_ru


        


More information about the flang-commits mailing list