[flang-commits] [flang] [flang][cuda] Add proper TODO for cuda fortran assigment (PR #85705)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Mon Mar 18 14:37:25 PDT 2024
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/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
>From 79c4bb4dff508a77c578aa11a56b096ce7a9d8eb Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 18 Mar 2024 14:34:31 -0700
Subject: [PATCH] [flang][cuda] Add proper TODO for cuda fortran assigment
---
flang/include/flang/Evaluate/tools.h | 14 ++++++++++++++
flang/lib/Lower/Bridge.cpp | 5 +++++
flang/test/Lower/CUDA/cuda-module-use.cuf | 2 +-
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index aba40025ca504d..9a32062440abc0 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -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 {
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 650ec5db2d0ccb..6c32c537198c67 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -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 =
diff --git a/flang/test/Lower/CUDA/cuda-module-use.cuf b/flang/test/Lower/CUDA/cuda-module-use.cuf
index f54083b026ee88..47d3805065a5a7 100644
--- a/flang/test/Lower/CUDA/cuda-module-use.cuf
+++ b/flang/test/Lower/CUDA/cuda-module-use.cuf
@@ -5,7 +5,7 @@
subroutine sub1()
use cuf_mod
- md = 1.0
+! md = 1.0 ! currently a TODO
end
! CHECK-LABEL: func.func @_QPsub1()
More information about the flang-commits
mailing list