Skip to content

Commit

Permalink
[flang][cuda] Add proper TODO for cuda fortran assignment (llvm#85705)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
clementval authored Mar 19, 2024
1 parent 42c38b1 commit 8a6a0f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions flang/include/flang/Evaluate/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,20 @@ bool CheckForCoindexedObject(parser::ContextualMessages &,
const std::optional<ActualArgument> &, const std::string &procName,
const std::string &argName);

/// Check if any of the symbols part of the expression has a cuda data
/// attribute.
inline bool HasCUDAAttrs(const Expr<SomeType> &expr) {
for (const Symbol &sym : CollectSymbols(expr)) {
if (const auto *details =
sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()) {
if (details->cudaDataAttr()) {
return true;
}
}
}
return false;
}

} // namespace Fortran::evaluate

namespace Fortran::semantics {
Expand Down
5 changes: 5 additions & 0 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3692,6 +3692,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
const Fortran::evaluate::ProcedureRef *userDefinedAssignment) {
mlir::Location loc = getCurrentLocation();
fir::FirOpBuilder &builder = getFirOpBuilder();

if (Fortran::evaluate::HasCUDAAttrs(assign.lhs) ||
Fortran::evaluate::HasCUDAAttrs(assign.rhs))
TODO(loc, "Assignement with CUDA Fortran variables");

// Gather some information about the assignment that will impact how it is
// lowered.
const bool isWholeAllocatableAssignment =
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Lower/CUDA/cuda-module-use.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

subroutine sub1()
use cuf_mod
md = 1.0
! md = 1.0 ! currently a TODO
end

! CHECK-LABEL: func.func @_QPsub1()
Expand Down

0 comments on commit 8a6a0f1

Please sign in to comment.