Skip to content

[flang] [cuda] implicitly set DEVICE attribute to scalars in device routines #140834

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 5 commits into from
May 21, 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
2 changes: 1 addition & 1 deletion flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9376,7 +9376,7 @@ static void SetImplicitCUDADevice(bool inDeviceSubprogram, Symbol &symbol) {
if (inDeviceSubprogram && symbol.has<ObjectEntityDetails>()) {
auto *object{symbol.detailsIf<ObjectEntityDetails>()};
if (!object->cudaDataAttr() && !IsValue(symbol) &&
(IsDummy(symbol) || object->IsArray())) {
!IsFunctionResult(symbol)) {
// Implicitly set device attribute if none is set in device context.
object->set_cudaDataAttr(common::CUDADataAttr::Device);
}
Expand Down
1 change: 1 addition & 0 deletions flang/test/Lower/CUDA/cuda-shared.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ end subroutine

! CHECK-LABEL: func.func @_QPsharedmem() attributes {cuf.proc_attr = #cuf.cuda_proc<global>}
! CHECK: %{{.*}} = cuf.shared_memory !fir.array<32xf32> {bindc_name = "s", uniq_name = "_QFsharedmemEs"} -> !fir.ref<!fir.array<32xf32>>
! CHECK: cuf.free %{{.*}}#0 : !fir.ref<i32> {data_attr = #cuf.cuda<device>}
! CHECK-NOT: cuf.free
27 changes: 27 additions & 0 deletions flang/test/Semantics/cuf21.cuf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! Test generic matching with scalars argument without device attr

module mlocModule
interface maxlocUpdate
module procedure :: &
maxlocUpdateR_32F, &
maxlocUpdateR_64F
end interface maxlocUpdate
contains

attributes(global) subroutine maxlocPartialMaskR_32F1D()
implicit none
real(4) :: mval

call maxlocUpdate(mval)

end subroutine maxlocPartialMaskR_32F1D

attributes(device) subroutine maxlocUpdateR_32F(mval)
real(4) :: mval
end subroutine maxlocUpdateR_32F

attributes(device) subroutine maxlocUpdateR_64F(mval)
real(8) :: mval
end subroutine maxlocUpdateR_64F
end module
Loading