Skip to content

[flang][openacc] Make async clause behavior homogenous #136610

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 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion flang/lib/Semantics/check-acc-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ void AccStructureChecker::Leave(const parser::OpenACCCacheConstruct &x) {

// Clause checkers
CHECK_SIMPLE_CLAUSE(Auto, ACCC_auto)
CHECK_SIMPLE_CLAUSE(Async, ACCC_async)
CHECK_SIMPLE_CLAUSE(Attach, ACCC_attach)
CHECK_SIMPLE_CLAUSE(Bind, ACCC_bind)
CHECK_SIMPLE_CLAUSE(Capture, ACCC_capture)
Expand Down Expand Up @@ -444,6 +443,12 @@ void AccStructureChecker::CheckMultipleOccurrenceInDeclare(
CheckMultipleOccurrenceInDeclare(objectList, clause);
}

void AccStructureChecker::Enter(const parser::AccClause::Async &c) {
llvm::acc::Clause crtClause = llvm::acc::Clause::ACCC_async;
CheckAllowed(crtClause);
CheckAllowedOncePerGroup(crtClause, llvm::acc::Clause::ACCC_device_type);
}

void AccStructureChecker::Enter(const parser::AccClause::Create &c) {
CheckAllowed(llvm::acc::Clause::ACCC_create);
const auto &modifierClause{c.v};
Expand Down
11 changes: 11 additions & 0 deletions flang/test/Semantics/OpenACC/acc-kernels.f90
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ program openacc_kernels_validity
!$acc kernels async(async1)
!$acc end kernels

!ERROR: At most one ASYNC clause can appear on the KERNELS directive or in group separated by the DEVICE_TYPE clause
!$acc kernels async(async1) async(2)
!$acc end kernels

!$acc kernels async(async1) device_type(multicore) async(2) ! ok
!$acc end kernels

!ERROR: At most one ASYNC clause can appear on the KERNELS directive or in group separated by the DEVICE_TYPE clause
!$acc kernels async(async1) device_type(multicore) async(2) async(3)
!$acc end kernels

!$acc kernels wait(wait1)
!$acc end kernels

Expand Down
11 changes: 11 additions & 0 deletions flang/test/Semantics/OpenACC/acc-parallel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ program openacc_parallel_validity
!$acc parallel async(1)
!$acc end parallel

!ERROR: At most one ASYNC clause can appear on the PARALLEL directive or in group separated by the DEVICE_TYPE clause
!$acc parallel async(1) async(2)
!$acc end parallel

!$acc parallel async(1) device_type(nvidia) async(3)
!$acc end parallel

!ERROR: At most one ASYNC clause can appear on the PARALLEL directive or in group separated by the DEVICE_TYPE clause
!$acc parallel async(1) device_type(nvidia) async(2) async(3)
!$acc end parallel

!$acc parallel async(async1)
!$acc end parallel

Expand Down
9 changes: 8 additions & 1 deletion flang/test/Semantics/OpenACC/acc-serial.f90
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ program openacc_serial_validity
!$acc serial async(1)
!$acc end serial

!ERROR: At most one ASYNC clause can appear on the SERIAL directive
!ERROR: At most one ASYNC clause can appear on the SERIAL directive or in group separated by the DEVICE_TYPE clause
!$acc serial async(1) async(2)
!$acc end serial

!ERROR: At most one ASYNC clause can appear on the SERIAL directive or in group separated by the DEVICE_TYPE clause
!$acc serial async(1) device_type(nvidia) async(2) async(4)
!$acc end serial

!$acc serial async(1) device_type(nvidia) async(2)
!$acc end serial

!$acc serial async(async1)
!$acc end serial

Expand Down
44 changes: 20 additions & 24 deletions llvm/include/llvm/Frontend/OpenACC/ACC.td
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ def ACC_Declare : Directive<"declare"> {

// 2.5.3
def ACC_Kernels : Directive<"kernels"> {
let allowedClauses = [VersionedClause<ACCC_Attach>,
let allowedClauses = [VersionedClause<ACCC_Async>,
VersionedClause<ACCC_Attach>,
VersionedClause<ACCC_Copy>,
VersionedClause<ACCC_Copyin>,
VersionedClause<ACCC_Copyout>,
Expand All @@ -338,8 +339,7 @@ def ACC_Kernels : Directive<"kernels"> {
VersionedClause<ACCC_DevicePtr>,
VersionedClause<ACCC_VectorLength>,
VersionedClause<ACCC_Wait>];
let allowedOnceClauses = [VersionedClause<ACCC_Async>,
VersionedClause<ACCC_Default>,
let allowedOnceClauses = [VersionedClause<ACCC_Default>,
VersionedClause<ACCC_If>,
VersionedClause<ACCC_Self>];
let association = AS_Block;
Expand Down Expand Up @@ -380,27 +380,23 @@ def ACC_Parallel : Directive<"parallel"> {
def ACC_Serial : Directive<"serial"> {
// Spec line 950-951: clause is as for the parallel construct except that the
// num_gangs, num_workers, and vector_length clauses are not permitted.
let allowedClauses = [
VersionedClause<ACCC_Attach>,
VersionedClause<ACCC_Copy>,
VersionedClause<ACCC_Copyin>,
VersionedClause<ACCC_Copyout>,
VersionedClause<ACCC_Create>,
VersionedClause<ACCC_DevicePtr>,
VersionedClause<ACCC_DeviceType>,
VersionedClause<ACCC_NoCreate>,
VersionedClause<ACCC_Present>,
VersionedClause<ACCC_Private>,
VersionedClause<ACCC_FirstPrivate>,
VersionedClause<ACCC_Reduction>,
VersionedClause<ACCC_Wait>
];
let allowedOnceClauses = [
VersionedClause<ACCC_Async>,
VersionedClause<ACCC_Default>,
VersionedClause<ACCC_If>,
VersionedClause<ACCC_Self>
];
let allowedClauses = [VersionedClause<ACCC_Async>,
VersionedClause<ACCC_Attach>,
VersionedClause<ACCC_Copy>,
VersionedClause<ACCC_Copyin>,
VersionedClause<ACCC_Copyout>,
VersionedClause<ACCC_Create>,
VersionedClause<ACCC_DevicePtr>,
VersionedClause<ACCC_DeviceType>,
VersionedClause<ACCC_NoCreate>,
VersionedClause<ACCC_Present>,
VersionedClause<ACCC_Private>,
VersionedClause<ACCC_FirstPrivate>,
VersionedClause<ACCC_Reduction>,
VersionedClause<ACCC_Wait>];
let allowedOnceClauses = [VersionedClause<ACCC_Default>,
VersionedClause<ACCC_If>,
VersionedClause<ACCC_Self>];
let association = AS_Block;
let category = CA_Executable;
}
Expand Down
Loading