gcc/libgomp/testsuite/libgomp.c-c++-common/map-arrayofstruct-1.c

52 lines
1.3 KiB
C
Raw Permalink Normal View History

OpenMP/OpenACC: Unordered/non-constant component offset runtime diagnostic This patch adds support for non-constant component offsets in "map" clauses for OpenMP (and the equivalants for OpenACC), which are not able to be sorted into order at compile time. Normally struct accesses in such clauses are gathered together and sorted into increasing address order after a "GOMP_MAP_STRUCT" node: if we have variable indices, that is no longer possible. This version of the patch scales back the previously-posted version to merely add a diagnostic for incorrect usage of component accesses with variably-indexed arrays of structs: the only permitted variant is where we have multiple indices that are the same, but we could not prove so at compile time. Rather than silently producing the wrong result for cases where the indices are in fact different, we error out (e.g., "map(dtarr(i)%arrptr, dtarr(j)%arrptr(4:8))", for different i/j). For now, multiple *constant* array indices are still supported (see map-arrayofstruct-1.c). That could perhaps be addressed with a follow-up patch, if necessary. This version of the patch renumbers the GOMP_MAP_STRUCT_UNORD kind to avoid clashing with the OpenACC "non-contiguous" dynamic array support (though that is not yet applied to mainline). 2023-08-18 Julian Brown <julian@codesourcery.com> gcc/ * gimplify.cc (extract_base_bit_offset): Add VARIABLE_OFFSET parameter. (omp_get_attachment, omp_group_last, omp_group_base, omp_directive_maps_explicitly): Add GOMP_MAP_STRUCT_UNORD support. (omp_accumulate_sibling_list): Update calls to extract_base_bit_offset. Support GOMP_MAP_STRUCT_UNORD. (omp_build_struct_sibling_lists, gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses, gimplify_omp_target_update): Add GOMP_MAP_STRUCT_UNORD support. * omp-low.cc (lower_omp_target): Add GOMP_MAP_STRUCT_UNORD support. * tree-pretty-print.cc (dump_omp_clause): Likewise. include/ * gomp-constants.h (gomp_map_kind): Add GOMP_MAP_STRUCT_UNORD. libgomp/ * oacc-mem.c (find_group_last, goacc_enter_data_internal, goacc_exit_data_internal, GOACC_enter_exit_data): Add GOMP_MAP_STRUCT_UNORD support. * target.c (gomp_map_vars_internal): Add GOMP_MAP_STRUCT_UNORD support. Detect incorrect use of variable indexing of arrays of structs. (GOMP_target_enter_exit_data, gomp_target_task_fn): Add GOMP_MAP_STRUCT_UNORD support. * testsuite/libgomp.c-c++-common/map-arrayofstruct-1.c: New test. * testsuite/libgomp.c-c++-common/map-arrayofstruct-2.c: New test. * testsuite/libgomp.c-c++-common/map-arrayofstruct-3.c: New test. * testsuite/libgomp.fortran/map-subarray-5.f90: New test.
2022-10-10 04:26:09 +08:00
#include <stdlib.h>
#include <assert.h>
struct st {
int *p;
};
int main (void)
{
struct st s[2];
s[0].p = (int *) calloc (5, sizeof (int));
s[1].p = (int *) calloc (5, sizeof (int));
/* These mappings not supported by the OpenMP spec, and are currently
implemented as an extension by GCC for legacy compatibility only. See
e.g. OpenMP 5.2, "5.8.3 map Clause":
"If multiple list items are explicitly mapped on the same construct and
have the same containing array or have base pointers that share original
storage, and if any of the list items do not have corresponding list
items that are present in the device data environment prior to a task
encountering the construct, then the list items must refer to the same
array elements of either the containing array or the implicit array of
the base pointers."
*/
#pragma omp target map(s[0].p, s[1].p, s[0].p[0:2], s[1].p[1:3])
{
s[0].p[0] = 5;
s[1].p[1] = 7;
}
#pragma omp target map(s, s[0].p[0:2], s[1].p[1:3])
{
s[0].p[0]++;
s[1].p[1]++;
}
#pragma omp target map(s[0:2], s[0].p[0:2], s[1].p[1:3])
{
s[0].p[0]++;
s[1].p[1]++;
}
assert (s[0].p[0] == 7);
assert (s[1].p[1] == 9);
free (s[0].p);
free (s[1].p);
return 0;
}