Skip to content

Conversation

@clementval
Copy link
Contributor

When the LHS is a device variable and the RHS has implicit transfer, this is considered as an illegal transfer according to https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/index.html#implicit-data-transfer-in-expressions.

Detect this is semantic .

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Feb 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 3, 2025

@llvm/pr-subscribers-flang-semantics

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

Changes

When the LHS is a device variable and the RHS has implicit transfer, this is considered as an illegal transfer according to https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/index.html#implicit-data-transfer-in-expressions.

Detect this is semantic .


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

2 Files Affected:

  • (modified) flang/lib/Semantics/assignment.cpp (+11)
  • (added) flang/test/Semantics/cuf18.cuf (+11)
diff --git a/flang/lib/Semantics/assignment.cpp b/flang/lib/Semantics/assignment.cpp
index 0b57197fb8db8b..2b562571a679ee 100644
--- a/flang/lib/Semantics/assignment.cpp
+++ b/flang/lib/Semantics/assignment.cpp
@@ -90,6 +90,17 @@ void AssignmentContext::Analyze(const parser::AssignmentStmt &stmt) {
     if (whereDepth_ > 0) {
       CheckShape(lhsLoc, &lhs);
     }
+    if (context_.foldingContext().languageFeatures().IsEnabled(
+            common::LanguageFeature::CUDA)) {
+      const auto &scope{context_.FindScope(lhsLoc)};
+      const Scope &progUnit{GetProgramUnitContaining(scope)};
+      if (!IsCUDADeviceContext(&progUnit)) {
+        if (Fortran::evaluate::HasCUDADeviceAttrs(lhs) &&
+            Fortran::evaluate::HasCUDAImplicitTransfer(rhs)) {
+          context_.Say(lhsLoc, "Unsupported CUDA data transfer"_err_en_US);
+        }
+      }
+    }
   }
 }
 
diff --git a/flang/test/Semantics/cuf18.cuf b/flang/test/Semantics/cuf18.cuf
new file mode 100644
index 00000000000000..ce9a2a31ca0d15
--- /dev/null
+++ b/flang/test/Semantics/cuf18.cuf
@@ -0,0 +1,11 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+subroutine sub1()
+  real, allocatable, device :: a(:)
+
+!ERROR: Unsupported CUDA data transfer
+  a = a + 10 ! Illegal expression according to 3.4.2
+end subroutine
+
+
+

@clementval clementval merged commit 7e1437b into llvm:main Feb 3, 2025
11 checks passed
@clementval clementval deleted the cuf_data_illegal branch February 3, 2025 23:00
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
When the LHS is a device variable and the RHS has implicit transfer,
this is considered as an illegal transfer according to
https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/index.html#implicit-data-transfer-in-expressions.

Detect this is semantic .
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