From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id E90BF385701E; Wed, 2 Nov 2022 20:22:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E90BF385701E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.95,234,1661846400"; d="scan'208,223";a="86104923" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 02 Nov 2022 12:22:32 -0800 IronPort-SDR: 46NU3awN8WlQNMz4zae/1yARJRB7ZYebjp63lY8Xlrw5qwGVjbJhP1XuuE20zpxQoLnmdEkklq NPADbSx4m6CccVWE70X4tVV6TclMvG1GhSoDO8c3Aaa65uk5XmISOtnvuph/2/k9BXteCjzvAd vKusw4gKUgIA865MtXACmAoYg1e4RCOprWY0wWP1ZZEY+CCPaFbgzd7ow5EJanmrgroaiN00hg N8fQBWn+YxKfKB1bbQySktSLOyjD23qa5pwZ3lRzjmF/8a52IcRN08HpeBoTXqHZDumSNT4Lg8 W5M= From: Thomas Schwinge To: , CC: , Subject: Support OpenACC 'declare create' with Fortran allocatable arrays, part I [PR106643] In-Reply-To: <871qqlkt98.fsf@euler.schwinge.homeip.net> References: <86f51209-c59d-a4cf-297d-9a072823aa61@codesourcery.com> <877d0dktqv.fsf@euler.schwinge.homeip.net> <874jvhktgx.fsf@euler.schwinge.homeip.net> <871qqlkt98.fsf@euler.schwinge.homeip.net> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/27.1 (x86_64-pc-linux-gnu) Date: Wed, 2 Nov 2022 21:22:25 +0100 Message-ID: <87y1stjeda.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --=-=-= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi! On 2022-11-02T21:15:31+0100, I wrote: > On 2022-11-02T21:10:54+0100, I wrote: >> On 2022-11-02T21:04:56+0100, I wrote: >>> --- /dev/null >>> +++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90 >>> @@ -0,0 +1,268 @@ >>> +! Test OpenACC 'declare create' with allocatable arrays. >>> + >>> +! { dg-do run } >>> + >>> +!TODO-OpenACC-declare-allocate >>> +! Not currently implementing correct '-DACC_MEM_SHARED=3D0' behavior: >>> +! Missing support for OpenACC "Changes from Version 2.0 to 2.5": >>> +! "The 'declare create' directive with a Fortran 'allocatable' has new= behavior". >>> +! { dg-xfail-run-if TODO { *-*-* } { -DACC_MEM_SHARED=3D0 } } >>> + >>> +[...] >> >> Getting rid of the "'dg-xfail-run-if' for '-DACC_MEM_SHARED=3D0'" via a >> work around (as seen in real-world code), I've pushed to master branch >> commit 59c6c5dbf267cd9d0a8df72b2a5eb5657b64268e >> "Add 'libgomp.oacc-fortran/declare-allocatable-1-runtime.f90'" > >> ... which is 'libgomp.oacc-fortran/declare-allocatable-1.f90' adjusted >> for missing support for OpenACC "Changes from Version 2.0 to 2.5": >> "The 'declare create' directive with a Fortran 'allocatable' has new beh= avior". >> Thus, after 'allocate'/before 'deallocate', call 'acc_create'/'acc_delet= e' >> manually. > > A similar test case, but with different focus, I've pushed to master > branch in commit abeaf3735fe2568b9d5b8096318da866b1fe1e5c > "Add 'libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-runtime= .f90'", > see attached. > --- /dev/null > +++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_de= scriptor-1-runtime.f90 > @@ -0,0 +1,402 @@ > +! Test OpenACC 'declare create' with allocatable arrays. > + > +! { dg-do run } > + > +! Note that we're not testing OpenACC semantics here, but rather documen= ting > +! current GCC behavior, specifically, behavior concerning updating of > +! host/device array descriptors. > +! { dg-skip-if n/a { *-*-* } { -DACC_MEM_SHARED=3D1 } } > + > +!TODO-OpenACC-declare-allocate > +! Missing support for OpenACC "Changes from Version 2.0 to 2.5": > +! "The 'declare create' directive with a Fortran 'allocatable' has new b= ehavior". > +! Thus, after 'allocate'/before 'deallocate', call 'acc_create'/'acc_del= ete' > +! manually. If instead of calling 'acc_create'/'acc_delete' we'd like to use '!$acc enter data create'/'!$acc exit data delete', we run into "[gfortran + OpenACC] Allocate in module causes refcount error". Pushed to master branchcommit da8e0e1191c5512244a752b30dea0eba83e3d10c "Support OpenACC 'declare create' with Fortran allocatable arrays, part I [= PR106643]", see attached. Gr=C3=BC=C3=9Fe Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955 --=-=-= Content-Type: text/x-diff; charset="utf-8" Content-Disposition: inline; filename="0001-Support-OpenACC-declare-create-with-Fortran-allocata.patch" Content-Transfer-Encoding: quoted-printable >From da8e0e1191c5512244a752b30dea0eba83e3d10c Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Thu, 27 Oct 2022 21:52:07 +0200 Subject: [PATCH] Support OpenACC 'declare create' with Fortran allocatable arrays, part I [PR106643] PR libgomp/106643 libgomp/ * oacc-mem.c (goacc_enter_data_internal): Support OpenACC 'declare create' with Fortran allocatable arrays, part I. * testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90: New. * testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-di= rective.f90: New. --- libgomp/oacc-mem.c | 28 +++++++++++++++++-- ...90 =3D> declare-allocatable-1-directive.f90} | 14 ++++++++-- ...ocatable-array_descriptor-1-directive.f90} | 12 ++++---- 3 files changed, 44 insertions(+), 10 deletions(-) copy libgomp/testsuite/libgomp.oacc-fortran/{declare-allocatable-1.f90 =3D= > declare-allocatable-1-directive.f90} (95%) copy libgomp/testsuite/libgomp.oacc-fortran/{declare-allocatable-array_des= criptor-1-runtime.f90 =3D> declare-allocatable-array_descriptor-1-directive= .f90} (98%) diff --git a/libgomp/oacc-mem.c b/libgomp/oacc-mem.c index 73b2710c2b8..ba010fddbb3 100644 --- a/libgomp/oacc-mem.c +++ b/libgomp/oacc-mem.c @@ -1150,8 +1150,7 @@ goacc_enter_data_internal (struct gomp_device_descr *= acc_dev, size_t mapnum, } else if (n && groupnum > 1) { - assert (n->refcount !=3D REFCOUNT_INFINITY - && n->refcount !=3D REFCOUNT_LINK); + assert (n->refcount !=3D REFCOUNT_LINK); =20 for (size_t j =3D i + 1; j <=3D group_last; j++) if ((kinds[j] & 0xff) =3D=3D GOMP_MAP_ATTACH) @@ -1166,6 +1165,31 @@ goacc_enter_data_internal (struct gomp_device_descr = *acc_dev, size_t mapnum, bool processed =3D false; =20 struct target_mem_desc *tgt =3D n->tgt; + + /* Arrange so that OpenACC 'declare' code =C3=A0 la PR106643 + "[gfortran + OpenACC] Allocate in module causes refcount error" + has a chance to work. */ + if ((kinds[i] & 0xff) =3D=3D GOMP_MAP_TO_PSET + && tgt->list_count =3D=3D 0) + { + /* 'declare target'. */ + assert (n->refcount =3D=3D REFCOUNT_INFINITY); + + for (size_t k =3D 1; k < groupnum; k++) + { + /* The only thing we expect to see here. */ + assert ((kinds[i + k] & 0xff) =3D=3D GOMP_MAP_POINTER); + } + + /* Given that 'goacc_exit_data_internal'/'goacc_exit_datum_1' + will always see 'n->refcount =3D=3D REFCOUNT_INFINITY', + there's no need to adjust 'n->dynamic_refcount' here. */ + + processed =3D true; + } + else + assert (n->refcount !=3D REFCOUNT_INFINITY); + for (size_t j =3D 0; j < tgt->list_count; j++) if (tgt->list[j].key =3D=3D n) { diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f= 90 b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive= .f90 similarity index 95% copy from libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90 copy to libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-direct= ive.f90 index 1c8ccd9f61f..759873bad67 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90 +++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-directiv= e.f90 @@ -3,10 +3,10 @@ ! { dg-do run } =20 !TODO-OpenACC-declare-allocate -! Not currently implementing correct '-DACC_MEM_SHARED=3D0' behavior: ! Missing support for OpenACC "Changes from Version 2.0 to 2.5": ! "The 'declare create' directive with a Fortran 'allocatable' has new beh= avior". -! { dg-xfail-run-if TODO { *-*-* } { -DACC_MEM_SHARED=3D0 } } +! Thus, after 'allocate'/before 'deallocate', do +! '!$acc enter data create'/'!$acc exit data delete' manually. =20 !TODO { dg-additional-options -fno-inline } for stable results regarding O= penACC 'routine'. =20 @@ -67,6 +67,7 @@ program test ! Test local usage of an allocated declared array. =20 allocate (b(n)) + !$acc enter data create (b) =20 if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop @@ -91,12 +92,14 @@ program test if (b(i) /=3D i*a) error stop end do =20 + !$acc exit data delete (b) deallocate (b) =20 ! Test the usage of an allocated declared array inside an acc ! routine subroutine. =20 allocate (b(n)) + !$acc enter data create (b) =20 if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop @@ -114,6 +117,7 @@ program test if (b(i) /=3D i*2) error stop end do =20 + !$acc exit data delete (b) deallocate (b) =20 ! Test the usage of an allocated declared array inside a host @@ -129,6 +133,7 @@ program test if (b(i) /=3D 1.0) error stop end do =20 + !$acc exit data delete (b) deallocate (b) =20 if (allocated (b)) error stop @@ -137,6 +142,7 @@ program test ! routine function. =20 allocate (b(n)) + !$acc enter data create (b) =20 if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop @@ -170,12 +176,14 @@ program test if (b(i) /=3D i) error stop end do =20 + !$acc exit data delete (b) deallocate (b) =20 ! Test the usage of an allocated declared array inside a host ! function. =20 allocate (b(n)) + !$acc enter data create (b) =20 if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop @@ -202,6 +210,7 @@ program test if (b(i) /=3D i*i) error stop end do =20 + !$acc exit data delete (b) deallocate (b) end program test ! { dg-line l[incr c] } ! { dg-bogus {note: variable 'overflow\.[0-9]+' declared in block isn't ca= ndidate for adjusting OpenACC privatization level: not addressable} {TODO n= /a} { xfail *-*-* } l$c } @@ -234,6 +243,7 @@ subroutine sub2 integer i =20 allocate (b(n)) + !$acc enter data create (b) =20 if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-arr= ay_descriptor-1-runtime.f90 b/libgomp/testsuite/libgomp.oacc-fortran/declar= e-allocatable-array_descriptor-1-directive.f90 similarity index 98% copy from libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_= descriptor-1-runtime.f90 copy to libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_de= scriptor-1-directive.f90 index b27f312631d..10e1d5bc378 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_desc= riptor-1-runtime.f90 +++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_desc= riptor-1-directive.f90 @@ -10,8 +10,8 @@ !TODO-OpenACC-declare-allocate ! Missing support for OpenACC "Changes from Version 2.0 to 2.5": ! "The 'declare create' directive with a Fortran 'allocatable' has new beh= avior". -! Thus, after 'allocate'/before 'deallocate', call 'acc_create'/'acc_delet= e' -! manually. +! Thus, after 'allocate'/before 'deallocate', do +! '!$acc enter data create'/'!$acc exit data delete' manually. =20 =20 !TODO { dg-additional-options -fno-inline } for stable results regarding O= penACC 'routine'. @@ -102,7 +102,7 @@ program test allocate (b(n1_lb:n1_ub)) call verify_n1_allocated if (acc_is_present (b)) error stop - call acc_create (b) + !$acc enter data create (b) ! This is now OpenACC "present": if (.not.acc_is_present (b)) error stop ! This still has the initial array descriptor: @@ -201,7 +201,7 @@ program test call verify_n1_allocated if (.not.acc_is_present (b)) error stop =20 - call acc_delete (b) + !$acc exit data delete (b) if (.not.allocated (b)) error stop if (acc_is_present (b)) error stop ! The device-side array descriptor doesn't get updated, so 'b' still app= ears @@ -241,7 +241,7 @@ program test allocate (b(n2_lb:n2_ub)) call verify_n2_allocated if (acc_is_present (b)) error stop - call acc_create (b) + !$acc enter data create (b) if (.not.acc_is_present (b)) error stop ! This still has the previous (n1) array descriptor: !$acc serial @@ -299,7 +299,7 @@ program test call verify_n2_allocated if (.not.acc_is_present (b)) error stop =20 - call acc_delete (b) + !$acc exit data delete (b) if (.not.allocated (b)) error stop if (acc_is_present (b)) error stop !$acc serial --=20 2.35.1 --=-=-=--