[flang-commits] [flang] [flang][cuda] Allow host array with PARAMETER attribute in device context (PR #120298)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Tue Dec 17 12:47:10 PST 2024
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/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.
>From f17e4f33705b69a706bf4a608110c713c2ad468f Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 17 Dec 2024 12:45:33 -0800
Subject: [PATCH] [flang][cuda] Allow host array with PARAMETER attribute in
device context
---
flang/lib/Semantics/check-cuda.cpp | 1 +
flang/test/Semantics/cuf09.cuf | 7 +++++++
2 files changed, 8 insertions(+)
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
More information about the flang-commits
mailing list