From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 36A9F3858D33 for ; Tue, 7 Feb 2023 22:47:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36A9F3858D33 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.97,279,1669104000"; d="scan'208,223";a="99956479" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 07 Feb 2023 14:47:35 -0800 IronPort-SDR: 68RBY1nGgZsZFI/1T8UGns5O/K9csYnDjSq46BaLo/o8NvUaZeq/ZKc5go+C1dWEyifOBuAAH5 aOhqJLO5b2mQqGL402+hq0sNTmeQnwFr+7BjqxQWXDXYXrlwNdFgq73X6/V7G8heBgpbzN6oij f1tdVJNI/+eAHDWlTwVz/0aZ58sRXLUVUSO2NDHn/EeeG4thG9yZN3znOQnjB+AvWXoiY6tzGM gzQDqgolRGst3L5FgK2KiVFEFY+jhGZQvOOXCfaXtnPxiPkwfqmDC9DTVug2+D7SlCTQy7ro9Y 4A8= From: Thomas Schwinge To: Tobias Burnus , CC: Jakub Jelinek Subject: Fix 'libgomp.fortran/reverse-offload-6.f90' nvptx offloading compilation (was: [Patch] libgomp: Fix reverse offload issues) In-Reply-To: References: <4c058f14-c719-b66a-f556-9bda3a4c4556@codesourcery.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Tue, 7 Feb 2023 23:47:25 +0100 Message-ID: <874jrxum82.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-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_LOTSOFHASH,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 Tobias! On 2023-02-03T11:38:29+0100, Tobias Burnus wrote: > Now committed as obvious as > r13-5680-g0b1ce70a813b98ef2893779d14ad6c90c5d06a71. I see: FAIL: libgomp.fortran/reverse-offload-6.f90 -O (test for excess erro= rs) ... due to: nvptx mkoffload: warning: 'omp requires reverse_offload' requires at le= ast 'sm_35' for '-foffload-options=3Dnvptx-none=3D-march=3D' - disabling of= fload-code generation for this device type I've pushed to master branch commit 7ab75a6e6dfd81c566f848ef0d8d06666ee15b81 "Fix 'libgomp.fortran/reverse-offload-6.f90' nvptx offloading compilation", see attached. Gr=C3=BC=C3=9Fe Thomas > I improved the wording in the commit comment a bit, compared to previous > attachment and I have verified that those features work with AMDGCN* and > without offloading. > > Tobias > > (* it seems as if there is still another issue with mapping, this time > for array-descriptor variables that do not exist on the host, i.e. that > have to be fully mapped to the host. I will look into this today or Monda= y.) > > On 02.02.23 15:13, Tobias Burnus wrote: >> Found when testing AMD GCN offloading, the second issue came up with >> libgomp.fortran/reverse-offload-5.f90. (But oddly not with nvptx.) >> >> While the first one (new test: libgomp.fortran/reverse-offload-6.f90) >> came up when debugging the issue. >> >> Tobias > commit 0b1ce70a813b98ef2893779d14ad6c90c5d06a71 > Author: Tobias Burnus > Date: Fri Feb 3 11:31:53 2023 +0100 > > libgomp: Fix reverse offload issues > > If there is nothing to map, skip the mapping and avoid attempting to > copy 0 bytes from addrs, sizes and kinds. > > Additionally, it could happen that a non-allocated address was deallo= cated, > such as a pointer set, leading to a free for the actual data. > > libgomp/ > * target.c (gomp_target_rev): Handle mapnum =3D=3D 0 and avoi= d > freeing not allocated memory. > * testsuite/libgomp.fortran/reverse-offload-6.f90: New test. > --- > libgomp/target.c | 8 +++--- > .../libgomp.fortran/reverse-offload-6.f90 | 32 ++++++++++++++++= ++++++ > 2 files changed, 36 insertions(+), 4 deletions(-) > > diff --git a/libgomp/target.c b/libgomp/target.c > index b16ee761a95..c1682caea13 100644 > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -3324,7 +3324,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, = uint64_t devaddrs_ptr, > gomp_fatal ("Cannot find reverse-offload function"); > void (*host_fn)() =3D (void (*)()) n->k->host_start; > > - if (devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) > + if ((devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) || mapnum = =3D=3D 0) > { > devaddrs =3D (uint64_t *) (uintptr_t) devaddrs_ptr; > sizes =3D (uint64_t *) (uintptr_t) sizes_ptr; > @@ -3402,7 +3402,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, = uint64_t devaddrs_ptr, > } > } > > - if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)) > + if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) && mapnum >= 0) > { > size_t j, struct_cpy =3D 0; > splay_tree_key n2; > @@ -3638,7 +3638,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, = uint64_t devaddrs_ptr, > > host_fn (devaddrs); > > - if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM)) > + if (!(devicep->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) && mapnum >= 0) > { > uint64_t struct_cpy =3D 0; > bool clean_struct =3D false; > @@ -3680,7 +3680,7 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, = uint64_t devaddrs_ptr, > clean_struct =3D true; > struct_cpy =3D sizes[i]; > } > - else if (cdata[i].aligned) > + else if (!cdata[i].present && cdata[i].aligned) > gomp_aligned_free ((void *) (uintptr_t) devaddrs[i]); > else if (!cdata[i].present) > free ((void *) (uintptr_t) devaddrs[i]); > diff --git a/libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90 b/li= bgomp/testsuite/libgomp.fortran/reverse-offload-6.f90 > new file mode 100644 > index 00000000000..04866edbba7 > --- /dev/null > +++ b/libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90 > @@ -0,0 +1,32 @@ > +! > +! Ensure that a mapping with no argument works > +! > + > +module m > + implicit none (type, external) > + integer :: x =3D 32 > + integer :: dev_num2 =3D -1 > +contains > +subroutine foo() > + use omp_lib, only: omp_get_device_num > + x =3D x + 10 > + dev_num2 =3D omp_get_device_num() > +end > +end module m > + > +use m > +use omp_lib > +!$omp requires reverse_offload > +implicit none (type, external) > +integer :: dev_num =3D -1 > +!$omp target map(from:dev_num) > + dev_num =3D omp_get_device_num() > + ! This calls GOMP_target_ext with number of maps =3D 0 > + !$omp target device(ancestor:1) > + call foo > + !$omp end target > +!$omp end target > + > +if (omp_get_num_devices() > 0 .and. dev_num2 =3D=3D dev_num) stop 1 > +if (x /=3D 42) stop 2 > +end ----------------- 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 Content-Disposition: inline; filename="0001-Fix-libgomp.fortran-reverse-offload-6.f90-nvptx-offl.patch" >From 7ab75a6e6dfd81c566f848ef0d8d06666ee15b81 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Tue, 7 Feb 2023 21:23:47 +0100 Subject: [PATCH] Fix 'libgomp.fortran/reverse-offload-6.f90' nvptx offloading compilation Fix-up for recent commit 0b1ce70a813b98ef2893779d14ad6c90c5d06a71 "libgomp: Fix reverse offload issues". libgomp/ * testsuite/libgomp.fortran/reverse-offload-6.f90: Fix nvptx offloading compilation. --- libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90 b/libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90 index 04866edbba7d..ddb7008cb1ad 100644 --- a/libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90 +++ b/libgomp/testsuite/libgomp.fortran/reverse-offload-6.f90 @@ -2,6 +2,8 @@ ! Ensure that a mapping with no argument works ! +! { dg-additional-options -foffload-options=nvptx-none=-misa=sm_35 { target offload_target_nvptx } } + module m implicit none (type, external) integer :: x = 32 -- 2.39.0 --=-=-=--