[flang-commits] [flang] [flang][cuda] Add a proper TODO for allocate statement for cuda var (PR #88034)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Tue Apr 9 09:17:28 PDT 2024


https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/88034

>From 1cf16605ee88983951d2b1050fba53cba8961320 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 8 Apr 2024 13:10:09 -0700
Subject: [PATCH 1/2] [flang][cuda] Add a proper TODO for allocate statement
 for cuda var

Allocate statement for variable with CUDA attributes need to allocate
memory on the device and not the host. Add a proper TODO so we keep
track of work to be done for it.
---
 flang/include/flang/Semantics/tools.h | 10 ++++++++++
 flang/lib/Lower/Allocatable.cpp       |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h
index f0eb82eebefa31..b982ffe7946b3a 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -212,6 +212,16 @@ inline bool IsCUDADeviceContext(const Scope *scope) {
   return false;
 }
 
+inline bool HasCUDAAttr(const Symbol &sym) {
+  if (const auto *details =
+          sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()) {
+    if (details->cudaDataAttr()) {
+      return true;
+    }
+  }
+  return false;
+}
+
 const Scope *FindCUDADeviceContext(const Scope *);
 std::optional<common::CUDADataAttr> GetCUDADataAttr(const Symbol *);
 
diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp
index 09180518ea41d9..ddde4a4730c3dc 100644
--- a/flang/lib/Lower/Allocatable.cpp
+++ b/flang/lib/Lower/Allocatable.cpp
@@ -379,6 +379,9 @@ class AllocateStmtHelper {
   }
 
   void lowerAllocation(const Allocation &alloc) {
+    if (HasCUDAAttr(alloc.getSymbol()))
+      TODO(loc, "Allocation of variable with CUDA attributes");
+
     fir::MutableBoxValue boxAddr =
         genMutableBoxValue(converter, loc, alloc.getAllocObj());
 

>From bbecacde346779479fa099d7e53d1f34e4127c01 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 9 Apr 2024 09:16:48 -0700
Subject: [PATCH 2/2] Address comments

---
 flang/include/flang/Semantics/tools.h | 4 ++--
 flang/lib/Lower/Allocatable.cpp       | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h
index b982ffe7946b3a..da10969ebc7021 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -213,8 +213,8 @@ inline bool IsCUDADeviceContext(const Scope *scope) {
 }
 
 inline bool HasCUDAAttr(const Symbol &sym) {
-  if (const auto *details =
-          sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()) {
+  if (const auto *details{
+          sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
     if (details->cudaDataAttr()) {
       return true;
     }
diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp
index ddde4a4730c3dc..42e78fc96e4445 100644
--- a/flang/lib/Lower/Allocatable.cpp
+++ b/flang/lib/Lower/Allocatable.cpp
@@ -379,7 +379,7 @@ class AllocateStmtHelper {
   }
 
   void lowerAllocation(const Allocation &alloc) {
-    if (HasCUDAAttr(alloc.getSymbol()))
+    if (Fortran::semantics::HasCUDAAttr(alloc.getSymbol()))
       TODO(loc, "Allocation of variable with CUDA attributes");
 
     fir::MutableBoxValue boxAddr =



More information about the flang-commits mailing list