Skip to content

Commit 9a698a6

Browse files
committed
[OpenACC] Implement new OpenACC device_type restriction
The OpenACC standard is going to change to clarify that init, shutdown, and set should only have a single architecture in each 'device_type' clause. This patch implements that restriction. See: OpenACC/openacc-spec#550
1 parent 489a41d commit 9a698a6

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13529,7 +13529,7 @@ def err_acc_invalid_modifier
1352913529
def err_acc_invalid_default_type
1353013530
: Error<"invalid value %0 in '%1' clause; valid values are %2">;
1353113531
def err_acc_device_type_multiple_archs
13532-
: Error<"OpenACC 'device_type' clause on a 'set' construct only permits "
13532+
: Error<"OpenACC 'device_type' clause on a '%0' construct only permits "
1353313533
"one architecture">;
1353413534
def warn_acc_var_referenced_non_const_array
1353513535
: Warning<"variable of array type %0 referenced in OpenACC '%1' clause "

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,13 +1054,17 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitWaitClause(
10541054
OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
10551055
SemaOpenACC::OpenACCParsedClause &Clause) {
10561056

1057-
// Based on discussions, having more than 1 'architecture' on a 'set' is
1058-
// nonsensical, so we're going to fix the standard to reflect this. Implement
1059-
// the limitation, since the Dialect requires this.
1060-
if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Set &&
1057+
// OpenACC Pull #550 (https://github.com/OpenACC/openacc-spec/pull/550)
1058+
// clarified that Init, Shutdown, and Set only support a single architecture.
1059+
// Though the dialect only requires it for 'set' as far as we know, we'll just
1060+
// implement all 3 here.
1061+
if ((Clause.getDirectiveKind() == OpenACCDirectiveKind::Init ||
1062+
Clause.getDirectiveKind() == OpenACCDirectiveKind::Shutdown ||
1063+
Clause.getDirectiveKind() == OpenACCDirectiveKind::Set) &&
10611064
Clause.getDeviceTypeArchitectures().size() > 1) {
10621065
SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].getLoc(),
1063-
diag::err_acc_device_type_multiple_archs);
1066+
diag::err_acc_device_type_multiple_archs)
1067+
<< Clause.getDirectiveKind();
10641068
return nullptr;
10651069
}
10661070

clang/test/CIR/CodeGenOpenACC/init.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ void acc_init(int cond) {
1111
// CHECK-NEXT: acc.init attributes {device_types = [#acc.device_type<star>]}
1212
#pragma acc init device_type(nvidia)
1313
// CHECK-NEXT: acc.init attributes {device_types = [#acc.device_type<nvidia>]}
14-
#pragma acc init device_type(host, multicore)
15-
// CHECK-NEXT: acc.init attributes {device_types = [#acc.device_type<host>, #acc.device_type<multicore>]}
1614
#pragma acc init device_type(NVIDIA)
1715
// CHECK-NEXT: acc.init attributes {device_types = [#acc.device_type<nvidia>]}
18-
#pragma acc init device_type(HoSt, MuLtIcORe)
19-
// CHECK-NEXT: acc.init attributes {device_types = [#acc.device_type<host>, #acc.device_type<multicore>]}
2016
#pragma acc init device_type(HoSt) device_type(MuLtIcORe)
2117
// CHECK-NEXT: acc.init attributes {device_types = [#acc.device_type<host>, #acc.device_type<multicore>]}
2218

clang/test/CIR/CodeGenOpenACC/shutdown.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ void acc_shutdown(int cond) {
1111
// CHECK-NEXT: acc.shutdown attributes {device_types = [#acc.device_type<star>]}
1212
#pragma acc shutdown device_type(nvidia)
1313
// CHECK-NEXT: acc.shutdown attributes {device_types = [#acc.device_type<nvidia>]}
14-
#pragma acc shutdown device_type(host, multicore)
15-
// CHECK-NEXT: acc.shutdown attributes {device_types = [#acc.device_type<host>, #acc.device_type<multicore>]}
1614
#pragma acc shutdown device_type(NVIDIA)
1715
// CHECK-NEXT: acc.shutdown attributes {device_types = [#acc.device_type<nvidia>]}
18-
#pragma acc shutdown device_type(HoSt, MuLtIcORe)
19-
// CHECK-NEXT: acc.shutdown attributes {device_types = [#acc.device_type<host>, #acc.device_type<multicore>]}
2016
#pragma acc shutdown device_type(HoSt) device_type(MuLtIcORe)
2117
// CHECK-NEXT: acc.shutdown attributes {device_types = [#acc.device_type<host>, #acc.device_type<multicore>]}
2218

clang/test/SemaOpenACC/init-construct.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ void uses() {
3434
// expected-error@+2{{OpenACC integer expression requires explicit conversion from 'struct ExplicitConvertOnly' to 'int'}}
3535
// expected-note@#EXPL_CONV{{conversion to integral type 'int'}}
3636
#pragma acc init device_num(Explicit)
37+
38+
// expected-error@+1{{OpenACC 'device_type' clause on a 'init' construct only permits one architecture}}
39+
#pragma acc init device_type(nvidia, radeon)
40+
41+
// expected-error@+1{{OpenACC 'device_type' clause on a 'init' construct only permits one architecture}}
42+
#pragma acc init device_type(nonsense, nvidia, radeon)
3743
}
3844

3945
template<typename T>

clang/test/SemaOpenACC/shutdown-construct.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ void uses() {
3434
// expected-error@+2{{OpenACC integer expression requires explicit conversion from 'struct ExplicitConvertOnly' to 'int'}}
3535
// expected-note@#EXPL_CONV{{conversion to integral type 'int'}}
3636
#pragma acc shutdown device_num(Explicit)
37+
38+
// expected-error@+1{{OpenACC 'device_type' clause on a 'shutdown' construct only permits one architecture}}
39+
#pragma acc shutdown device_type(nvidia, radeon)
40+
41+
// expected-error@+1{{OpenACC 'device_type' clause on a 'shutdown' construct only permits one architecture}}
42+
#pragma acc shutdown device_type(nonsense, nvidia, radeon)
3743
}
3844

3945
template<typename T>

0 commit comments

Comments
 (0)