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

via flang-commits flang-commits at lists.llvm.org
Tue Dec 17 13:41:28 PST 2024


Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-12-17T13:41:24-08:00
New Revision: 97b7bace67c4fb7d62892f5bc6d7614a65d0fb3e

URL: https://github.com/llvm/llvm-project/commit/97b7bace67c4fb7d62892f5bc6d7614a65d0fb3e
DIFF: https://github.com/llvm/llvm-project/commit/97b7bace67c4fb7d62892f5bc6d7614a65d0fb3e.diff

LOG: [flang][cuda] Allow host array with PARAMETER attribute in device context (#120298)

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.

Added: 
    

Modified: 
    flang/lib/Semantics/check-cuda.cpp
    flang/test/Semantics/cuf09.cuf

Removed: 
    


################################################################################
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 e0ca814aec26a0..e2247da961f7ee 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
@@ -23,6 +24,12 @@ module m
     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
+
   attributes(global) subroutine localarray()
     integer :: a(10)
     i = threadIdx%x


        


More information about the flang-commits mailing list