[flang-commits] [flang] [flang][cuda] Avoid triggering host array error in host device proc (PR #134909)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Tue Apr 8 12:04:19 PDT 2025
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/134909
we cannot enforce the detection of host arrays in device code when the procedure is host, device. Relax the check for those.
>From 949e60cd1468d94eb3bc9db62d0d3564b0401365 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 8 Apr 2025 12:03:02 -0700
Subject: [PATCH] [flang][cuda] Avoid triggering host array error in host
device proc
---
flang/lib/Semantics/check-cuda.cpp | 6 ++++++
flang/test/Semantics/cuf09.cuf | 7 +++++++
2 files changed, 13 insertions(+)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index dea170f7e099b..fd1ec2b2c69f8 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -261,6 +261,9 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
subp->cudaSubprogramAttrs().value_or(
common::CUDASubprogramAttrs::Host) !=
common::CUDASubprogramAttrs::Host) {
+ isHostDevice = subp->cudaSubprogramAttrs() &&
+ subp->cudaSubprogramAttrs() ==
+ common::CUDASubprogramAttrs::HostDevice;
Check(body);
}
}
@@ -357,6 +360,8 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
}
template <typename A>
void ErrorIfHostSymbol(const A &expr, parser::CharBlock source) {
+ if (isHostDevice)
+ return;
if (const Symbol * hostArray{FindHostArray{}(expr)}) {
context_.Say(source,
"Host array '%s' cannot be present in device context"_err_en_US,
@@ -502,6 +507,7 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
}
SemanticsContext &context_;
+ bool isHostDevice{false};
};
void CUDAChecker::Enter(const parser::SubroutineSubprogram &x) {
diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index b59d02192f618..193b22213da61 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -221,3 +221,10 @@ subroutine ieee_test
ll(i) = ieee_is_finite(y(i)) ! allow ieee_arithmetic functions on the device.
end do
end subroutine
+
+attributes(host,device) subroutine do2(a,b,c,i)
+ integer a(*), b(*), c(*)
+ integer, value :: i
+ c(i) = a(i) - b(i) ! ok. Should not error with Host array
+ ! cannot be present in device context
+end
More information about the flang-commits
mailing list