Skip to content

Commit fed0f58

Browse files
authored
[flang][cuda] Avoid triggering host array error in host device proc (llvm#134909)
we cannot enforce the detection of host arrays in device code when the procedure is host, device. Relax the check for those.
1 parent c4b343a commit fed0f58

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

flang/lib/Semantics/check-cuda.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
261261
subp->cudaSubprogramAttrs().value_or(
262262
common::CUDASubprogramAttrs::Host) !=
263263
common::CUDASubprogramAttrs::Host) {
264+
isHostDevice = subp->cudaSubprogramAttrs() &&
265+
subp->cudaSubprogramAttrs() ==
266+
common::CUDASubprogramAttrs::HostDevice;
264267
Check(body);
265268
}
266269
}
@@ -357,6 +360,8 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
357360
}
358361
template <typename A>
359362
void ErrorIfHostSymbol(const A &expr, parser::CharBlock source) {
363+
if (isHostDevice)
364+
return;
360365
if (const Symbol * hostArray{FindHostArray{}(expr)}) {
361366
context_.Say(source,
362367
"Host array '%s' cannot be present in device context"_err_en_US,
@@ -502,6 +507,7 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
502507
}
503508

504509
SemanticsContext &context_;
510+
bool isHostDevice{false};
505511
};
506512

507513
void CUDAChecker::Enter(const parser::SubroutineSubprogram &x) {

flang/test/Semantics/cuf09.cuf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,10 @@ subroutine ieee_test
221221
ll(i) = ieee_is_finite(y(i)) ! allow ieee_arithmetic functions on the device.
222222
end do
223223
end subroutine
224+
225+
attributes(host,device) subroutine do2(a,b,c,i)
226+
integer a(*), b(*), c(*)
227+
integer, value :: i
228+
c(i) = a(i) - b(i) ! ok. Should not error with Host array
229+
! cannot be present in device context
230+
end

0 commit comments

Comments
 (0)