Skip to content

Commit 97b7bac

Browse files
authored
[flang][cuda] Allow host array with PARAMETER attribute in device context (#120298)
Host arrays are normally not allowed in device context unless they have a `PARAMETER` attribute. This patch update the check so no error is emitted.
1 parent eb59fe8 commit 97b7bac

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

flang/lib/Semantics/check-cuda.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct FindHostArray
110110
if (const auto *details{
111111
symbol.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
112112
if (details->IsArray() &&
113+
!symbol.attrs().test(Fortran::semantics::Attr::PARAMETER) &&
113114
(!details->cudaDataAttr() ||
114115
(details->cudaDataAttr() &&
115116
*details->cudaDataAttr() != common::CUDADataAttr::Device &&

flang/test/Semantics/cuf09.cuf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
22
module m
33
integer :: m(100)
4+
integer, parameter :: p(5) = [1,2,3,4,5]
45
contains
56
attributes(device) subroutine devsub
67
!ERROR: Statement may not appear in device code
@@ -23,6 +24,12 @@ module m
2324
if (i .le. N) a(i) = m(i)
2425
end subroutine
2526

27+
attributes(global) subroutine hostparameter(a)
28+
integer :: a(*)
29+
i = threadIdx%x
30+
if (i .le. N) a(i) = p(i) ! ok. p is parameter
31+
end subroutine
32+
2633
attributes(global) subroutine localarray()
2734
integer :: a(10)
2835
i = threadIdx%x

0 commit comments

Comments
 (0)