[flang-commits] [flang] 8a6a0f1 - [flang][cuda] Add proper TODO for cuda fortran assignment (#85705)

via flang-commits flang-commits at lists.llvm.org
Mon Mar 18 17:11:08 PDT 2024


Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-03-18T17:11:04-07:00
New Revision: 8a6a0f1954937341abd501529f3d7454937110a5

URL: https://github.com/llvm/llvm-project/commit/8a6a0f1954937341abd501529f3d7454937110a5
DIFF: https://github.com/llvm/llvm-project/commit/8a6a0f1954937341abd501529f3d7454937110a5.diff

LOG: [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

Added: 
    

Modified: 
    flang/include/flang/Evaluate/tools.h
    flang/lib/Lower/Bridge.cpp
    flang/test/Lower/CUDA/cuda-module-use.cuf

Removed: 
    


################################################################################
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