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

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Tue Apr 8 11:47:09 PDT 2025


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/134905

None

>From 691e379a5a2b88bb24ac29670e900da8f0013e74 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 8 Apr 2025 11:46:22 -0700
Subject: [PATCH] [flang][cuda] Implicitly load cudadevice in host,device and
 grid_global procedures

---
 flang/lib/Semantics/resolve-names.cpp            |  4 +++-
 flang/test/Semantics/cuf-device-procedures02.cuf | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

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