[flang-commits] [flang] c4b343a - [flang][cuda] Implicitly load cudadevice in host, device and grid_global procedures (#134905)

via flang-commits flang-commits at lists.llvm.org
Tue Apr 8 12:54:51 PDT 2025


Author: Valentin Clement (バレンタイン クレメン)
Date: 2025-04-08T12:54:48-07:00
New Revision: c4b343aeebe28462d13a773e05a5a667420abe7e

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

LOG: [flang][cuda] Implicitly load cudadevice in host,device and grid_global procedures (#134905)

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/cuf-device-procedures02.cuf

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 50ca58ea01429..74367b5229548 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -4343,7 +4343,9 @@ bool SubprogramVisitor::Pre(const parser::PrefixSpec::Attributes &attrs) {
     }
     if (auto attrs{subp->cudaSubprogramAttrs()}) {
       if (*attrs == common::CUDASubprogramAttrs::Global ||
-          *attrs == common::CUDASubprogramAttrs::Device) {
+          *attrs == common::CUDASubprogramAttrs::Grid_Global ||
+          *attrs == common::CUDASubprogramAttrs::Device ||
+          *attrs == common::CUDASubprogramAttrs::HostDevice) {
         const Scope &scope{currScope()};
         const Scope *mod{FindModuleContaining(scope)};
         if (mod &&

diff  --git a/flang/test/Semantics/cuf-device-procedures02.cuf b/flang/test/Semantics/cuf-device-procedures02.cuf
index c93fc4033b8f0..5945abb013eed 100644
--- a/flang/test/Semantics/cuf-device-procedures02.cuf
+++ b/flang/test/Semantics/cuf-device-procedures02.cuf
@@ -13,5 +13,17 @@ contains
 !ERROR: 'threadfence' is use-associated from module 'cudadevice' and cannot be re-declared
     integer :: threadfence
   end subroutine
+
+  attributes(host,device) subroutine sub3()
+    if (on_device()) then
+      print*, 'on device'
+    else
+      print*, 'on host'
+    end if
+  end subroutine
+
+  attributes(grid_global) subroutine sub4()
+    call threadfence()
+  end subroutine
 end module
 


        


More information about the flang-commits mailing list