Skip to content

Commit 67ae944

Browse files
authored
[flang][cuda] Check for use of host array in device context (#119756)
Now that variables have implicit attribute, we can check for illegal use of module host variable in device context.
1 parent 484a281 commit 67ae944

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

flang/lib/Semantics/check-cuda.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
340340
void ErrorIfHostSymbol(const A &expr, parser::CharBlock source) {
341341
if (const Symbol * hostArray{FindHostArray{}(expr)}) {
342342
context_.Say(source,
343-
"Host array '%s' cannot be present in CUF kernel"_err_en_US,
343+
"Host array '%s' cannot be present in device context"_err_en_US,
344344
hostArray->name());
345345
}
346346
}
@@ -387,13 +387,10 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
387387
Check(x.value());
388388
},
389389
[&](const common::Indirection<parser::AssignmentStmt> &x) {
390-
if (IsCUFKernelDo) {
391-
const evaluate::Assignment *assign{
392-
semantics::GetAssignment(x.value())};
393-
if (assign) {
394-
ErrorIfHostSymbol(assign->lhs, source);
395-
ErrorIfHostSymbol(assign->rhs, source);
396-
}
390+
if (const evaluate::Assignment *
391+
assign{semantics::GetAssignment(x.value())}) {
392+
ErrorIfHostSymbol(assign->lhs, source);
393+
ErrorIfHostSymbol(assign->rhs, source);
397394
}
398395
if (auto msg{ActionStmtChecker<IsCUFKernelDo>::WhyNotOk(x)}) {
399396
context_.Say(source, std::move(*msg));

flang/test/Semantics/cuf09.cuf

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
22
module m
3+
integer :: m(100)
34
contains
45
attributes(device) subroutine devsub
56
!ERROR: Statement may not appear in device code
@@ -15,6 +16,12 @@ module m
1516
!WARNING: I/O statement might not be supported on device
1617
write(12,'(10F4.1)'), x
1718
end
19+
attributes(global) subroutine hostglobal(a)
20+
integer :: a(*)
21+
i = threadIdx%x
22+
!ERROR: Host array 'm' cannot be present in device context
23+
if (i .le. N) a(i) = m(i)
24+
end subroutine
1825
end
1926

2027
program main
@@ -96,7 +103,7 @@ program main
96103
!$cuf kernel do (2) <<<*, *>>>
97104
do j = 1, 10
98105
do i = 1, 10
99-
!ERROR: Host array 'b' cannot be present in CUF kernel
106+
!ERROR: Host array 'b' cannot be present in device context
100107
a_d(i,j) = b(i,j)
101108
enddo
102109
enddo

0 commit comments

Comments
 (0)