[PATCH, OpenACC] Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACC

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH, OpenACC] Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACC

Julian Brown-2
This patch (by Cesar) changes the way that mapping of firstprivate
scalars works for OpenACC. For scalars whose type has a size equal to or
smaller than the size of a pointer, rather than copying the value of
the scalar to the target device and having a separate mapping for a
pointer to the copied value, a single "pointer" is mapped whose bits
are a type-punned representation of the value itself.

This is a performance optimisation: the idea, IIUC, is that it is a
good idea to avoid having all launched compute resources contend for a
single memory location -- the pointed-to cell containing the scalar on
the device, in this case. Cesar talks about speedups obtained here
(for an earlier version of the patch):

https://gcc.gnu.org/ml/gcc-patches/2017-01/msg02171.html

The patch implies an API change for the libgomp plugin, in that it must
now understand that NULL device pointers correspond to host pointers
that are actually type-punned scalars.

Tested with offloading to NVPTX and bootstrapped. OK for mainline?

Julian

ChangeLog

2018-09-20  Cesar Philippidis  <[hidden email]>
            Julian Brown  <[hidden email]>

        gcc/
        * omp-low.c (maybe_lookup_field_in_outer_ctx): New function.
        (convert_to_firstprivate_int): New function.
        (convert_from_firstprivate_int): New function.
        (lower_omp_target): Enable GOMP_MAP_FIRSTPRIVATE_INT in OpenACC.

        libgomp/
        * oacc-parallel.c (GOACC_parallel_keyed): Handle
        GOMP_MAP_FIRSTPRIVATE_INT host addresses.
        * plugin/plugin-nvptx.c (nvptx_exec): Handle
        GOMP_MAP_FIRSTPRIVATE_INT host addresses.
        * testsuite/libgomp.oacc-c++/firstprivate-int.C: New test.
        * testsuite/libgomp.oacc-c-c++-common/firstprivate-int.c: New
        test.
        * testsuite/libgomp.oacc-fortran/firstprivate-int.f90: New test.

0001-Enable-GOMP_MAP_FIRSTPRIVATE_INT-for-OpenACC.patch (20K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH, OpenACC] Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACC

Jakub Jelinek
On Thu, Sep 20, 2018 at 07:38:04PM -0400, Julian Brown wrote:

> 2018-09-20  Cesar Philippidis  <[hidden email]>
>             Julian Brown  <[hidden email]>
>
> gcc/
> * omp-low.c (maybe_lookup_field_in_outer_ctx): New function.
> (convert_to_firstprivate_int): New function.
> (convert_from_firstprivate_int): New function.
> (lower_omp_target): Enable GOMP_MAP_FIRSTPRIVATE_INT in OpenACC.
>
> libgomp/
> * oacc-parallel.c (GOACC_parallel_keyed): Handle
> GOMP_MAP_FIRSTPRIVATE_INT host addresses.
> * plugin/plugin-nvptx.c (nvptx_exec): Handle
> GOMP_MAP_FIRSTPRIVATE_INT host addresses.
> * testsuite/libgomp.oacc-c++/firstprivate-int.C: New test.
> * testsuite/libgomp.oacc-c-c++-common/firstprivate-int.c: New
> test.
> * testsuite/libgomp.oacc-fortran/firstprivate-int.f90: New test.

> @@ -8039,7 +8182,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
>      if (omp_is_reference (ovar))
>        type = TREE_TYPE (type);
>      if ((INTEGRAL_TYPE_P (type)
> - && TYPE_PRECISION (type) <= POINTER_SIZE)
> + && tree_to_uhwi (TYPE_SIZE (type)) <= POINTER_SIZE)
>   || TREE_CODE (type) == POINTER_TYPE)
>        {
>   tkind = GOMP_MAP_FIRSTPRIVATE_INT;
> @@ -8194,7 +8337,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
>   if (omp_is_reference (var))
>    type = TREE_TYPE (type);
>   if ((INTEGRAL_TYPE_P (type)
> -     && TYPE_PRECISION (type) <= POINTER_SIZE)
> +     && tree_to_uhwi (TYPE_SIZE (type)) <= POINTER_SIZE)
>      || TREE_CODE (type) == POINTER_TYPE)
>    {
>      x = build_receiver_ref (var, false, ctx);

Why this?

        Jakub
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH, OpenACC] Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACC

Julian Brown-2
On Tue, 4 Dec 2018 15:27:12 +0100
Jakub Jelinek <[hidden email]> wrote:

> On Thu, Sep 20, 2018 at 07:38:04PM -0400, Julian Brown wrote:
> > 2018-09-20  Cesar Philippidis  <[hidden email]>
> >             Julian Brown  <[hidden email]>
> >
> > gcc/
> > * omp-low.c (maybe_lookup_field_in_outer_ctx): New function.
> > (convert_to_firstprivate_int): New function.
> > (convert_from_firstprivate_int): New function.
> > (lower_omp_target): Enable GOMP_MAP_FIRSTPRIVATE_INT in
> > OpenACC.
> >
> > libgomp/
> > * oacc-parallel.c (GOACC_parallel_keyed): Handle
> > GOMP_MAP_FIRSTPRIVATE_INT host addresses.
> > * plugin/plugin-nvptx.c (nvptx_exec): Handle
> > GOMP_MAP_FIRSTPRIVATE_INT host addresses.
> > * testsuite/libgomp.oacc-c++/firstprivate-int.C: New test.
> > * testsuite/libgomp.oacc-c-c++-common/firstprivate-int.c:
> > New test.
> > * testsuite/libgomp.oacc-fortran/firstprivate-int.f90: New
> > test.  
>
> > @@ -8039,7 +8182,7 @@ lower_omp_target (gimple_stmt_iterator
> > *gsi_p, omp_context *ctx) if (omp_is_reference (ovar))
> >        type = TREE_TYPE (type);
> >      if ((INTEGRAL_TYPE_P (type)
> > - && TYPE_PRECISION (type) <= POINTER_SIZE)
> > + && tree_to_uhwi (TYPE_SIZE (type)) <=
> > POINTER_SIZE) || TREE_CODE (type) == POINTER_TYPE)
> >        {
> >   tkind = GOMP_MAP_FIRSTPRIVATE_INT;
> > @@ -8194,7 +8337,7 @@ lower_omp_target (gimple_stmt_iterator
> > *gsi_p, omp_context *ctx) if (omp_is_reference (var))
> >    type = TREE_TYPE (type);
> >   if ((INTEGRAL_TYPE_P (type)
> > -     && TYPE_PRECISION (type) <= POINTER_SIZE)
> > +     && tree_to_uhwi (TYPE_SIZE (type)) <=
> > POINTER_SIZE) || TREE_CODE (type) == POINTER_TYPE)
> >    {
> >      x = build_receiver_ref (var, false, ctx);  
>
> Why this?
My *guess* is that it was an attempt to handle cases where the type
precision is less than the type size, and maybe it was feared that
type-punning to an int would then copy the wrong bits. Those changes
appear to not have been necessary though, at least with respect to
testsuite coverage. I also fixed the Fortran test to use "STOP n"
instead of "call abort".

I re-tested the attached with offloading to nvptx. OK?

Thanks,

Julian

firstprivate-int-2.diff (18K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH, OpenACC] Enable GOMP_MAP_FIRSTPRIVATE_INT for OpenACC

Jakub Jelinek
On Thu, Dec 06, 2018 at 10:40:41PM +0000, Julian Brown wrote:
> + && (TREE_CODE (inner_type) == REAL_TYPE
> +    || (!omp_is_reference (var)
> + && INTEGRAL_TYPE_P (inner_type))
> +    || TREE_CODE (inner_type) == INTEGER_TYPE)

Not sure I understand the above.  INTEGRAL_TYPE_P is INTEGER_TYPE,
BOOLEAN_TYPE and ENUMERAL_TYPE, so you want to handle INTEGER_TYPE
no magger whether var should be passed by reference or not, but BOOLEAN_TYPE
or ENUMERAL_TYPE only if it is not a reference?
That is just weird.  Any test to back that up?

> +    if ((TREE_CODE (inner_type) == REAL_TYPE
> + || (!omp_is_reference (var)
> +     && INTEGRAL_TYPE_P (inner_type))
> + || TREE_CODE (inner_type) == INTEGER_TYPE)

Ditto here.

        Jakub