-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[flang][cuda] Do not lower device target in porgram as global #120126
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-flang-semantics @llvm/pr-subscribers-flang-fir-hlfir Author: Valentin Clement (バレンタイン クレメン) (clementval) ChangesAs it was done in #102512, do not create global for arrays declared in program unit with cuda data attribute. Full diff: https://github.com/llvm/llvm-project/pull/120126.diff 2 Files Affected:
diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index a040f7ce79dc10..fed5f5b39a1868 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -1719,7 +1719,8 @@ bool IsSaved(const Symbol &original) {
return false;
} else if (scopeKind == Scope::Kind::Module ||
(scopeKind == Scope::Kind::MainProgram &&
- (symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)))) {
+ (symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)) &&
+ Fortran::evaluate::CanCUDASymbolHaveSaveAttr(symbol))) {
// 8.5.16p4
// In main programs, implied SAVE matters only for pointer
// initialization targets and coarrays.
@@ -1747,7 +1748,7 @@ bool IsSaved(const Symbol &original) {
} else if (symbol.test(Symbol::Flag::InDataStmt)) {
return true;
} else if (const auto *object{symbol.detailsIf<ObjectEntityDetails>()};
- object && object->init()) {
+ object && object->init()) {
return true;
} else if (IsProcedurePointer(symbol) && symbol.has<ProcEntityDetails>() &&
symbol.get<ProcEntityDetails>().init()) {
@@ -1755,7 +1756,7 @@ bool IsSaved(const Symbol &original) {
} else if (scope.hasSAVE()) {
return true; // bare SAVE statement
} else if (const Symbol * block{FindCommonBlockContaining(symbol)};
- block && block->attrs().test(Attr::SAVE)) {
+ block && block->attrs().test(Attr::SAVE)) {
return true; // in COMMON with SAVE
} else {
return false;
diff --git a/flang/test/Lower/CUDA/cuda-program-global.cuf b/flang/test/Lower/CUDA/cuda-program-global.cuf
index 90b401c9ba6a5c..a21fc06537f75d 100644
--- a/flang/test/Lower/CUDA/cuda-program-global.cuf
+++ b/flang/test/Lower/CUDA/cuda-program-global.cuf
@@ -7,6 +7,7 @@ program test
integer, device :: a(10)
integer, unified :: u(10)
integer, allocatable, pinned :: p(:)
+ real, device, target :: t(10)
integer :: b(10)
integer :: i
print*,i
@@ -18,6 +19,7 @@ end
! CHECK: %[[ALLOCA:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
! CHECK: hlfir.declare %[[ALLOCA]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
! CHECK: cuf.alloc !fir.box<!fir.heap<!fir.array<?xi32>>> {bindc_name = "p", data_attr = #cuf.cuda<pinned>, uniq_name = "_QFEp"} -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
+! CHECK: cuf.alloc !fir.array<10xf32> {bindc_name = "t", data_attr = #cuf.cuda<device>, uniq_name = "_QFEt"} -> !fir.ref<!fir.array<10xf32>>
! CHECK-NOT: fir.global internal @_QFEa {data_attr = #cuf.cuda<device>} : !fir.array<10xi32> {{{$}}
! CHECK: fir.global internal @_QFEb : !fir.array<10xi32> {{{$}}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
clementval
commented
Dec 16, 2024
clementval
commented
Dec 16, 2024
wangzpgi
approved these changes
Dec 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As it was done in #102512, do not create global for arrays declared in program unit with cuda data attribute.