From patchwork Thu Feb 28 21:12:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 1049778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-497180-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="khS/LwtJ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 449QHd2ztvz9s2R for ; Fri, 1 Mar 2019 08:12:39 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; q=dns; s=default; b=IuEQL8yBP+lesKH5 eFdx3JZDHqj6C0peIlSG93QMOQDJHXu4KSAmW41iomb5Ec+yb1GbjG0imV6zd3LA LIu0WJe88evEF+pfoVoqjUTEHicak+4FwwdVHN86HFXvFTxy8GILPLkDRZcLh/0U Pa8exTfDpk9jRaqIegspfaLySx8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; s=default; bh=FmnDqFuvmNe+Cz9Q6LDtny YelSI=; b=khS/LwtJR57WYon+3rn1pToAnkZy2uOnNOXz8vsCPtraaeEkoiGlv3 W3kBp+R2AbxglYeROnPWI9wORe6Tgi6PRvgL7vdUZ0WJ4Tuw+MpfO96eC7riSx8M plfvKIgSLKQXQ0aRumL6t3Vdh71X5zxsZXpTpMGUKplqnVgBVnEkE= Received: (qmail 2838 invoked by alias); 28 Feb 2019 21:12:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 2254 invoked by uid 89); 28 Feb 2019 21:12:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:dgaddi, sk:dg-addi, modulec, sk:fopt-in 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; Thu, 28 Feb 2019 21:12:21 +0000 Received: from svr-orw-mbx-05.mgc.mentorg.com ([147.34.90.205]) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1gzSyY-0003Du-9c from Thomas_Schwinge@mentor.com ; Thu, 28 Feb 2019 13:12:18 -0800 Received: from svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) by SVR-ORW-MBX-05.mgc.mentorg.com (147.34.90.205) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Thu, 28 Feb 2019 13:12:15 -0800 Received: from tftp-cs (147.34.91.1) by svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) with Microsoft SMTP Server id 15.0.1320.4 via Frontend Transport; Thu, 28 Feb 2019 13:12:15 -0800 Received: by tftp-cs (Postfix, from userid 49978) id 4B664C23D1; Thu, 28 Feb 2019 13:12:15 -0800 (PST) From: Thomas Schwinge To: , CC: Tobias Burnus , Jakub Jelinek Subject: [PR72741] Encode OpenACC 'routine' directive inside Fortran module files In-Reply-To: <5762190F.4030102@codesourcery.com> References: <5762190F.4030102@codesourcery.com> User-Agent: Notmuch/0.9-125-g4686d11 (http://notmuchmail.org) Emacs/25.2.2 (x86_64-pc-linux-gnu) Date: Thu, 28 Feb 2019 22:12:00 +0100 Message-ID: <87y35zmxcv.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Hi! On Wed, 15 Jun 2016 20:12:15 -0700, Cesar Philippidis wrote: > [...], this patch updates the way that > the fortran FE handles the 'acc routine' attribute in modules. Before, > it only recorded that a function was marked as an acc routine. (By means of 'OMP_DECLARE_TARGET', that is.) > With this > patch, it now records the level of parallelism the routine has. This is > necessary for the middle end to validate compatible parallelism between > the loop calling the routine and the routine itself. This patch has seen a bunch of further revisions later on. I've now singled out the changes that are actually relevant for the feature under discussion here, and added test cases that actually test what they describe to be testing... ;-) 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? We might be able to resolve this by encoding individual "bits" for the 'gang'/'worker'/'vector'/'seq' clauses, instead of using the values for 'enum oacc_routine_lop' via 'oacc_routine_lop_types'. The earlier Fortran module files would simply not have these bits set, and could thus still be read (given 'MOD_VERSION' not incremented). Would that be a solution to this issue? (You'd then get a parse error when trying to use with an older version of GCC any Fortran module files created with a newer version, which seems OK?) Or, an idea I just had (but not yet verified), guard the stream-out and stream-in of 'attr->oacc_routine_lop' to just happen if '-fopenacc' is active (or some such), which thus won't affect that majority of users. Would that be a solution to this issue? See attached, any comments? And, can this still go into trunk now? (Rationale: I'd like to later fix this issue on GCC release branches also, because this is quite a limitation to usage. This will thus again bring up the 'MOD_VERSION' issue.) Grüße Thomas From d947a297d224ced389abd7ad74d3519b4a0e8d32 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 28 Feb 2019 21:58:14 +0100 Subject: [PATCH 2/2] [PR72741] Encode OpenACC 'routine' directive inside Fortran module files gcc/fortran/ * gfortran.h (oacc_routine_lop_types): Declare. * module.c (MOD_VERSION): Increment (oacc_routine_lop): New DECL_MIO_NAME. (mio_symbol_attribute): Set the oacc_routine_lop attribute. * symbol.c (oacc_routine_lop_types): Define. 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/gfortran.h | 1 + gcc/fortran/module.c | 6 +- gcc/fortran/symbol.c | 12 +++ .../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, 175 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/gfortran.h b/gcc/fortran/gfortran.h index 3e0f634c3a8e..0d929d4d0c2c 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -336,6 +336,7 @@ extern const mstring intents[]; extern const mstring access_types[]; extern const mstring ifsrc_types[]; extern const mstring save_status[]; +extern const mstring oacc_routine_lop_types[]; /* Strings for DTIO procedure names. In symbol.c. */ extern const mstring dtio_procs[]; diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 320b30c529ac..ce43997ccf48 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -84,7 +84,7 @@ along with GCC; see the file COPYING3. If not see /* Don't put any single quote (') in MOD_VERSION, if you want it to be recognized. */ -#define MOD_VERSION "15" +#define MOD_VERSION "16" /* Structure that describes a position within a module file. */ @@ -2126,6 +2126,7 @@ DECL_MIO_NAME (ref_type) DECL_MIO_NAME (sym_flavor) DECL_MIO_NAME (sym_intent) DECL_MIO_NAME (inquiry_type) +DECL_MIO_NAME (oacc_routine_lop) #undef DECL_MIO_NAME /* Symbol attributes are stored in list with the first three elements @@ -2147,6 +2148,9 @@ mio_symbol_attribute (symbol_attribute *attr) attr->proc = MIO_NAME (procedure_type) (attr->proc, procedures); attr->if_source = MIO_NAME (ifsrc) (attr->if_source, ifsrc_types); attr->save = MIO_NAME (save_state) (attr->save, save_status); + attr->oacc_routine_lop + = MIO_NAME (oacc_routine_lop) (attr->oacc_routine_lop, + oacc_routine_lop_types); ext_attr = attr->ext_attr; mio_integer ((int *) &ext_attr); diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c index c8a1f842d353..3c3d8cb22f7b 100644 --- a/gcc/fortran/symbol.c +++ b/gcc/fortran/symbol.c @@ -96,6 +96,18 @@ const mstring dtio_procs[] = minit ("_dtio_unformatted_write", DTIO_WUF), }; +const mstring oacc_routine_lop_types[] = +{ + minit ("OACC_ROUTINE_LOP_NONE", OACC_ROUTINE_LOP_NONE), + minit ("OACC_ROUTINE_LOP_GANG", OACC_ROUTINE_LOP_GANG), + minit ("OACC_ROUTINE_LOP_WORKER", OACC_ROUTINE_LOP_WORKER), + minit ("OACC_ROUTINE_LOP_VECTOR", OACC_ROUTINE_LOP_VECTOR), + minit ("OACC_ROUTINE_LOP_SEQ", OACC_ROUTINE_LOP_SEQ), + /* 'OACC_ROUTINE_LOP_ERROR' intentionally ommitted here; it's only unsed + internally. */ + minit (NULL, -1) +}; + /* This is to make sure the backend generates setup code in the correct order. */ 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..8f73db41d523 --- /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 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 + end subroutine pl_1 +end module routine_module_mod_1 -- 2.17.1