]> git.ipfire.org Git - thirdparty/gcc.git/commit
openmp: Fix up handling of target constructs in offloaded routines [PR100573]
authorJakub Jelinek <jakub@redhat.com>
Wed, 26 May 2021 13:15:19 +0000 (15:15 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 26 May 2021 13:15:43 +0000 (15:15 +0200)
commitbdc5aeca04c67fbea8b51a68b0e6641042585699
tree12392de27cf4f7166b2f1b12ef84986aa5337b57
parentd179c16a366ddb16faaa49efbb9020b4c0fd2a8f
openmp: Fix up handling of target constructs in offloaded routines [PR100573]

OpenMP Nesting of Regions restrictions say:
- If a target update, target data, target enter data, or target exit data
construct is encountered during execution of a target region, the behavior is unspecified.
- If a target construct is encountered during execution of a target region and a device
clause in which the ancestor device-modifier appears is not present on the construct, the
behavior is unspecified.
That wording is about the dynamic (runtime) behavior, not about lexical nesting,
so while it is UB if omp target * is encountered in the target region, we need to make
it compile and link (for lexical nesting of target * inside of target we actually
emit a warning).

To make this work, I had to do multiple changes.
One was to mark .omp_data_{sizes,kinds}.* variables when static as "omp declare target".
Another one was to add stub GOMP_target* entrypoints to nvptx and gcn libgomp.a.
The entrypoint functions shouldn't be called or passed in the offload regions,
otherwise
libgomp: cuLaunchKernel error: too many resources requested for launch
was reported; fixed by changing those arguments of calls to GOMP_target_ext
to NULL.
And we didn't mark the entrypoints "omp target entrypoint" when the caller
has been "omp declare target".

2021-05-26  Jakub Jelinek  <jakub@redhat.com>

PR libgomp/100573
gcc/
* omp-low.c: Include omp-offload.h.
(create_omp_child_function): If current_function_decl has
"omp declare target" attribute and is_gimple_omp_offloaded,
remove that attribute from the copy of attribute list and
add "omp target entrypoint" attribute instead.
(lower_omp_target): Mark .omp_data_sizes.* and .omp_data_kinds.*
variables for offloading if in omp_maybe_offloaded_ctx.
* omp-offload.c (pass_omp_target_link::execute): Nullify second
argument to GOMP_target_data_ext in offloaded code.
libgomp/
* config/nvptx/target.c (GOMP_target_ext, GOMP_target_data_ext,
GOMP_target_end_data, GOMP_target_update_ext,
GOMP_target_enter_exit_data): New dummy entrypoints.
* config/gcn/target.c (GOMP_target_ext, GOMP_target_data_ext,
GOMP_target_end_data, GOMP_target_update_ext,
GOMP_target_enter_exit_data): Likewise.
* testsuite/libgomp.c-c++-common/for-3.c (DO_PRAGMA, OMPTEAMS,
OMPFROM, OMPTO): Define.
(main): Remove #pragma omp target teams around all the tests.
* testsuite/libgomp.c-c++-common/target-41.c: New test.
* testsuite/libgomp.c-c++-common/target-42.c: New test.

(cherry picked from commit 95d67762171f83277a5700b270c0d1e2756f83f4)
gcc/ChangeLog.omp
gcc/omp-low.c
gcc/omp-offload.c
libgomp/ChangeLog.omp
libgomp/config/gcn/target.c
libgomp/config/nvptx/target.c
libgomp/testsuite/libgomp.c-c++-common/for-3.c
libgomp/testsuite/libgomp.c-c++-common/target-41.c [new file with mode: 0644]
libgomp/testsuite/libgomp.c-c++-common/target-42.c [new file with mode: 0644]