Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7be448e

Browse files
authored
[flang][cuda][openacc] Don't apply CUDA Fortran COMMON/EQUIVALENCE rule to internal UseDevice marker (#197036)
`CUDADataAttr::UseDevice` is not user-spellable; the symbol that actually lives in COMMON/EQUIVALENCE carries no CUDA attribute. The CUDA Fortran restriction (CUDA Fortran Programming Guide §3.2) does not apply to it. Exclude `UseDevice` from the COMMON/EQUIVALENCE check alongside the existing `Pinned` exclusion, and add a Semantics regression test.
1 parent b32f982 commit 7be448e

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

flang/lib/Semantics/check-declarations.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,14 @@ void CheckHelper::CheckObjectEntity(
12431243
case common::CUDADataAttr::UseDevice:
12441244
break;
12451245
}
1246-
if (attr != common::CUDADataAttr::Pinned) {
1246+
// CUDADataAttr::UseDevice is not user-spellable; it is set internally on
1247+
// construct-scoped symbol copies created for OpenACC `host_data
1248+
// use_device(...)` operands so that later passes can resolve them to the
1249+
// device address. The original symbol that actually lives in COMMON or an
1250+
// equivalence group carries no CUDA attribute, so the CUDA Fortran
1251+
// restrictions on user-written ATTRIBUTES(...) do not apply to it.
1252+
if (attr != common::CUDADataAttr::Pinned &&
1253+
attr != common::CUDADataAttr::UseDevice) {
12471254
if (details.commonBlock()) {
12481255
messages_.Say(
12491256
"Object '%s' with ATTRIBUTES(%s) may not be in COMMON"_err_en_US,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenacc
2+
3+
! Regression test: a variable that lives in a COMMON block must not be
4+
! rejected when it appears in an OpenACC `host_data use_device(...)`
5+
! clause. The CUDA Fortran restriction "object with ATTRIBUTES(USEDEVICE)
6+
! may not be in COMMON" applies only to user-spelled
7+
! `attributes(usedevice)` dummy arguments, not to the internal
8+
! CUDADataAttr::UseDevice marker that name resolution attaches to
9+
! construct-scoped copies of `use_device` operands.
10+
11+
subroutine vadd(a, b, c, n)
12+
real(8) :: a(*), b(*), c(*)
13+
integer :: n, i
14+
do i = 1, n - 1
15+
c(i) = a(i) + b(i)
16+
end do
17+
end subroutine
18+
19+
program acc_host_data_common
20+
integer, parameter :: N = 100
21+
real(8) :: a(2:N), b(2:N), c0(2:N), c1(2:N)
22+
common /arrays/ a, b, c0, c1
23+
integer :: i
24+
25+
!$acc data copy(a, b, c0)
26+
!$acc parallel loop
27+
do i = 2, N
28+
a(i) = i
29+
b(i) = 2.0_8 * i
30+
end do
31+
32+
!$acc host_data use_device(a, b, c0)
33+
call vadd(a, b, c0, N)
34+
!$acc end host_data
35+
!$acc end data
36+
end program

0 commit comments

Comments
 (0)