https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100573

--- Comment #21 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:95d67762171f83277a5700b270c0d1e2756f83f4

commit r12-1066-g95d67762171f83277a5700b270c0d1e2756f83f4
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Wed May 26 11:18:07 2021 +0200

    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  <ja...@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.

Reply via email to