From patchwork Wed Nov 2 20:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 59805 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D0F233856DEC for ; Wed, 2 Nov 2022 20:22:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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: , 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: rcheruku@amd.com, hberre3@gatech.edu Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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=0' 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=0 } } >>> + >>> +[...] >> >> Getting rid of the "'dg-xfail-run-if' for '-DACC_MEM_SHARED=0'" 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 behavior". >> Thus, after 'allocate'/before 'deallocate', call 'acc_create'/'acc_delete' >> 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_descriptor-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 documenting > +! current GCC behavior, specifically, behavior concerning updating of > +! host/device array descriptors. > +! { dg-skip-if n/a { *-*-* } { -DACC_MEM_SHARED=1 } } > + > +!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 behavior". > +! Thus, after 'allocate'/before 'deallocate', call 'acc_create'/'acc_delete' > +! 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üße Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 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-directive.f90: New. --- libgomp/oacc-mem.c | 28 +++++++++++++++++-- ...90 => 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 => declare-allocatable-1-directive.f90} (95%) copy libgomp/testsuite/libgomp.oacc-fortran/{declare-allocatable-array_descriptor-1-runtime.f90 => 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 != REFCOUNT_INFINITY - && n->refcount != REFCOUNT_LINK); + assert (n->refcount != REFCOUNT_LINK); for (size_t j = i + 1; j <= group_last; j++) if ((kinds[j] & 0xff) == GOMP_MAP_ATTACH) @@ -1166,6 +1165,31 @@ goacc_enter_data_internal (struct gomp_device_descr *acc_dev, size_t mapnum, bool processed = false; struct target_mem_desc *tgt = n->tgt; + + /* Arrange so that OpenACC 'declare' code à la PR106643 + "[gfortran + OpenACC] Allocate in module causes refcount error" + has a chance to work. */ + if ((kinds[i] & 0xff) == GOMP_MAP_TO_PSET + && tgt->list_count == 0) + { + /* 'declare target'. */ + assert (n->refcount == REFCOUNT_INFINITY); + + for (size_t k = 1; k < groupnum; k++) + { + /* The only thing we expect to see here. */ + assert ((kinds[i + k] & 0xff) == GOMP_MAP_POINTER); + } + + /* Given that 'goacc_exit_data_internal'/'goacc_exit_datum_1' + will always see 'n->refcount == REFCOUNT_INFINITY', + there's no need to adjust 'n->dynamic_refcount' here. */ + + processed = true; + } + else + assert (n->refcount != REFCOUNT_INFINITY); + for (size_t j = 0; j < tgt->list_count; j++) if (tgt->list[j].key == n) { diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90 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-directive.f90 index 1c8ccd9f61f..759873bad67 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1.f90 +++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-1-directive.f90 @@ -3,10 +3,10 @@ ! { dg-do run } !TODO-OpenACC-declare-allocate -! Not currently implementing correct '-DACC_MEM_SHARED=0' 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=0 } } +! Thus, after 'allocate'/before 'deallocate', do +! '!$acc enter data create'/'!$acc exit data delete' manually. !TODO { dg-additional-options -fno-inline } for stable results regarding OpenACC 'routine'. @@ -67,6 +67,7 @@ program test ! Test local usage of an allocated declared array. allocate (b(n)) + !$acc enter data create (b) if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop @@ -91,12 +92,14 @@ program test if (b(i) /= i*a) error stop end do + !$acc exit data delete (b) deallocate (b) ! Test the usage of an allocated declared array inside an acc ! routine subroutine. allocate (b(n)) + !$acc enter data create (b) if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop @@ -114,6 +117,7 @@ program test if (b(i) /= i*2) error stop end do + !$acc exit data delete (b) deallocate (b) ! Test the usage of an allocated declared array inside a host @@ -129,6 +133,7 @@ program test if (b(i) /= 1.0) error stop end do + !$acc exit data delete (b) deallocate (b) if (allocated (b)) error stop @@ -137,6 +142,7 @@ program test ! routine function. allocate (b(n)) + !$acc enter data create (b) if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop @@ -170,12 +176,14 @@ program test if (b(i) /= i) error stop end do + !$acc exit data delete (b) deallocate (b) ! Test the usage of an allocated declared array inside a host ! function. allocate (b(n)) + !$acc enter data create (b) if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop @@ -202,6 +210,7 @@ program test if (b(i) /= i*i) error stop end do + !$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 candidate for adjusting OpenACC privatization level: not addressable} {TODO n/a} { xfail *-*-* } l$c } @@ -234,6 +243,7 @@ subroutine sub2 integer i allocate (b(n)) + !$acc enter data create (b) if (.not.allocated (b)) error stop if (.not.acc_is_present (b)) error stop diff --git a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-runtime.f90 b/libgomp/testsuite/libgomp.oacc-fortran/declare-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_descriptor-1-directive.f90 index b27f312631d..10e1d5bc378 100644 --- a/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-1-runtime.f90 +++ b/libgomp/testsuite/libgomp.oacc-fortran/declare-allocatable-array_descriptor-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 behavior". -! Thus, after 'allocate'/before 'deallocate', call 'acc_create'/'acc_delete' -! manually. +! Thus, after 'allocate'/before 'deallocate', do +! '!$acc enter data create'/'!$acc exit data delete' manually. !TODO { dg-additional-options -fno-inline } for stable results regarding OpenACC '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 - 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 appears @@ -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 - call acc_delete (b) + !$acc exit data delete (b) if (.not.allocated (b)) error stop if (acc_is_present (b)) error stop !$acc serial -- 2.35.1