Skip to content

[flang][cuda] Fix CUDA generic resolution for VALUE arguments in device procedures #140952

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 7 commits into from
Jun 10, 2025

Conversation

wangzpgi
Copy link
Contributor

For variables that have VALUE attribute inside device routines, implicitly set DEVICE attribute.

@wangzpgi wangzpgi requested a review from clementval May 21, 2025 18:59
@wangzpgi wangzpgi self-assigned this May 21, 2025
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels May 21, 2025
@llvmbot
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-flang-semantics

Author: Zhen Wang (wangzpgi)

Changes

For variables that have VALUE attribute inside device routines, implicitly set DEVICE attribute.


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

3 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+1-2)
  • (modified) flang/test/Semantics/cuf21.cuf (+9-5)
  • (modified) flang/test/Semantics/modfile55.cuf (+1)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 3f4a06444c4f3..f7c6a948375e4 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -9375,8 +9375,7 @@ void ResolveNamesVisitor::CreateGeneric(const parser::GenericSpec &x) {
 static void SetImplicitCUDADevice(bool inDeviceSubprogram, Symbol &symbol) {
   if (inDeviceSubprogram && symbol.has<ObjectEntityDetails>()) {
     auto *object{symbol.detailsIf<ObjectEntityDetails>()};
-    if (!object->cudaDataAttr() && !IsValue(symbol) &&
-        !IsFunctionResult(symbol)) {
+    if (!object->cudaDataAttr() && !IsFunctionResult(symbol)) {
       // Implicitly set device attribute if none is set in device context.
       object->set_cudaDataAttr(common::CUDADataAttr::Device);
     }
diff --git a/flang/test/Semantics/cuf21.cuf b/flang/test/Semantics/cuf21.cuf
index b8b99a8d1d9be..4251493c52e65 100644
--- a/flang/test/Semantics/cuf21.cuf
+++ b/flang/test/Semantics/cuf21.cuf
@@ -1,5 +1,6 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
-! Test generic matching with scalars argument without device attr
+! Test generic matching with scalars argument and argument
+! with VALUE attribute without DEVICE attr inside device routine
 
 module mlocModule
   interface maxlocUpdate
@@ -9,19 +10,22 @@ module mlocModule
   end interface maxlocUpdate
 contains
 
-  attributes(global) subroutine maxlocPartialMaskR_32F1D()
+  attributes(global) subroutine maxlocPartialMaskR_32F1D(back)
     implicit none
+    logical, intent(in), value :: back
     real(4) :: mval
 
-    call maxlocUpdate(mval)
+    call maxlocUpdate(mval, back)
 
   end subroutine maxlocPartialMaskR_32F1D
 
-  attributes(device) subroutine maxlocUpdateR_32F(mval)
+  attributes(device) subroutine maxlocUpdateR_32F(mval, back)
     real(4) :: mval
+    logical :: back
   end subroutine maxlocUpdateR_32F
 
-  attributes(device) subroutine maxlocUpdateR_64F(mval)
+  attributes(device) subroutine maxlocUpdateR_64F(mval, back)
     real(8) :: mval
+    logical :: back
   end subroutine maxlocUpdateR_64F
 end module
diff --git a/flang/test/Semantics/modfile55.cuf b/flang/test/Semantics/modfile55.cuf
index 2338b745d8355..abe6c30fa0f67 100644
--- a/flang/test/Semantics/modfile55.cuf
+++ b/flang/test/Semantics/modfile55.cuf
@@ -33,6 +33,7 @@ end
 !contains
 !attributes(global) subroutine globsub(x,y,z)
 !real(4),value::x
+!attributes(device)x
 !real(4)::y
 !attributes(device) y
 !real(4)::z

@wangzpgi wangzpgi changed the title implicitly set device attribute for variables have VALUE attribute in device routine [flang] [cuda] implicitly set device attribute for variables have VALUE attribute in device routine May 21, 2025
@clementval
Copy link
Contributor

Should we close this or does it still makes sense?

@wangzpgi
Copy link
Contributor Author

wangzpgi commented Jun 5, 2025

Should we close this or does it still makes sense?

Let me evaluate, and I will probably end up with closing this one. Thanks for the reminder.

@wangzpgi wangzpgi changed the title [flang] [cuda] implicitly set device attribute for variables have VALUE attribute in device routine [flang] [cuda] Fix CUDA generic resolution for VALUE arguments in device procedures Jun 10, 2025
@wangzpgi
Copy link
Contributor Author

I have updated this PR with an alternate fix.

@wangzpgi wangzpgi requested a review from clementval June 10, 2025 20:22
@clementval clementval changed the title [flang] [cuda] Fix CUDA generic resolution for VALUE arguments in device procedures [flang][cuda] Fix CUDA generic resolution for VALUE arguments in device procedures Jun 10, 2025
@wangzpgi wangzpgi requested a review from clementval June 10, 2025 22:02
Copy link
Contributor

@clementval clementval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wangzpgi wangzpgi merged commit 48122a7 into llvm:main Jun 10, 2025
6 of 7 checks passed
@wangzpgi wangzpgi deleted the value branch June 11, 2025 02:53
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
…ce procedures (llvm#140952)

For actual arguments that have VALUE attribute inside device routines, treat them as if they have device attribute.
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
…ce procedures (llvm#140952)

For actual arguments that have VALUE attribute inside device routines, treat them as if they have device attribute.
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
…ce procedures (llvm#140952)

For actual arguments that have VALUE attribute inside device routines, treat them as if they have device attribute.
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