Skip to content

[flang] [cuda] implicitly set device attribute for variables have VALUE attribute in device routine #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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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
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.

2 participants