diff mbox series

[OpenACC] (2/2) Fix implicit mapping for array slices on lexically-enclosing data constructs (PR70828)

Message ID 20180828151934.1d60ea68@squid.athome
State New
Headers show
Series [OpenACC] (2/2) Fix implicit mapping for array slices on lexically-enclosing data constructs (PR70828) | expand

Commit Message

Julian Brown Aug. 28, 2018, 7:19 p.m. UTC
This follow-up patch enables the "inheritance" of mappings for OpenACC
data constructs to work also for Fortran assumed-size arrays.
Otherwise, such arrays are (arguably, prematurely) bailed out on in the
Fortran front-end.

Tested alongside the previous patch with offloading to nvptx.

OK to apply?

Thanks,

Julian

2018-08-28  Julian Brown  <julian@codesourcery.com>

	gcc/fortran/
	* trans-openmp.c (gfc_omp_finish_clause): Don't raise error for
	assumed-size array if present in a lexically-enclosing data construct.

	libgomp/
	* testsuite/libgomp.oacc-fortran/pr70828-4.f90: New test.

Comments

Cesar Philippidis Aug. 28, 2018, 7:23 p.m. UTC | #1
On 08/28/2018 12:19 PM, Julian Brown wrote:

> diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
> index f038f4c..86be407 100644
> --- a/gcc/fortran/trans-openmp.c
> +++ b/gcc/fortran/trans-openmp.c
> @@ -1045,9 +1045,13 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p)
>  
>    tree decl = OMP_CLAUSE_DECL (c);
>  
> -  /* Assumed-size arrays can't be mapped implicitly, they have to be
> -     mapped explicitly using array sections.  */
> -  if (TREE_CODE (decl) == PARM_DECL
> +  /* Assumed-size arrays can't be mapped implicitly, they have to be mapped
> +     explicitly using array sections.  An exception is if the array is
> +     mapped explicitly in an enclosing data construct for OpenACC, in which
> +     case we see GOMP_MAP_FORCE_PRESENT here and do not need to raise an
> +     error.  */
> +  if (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_PRESENT
> +      && TREE_CODE (decl) == PARM_DECL
>        && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
>        && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_UNKNOWN
>        && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),

This is specific to OpenACC, and needs to be guarded as such.

Cesar
Julian Brown Aug. 28, 2018, 9:32 p.m. UTC | #2
On Tue, 28 Aug 2018 12:23:22 -0700
Cesar Philippidis <cesar@codesourcery.com> wrote:

> On 08/28/2018 12:19 PM, Julian Brown wrote:
> 
> > diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
> > index f038f4c..86be407 100644
> > --- a/gcc/fortran/trans-openmp.c
> > +++ b/gcc/fortran/trans-openmp.c
> > @@ -1045,9 +1045,13 @@ gfc_omp_finish_clause (tree c, gimple_seq
> > *pre_p) 
> >    tree decl = OMP_CLAUSE_DECL (c);
> >  
> > -  /* Assumed-size arrays can't be mapped implicitly, they have to
> > be
> > -     mapped explicitly using array sections.  */
> > -  if (TREE_CODE (decl) == PARM_DECL
> > +  /* Assumed-size arrays can't be mapped implicitly, they have to
> > be mapped
> > +     explicitly using array sections.  An exception is if the
> > array is
> > +     mapped explicitly in an enclosing data construct for OpenACC,
> > in which
> > +     case we see GOMP_MAP_FORCE_PRESENT here and do not need to
> > raise an
> > +     error.  */
> > +  if (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_PRESENT
> > +      && TREE_CODE (decl) == PARM_DECL
> >        && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
> >        && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) ==
> > GFC_ARRAY_UNKNOWN && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),  
> 
> This is specific to OpenACC, and needs to be guarded as such.

Are you sure that condition can be true for OpenMP? I'd assumed not...

Julian
Cesar Philippidis Aug. 28, 2018, 10:06 p.m. UTC | #3
On 08/28/2018 02:32 PM, Julian Brown wrote:
> On Tue, 28 Aug 2018 12:23:22 -0700
> Cesar Philippidis <cesar@codesourcery.com> wrote:

>> This is specific to OpenACC, and needs to be guarded as such.
> 
> Are you sure that condition can be true for OpenMP? I'd assumed not...

My bad, you're correct. OMP doesn't use those GOMP_MAP_FORCE map types
anymore.

Cesar
Jakub Jelinek Dec. 4, 2018, 2:05 p.m. UTC | #4
On Tue, Aug 28, 2018 at 03:19:34PM -0400, Julian Brown wrote:
> 2018-08-28  Julian Brown  <julian@codesourcery.com>
> 
> 	gcc/fortran/
> 	* trans-openmp.c (gfc_omp_finish_clause): Don't raise error for
> 	assumed-size array if present in a lexically-enclosing data construct.
> 
> 	libgomp/
> 	* testsuite/libgomp.oacc-fortran/pr70828-4.f90: New test.

This is ok for trunk if whatever it depends on is committed.

	Jakub
diff mbox series

Patch

From 9214ffc6bb2ac7cf023f4e62ca324b1a47123ffc Mon Sep 17 00:00:00 2001
From: Julian Brown <julian@codesourcery.com>
Date: Tue, 28 Aug 2018 09:01:15 -0700
Subject: [PATCH 2/2] Assumed-size array fix

2018-08-28  Julian Brown  <julian@codesourcery.com>

	gcc/fortran/
	* trans-openmp.c (gfc_omp_finish_clause): Don't raise error for
	assumed-size array if present in a lexically-enclosing data construct.

	libgomp/
	* testsuite/libgomp.oacc-fortran/pr70828-4.f90: New test.
---
 gcc/fortran/trans-openmp.c                         | 10 ++++---
 .../testsuite/libgomp.oacc-fortran/pr70828-4.f90   | 31 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.oacc-fortran/pr70828-4.f90

diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index f038f4c..86be407 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -1045,9 +1045,13 @@  gfc_omp_finish_clause (tree c, gimple_seq *pre_p)
 
   tree decl = OMP_CLAUSE_DECL (c);
 
-  /* Assumed-size arrays can't be mapped implicitly, they have to be
-     mapped explicitly using array sections.  */
-  if (TREE_CODE (decl) == PARM_DECL
+  /* Assumed-size arrays can't be mapped implicitly, they have to be mapped
+     explicitly using array sections.  An exception is if the array is
+     mapped explicitly in an enclosing data construct for OpenACC, in which
+     case we see GOMP_MAP_FORCE_PRESENT here and do not need to raise an
+     error.  */
+  if (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_PRESENT
+      && TREE_CODE (decl) == PARM_DECL
       && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
       && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_UNKNOWN
       && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/pr70828-4.f90 b/libgomp/testsuite/libgomp.oacc-fortran/pr70828-4.f90
new file mode 100644
index 0000000..01da999
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/pr70828-4.f90
@@ -0,0 +1,31 @@ 
+! Subarrays declared on data construct: assumed-size array.
+
+subroutine s1(n, arr)
+  integer :: n
+  integer :: arr(*)
+
+  !$acc data copy(arr(5:n-10))
+  !$acc parallel loop
+  do i = 10, n - 10
+     arr(i) = i
+  end do
+  !$acc end parallel loop
+  !$acc end data
+end subroutine s1
+
+program test
+  integer, parameter :: n = 100
+  integer i, data(n)
+
+  data(:) = 0
+
+  call s1(n, data)
+
+  do i = 1, n
+     if ((i < 10 .or. i > n-10)) then
+        if ((data(i) .ne. 0)) call abort
+     else if (data(i) .ne. i) then
+        call abort
+     end if
+  end do
+end program test
-- 
1.8.1.1