[flang-commits] [flang] [flang][cuda] Check for use of host array in device context (PR #119756)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Mon Dec 16 07:21:43 PST 2024
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/119756
>From 30817dc2b76147e47f3b3ca34274782e6ee6fc73 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 12 Dec 2024 11:00:47 -0800
Subject: [PATCH 1/2] [flang][cuda] Check for use of host array in device
context
---
flang/lib/Semantics/check-cuda.cpp | 14 ++++++--------
flang/test/Semantics/cuf09.cuf | 9 ++++++++-
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 79b7a26ef222f8..dd3472aad40bcb 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -340,7 +340,7 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
void ErrorIfHostSymbol(const A &expr, parser::CharBlock source) {
if (const Symbol * hostArray{FindHostArray{}(expr)}) {
context_.Say(source,
- "Host array '%s' cannot be present in CUF kernel"_err_en_US,
+ "Host array '%s' cannot be present in device context"_err_en_US,
hostArray->name());
}
}
@@ -387,13 +387,11 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
Check(x.value());
},
[&](const common::Indirection<parser::AssignmentStmt> &x) {
- if (IsCUFKernelDo) {
- const evaluate::Assignment *assign{
- semantics::GetAssignment(x.value())};
- if (assign) {
- ErrorIfHostSymbol(assign->lhs, source);
- ErrorIfHostSymbol(assign->rhs, source);
- }
+ const evaluate::Assignment *assign{
+ semantics::GetAssignment(x.value())};
+ if (assign) {
+ ErrorIfHostSymbol(assign->lhs, source);
+ ErrorIfHostSymbol(assign->rhs, source);
}
if (auto msg{ActionStmtChecker<IsCUFKernelDo>::WhyNotOk(x)}) {
context_.Say(source, std::move(*msg));
diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index 195ddac11d575f..c551ecbff2cc06 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -1,5 +1,6 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
module m
+ integer :: m(100)
contains
attributes(device) subroutine devsub
!ERROR: Statement may not appear in device code
@@ -15,6 +16,12 @@ module m
!WARNING: I/O statement might not be supported on device
write(12,'(10F4.1)'), x
end
+ attributes(global) subroutine hostglobal(a)
+ integer :: a(*)
+ i = threadIdx%x
+ !ERROR: Host array 'm' cannot be present in device context
+ if (i .le. N) a(i) = m(i)
+ end subroutine
end
program main
@@ -96,7 +103,7 @@ program main
!$cuf kernel do (2) <<<*, *>>>
do j = 1, 10
do i = 1, 10
- !ERROR: Host array 'b' cannot be present in CUF kernel
+ !ERROR: Host array 'b' cannot be present in device context
a_d(i,j) = b(i,j)
enddo
enddo
>From cbcd5f345afb700ea51a624e75512e8c27f35adc Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 16 Dec 2024 07:20:44 -0800
Subject: [PATCH 2/2] Make assign local
---
flang/lib/Semantics/check-cuda.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index dd3472aad40bcb..9c044a47c79834 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -387,9 +387,8 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
Check(x.value());
},
[&](const common::Indirection<parser::AssignmentStmt> &x) {
- const evaluate::Assignment *assign{
- semantics::GetAssignment(x.value())};
- if (assign) {
+ if (const evaluate::Assignment *
+ assign{semantics::GetAssignment(x.value())}) {
ErrorIfHostSymbol(assign->lhs, source);
ErrorIfHostSymbol(assign->rhs, source);
}
More information about the flang-commits
mailing list