Skip to content

Commit

Permalink
[OpenMP][Clang] Force use of num_teams and thread_limit for bare …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
shiltian committed Dec 18, 2023
1 parent 1580877 commit 0f5eef1
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 104 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11368,6 +11368,8 @@ def err_openmp_vla_in_task_untied : Error<
def warn_omp_unterminated_declare_target : Warning<
"expected '#pragma omp end declare target' at end of file to match '#pragma omp %0'">,
InGroup<SourceUsesOpenMP>;
def err_ompx_bare_no_grid : Error<
"'ompx_bare' clauses requires explicit grid size via 'num_teams' and 'thread_limit' clauses">;
} // end of OpenMP category

let CategoryName = "Related Result Type Issue" in {
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14658,6 +14658,19 @@ StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses,
}
setFunctionHasBranchProtectedScope();

const OMPClause *BareClause = nullptr;
bool HasThreadLimitAndNumTeamsClause = hasClauses(Clauses, OMPC_num_teams) &&
hasClauses(Clauses, OMPC_thread_limit);
bool HasBareClause = llvm::any_of(Clauses, [&](const OMPClause *C) {
BareClause = C;
return C->getClauseKind() == OMPC_ompx_bare;
});

if (HasBareClause && !HasThreadLimitAndNumTeamsClause) {
Diag(BareClause->getBeginLoc(), diag::err_ompx_bare_no_grid);
return StmtError();
}

return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses,
AStmt);
}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/nvptx_target_teams_ompx_bare_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ template<typename tx>
tx ftemplate(int n) {
tx a = 0;

#pragma omp target teams ompx_bare
#pragma omp target teams ompx_bare num_teams(1) thread_limit(32)
{
a = 2;
}
Expand Down
7 changes: 5 additions & 2 deletions clang/test/OpenMP/ompx_bare_messages.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown %s
// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -fopenmp-targets=nvptx64 %s
// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-unknown %s
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown -fopenmp-targets=nvptx64 %s

void foo() {
}
Expand All @@ -18,4 +18,7 @@ void bar() {
#pragma omp target
#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'}}
foo();

#pragma omp target teams ompx_bare // expected-error {{'ompx_bare' clauses requires explicit grid size via 'num_teams' and 'thread_limit' clauses}}
foo();
}
4 changes: 2 additions & 2 deletions clang/test/OpenMP/target_teams_ast_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ int main (int argc, char **argv) {
// CHECK-NEXT: #pragma omp target teams
a=2;
// CHECK-NEXT: a = 2;
#pragma omp target teams ompx_bare
// CHECK-NEXT: #pragma omp target teams ompx_bare
#pragma omp target teams ompx_bare num_teams(1) thread_limit(32)
// CHECK-NEXT: #pragma omp target teams ompx_bare num_teams(1) thread_limit(32)
a=3;
// CHECK-NEXT: a = 3;
#pragma omp target teams default(none), private(argc,b) num_teams(f) firstprivate(argv) reduction(| : c, d) reduction(* : e) thread_limit(f+g)
Expand Down

0 comments on commit 0f5eef1

Please sign in to comment.