[flang-commits] [flang] [flang][cuda] Allow host array with PARAMETER attribute in device context (PR #120298)

via flang-commits flang-commits at lists.llvm.org
Tue Dec 17 12:47:45 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

<details>
<summary>Changes</summary>

Host arrays are normally not allowed in device context unless they have a `PARAMETER` attribute. This patch update the check so no error is emitted. 

---
Full diff: https://github.com/llvm/llvm-project/pull/120298.diff


2 Files Affected:

- (modified) flang/lib/Semantics/check-cuda.cpp (+1) 
- (modified) flang/test/Semantics/cuf09.cuf (+7) 


``````````diff
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 9c044a47c79834..d8c9db22417398 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -110,6 +110,7 @@ struct FindHostArray
     if (const auto *details{
             symbol.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
       if (details->IsArray() &&
+          !symbol.attrs().test(Fortran::semantics::Attr::PARAMETER) &&
           (!details->cudaDataAttr() ||
               (details->cudaDataAttr() &&
                   *details->cudaDataAttr() != common::CUDADataAttr::Device &&
diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index c551ecbff2cc06..f120c931926cbc 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -1,6 +1,7 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
 module m
  integer :: m(100)
+ integer, parameter :: p(5) = [1,2,3,4,5]
  contains
   attributes(device) subroutine devsub
     !ERROR: Statement may not appear in device code
@@ -22,6 +23,12 @@ module m
     !ERROR: Host array 'm' cannot be present in device context
     if (i .le. N) a(i) = m(i)
   end subroutine
+
+  attributes(global) subroutine hostparameter(a)
+    integer :: a(*)
+    i = threadIdx%x
+    if (i .le. N) a(i) = p(i) ! ok. p is parameter
+  end subroutine
 end
 
 program main

``````````

</details>


https://github.com/llvm/llvm-project/pull/120298


More information about the flang-commits mailing list