Skip to content

[flang][cuda] Allow assumed-size declaration for SHARED variable #130833

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
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions flang/include/flang/Lower/BoxAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ class BoxAnalyzer : public fir::details::matcher<BoxAnalyzer> {
continue;
}
} else if (subs.ubound().isStar()) {
assert(Fortran::semantics::IsNamedConstant(sym) &&
"expect implied shape constant");
assert(Fortran::semantics::IsNamedConstant(sym) ||
Fortran::semantics::IsCUDAShared(sym) &&
"expect implied shape constant");
shapes.push_back(fir::SequenceType::getUnknownExtent());
continue;
}
Expand Down
10 changes: 10 additions & 0 deletions flang/include/flang/Semantics/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ inline bool HasCUDAAttr(const Symbol &sym) {
return false;
}

inline bool IsCUDAShared(const Symbol &sym) {
if (const auto *details{sym.GetUltimate().detailsIf<ObjectEntityDetails>()}) {
if (details->cudaDataAttr() &&
*details->cudaDataAttr() == common::CUDADataAttr::Shared) {
return true;
}
}
return false;
}

inline bool NeedCUDAAlloc(const Symbol &sym) {
if (IsDummy(sym)) {
return false;
Expand Down
9 changes: 9 additions & 0 deletions flang/test/Lower/CUDA/cuda-shared01.cuf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s

attributes(global) subroutine sharedstar()
real, shared :: s(*) ! ok. dynamic shared memory.
end subroutine

! CHECK-LABEL: func.func @_QPsharedstar()
! CHECK: hlfir.declare %{{.*}}(%{{.*}}) {data_attr = #cuf.cuda<shared>, uniq_name = "_QFsharedstarEs"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)