[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
jplehr wrote: It seems that this broke the AMDGPU OpenMP buildbot https://lab.llvm.org/buildbot/#/builders/193/builds/39393 I saw that you have since pushed up one patch regarding pointer compares. Are you looking at the remaining test fails as well? https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
https://github.com/shiltian closed https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
https://github.com/shiltian edited https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
https://github.com/jdoerfert approved this pull request. LG, we need runtime tests in a follow up. https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
https://github.com/shiltian resolved https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
@@ -752,27 +751,41 @@ void CGOpenMPRuntimeGPU::emitNonSPMDKernel(const OMPExecutableDirective , EntryFunctionState EST; WrapperFunctionsMap.clear(); + bool IsBareKernel = D.getSingleClause(); shiltian wrote: I made the change in the parent scope such that a bare kernel is taken as SPMD as well. https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
shiltian wrote: > Where is the code that prevents the init/deinit calls from being created? It's in the early exit. https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
@@ -752,27 +751,41 @@ void CGOpenMPRuntimeGPU::emitNonSPMDKernel(const OMPExecutableDirective , EntryFunctionState EST; WrapperFunctionsMap.clear(); + bool IsBareKernel = D.getSingleClause(); shiltian wrote: So `target teams` is generic mode. Since we don't emit the kernel init/deinit, the kernel env will not be emitted as well. At runtime we will default to SPMD mode. As discussed offline, we will need an extra mode, if we want, but no kernel env should work perfectly fine. https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
https://github.com/jdoerfert edited https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
@@ -752,27 +751,41 @@ void CGOpenMPRuntimeGPU::emitNonSPMDKernel(const OMPExecutableDirective , EntryFunctionState EST; WrapperFunctionsMap.clear(); + bool IsBareKernel = D.getSingleClause(); jdoerfert wrote: How can a non-spmd kernel be bare? We should force bare kernels to be SPMD, make this an assertion. https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
https://github.com/jdoerfert commented: Where is the code that prevents the init/deinit calls from being created? https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
https://github.com/shiltian resolved https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
@@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -verify -fopenmp %s +// RUN: %clang_cc1 -verify -fopenmp-simd %s +// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=nvptx64 %s + +void foo() { +} + +void bar() { +#pragma omp target ompx_bare // expected-error {{unexpected OpenMP clause 'ompx_bare' in directive '#pragma omp target'}} expected-note {{OpenMP extension clause 'ompx_bare' only allowed with '#pragma omp target'}} shiltian wrote: I figured the note is not helpful at all since we need it to be on `target teams` instead of `target`. Updated. https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
@@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -verify -fopenmp %s +// RUN: %clang_cc1 -verify -fopenmp-simd %s +// RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=nvptx64 %s + +void foo() { +} + +void bar() { +#pragma omp target ompx_bare // expected-error {{unexpected OpenMP clause 'ompx_bare' in directive '#pragma omp target'}} expected-note {{OpenMP extension clause 'ompx_bare' only allowed with '#pragma omp target'}} jdoerfert wrote: This message seems unhelpful. https://github.com/llvm/llvm-project/pull/66844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenMP] Introduce the initial support for OpenMP kernel language (PR #66844)
llvmbot wrote: @llvm/pr-subscribers-clang Changes This patch starts the support for OpenMP kernel language, basically to write OpenMP target region in SIMT style, similar to kernel languages such as CUDA. What included in this first patch is the `ompx_bare` clause for `target teams` directive. When `ompx_bare` exists, globalization is disabled such that local variables will not be globalized. The runtime init/deinit function calls will not be emitted. That being said, almost all OpenMP executable directives are not supported in the region, such as parallel, task. This patch doesn't include the Sema checks for that, so the use of them is UB. Simple directives, such as atomic, can be used. We provide a set of APIs (for C, they are prefix with `ompx_`; for C++, they are in `ompx` namespace) to get thread id, block id, etc. For more details, you can refer to https://tianshilei.me/wp-content/uploads/llvm-hpc-2022.pdf?swcfpc=1. --- Patch is 232.77 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/66844.diff 19 Files Affected: - (modified) clang/include/clang/AST/OpenMPClause.h (+21) - (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+5) - (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+4) - (modified) clang/include/clang/Sema/Sema.h (+4) - (modified) clang/lib/AST/OpenMPClause.cpp (+5) - (modified) clang/lib/AST/StmtProfile.cpp (+1) - (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+54-19) - (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.h (+18-11) - (modified) clang/lib/Parse/ParseOpenMP.cpp (+11) - (modified) clang/lib/Sema/SemaOpenMP.cpp (+8) - (modified) clang/lib/Sema/TreeTransform.h (+14) - (modified) clang/lib/Serialization/ASTReader.cpp (+5) - (modified) clang/lib/Serialization/ASTWriter.cpp (+2) - (modified) clang/test/OpenMP/nvptx_target_teams_codegen.cpp (+81-14) - (added) clang/test/OpenMP/ompx_bare_messages.c (+21) - (modified) clang/test/OpenMP/target_teams_ast_print.cpp (+4) - (modified) clang/test/OpenMP/target_teams_codegen.cpp (+917-629) - (modified) clang/tools/libclang/CIndex.cpp (+1) - (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+5) ``diff diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index 31ae3d42e232fca..eeeca1998f9fa9c 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -9220,6 +9220,27 @@ class OMPXAttributeClause } }; +/// This represents 'ompx_bare' clause in the '#pragma omp target teams ...' +/// directive. +/// +/// \code +/// #pragma omp target teams ompx_bare +/// \endcode +/// In this example directive '#pragma omp target teams' has a 'ompx_bare' +/// clause. +class OMPXBareClause : public OMPNoChildClause { +public: + /// Build 'ompx_bare' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPNoChildClause(StartLoc, EndLoc) {} + + /// Build an empty clause. + OMPXBareClause() = default; +}; + } // namespace clang #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index d4146d52893ffb1..298489e7d4fc413 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -3890,6 +3890,11 @@ bool RecursiveASTVisitor::VisitOMPXAttributeClause( return true; } +template +bool RecursiveASTVisitor::VisitOMPXBareClause(OMPXBareClause *C) { + return true; +} + // FIXME: look at the following tricky-seeming exprs to see if we // need to recurse on anything. These are ones that have methods // returning decls or qualtypes or nestednamespecifier -- though I'm diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 178761bdcf4d5e3..43a5f000eda6cb9 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1360,6 +1360,8 @@ def warn_clause_expected_string : Warning< "expected string literal in 'clause %0' - ignoring">, InGroup; def err_omp_unexpected_clause : Error< "unexpected OpenMP clause '%0' in directive '#pragma omp %1'">; +def err_omp_unexpected_clause_extension_only : Error< + "OpenMP clause '%0' is only available as extension, use '-fopenmp-extensions'">; def err_omp_immediate_directive : Error< "'#pragma omp %0' %select{|with '%2' clause }1cannot be an immediate substatement">; def err_omp_expected_identifier_for_critical : Error< @@ -1452,6 +1454,8 @@ def warn_unknown_declare_variant_isa_trait "spelling or consider restricting the context selector with the " "'arch' selector further">, InGroup; +def note_ompx_bare_clause : Note< + "OpenMP extension clause '%0' only allowed