Skip to content

Commit 8a6a0f1

Browse files
authored
[flang][cuda] Add proper TODO for cuda fortran assignment (#85705)
Data transfer between host and device can be done with assignment statements in CUDA Fortran. This is currently not lowered so adding a proper TODO. https://docs.nvidia.com/hpc-sdk/archive/24.3/compilers/cuda-fortran-prog-guide/index.html#cfref-data-trans-assgn-statemts
1 parent 42c38b1 commit 8a6a0f1

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,20 @@ bool CheckForCoindexedObject(parser::ContextualMessages &,
12181218
const std::optional<ActualArgument> &, const std::string &procName,
12191219
const std::string &argName);
12201220

1221+
/// Check if any of the symbols part of the expression has a cuda data
1222+
/// attribute.
1223+
inline bool HasCUDAAttrs(const Expr<SomeType> &expr) {
1224+
for (const Symbol &sym : CollectSymbols(expr)) {
1225+
if (const auto *details =
1226+
sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()) {
1227+
if (details->cudaDataAttr()) {
1228+
return true;
1229+
}
1230+
}
1231+
}
1232+
return false;
1233+
}
1234+
12211235
} // namespace Fortran::evaluate
12221236

12231237
namespace Fortran::semantics {

flang/lib/Lower/Bridge.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3692,6 +3692,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
36923692
const Fortran::evaluate::ProcedureRef *userDefinedAssignment) {
36933693
mlir::Location loc = getCurrentLocation();
36943694
fir::FirOpBuilder &builder = getFirOpBuilder();
3695+
3696+
if (Fortran::evaluate::HasCUDAAttrs(assign.lhs) ||
3697+
Fortran::evaluate::HasCUDAAttrs(assign.rhs))
3698+
TODO(loc, "Assignement with CUDA Fortran variables");
3699+
36953700
// Gather some information about the assignment that will impact how it is
36963701
// lowered.
36973702
const bool isWholeAllocatableAssignment =

flang/test/Lower/CUDA/cuda-module-use.cuf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
subroutine sub1()
77
use cuf_mod
8-
md = 1.0
8+
! md = 1.0 ! currently a TODO
99
end
1010

1111
! CHECK-LABEL: func.func @_QPsub1()

0 commit comments

Comments
 (0)