Skip to content

[flang][openacc] Make num_gangs, num_workers and vector_length behavior homogenous with parallel #136341

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

Conversation

clementval
Copy link
Contributor

The num_gangs, num_workers and vector_length clauses should behave the same way as with the parallel directive. Update the ACC.td file to allow the clauses multiple times and let the semantic check the device_type sections.

Add some tests.

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

llvmbot commented Apr 18, 2025

@llvm/pr-subscribers-openacc

@llvm/pr-subscribers-flang-semantics

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

Changes

The num_gangs, num_workers and vector_length clauses should behave the same way as with the parallel directive. Update the ACC.td file to allow the clauses multiple times and let the semantic check the device_type sections.

Add some tests.


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

2 Files Affected:

  • (modified) flang/test/Semantics/OpenACC/acc-kernels.f90 (+33)
  • (modified) llvm/include/llvm/Frontend/OpenACC/ACC.td (+17-21)
diff --git a/flang/test/Semantics/OpenACC/acc-kernels.f90 b/flang/test/Semantics/OpenACC/acc-kernels.f90
index 8a209040a7793..33e253ca8d874 100644
--- a/flang/test/Semantics/OpenACC/acc-kernels.f90
+++ b/flang/test/Semantics/OpenACC/acc-kernels.f90
@@ -61,12 +61,45 @@ program openacc_kernels_validity
   !$acc kernels num_gangs(8)
   !$acc end kernels
 
+  !ERROR: At most one NUM_GANGS clause can appear on the KERNELS directive or in group separated by the DEVICE_TYPE clause
+  !$acc kernels num_gangs(8) num_gangs(10)
+  !$acc end kernels
+
+  !ERROR: At most one NUM_GANGS clause can appear on the KERNELS directive or in group separated by the DEVICE_TYPE clause
+  !$acc kernels device_type(nvidia) num_gangs(8) num_gangs(10)
+  !$acc end kernels
+
+  !$acc kernels device_type(nvidia) num_gangs(8) device_type(radeon) num_gangs(10)
+  !$acc end kernels
+
   !$acc kernels num_workers(8)
   !$acc end kernels
 
+  !ERROR: At most one NUM_WORKERS clause can appear on the KERNELS directive or in group separated by the DEVICE_TYPE clause
+  !$acc kernels num_workers(8) num_workers(4)
+  !$acc end kernels
+
+  !ERROR: At most one NUM_WORKERS clause can appear on the KERNELS directive or in group separated by the DEVICE_TYPE clause
+  !$acc kernels device_type(nvidia) num_workers(8) num_workers(4)
+  !$acc end kernels
+
+  !$acc kernels device_type(nvidia) num_workers(8) device_type(radeon) num_workers(4)
+  !$acc end kernels
+
   !$acc kernels vector_length(128)
   !$acc end kernels
 
+  !ERROR: At most one VECTOR_LENGTH clause can appear on the KERNELS directive or in group separated by the DEVICE_TYPE clause
+  !$acc kernels vector_length(128) vector_length(124)
+  !$acc end kernels
+
+  !ERROR: At most one VECTOR_LENGTH clause can appear on the KERNELS directive or in group separated by the DEVICE_TYPE clause
+  !$acc kernels device_type(nvidia) vector_length(256) vector_length(128)
+  !$acc end kernels
+
+  !$acc kernels device_type(nvidia) vector_length(256) device_type(radeon) vector_length(128)
+  !$acc end kernels
+
   !$acc kernels if(.true.)
   !$acc end kernels
 
diff --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index e1a4183785d1f..898b7dc9e230f 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -319,27 +319,23 @@ def ACC_Declare : Directive<"declare"> {
 
 // 2.5.3
 def ACC_Kernels : Directive<"kernels"> {
-  let allowedClauses = [
-    VersionedClause<ACCC_Attach>,
-    VersionedClause<ACCC_Copy>,
-    VersionedClause<ACCC_Copyin>,
-    VersionedClause<ACCC_Copyout>,
-    VersionedClause<ACCC_Create>,
-    VersionedClause<ACCC_DeviceType>,
-    VersionedClause<ACCC_NoCreate>,
-    VersionedClause<ACCC_Present>,
-    VersionedClause<ACCC_DevicePtr>,
-    VersionedClause<ACCC_Wait>
-  ];
-  let allowedOnceClauses = [
-    VersionedClause<ACCC_Async>,
-    VersionedClause<ACCC_Default>,
-    VersionedClause<ACCC_If>,
-    VersionedClause<ACCC_NumGangs>,
-    VersionedClause<ACCC_NumWorkers>,
-    VersionedClause<ACCC_Self>,
-    VersionedClause<ACCC_VectorLength>
-  ];
+  let allowedClauses = [VersionedClause<ACCC_Attach>,
+                        VersionedClause<ACCC_Copy>,
+                        VersionedClause<ACCC_Copyin>,
+                        VersionedClause<ACCC_Copyout>,
+                        VersionedClause<ACCC_Create>,
+                        VersionedClause<ACCC_DeviceType>,
+                        VersionedClause<ACCC_NoCreate>,
+                        VersionedClause<ACCC_NumGangs>,
+                        VersionedClause<ACCC_NumWorkers>,
+                        VersionedClause<ACCC_Present>,
+                        VersionedClause<ACCC_DevicePtr>,
+                        VersionedClause<ACCC_VectorLength>,
+                        VersionedClause<ACCC_Wait>];
+  let allowedOnceClauses = [VersionedClause<ACCC_Async>,
+                            VersionedClause<ACCC_Default>,
+                            VersionedClause<ACCC_If>,
+                            VersionedClause<ACCC_Self>];
   let association = AS_Block;
   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 7c9f4f1 into llvm:main Apr 18, 2025
15 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 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 openacc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants