[flang-commits] [flang] fed0f58 - [flang][cuda] Avoid triggering host array error in host device proc (#134909)
via flang-commits
flang-commits at lists.llvm.org
Tue Apr 8 12:55:15 PDT 2025
Author: Valentin Clement (バレンタイン クレメン)
Date: 2025-04-08T12:55:12-07:00
New Revision: fed0f58547f801d775d8f763cca5fe4eddd325cb
URL: https://github.com/llvm/llvm-project/commit/fed0f58547f801d775d8f763cca5fe4eddd325cb
DIFF: https://github.com/llvm/llvm-project/commit/fed0f58547f801d775d8f763cca5fe4eddd325cb.diff
LOG: [flang][cuda] Avoid triggering host array error in host device proc (#134909)
we cannot enforce the detection of host arrays in device code when the
procedure is host, device. Relax the check for those.
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 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