Hi!

On Wed, 13 Mar 2019 18:50:38 +0100, I wrote:
> On Thu, 28 Feb 2019 22:17:01 +0100, Jakub Jelinek <ja...@redhat.com> wrote:
> > On Thu, Feb 28, 2019 at 10:12:00PM +0100, Thomas Schwinge wrote:
> > > On Wed, 15 Jun 2016 20:12:15 -0700, Cesar Philippidis 
> > > <ce...@codesourcery.com> wrote:
> > > The code changes now are actually very simple.  The "problem" is that
> > > we're incrementing the Fortran module version, 'MOD_VERSION', which
> > > breaks binary compatibility with Fortran module files created with
> > > earlier versions of GCC, which is something that is to be avoided, as
> > > I've heard.  Or, is it not that bad actually?
> > 
> > It is bad and we certainly shouldn't change it on release branches.
> 
> ACK.
> 
> > There are many ways to deal with it without bumping MOD_VERSION in a
> > backwards but not forwards compatible way, so that a newer compiler will be
> > able to parse old *.mod files, and newer compiler new ones as long as this
> > problematic stuff doesn't appear in.
> 
> Like the attached, actually pretty simple now?
> 
> It may seem wasteful to use individual bits for 'gang', 'worker',
> 'vector', 'seq', but that makes it easy to implement the behavior
> described above by Jakub, and I've heard rumors that OpenACC might at
> some point allow several of these level of parallelism clauses to be
> specified (plus a new 'auto' clause?), and then this will be necessary
> anyway (several of these bits can then in fact appear).

Committed to trunk in r269854 "[testsuite, Fortran] Provide
'dg-compile-aux-modules' in 'gfortran.dg/goacc/goacc.exp'", r269855
"[PR72741] Encode OpenACC 'routine' directive's level of parallelism
inside Fortran module files", see attached.


Grüße
 Thomas


From 44ff9fb6a5f3db5c2db521bdd2aed0d2c24e1f83 Mon Sep 17 00:00:00 2001
From: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 21 Mar 2019 19:44:34 +0000
Subject: [PATCH 1/2] [testsuite, Fortran] Provide 'dg-compile-aux-modules' in
 'gfortran.dg/goacc/goacc.exp'

..., as yet another copy from 'gfortran.dg/dg.exp', which there are a few
already.

	gcc/testsuite/
	* gfortran.dg/goacc/goacc.exp (dg-compile-aux-modules): New proc.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@269854 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/testsuite/ChangeLog                   |  2 ++
 gcc/testsuite/gfortran.dg/goacc/goacc.exp | 25 +++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a5211cca6c6a..1f2f3eba6f40 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,7 @@
 2019-03-21  Thomas Schwinge  <tho...@codesourcery.com>
 
+	* gfortran.dg/goacc/goacc.exp (dg-compile-aux-modules): New proc.
+
 	PR fortran/56408
 	* gcc.target/powerpc/ppc-fortran/ppc-fortran.exp
 	(dg-compile-aux-modules): Fix diagnostic.
diff --git a/gcc/testsuite/gfortran.dg/goacc/goacc.exp b/gcc/testsuite/gfortran.dg/goacc/goacc.exp
index f1adb186a1e4..1b093f6d41f5 100644
--- a/gcc/testsuite/gfortran.dg/goacc/goacc.exp
+++ b/gcc/testsuite/gfortran.dg/goacc/goacc.exp
@@ -28,6 +28,31 @@ if ![check_effective_target_fopenacc] {
 # Initialize `dg'.
 dg-init
 
+global gfortran_test_path
+global gfortran_aux_module_flags
+set gfortran_test_path $srcdir/$subdir
+set gfortran_aux_module_flags "-fopenacc"
+proc dg-compile-aux-modules { args } {
+    global gfortran_test_path
+    global gfortran_aux_module_flags
+    if { [llength $args] != 2 } {
+	error "dg-compile-aux-modules: needs one argument"
+	return
+    }
+
+    set level [info level]
+    if { [info procs dg-save-unknown] != [list] } {
+	rename dg-save-unknown dg-save-unknown-level-$level
+    }
+
+    dg-test $gfortran_test_path/[lindex $args 1] "" $gfortran_aux_module_flags
+    # cleanup-modules is intentionally not invoked here.
+
+    if { [info procs dg-save-unknown-level-$level] != [list] } {
+	rename dg-save-unknown-level-$level dg-save-unknown
+    }
+}
+
 # Main loop.
 gfortran-dg-runtest [lsort \
        [find $srcdir/$subdir *.\[fF\]{,90,95,03,08} ] ] "" "-fopenacc"
-- 
2.17.1

From 44ff4c8d4b40c8d9969066b8c38b3df6b76acf17 Mon Sep 17 00:00:00 2001
From: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 21 Mar 2019 19:44:45 +0000
Subject: [PATCH 2/2] [PR72741] Encode OpenACC 'routine' directive's level of
 parallelism inside Fortran module files

If 'use'ing with an old GCC a new module file (with OpenACC 'routine'
directive's level of parallelism encoded), then that expectedly fails as
follows:

    f951: Fatal Error: Reading module 'routine_module_mod_1' at line 27 column 21: find_enum(): Enum not found

If 'use'ing with a new GCC an old module file (without OpenACC 'routine'
directive's level of parallelism encoded), then that (silently) continues to
accept the module file, and will proceed with the previous, erroneous behavior.

These seem to be acceptable compromises, instead of incrementing 'MOD_VERSION'.

	gcc/fortran/
	PR fortran/72741
	* module.c (verify_OACC_ROUTINE_LOP_NONE): New function.
	(enum ab_attribute): Add AB_OACC_ROUTINE_LOP_GANG,
	AB_OACC_ROUTINE_LOP_WORKER, AB_OACC_ROUTINE_LOP_VECTOR,
	AB_OACC_ROUTINE_LOP_SEQ.
	(attr_bits): Add these.
	(mio_symbol_attribute): Handle these.
	gcc/testsuite/
	PR fortran/72741
	* gfortran.dg/goacc/routine-module-1.f90: New file.
	* gfortran.dg/goacc/routine-module-2.f90: Likewise.
	* gfortran.dg/goacc/routine-module-mod-1.f90: Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@269855 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/fortran/ChangeLog                         | 10 +++
 gcc/fortran/module.c                          | 57 ++++++++++++-
 gcc/testsuite/ChangeLog                       |  5 ++
 .../gfortran.dg/goacc/routine-module-1.f90    | 47 +++++++++++
 .../gfortran.dg/goacc/routine-module-2.f90    | 31 ++++++++
 .../goacc/routine-module-mod-1.f90            | 79 +++++++++++++++++++
 6 files changed, 228 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/routine-module-1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/routine-module-2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/routine-module-mod-1.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 2a585dc45f5e..2afab3920bda 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,13 @@
+2019-03-21  Thomas Schwinge  <tho...@codesourcery.com>
+
+	PR fortran/72741
+	* module.c (verify_OACC_ROUTINE_LOP_NONE): New function.
+	(enum ab_attribute): Add AB_OACC_ROUTINE_LOP_GANG,
+	AB_OACC_ROUTINE_LOP_WORKER, AB_OACC_ROUTINE_LOP_VECTOR,
+	AB_OACC_ROUTINE_LOP_SEQ.
+	(attr_bits): Add these.
+	(mio_symbol_attribute): Handle these.
+
 2019-03-20  Janus Weil  <ja...@gcc.gnu.org>
 
 	PR fortran/71861
diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c
index 0c2699c12609..3d4b17b599ee 100644
--- a/gcc/fortran/module.c
+++ b/gcc/fortran/module.c
@@ -2011,7 +2011,9 @@ enum ab_attribute
   AB_OACC_DECLARE_COPYIN, AB_OACC_DECLARE_DEVICEPTR,
   AB_OACC_DECLARE_DEVICE_RESIDENT, AB_OACC_DECLARE_LINK,
   AB_OMP_DECLARE_TARGET_LINK, AB_PDT_KIND, AB_PDT_LEN, AB_PDT_TYPE,
-  AB_PDT_TEMPLATE, AB_PDT_ARRAY, AB_PDT_STRING
+  AB_PDT_TEMPLATE, AB_PDT_ARRAY, AB_PDT_STRING,
+  AB_OACC_ROUTINE_LOP_GANG, AB_OACC_ROUTINE_LOP_WORKER,
+  AB_OACC_ROUTINE_LOP_VECTOR, AB_OACC_ROUTINE_LOP_SEQ
 };
 
 static const mstring attr_bits[] =
@@ -2081,6 +2083,10 @@ static const mstring attr_bits[] =
     minit ("PDT_TEMPLATE", AB_PDT_TEMPLATE),
     minit ("PDT_ARRAY", AB_PDT_ARRAY),
     minit ("PDT_STRING", AB_PDT_STRING),
+    minit ("OACC_ROUTINE_LOP_GANG", AB_OACC_ROUTINE_LOP_GANG),
+    minit ("OACC_ROUTINE_LOP_WORKER", AB_OACC_ROUTINE_LOP_WORKER),
+    minit ("OACC_ROUTINE_LOP_VECTOR", AB_OACC_ROUTINE_LOP_VECTOR),
+    minit ("OACC_ROUTINE_LOP_SEQ", AB_OACC_ROUTINE_LOP_SEQ),
     minit (NULL, -1)
 };
 
@@ -2128,6 +2134,15 @@ DECL_MIO_NAME (sym_intent)
 DECL_MIO_NAME (inquiry_type)
 #undef DECL_MIO_NAME
 
+/* Verify OACC_ROUTINE_LOP_NONE.  */
+
+static void
+verify_OACC_ROUTINE_LOP_NONE (enum oacc_routine_lop lop)
+{
+  if (lop != OACC_ROUTINE_LOP_NONE)
+    bad_module ("Unsupported: multiple OpenACC 'routine' levels of parallelism");
+}
+
 /* Symbol attributes are stored in list with the first three elements
    being the enumerated fields, while the remaining elements (if any)
    indicate the individual attribute bits.  The access field is not
@@ -2292,6 +2307,30 @@ mio_symbol_attribute (symbol_attribute *attr)
 	MIO_NAME (ab_attribute) (AB_PDT_ARRAY, attr_bits);
       if (attr->pdt_string)
 	MIO_NAME (ab_attribute) (AB_PDT_STRING, attr_bits);
+      switch (attr->oacc_routine_lop)
+	{
+	case OACC_ROUTINE_LOP_NONE:
+	  /* This is the default anyway, and for maintaining compatibility with
+	     the current MOD_VERSION, we're not emitting anything in that
+	     case.  */
+	  break;
+	case OACC_ROUTINE_LOP_GANG:
+	  MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_GANG, attr_bits);
+	  break;
+	case OACC_ROUTINE_LOP_WORKER:
+	  MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_WORKER, attr_bits);
+	  break;
+	case OACC_ROUTINE_LOP_VECTOR:
+	  MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_VECTOR, attr_bits);
+	  break;
+	case OACC_ROUTINE_LOP_SEQ:
+	  MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_SEQ, attr_bits);
+	  break;
+	case OACC_ROUTINE_LOP_ERROR:
+	  /* ... intentionally omitted here; it's only unsed internally.  */
+	default:
+	  gcc_unreachable ();
+	}
 
       mio_rparen ();
 
@@ -2503,6 +2542,22 @@ mio_symbol_attribute (symbol_attribute *attr)
 	    case AB_PDT_STRING:
 	      attr->pdt_string = 1;
 	      break;
+	    case AB_OACC_ROUTINE_LOP_GANG:
+	      verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
+	      attr->oacc_routine_lop = OACC_ROUTINE_LOP_GANG;
+	      break;
+	    case AB_OACC_ROUTINE_LOP_WORKER:
+	      verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
+	      attr->oacc_routine_lop = OACC_ROUTINE_LOP_WORKER;
+	      break;
+	    case AB_OACC_ROUTINE_LOP_VECTOR:
+	      verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
+	      attr->oacc_routine_lop = OACC_ROUTINE_LOP_VECTOR;
+	      break;
+	    case AB_OACC_ROUTINE_LOP_SEQ:
+	      verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
+	      attr->oacc_routine_lop = OACC_ROUTINE_LOP_SEQ;
+	      break;
 	    }
 	}
     }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1f2f3eba6f40..8afdf3e980e9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2019-03-21  Thomas Schwinge  <tho...@codesourcery.com>
 
+	PR fortran/72741
+	* gfortran.dg/goacc/routine-module-1.f90: New file.
+	* gfortran.dg/goacc/routine-module-2.f90: Likewise.
+	* gfortran.dg/goacc/routine-module-mod-1.f90: Likewise.
+
 	* gfortran.dg/goacc/goacc.exp (dg-compile-aux-modules): New proc.
 
 	PR fortran/56408
diff --git a/gcc/testsuite/gfortran.dg/goacc/routine-module-1.f90 b/gcc/testsuite/gfortran.dg/goacc/routine-module-1.f90
new file mode 100644
index 000000000000..4e81f11fec86
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/routine-module-1.f90
@@ -0,0 +1,47 @@
+! Valid use of routines defined inside a Fortran module.
+
+! { dg-compile-aux-modules "routine-module-mod-1.f90" }
+! { dg-additional-options "-fopt-info-optimized-omp" }
+
+program main
+  use routine_module_mod_1
+  implicit none
+
+  integer :: i
+
+  call pl_1
+
+  !$acc parallel loop seq ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+  do i = 1, 10
+     call s_1 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+     call s_2 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+     call g_1 ! { dg-message "optimized: assigned OpenACC gang worker vector loop parallelism" }
+     call w_1 ! { dg-message "optimized: assigned OpenACC worker vector loop parallelism" }
+     call v_1 ! { dg-message "optimized: assigned OpenACC vector loop parallelism" }
+  end do
+  !$acc end parallel loop
+
+  !$acc parallel loop gang ! { dg-message "optimized: assigned OpenACC gang loop parallelism" }
+  do i = 1, 10
+     call s_1 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+     call s_2 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+     call w_1 ! { dg-message "optimized: assigned OpenACC worker vector loop parallelism" }
+     call v_1 ! { dg-message "optimized: assigned OpenACC vector loop parallelism" }
+  end do
+  !$acc end parallel loop
+
+  !$acc parallel loop worker ! { dg-message "optimized: assigned OpenACC worker loop parallelism" }
+  do i = 1, 10
+     call s_1 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+     call s_2 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+     call v_1 ! { dg-message "optimized: assigned OpenACC vector loop parallelism" }
+  end do
+  !$acc end parallel loop
+
+  !$acc parallel loop vector ! { dg-message "optimized: assigned OpenACC vector loop parallelism" }
+  do i = 1, 10
+     call s_1 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+     call s_2 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+  end do
+  !$acc end parallel loop
+end program main
diff --git a/gcc/testsuite/gfortran.dg/goacc/routine-module-2.f90 b/gcc/testsuite/gfortran.dg/goacc/routine-module-2.f90
new file mode 100644
index 000000000000..eae0807643c9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/routine-module-2.f90
@@ -0,0 +1,31 @@
+! Invalid use of routines defined inside a Fortran module.
+
+! { dg-compile-aux-modules "routine-module-mod-1.f90" }
+
+program main
+  use routine_module_mod_1
+  implicit none
+
+  integer :: i
+
+  !$acc parallel loop gang
+  do i = 1, 10
+     call g_1 ! { dg-error "routine call uses same OpenACC parallelism as containing loop" }
+  end do
+  !$acc end parallel loop
+
+  !$acc parallel loop worker
+  do i = 1, 10
+     call g_1 ! { dg-error "routine call uses same OpenACC parallelism as containing loop" }
+     call w_1 ! { dg-error "routine call uses same OpenACC parallelism as containing loop" }
+  end do
+  !$acc end parallel loop
+
+  !$acc parallel loop vector
+  do i = 1, 10
+     call g_1 ! { dg-error "routine call uses same OpenACC parallelism as containing loop" }
+     call w_1 ! { dg-error "routine call uses same OpenACC parallelism as containing loop" }
+     call v_1 ! { dg-error "routine call uses same OpenACC parallelism as containing loop" }
+  end do
+  !$acc end parallel loop
+end program main
diff --git a/gcc/testsuite/gfortran.dg/goacc/routine-module-mod-1.f90 b/gcc/testsuite/gfortran.dg/goacc/routine-module-mod-1.f90
new file mode 100644
index 000000000000..3855b8c88596
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/routine-module-mod-1.f90
@@ -0,0 +1,79 @@
+! OpenACC 'routine' directives inside a Fortran module.
+
+! { dg-additional-options "-fopt-info-optimized-omp" }
+
+module routine_module_mod_1
+contains
+  subroutine s_1
+    implicit none
+    !$acc routine
+
+    integer :: i
+
+    !$acc loop ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+    ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
+    do i = 1, 3
+    end do
+  end subroutine s_1
+
+  subroutine s_2
+    implicit none
+    !$acc routine seq
+
+    integer :: i
+
+    !$acc loop ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+    ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
+    do i = 1, 3
+    end do
+  end subroutine s_2
+
+  subroutine v_1
+    implicit none
+    !$acc routine vector
+
+    integer :: i
+
+    !$acc loop ! { dg-message "optimized: assigned OpenACC vector loop parallelism" }
+    do i = 1, 3
+    end do
+  end subroutine v_1
+
+  subroutine w_1
+    implicit none
+    !$acc routine worker
+
+    integer :: i
+
+    !$acc loop ! { dg-message "optimized: assigned OpenACC worker vector loop parallelism" }
+    do i = 1, 3
+    end do
+  end subroutine w_1
+
+  subroutine g_1
+    implicit none
+    !$acc routine gang
+
+    integer :: i
+
+    !$acc loop ! { dg-message "optimized: assigned OpenACC gang vector loop parallelism" }
+    do i = 1, 3
+    end do
+  end subroutine g_1
+
+  subroutine pl_1
+    implicit none
+
+    integer :: i
+
+    !$acc parallel loop ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+    ! { dg-warning "insufficient partitioning available to parallelize loop" "" { target *-*-* } .-1 }
+    do i = 1, 3
+       call s_1 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+       call s_2 ! { dg-message "optimized: assigned OpenACC seq loop parallelism" }
+       call v_1 ! { dg-message "optimized: assigned OpenACC vector loop parallelism" }
+       call w_1 ! { dg-message "optimized: assigned OpenACC worker vector loop parallelism" }
+       call g_1 ! { dg-message "optimized: assigned OpenACC gang worker vector loop parallelism" }
+    end do
+  end subroutine pl_1
+end module routine_module_mod_1
-- 
2.17.1

Attachment: signature.asc
Description: PGP signature

Reply via email to