Skip to content

Commit 7141837

Browse files
authored
[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.
1 parent 463e93b commit 7141837

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8953,6 +8953,18 @@ void ResolveNamesVisitor::FinishSpecificationPart(
89538953
misparsedStmtFuncFound_ = false;
89548954
funcResultStack().CompleteFunctionResultType();
89558955
CheckImports();
8956+
bool inDeviceSubprogram = false;
8957+
if (auto *subp{currScope().symbol()
8958+
? currScope().symbol()->detailsIf<SubprogramDetails>()
8959+
: nullptr}) {
8960+
if (auto attrs{subp->cudaSubprogramAttrs()}) {
8961+
if (*attrs != common::CUDASubprogramAttrs::Device ||
8962+
*attrs != common::CUDASubprogramAttrs::Global ||
8963+
*attrs != common::CUDASubprogramAttrs::Grid_Global) {
8964+
inDeviceSubprogram = true;
8965+
}
8966+
}
8967+
}
89568968
for (auto &pair : currScope()) {
89578969
auto &symbol{*pair.second};
89588970
if (inInterfaceBlock()) {
@@ -8961,6 +8973,14 @@ void ResolveNamesVisitor::FinishSpecificationPart(
89618973
if (NeedsExplicitType(symbol)) {
89628974
ApplyImplicitRules(symbol);
89638975
}
8976+
if (inDeviceSubprogram && IsDummy(symbol) &&
8977+
symbol.has<ObjectEntityDetails>()) {
8978+
auto *dummy{symbol.detailsIf<ObjectEntityDetails>()};
8979+
if (!dummy->cudaDataAttr()) {
8980+
// Implicitly set device attribute if none is set in device context.
8981+
dummy->set_cudaDataAttr(common::CUDADataAttr::Device);
8982+
}
8983+
}
89648984
if (IsDummy(symbol) && isImplicitNoneType() &&
89658985
symbol.test(Symbol::Flag::Implicit) && !context().HasError(symbol)) {
89668986
Say(symbol.name(),

flang/test/Semantics/modfile55.cuf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ end
2929
!contains
3030
!attributes(global) subroutine globsub(x,y,z)
3131
!real(4),value::x
32+
!attributes(device) x
3233
!real(4)::y
3334
!attributes(device) y
3435
!real(4)::z

0 commit comments

Comments
 (0)