Skip to content

Commit 20fdd53

Browse files
authored
[flang][cuda] Handle associated variables in data transfer (#163668)
1 parent c2e42e3 commit 20fdd53

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,16 +1289,7 @@ bool CheckForCoindexedObject(parser::ContextualMessages &,
12891289
const std::optional<ActualArgument> &, const std::string &procName,
12901290
const std::string &argName);
12911291

1292-
inline bool IsCUDADeviceSymbol(const Symbol &sym) {
1293-
if (const auto *details =
1294-
sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()) {
1295-
if (details->cudaDataAttr() &&
1296-
*details->cudaDataAttr() != common::CUDADataAttr::Pinned) {
1297-
return true;
1298-
}
1299-
}
1300-
return false;
1301-
}
1292+
bool IsCUDADeviceSymbol(const Symbol &sym);
13021293

13031294
inline bool IsCUDAManagedOrUnifiedSymbol(const Symbol &sym) {
13041295
if (const auto *details =

flang/lib/Evaluate/tools.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,18 @@ bool HasCUDAImplicitTransfer(const Expr<SomeType> &expr) {
11531153
return (hasConstant || (hostSymbols.size() > 0)) && deviceSymbols.size() > 0;
11541154
}
11551155

1156+
bool IsCUDADeviceSymbol(const Symbol &sym) {
1157+
if (const auto *details =
1158+
sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()) {
1159+
return details->cudaDataAttr() &&
1160+
*details->cudaDataAttr() != common::CUDADataAttr::Pinned;
1161+
} else if (const auto *details =
1162+
sym.GetUltimate().detailsIf<semantics::AssocEntityDetails>()) {
1163+
return GetNbOfCUDADeviceSymbols(details->expr()) > 0;
1164+
}
1165+
return false;
1166+
}
1167+
11561168
// HasVectorSubscript()
11571169
struct HasVectorSubscriptHelper
11581170
: public AnyTraverse<HasVectorSubscriptHelper, bool,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
2+
3+
! Test detection of CUDA Fortran data transfer in presence of associuate
4+
! statement.
5+
6+
module m
7+
real(8), device, dimension(10,10,10) :: d
8+
end module m
9+
10+
subroutine foo
11+
use m
12+
!@CUF associate(d1 => d)
13+
d1 = 0.0
14+
!@CUF end associate
15+
end subroutine
16+
17+
! CHECK-LABEL: func.func @_QPfoo()
18+
! CHECK: %[[D:.*]] = fir.address_of(@_QMmEd) : !fir.ref<!fir.array<10x10x10xf64>>
19+
! CHECK: %[[D_DECL:.*]]:2 = hlfir.declare %[[D]](%{{.*}}) {data_attr = #cuf.cuda<device>, uniq_name = "_QMmEd"} : (!fir.ref<!fir.array<10x10x10xf64>>, !fir.shape<3>) -> (!fir.ref<!fir.array<10x10x10xf64>>, !fir.ref<!fir.array<10x10x10xf64>>)
20+
! CHECK: %[[D1_DECL:.*]]:2 = hlfir.declare %[[D_DECL]]#0(%4) {uniq_name = "_QFfooEd1"} : (!fir.ref<!fir.array<10x10x10xf64>>, !fir.shape<3>) -> (!fir.ref<!fir.array<10x10x10xf64>>, !fir.ref<!fir.array<10x10x10xf64>>)
21+
! CHECK: cuf.data_transfer %{{.*}} to %[[D1_DECL]]#0 {transfer_kind = #cuf.cuda_transfer<host_device>} : f64, !fir.ref<!fir.array<10x10x10xf64>>

0 commit comments

Comments
 (0)