Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

clementval
Copy link
Contributor

No description provided.

@clementval clementval requested a review from wangzpgi April 8, 2025 18:47
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Apr 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 8, 2025

@llvm/pr-subscribers-flang-semantics

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

Changes

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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+3-1)
  • (modified) flang/test/Semantics/cuf-device-procedures02.cuf (+12)
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
 

@clementval clementval merged commit c4b343a into llvm:main Apr 8, 2025
7 of 8 checks passed
@clementval clementval deleted the cuf_implicit_cudadevice branch April 8, 2025 19:54
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants