Skip to content

Conversation

@clementval
Copy link
Contributor

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

@clementval clementval requested a review from wangzpgi January 10, 2025 21:48
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Jan 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 10, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/122535.diff

2 Files Affected:

  • (modified) flang/module/cudadevice.f90 (+14)
  • (added) flang/test/Lower/CUDA/cuda-intrinsic.cuf (+17)
diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90
index 1402bd4e150419..74825c36f7a95f 100644
--- a/flang/module/cudadevice.f90
+++ b/flang/module/cudadevice.f90
@@ -71,4 +71,18 @@ 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 :: x, y, __fadd_rd
+    end function
+  end interface
+  public :: __fadd_rd
+
+  interface
+    attributes(device) function __fadd_ru(x, y) bind(c, name='__nv_fadd_ru')
+      real :: x, y, __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

@clementval clementval merged commit df808df into llvm:main Jan 11, 2025
8 checks passed
@clementval clementval deleted the cuf_fadd branch January 11, 2025 03:15
BaiXilin pushed a commit to BaiXilin/llvm-project that referenced this pull request Jan 12, 2025
…m#122535)

Function like `__fadd_rd ` and `__fadd_ru ` need to be converted to the
cuda equivalent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang Flang issues not falling into any other category mlir:llvm mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants