public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [og7] Enable fortran derived types in acc enter/exit data
@ 2017-10-11 14:04 Cesar Philippidis
  0 siblings, 0 replies; only message in thread
From: Cesar Philippidis @ 2017-10-11 14:04 UTC (permalink / raw)
  To: Fortran List, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 322 bytes --]

This patch enables fortran derived type members to be used in acc
enter/exit data constructs. Now, both acc enter/exit data and acc update
support individual derived type members. Eventually, I'd like all of the
acc data clauses to support individual derived type members. But that
may not happen in the near term.

Cesar

[-- Attachment #2: og7-enter_exit-dtype.diff --]
[-- Type: text/x-patch, Size: 3755 bytes --]

2017-10-11  Cesar Philippidis  <cesar@codesourcery.com>

	gcc/fortran/
	* openmp.c (match_acc): Add new argument derived_types. Propagate
	it to gfc_match_omp_clauses.
	(gfc_match_oacc_enter_data): Update call to match_acc.
	(gfc_match_oacc_exit_data): Likewise.

	gcc/testsuite/
	* gfortran.dg/goacc/derived-types.f90: Adjust test case.

	libgomp/
	* testsuite/libgomp.oacc-fortran/derived-type-2.f90: New test.


diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index a59b7d27e9c..5562f4e02f7 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -2141,10 +2141,12 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, omp_mask mask,
 
 
 static match
-match_acc (gfc_exec_op op, const omp_mask mask, const omp_mask dtype_mask)
+match_acc (gfc_exec_op op, const omp_mask mask, const omp_mask dtype_mask,
+	   bool derived_types=false)
 {
   gfc_omp_clauses *c;
-  if (gfc_match_omp_clauses (&c, mask, dtype_mask, false, false, true)
+  if (gfc_match_omp_clauses (&c, mask, dtype_mask, false, false, true,
+			     derived_types)
       != MATCH_YES)
     return MATCH_ERROR;
   new_st.op = op;
@@ -2329,7 +2331,7 @@ match
 gfc_match_oacc_enter_data (void)
 {
   return match_acc (EXEC_OACC_ENTER_DATA, OACC_ENTER_DATA_CLAUSES,
-		    OMP_MASK2_LAST);
+		    OMP_MASK2_LAST, true);
 }
 
 
@@ -2337,7 +2339,7 @@ match
 gfc_match_oacc_exit_data (void)
 {
   return match_acc (EXEC_OACC_EXIT_DATA, OACC_EXIT_DATA_CLAUSES,
-		    OMP_MASK2_LAST);
+		    OMP_MASK2_LAST, true);
 }
 
 
diff --git a/gcc/testsuite/gfortran.dg/goacc/derived-types.f90 b/gcc/testsuite/gfortran.dg/goacc/derived-types.f90
index 44a38149560..11d055a79f2 100644
--- a/gcc/testsuite/gfortran.dg/goacc/derived-types.f90
+++ b/gcc/testsuite/gfortran.dg/goacc/derived-types.f90
@@ -28,11 +28,14 @@ program derived_acc
   !$acc update self(var%a)
   
   !$acc enter data copyin(var)
-  !$acc enter data copyin(var%a) ! { dg-error "Syntax error in OpenMP" }
+  !$acc enter data copyin(var%a)
 
   !$acc exit data copyout(var)
-  !$acc exit data copyout(var%a) ! { dg-error "Syntax error in OpenMP" }
+  !$acc exit data copyout(var%a)
 
+  !$acc data copy(var%a) ! { dg-error "Syntax error in OpenMP" }
+  !$acc end data ! { dg-error "Unexpected ..ACC END DATA" }
+  
   !$acc data copy(var)
   !$acc end data
 
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/derived-type-2.f90 b/libgomp/testsuite/libgomp.oacc-fortran/derived-type-2.f90
new file mode 100644
index 00000000000..3ed21953261
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/derived-type-2.f90
@@ -0,0 +1,67 @@
+! Test derived types in data clauses.
+
+! { dg-do run }
+
+module newtype
+  type dtype
+     integer :: a, b, c
+     integer, allocatable :: ary(:)
+  end type dtype
+end module newtype
+
+program main
+  use newtype
+  implicit none
+  integer, parameter :: n = 100
+  integer i
+  type (dtype), dimension(n) :: d1
+  type (dtype) :: d2
+  external process
+
+  allocate (d2%ary(n))
+
+  !$acc enter data create (d2%ary)
+
+  do i = 1, n
+     d2%ary(i) = 1
+  end do
+
+  !$acc update device (d2%ary)
+
+  call process (n, d2%ary)
+
+  !$acc exit data copyout (d2%ary)
+
+  do i = 1, n
+     if (d2%ary(i) /= i + 1) call abort
+  end do
+
+  !$acc data copy(d1(1:n))
+  !$acc parallel loop
+  do i = 1, n
+     d1(i)%a = i
+     d1(i)%b = i-1
+     d1(i)%c = i+1
+  end do
+  !$acc end data
+
+  do i = 1, n
+     if (d1(i)%a /= i) call abort
+     if (d1(i)%b /= i-1) call abort
+     if (d1(i)%c /= i+1) call abort
+  end do
+
+  deallocate (d2%ary)
+end program main
+
+subroutine process (a, b)
+  use newtype
+  implicit none
+  integer :: a, i
+  integer :: b(a)
+
+  !$acc parallel loop present (b(1:a))
+  do i = 1, a
+     b(i) = b(i) + i
+  end do
+end subroutine process

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-10-11 14:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-11 14:04 [og7] Enable fortran derived types in acc enter/exit data Cesar Philippidis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).