[flang-commits] [flang] 7141837 - [flang][cuda] Implicitly add DEVICE attribute in device/global functions (#119743)
via flang-commits
flang-commits at lists.llvm.org
Thu Dec 12 12:47:38 PST 2024
Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-12-12T12:47:34-08:00
New Revision: 71418379574d2df5e435f67c4b8d7591bd2038e9
URL: https://github.com/llvm/llvm-project/commit/71418379574d2df5e435f67c4b8d7591bd2038e9
DIFF: https://github.com/llvm/llvm-project/commit/71418379574d2df5e435f67c4b8d7591bd2038e9.diff
LOG: [flang][cuda] Implicitly add DEVICE attribute in device/global functions (#119743)
Variables in global and device function/subroutine that have no CUDA
Fortran data attribute are implicitly DEVICE.
Added:
Modified:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/modfile55.cuf
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b576f59e8c7e52..aef2898919f3ff 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -8953,6 +8953,18 @@ void ResolveNamesVisitor::FinishSpecificationPart(
misparsedStmtFuncFound_ = false;
funcResultStack().CompleteFunctionResultType();
CheckImports();
+ bool inDeviceSubprogram = false;
+ if (auto *subp{currScope().symbol()
+ ? currScope().symbol()->detailsIf<SubprogramDetails>()
+ : nullptr}) {
+ if (auto attrs{subp->cudaSubprogramAttrs()}) {
+ if (*attrs != common::CUDASubprogramAttrs::Device ||
+ *attrs != common::CUDASubprogramAttrs::Global ||
+ *attrs != common::CUDASubprogramAttrs::Grid_Global) {
+ inDeviceSubprogram = true;
+ }
+ }
+ }
for (auto &pair : currScope()) {
auto &symbol{*pair.second};
if (inInterfaceBlock()) {
@@ -8961,6 +8973,14 @@ void ResolveNamesVisitor::FinishSpecificationPart(
if (NeedsExplicitType(symbol)) {
ApplyImplicitRules(symbol);
}
+ if (inDeviceSubprogram && IsDummy(symbol) &&
+ symbol.has<ObjectEntityDetails>()) {
+ auto *dummy{symbol.detailsIf<ObjectEntityDetails>()};
+ if (!dummy->cudaDataAttr()) {
+ // Implicitly set device attribute if none is set in device context.
+ dummy->set_cudaDataAttr(common::CUDADataAttr::Device);
+ }
+ }
if (IsDummy(symbol) && isImplicitNoneType() &&
symbol.test(Symbol::Flag::Implicit) && !context().HasError(symbol)) {
Say(symbol.name(),
diff --git a/flang/test/Semantics/modfile55.cuf b/flang/test/Semantics/modfile55.cuf
index cf01bdd5f58f6f..6c0d152a382a88 100644
--- a/flang/test/Semantics/modfile55.cuf
+++ b/flang/test/Semantics/modfile55.cuf
@@ -29,6 +29,7 @@ end
!contains
!attributes(global) subroutine globsub(x,y,z)
!real(4),value::x
+!attributes(device) x
!real(4)::y
!attributes(device) y
!real(4)::z
More information about the flang-commits
mailing list