Skip to content

[flang][cuda] Avoid triggering host array error in host device proc #134909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

clementval
Copy link
Contributor

we cannot enforce the detection of host arrays in device code when the procedure is host, device. Relax the check for those.

@clementval clementval requested a review from wangzpgi April 8, 2025 19:04
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Apr 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 8, 2025

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

we cannot enforce the detection of host arrays in device code when the procedure is host, device. Relax the check for those.


Full diff: https://github.com/llvm/llvm-project/pull/134909.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-cuda.cpp (+6)
  • (modified) flang/test/Semantics/cuf09.cuf (+7)
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

@clementval clementval merged commit fed0f58 into llvm:main Apr 8, 2025
12 of 13 checks passed
@clementval clementval deleted the cuf_host_array_host_device branch April 8, 2025 19:55
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…lvm#134909)

we cannot enforce the detection of host arrays in device code when the
procedure is host, device. Relax the check for those.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants