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

            Bug ID: 129177
           Summary: 'iterator' modifier with non-contiguous array section
                    in 'target update'
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
          Assignee: unassigned at gcc dot gnu.org
          Reporter: parras at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

Created attachment 66351
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66351&action=edit
Runtime test

With the non-contiguous/strided 'target update' patches applied, an 'iterator'
modifier on a to/from clause whose list item is a non-contiguous array section
is still unsupported.

See the attached testcase.

  #pragma omp target update from(iterator(i=0:N): x[i][0:M/2:2])

The same update written without the iterator works.

Disabling the sorry exposes two bugs, even in the simple case where the
iterator only affects the base address:

1. omp-low.cc (lower_omp_target): the host address of the
   GOMP_MAP_TO_GRID/FROM_GRID clause is assigned without going through
   lower_omp_map_iterator_expr, but its size does go through
   lower_omp_map_iterator_size.  The iterator loop therefore fills only the
   size slots of the elems array, and libgomp receives &x[i] evaluated after
   the loop, i.e. &x[N], with size SIZE_MAX.  libgomp reads the word past the
   end of x as the iteration count; in the testcase it is 0, so the update
   silently does nothing and the check aborts.

2. libgomp (gomp_update): each GOMP_MAP_TO_GRID/FROM_GRID entry is assumed to
be
   immediately followed by its GOMP_MAP_TO_PSET descriptor (hostaddrs[i + 1],
   sizes[i + 1]).  gomp_merge_iterator_maps expands the grid entry into one
   entry per iteration but leaves the single descriptor after all of them, so
   the next iteration's entry is read as the descriptor.  With (1) fixed, the
   testcase segfaults in omp_target_memcpy_rect_worker (num_dims = -1).

Full support also needs per-iteration descriptors when the iterator appears in
a dimension's index, length or stride, e.g. x[2][:][i][:] or x[2][i][:i][:].
Currently the descriptor is built once, outside the iterator loop.

Reply via email to