95d6776217
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.
27 lines
713 B
C
27 lines
713 B
C
/* PR libgomp/100573 */
|
|
|
|
int
|
|
foo (int a)
|
|
{
|
|
#pragma omp target firstprivate(a)
|
|
if (a == 0)
|
|
{
|
|
a++;
|
|
#pragma omp target map(tofrom:a) /* { dg-warning "'target' construct inside of 'target' region" } */
|
|
a = foo (a);
|
|
#pragma omp target data map(tofrom:a) /* { dg-warning "'target data' construct inside of 'target' region" } */
|
|
a++;
|
|
#pragma omp target enter data map(to:a) /* { dg-warning "'target enter data' construct inside of 'target' region" } */
|
|
#pragma omp target exit data map(from:a) /* { dg-warning "'target exit data' construct inside of 'target' region" } */
|
|
}
|
|
return a + 1;
|
|
}
|
|
|
|
int
|
|
main ()
|
|
{
|
|
if (foo (1) != 2)
|
|
__builtin_abort ();
|
|
return 0;
|
|
}
|