Paul-Antoine Arras wrote:
This patch adds support for OpenMP 5.0 strided updates and the
array-shaping operator ("([x][y][z]) foo[0:n]...").  This is mostly for
C++ only so far, though necessary changes have been made to the C FE to
adjust for changes to shared data structures.

LGTM - I have only three (four?) minor nits below.

And two general remarks. And some testcase remark
directly following.

(BTW: I am wondering what gcc.sashiko.dev would find, but
your patch is too old for it.)

* * *

libgomp.c-c++-common/target-update-iterators-5.c states:

+/* Currently rejected with a "sorry"; switch back to "dg-do run" and drop the
+   dg-message directives once GCC PR 127616 is fixed.  */
→ https://gcc.gnu.org/PR127616

Sandra remarked that she has a fix for this - and I think she
will soon post a new patch/patch set, which could fix this.

If her patch lands first, please update. If your patch lands first,
please mention this one in the PR such that is can be enabled once
the other patch lands.

* * *

And the following: I noticed that you did not include

  testsuite/libgomp.c++/array-shaping-14.C

of v2 of the patches. Why?

On the other hand, new are:
 gcc/testsuite/g++.dg/gomp/array-shaping-3.C   |  12 +
 .../target-update-strided-bias-1.c            |  57 ++
 .../target-update-strided-overrun-1.c         |  56 ++
 .../target-update-strided-overrun-2.c         |  51 ++
 .../target-update-trailing-dims-1.c           |  42 ++
 libgomp/testsuite/libgomp.c/array-section-1.c |  49 ++

I have not tried to understand whether the -14 patch is
covered by the others, is invalid or ...

* * *

Thanks for updating the descriptor to use strides in bytes - or
rather use a "span" field with that semantic.

I have not checked patch 3/3 (i.e. the Fortran one), but I believe
that there is no need to update the descriptor there any more?

If so, I think once this patch, if fine, it can land without waiting
for the Fortran or C one as it would not involve any ABI changes when
the latter land. (Barring finding issues, but I hope there are not.)

* * *

Talking of which:
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
...
+/* A rectangular section of an array, for noncontiguous target update
+   operations.  Must be kept in sync with
+   omp-low.cc:omp_noncontig_descriptor_type.  */
Maybe add in the comment:
  elemsize and span are in bytes while index, length, and stride
  refer to values specified in the the array section.

Otherwise, specially "length" but also "stride" are slightly unclear:
+typedef struct {
+  size_t ndims;
+  size_t elemsize;
+  size_t span;
+  size_t *dim;
+  size_t *index;
+  size_t *length;
+  size_t *stride;
+} omp_noncontig_array_desc;

An implementation variant would be to have non 'span' and to use:

sm[0] = span * stride[0]
etc.

That's what Fortran does (in GCC: libgfortran/ISO_Fortran_binding.h),
namely:

[Actually, ISO Fortran does not require that those are the only fields
in the struct, but only requires that the following with a defined
meaning exist. In GCC, only those exist; as an API routine is used
to fill those values, that's transparent to the C program.]

typedef struct CFI_cdesc_t
 {
    void *base_addr;
    size_t elem_len;
    int version;
    CFI_rank_t rank;
    CFI_attribute_t attribute;
    CFI_type_t type;
    CFI_dim_t dim[];
 }
CFI_cdesc_t;

with

/* CFI_dim_t. */
typedef struct CFI_dim_t
  {
    CFI_index_t lower_bound;
    CFI_index_t extent;
    CFI_index_t sm;
  }
CFI_dim_t;

with (ISO Fortran quote):

"CFI_index_t sm; The value is equal to the memory stride for a
 dimension; this is the difference in bytes between the addresses
 of successive elements in the dimension being described."

* * *

This variant avoids the use of having one extra "span" field.
However, using 'stride[]' + 'span' also works - and I don't have
a strong preference for one or the other.

Let's just hope that we never need to update that one – such
that we will miss the 'version' field ...

* * *

In c-family/c-omp.cc:

  c_omp_address_inspector::expand_array_base (tree c,
...
    bool decl_p = DECL_P (decl);
-  bool declare_target_p = (decl_p
+  bool declare_target_p = (DECL_P (decl)
                            && is_global_var (decl)
                            && lookup_attribute ("omp declare target",
                                                 DECL_ATTRIBUTES (decl)));
Why?

* * *

@@ -4008,40 +4138,74 @@ c_omp_address_inspector::expand_array_base (tree c,
...
+    case ACCESS_NONCONTIG_REF_TO_ARRAY:
+      {
+       gcc_assert (!map_p);
+
+       if (decl_p)
+         c_common_mark_addressable_vec (addr_tokens[acc]->expr);
+
+       /* Or here.  */
+       gcc_assert (!chain_p);
This looks like a left-over comment.

* * *

libgomp/target.c (again):
  omp_target_memcpy_rect_worker (void *dst, const void *src, size_t 
element_size,
...
+  if (num_dims == 1 && (!strides || (strides[0] == 1 && element_size == span)))
...
+  else if (num_dims == 1 && strides)

Maybe

   else if (num_dims)  /* With strides.  */

is a bit clearer? The '&& sides' is always true. However, it shouldn't
really matter - the 'if' block is fortunately that far from 'else if'.


Thanks,

Tobias

Reply via email to