Skip to content

Commit c4b343a

Browse files
authored
[flang][cuda] Implicitly load cudadevice in host,device and grid_global procedures (llvm#134905)
1 parent 6f92339 commit c4b343a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4343,7 +4343,9 @@ bool SubprogramVisitor::Pre(const parser::PrefixSpec::Attributes &attrs) {
43434343
}
43444344
if (auto attrs{subp->cudaSubprogramAttrs()}) {
43454345
if (*attrs == common::CUDASubprogramAttrs::Global ||
4346-
*attrs == common::CUDASubprogramAttrs::Device) {
4346+
*attrs == common::CUDASubprogramAttrs::Grid_Global ||
4347+
*attrs == common::CUDASubprogramAttrs::Device ||
4348+
*attrs == common::CUDASubprogramAttrs::HostDevice) {
43474349
const Scope &scope{currScope()};
43484350
const Scope *mod{FindModuleContaining(scope)};
43494351
if (mod &&

flang/test/Semantics/cuf-device-procedures02.cuf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,17 @@ contains
1313
!ERROR: 'threadfence' is use-associated from module 'cudadevice' and cannot be re-declared
1414
integer :: threadfence
1515
end subroutine
16+
17+
attributes(host,device) subroutine sub3()
18+
if (on_device()) then
19+
print*, 'on device'
20+
else
21+
print*, 'on host'
22+
end if
23+
end subroutine
24+
25+
attributes(grid_global) subroutine sub4()
26+
call threadfence()
27+
end subroutine
1628
end module
1729

0 commit comments

Comments
 (0)