From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109941 invoked by alias); 13 Mar 2019 17:50:56 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 109927 invoked by uid 89); 13 Mar 2019 17:50:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: =?ISO-8859-1?Q?No, score=-15.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=gr=c3=bc=c3, useing, H*f:sk:2019022?= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Mar 2019 17:50:53 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-01.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1h481g-0007cz-Ue from Thomas_Schwinge@mentor.com ; Wed, 13 Mar 2019 10:50:49 -0700 Received: from hertz.schwinge.homeip.net (137.202.0.90) by svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Wed, 13 Mar 2019 17:50:45 +0000 From: Thomas Schwinge To: , , Jakub Jelinek CC: Tobias Burnus Subject: [PR72741] Encode OpenACC 'routine' directive's level of parallelism inside Fortran module files In-Reply-To: <20190228211701.GG7611@tucnak> References: <5762190F.4030102@codesourcery.com> <87y35zmxcv.fsf@euler.schwinge.homeip.net> <20190228211701.GG7611@tucnak> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/25.2.2 (x86_64-pc-linux-gnu) Date: Wed, 13 Mar 2019 17:50:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-SW-Source: 2019-03/txt/msg00077.txt.bz2 --=-=-= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-length: 1579 Hi! On Thu, 28 Feb 2019 22:17:01 +0100, Jakub Jelinek 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 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? >=20 > 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). If approving this patch, please respond with "Reviewed-by: NAME " so that your effort will be recorded in the commit log, see . Gr=C3=BC=C3=9Fe Thomas --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename="0001-PR72741-Encode-OpenACC-routine-directive-s-level-of-.patch" Content-length: 11632 >From b2f200d24d040c6d34b5b4421e4cb1be9786030f Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 13 Mar 2019 18:39:53 +0100 Subject: [PATCH] [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/ * 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/ * 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. --- gcc/fortran/module.c | 57 ++++++++++++- .../gfortran.dg/goacc/routine-module-1.f90 | 47 +++++++++++ .../gfortran.dg/goacc/routine-module-2.f90 | 31 ++++++++ .../goacc/routine-module-mod-1.f90 | 79 +++++++++++++++++++ 4 files changed, 213 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/module.c b/gcc/fortran/module.c index 0572b8e02c17..39b420039dff 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/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 --=-=-=--