Skip to content

Commit 4042a00

Browse files
authored
[flang] [cuda] implicitly set DEVICE attribute to scalars in device routines (#140834)
Scalars inside device routines also need to implicitly set the DEVICE attribute, except for function results.
1 parent 0954c9d commit 4042a00

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9376,7 +9376,7 @@ static void SetImplicitCUDADevice(bool inDeviceSubprogram, Symbol &symbol) {
93769376
if (inDeviceSubprogram && symbol.has<ObjectEntityDetails>()) {
93779377
auto *object{symbol.detailsIf<ObjectEntityDetails>()};
93789378
if (!object->cudaDataAttr() && !IsValue(symbol) &&
9379-
(IsDummy(symbol) || object->IsArray())) {
9379+
!IsFunctionResult(symbol)) {
93809380
// Implicitly set device attribute if none is set in device context.
93819381
object->set_cudaDataAttr(common::CUDADataAttr::Device);
93829382
}

flang/test/Lower/CUDA/cuda-shared.cuf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ end subroutine
99

1010
! CHECK-LABEL: func.func @_QPsharedmem() attributes {cuf.proc_attr = #cuf.cuda_proc<global>}
1111
! CHECK: %{{.*}} = cuf.shared_memory !fir.array<32xf32> {bindc_name = "s", uniq_name = "_QFsharedmemEs"} -> !fir.ref<!fir.array<32xf32>>
12+
! CHECK: cuf.free %{{.*}}#0 : !fir.ref<i32> {data_attr = #cuf.cuda<device>}
1213
! CHECK-NOT: cuf.free

flang/test/Semantics/cuf21.cuf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
! Test generic matching with scalars argument without device attr
3+
4+
module mlocModule
5+
interface maxlocUpdate
6+
module procedure :: &
7+
maxlocUpdateR_32F, &
8+
maxlocUpdateR_64F
9+
end interface maxlocUpdate
10+
contains
11+
12+
attributes(global) subroutine maxlocPartialMaskR_32F1D()
13+
implicit none
14+
real(4) :: mval
15+
16+
call maxlocUpdate(mval)
17+
18+
end subroutine maxlocPartialMaskR_32F1D
19+
20+
attributes(device) subroutine maxlocUpdateR_32F(mval)
21+
real(4) :: mval
22+
end subroutine maxlocUpdateR_32F
23+
24+
attributes(device) subroutine maxlocUpdateR_64F(mval)
25+
real(8) :: mval
26+
end subroutine maxlocUpdateR_64F
27+
end module

0 commit comments

Comments
 (0)