[flang-commits] [flang] [flang][cuda] Implicitly add DEVICE attribute in device/global functions (PR #119743)
via flang-commits
flang-commits at lists.llvm.org
Thu Dec 12 10:55:14 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Valentin Clement (バレンタイン クレメン) (clementval)
<details>
<summary>Changes</summary>
Variables in global and device function/subroutine that have no CUDA Fortran data attribute are implicitly DEVICE.
---
Full diff: https://github.com/llvm/llvm-project/pull/119743.diff
2 Files Affected:
- (modified) flang/lib/Semantics/resolve-names.cpp (+19)
- (modified) flang/test/Semantics/modfile55.cuf (+1)
``````````diff
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b576f59e8c7e52..a38c86e683b6b3 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,13 @@ 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/119743
More information about the flang-commits
mailing list