[flang][cuda] Diagnose host reads of device data (#228287)
Host code may only use device data in a data transfer assignment or as
an
actual argument. When device data appeared anywhere else, such as in an
IF
condition, flang accepted it silently and lowered it to a plain host
load of
device memory:
subroutine s(h, a)
double precision :: h, a(10)
attributes(device) :: a
if (a(3) > 2.5d0) h = 1.0d0
end subroutine
The CUDA checker now emits an error when host code reads data with the
DEVICE or CONSTANT attribute in a scalar expression. These expressions
include IF and ELSE IF conditions, DO bounds, DO WHILE, SELECT CASE
selectors, STOP codes and allocate bounds.
Device data that is only designated is not read and is still accepted.
This
covers inquiry intrinsics (ALLOCATED, SIZE, LBOUND, ...), address
intrinsics
(LOC, C_LOC, C_DEVLOC), and variables passed as actual arguments.
Subscripts
of these designators are still checked, so f(d(n_dev)) is an error.
Managed and unified data are host accessible and are not diagnosed.
Device subprograms, CUF kernels and OpenACC compute constructs are
skipped.
Assignments keep their existing data transfer checks.