Skip to content

[flang][openacc] Allow multiple device_type clauses on init and shutdown #135314

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 11, 2025

Conversation

clementval
Copy link
Contributor

Relax the restriction for init and shutdown directives for device_type clause. The clause can be allowed multiple times.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir openacc flang:semantics labels Apr 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 11, 2025

@llvm/pr-subscribers-openacc
@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-fir-hlfir

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

Changes

Relax the restriction for init and shutdown directives for device_type clause. The clause can be allowed multiple times.


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

5 Files Affected:

  • (modified) flang/test/Lower/OpenACC/acc-init.f90 (+3)
  • (modified) flang/test/Lower/OpenACC/acc-shutdown.f90 (+3)
  • (modified) flang/test/Semantics/OpenACC/acc-init-validity.f90 (+1-1)
  • (modified) flang/test/Semantics/OpenACC/acc-shutdown-validity.f90 (+1-1)
  • (modified) llvm/include/llvm/Frontend/OpenACC/ACC.td (+6-10)
diff --git a/flang/test/Lower/OpenACC/acc-init.f90 b/flang/test/Lower/OpenACC/acc-init.f90
index 2fbb9550548a9..cc1abc4b294c7 100644
--- a/flang/test/Lower/OpenACC/acc-init.f90
+++ b/flang/test/Lower/OpenACC/acc-init.f90
@@ -35,4 +35,7 @@ subroutine acc_init
    !$acc init device_type(nvidia)
 !CHECK: acc.init attributes {device_types = [#acc.device_type<nvidia>]}
 
+  !$acc init device_type(host) device_type(multicore)
+!CHECK: acc.init attributes {device_types = [#acc.device_type<host>, #acc.device_type<multicore>]}
+
 end subroutine acc_init
diff --git a/flang/test/Lower/OpenACC/acc-shutdown.f90 b/flang/test/Lower/OpenACC/acc-shutdown.f90
index 6c080b932f92e..304dd4fae6db5 100644
--- a/flang/test/Lower/OpenACC/acc-shutdown.f90
+++ b/flang/test/Lower/OpenACC/acc-shutdown.f90
@@ -25,4 +25,7 @@ subroutine acc_shutdown
 !CHECK: [[DEVNUM:%.*]] = arith.constant 1 : i32
 !CHECK: acc.shutdown device_num([[DEVNUM]] : i32) attributes {device_types = [#acc.device_type<default>, #acc.device_type<nvidia>]} 
 
+  !$acc shutdown device_type(default) device_type(nvidia)
+!CHECK: acc.shutdown attributes {device_types = [#acc.device_type<default>, #acc.device_type<nvidia>]} 
+
 end subroutine acc_shutdown
diff --git a/flang/test/Semantics/OpenACC/acc-init-validity.f90 b/flang/test/Semantics/OpenACC/acc-init-validity.f90
index 3b594a25217c0..083a2415a5d77 100644
--- a/flang/test/Semantics/OpenACC/acc-init-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-init-validity.f90
@@ -93,7 +93,7 @@ program openacc_init_validity
   !ERROR: At most one DEVICE_NUM clause can appear on the INIT directive
   !$acc init device_num(1) device_num(i)
 
-  !ERROR: At most one DEVICE_TYPE clause can appear on the INIT directive
+  ! OK
   !$acc init device_type(nvidia) device_type(default, *)
 
   !ERROR: Must have LOGICAL or INTEGER type
diff --git a/flang/test/Semantics/OpenACC/acc-shutdown-validity.f90 b/flang/test/Semantics/OpenACC/acc-shutdown-validity.f90
index 43aed4fc98f42..163130d41bdcc 100644
--- a/flang/test/Semantics/OpenACC/acc-shutdown-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-shutdown-validity.f90
@@ -90,7 +90,7 @@ program openacc_shutdown_validity
   !ERROR: At most one DEVICE_NUM clause can appear on the SHUTDOWN directive
   !$acc shutdown device_num(1) device_num(i)
 
-  !ERROR: At most one DEVICE_TYPE clause can appear on the SHUTDOWN directive
+  ! OK
   !$acc shutdown device_type(*) device_type(host, default)
 
 end program openacc_shutdown_validity
diff --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index f3eefb52fc46d..8729d4505205b 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -432,11 +432,9 @@ def ACC_Cache : Directive<"cache"> {
 
 // 2.14.1
 def ACC_Init : Directive<"init"> {
-  let allowedOnceClauses = [
-    VersionedClause<ACCC_DeviceNum>,
-    VersionedClause<ACCC_DeviceType>,
-    VersionedClause<ACCC_If>
-  ];
+  let allowedOnceClauses = [VersionedClause<ACCC_DeviceNum>,
+                            VersionedClause<ACCC_If>];
+  let allowedClauses = [VersionedClause<ACCC_DeviceType>];
   let association = AS_None;
   let category = CA_Executable;
 }
@@ -480,11 +478,9 @@ def ACC_Set : Directive<"set"> {
 
 // 2.14.2
 def ACC_Shutdown : Directive<"shutdown"> {
-  let allowedOnceClauses = [
-    VersionedClause<ACCC_DeviceNum>,
-    VersionedClause<ACCC_DeviceType>,
-    VersionedClause<ACCC_If>
-  ];
+  let allowedOnceClauses = [VersionedClause<ACCC_DeviceNum>,
+                            VersionedClause<ACCC_If>];
+  let allowedClauses = [VersionedClause<ACCC_DeviceType>];
   let association = AS_None;
   let category = CA_Executable;
 }

Copy link
Contributor

@razvanlupusoru razvanlupusoru left a comment

Choose a reason for hiding this comment

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

Thank you.

@clementval clementval merged commit 8fb6bb3 into llvm:main Apr 11, 2025
16 checks passed
@clementval clementval deleted the flang_acc_init_shutdown_dtype branch April 11, 2025 17:15
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…own (llvm#135314)

Relax the restriction for init and shutdown directives for device_type
clause. The clause can be allowed multiple times.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:semantics flang Flang issues not falling into any other category openacc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants