Skip to content

Commit 0f5eef1

Browse files
authored
[OpenMP][Clang] Force use of num_teams and thread_limit for bare kernel (#68373)
This patch makes `num_teams` and `thread_limit` mandatory for bare kernels, similar to a reguar kernel language that when launching a kernel, the grid size has to be set explicitly.
1 parent 1580877 commit 0f5eef1

File tree

6 files changed

+130
-104
lines changed

6 files changed

+130
-104
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11368,6 +11368,8 @@ def err_openmp_vla_in_task_untied : Error<
1136811368
def warn_omp_unterminated_declare_target : Warning<
1136911369
"expected '#pragma omp end declare target' at end of file to match '#pragma omp %0'">,
1137011370
InGroup<SourceUsesOpenMP>;
11371+
def err_ompx_bare_no_grid : Error<
11372+
"'ompx_bare' clauses requires explicit grid size via 'num_teams' and 'thread_limit' clauses">;
1137111373
} // end of OpenMP category
1137211374

1137311375
let CategoryName = "Related Result Type Issue" in {

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14658,6 +14658,19 @@ StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses,
1465814658
}
1465914659
setFunctionHasBranchProtectedScope();
1466014660

14661+
const OMPClause *BareClause = nullptr;
14662+
bool HasThreadLimitAndNumTeamsClause = hasClauses(Clauses, OMPC_num_teams) &&
14663+
hasClauses(Clauses, OMPC_thread_limit);
14664+
bool HasBareClause = llvm::any_of(Clauses, [&](const OMPClause *C) {
14665+
BareClause = C;
14666+
return C->getClauseKind() == OMPC_ompx_bare;
14667+
});
14668+
14669+
if (HasBareClause && !HasThreadLimitAndNumTeamsClause) {
14670+
Diag(BareClause->getBeginLoc(), diag::err_ompx_bare_no_grid);
14671+
return StmtError();
14672+
}
14673+
1466114674
return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses,
1466214675
AStmt);
1466314676
}

clang/test/OpenMP/nvptx_target_teams_ompx_bare_codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ template<typename tx>
1010
tx ftemplate(int n) {
1111
tx a = 0;
1212

13-
#pragma omp target teams ompx_bare
13+
#pragma omp target teams ompx_bare num_teams(1) thread_limit(32)
1414
{
1515
a = 2;
1616
}

clang/test/OpenMP/ompx_bare_messages.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown %s
2-
// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
3-
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -fopenmp-targets=nvptx64 %s
2+
// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
3+
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -fopenmp-targets=nvptx64 %s
44

55
void foo() {
66
}
@@ -18,4 +18,7 @@ void bar() {
1818
#pragma omp target
1919
#pragma omp teams ompx_bare // expected-error {{unexpected OpenMP clause 'ompx_bare' in directive '#pragma omp teams'}} expected-note {{OpenMP extension clause 'ompx_bare' only allowed with '#pragma omp target teams'}}
2020
foo();
21+
22+
#pragma omp target teams ompx_bare // expected-error {{'ompx_bare' clauses requires explicit grid size via 'num_teams' and 'thread_limit' clauses}}
23+
foo();
2124
}

clang/test/OpenMP/target_teams_ast_print.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ int main (int argc, char **argv) {
111111
// CHECK-NEXT: #pragma omp target teams
112112
a=2;
113113
// CHECK-NEXT: a = 2;
114-
#pragma omp target teams ompx_bare
115-
// CHECK-NEXT: #pragma omp target teams ompx_bare
114+
#pragma omp target teams ompx_bare num_teams(1) thread_limit(32)
115+
// CHECK-NEXT: #pragma omp target teams ompx_bare num_teams(1) thread_limit(32)
116116
a=3;
117117
// CHECK-NEXT: a = 3;
118118
#pragma omp target teams default(none), private(argc,b) num_teams(f) firstprivate(argv) reduction(| : c, d) reduction(* : e) thread_limit(f+g)

0 commit comments

Comments
 (0)