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 708E43858D33 for ; Tue, 7 Feb 2023 22:51:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 708E43858D33 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";a="99956778" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 07 Feb 2023 14:51:40 -0800 IronPort-SDR: AOVDsbd3pObfdYOTf6AggOybwij7s/p5yipK59sE8SMwqwkJeTCB/08PrxJc0x8RPIM+sgsukY BAIhAMct/efA7/vzgdwXZxjBXkoSzVH8E9uO98SbUMNprSXYl7GDRDBlcFdq+QgpNszLXm34su L0yQCBS7zey7JqCv6Ftz8AX+QP2ZPzPsraA22uPN/skr011SnpFq4p5O03RktWwddQi8O4Y8Wo S4s/6B00dqUAFPWp/wE6AGt2ug5fP30GYpOm7M3phqNCM3XouKFLTCNQy6bEPIH3XTYwM0iMHZ dQ8= From: Thomas Schwinge To: Tobias Burnus CC: , Jakub Jelinek Subject: Re: [Patch] libgomp: Fix reverse-offload for GOMP_MAP_TO_PSET In-Reply-To: <85ecf108-8249-21a3-b9ee-23b89b6816bd@codesourcery.com> References: <85ecf108-8249-21a3-b9ee-23b89b6816bd@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:51:23 +0100 Message-ID: <87357hum1g.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) 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,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: Hi Tobias! On 2023-02-06T12:52:11+0100, Tobias Burnus wrote: > Seems as if I missed a GOMP_MAP_TO_PSET issue before. As nvptx is > XFAILed before, I only found it when testing on AMDGCN. > > For an array-descriptor 'ai' variable, omplower has: > map(tofrom:MEM [(integer(kind=3D4)[0:] *)D.434= 6] [len: D.4345]) > map(to:ai [pointer set, len: 64]) > map(alloc:ai.data [pointer assign, bias: 0]) > > The latter reaches GCC with the same address as 'ai' =E2=80=93 i.e. the > one of the array descriptor. This then needs to be dereferenced > to get the address of the actual pointer. > The patch assumes (and asserts) that 'ai.data' is part of the 'ai' > such that I can use the host address of 'ai' to access the data. > If that's not guaranteed, we have to find another way (e.g. another > lookup). But so far it seems to hold and I have not seen a bias > other than 0. > > With that patch, libgomp.fortran/reverse-offload-5.f90 now works > with AMDGCN. Confirming the latter, thanks. (..., but I've not actually reviewed the code changes.) > OK? Any comments to the attached patch? Yes: > libgomp: Fix reverse-offload for GOMP_MAP_TO_PSET > > libgomp/ > * target.c (gomp_target_rev): Dereference ptr > to get device address. > * libgomp.fortran/reverse-offload-5.f90: Add test > for unallocated allocatable. > > libgomp/target.c | 7 ++++++- > libgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 | 6 ++++-- > 2 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/libgomp/target.c b/libgomp/target.c > index c1682caea13..5cdd845291a 100644 > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -3579,8 +3579,13 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum,= uint64_t devaddrs_ptr, > } > int k; > n2 =3D NULL; > - cdata[i].present =3D true; > + /* Dereference devaddrs[j] to get the device addr. */ > + assert (devaddrs[j]-sizes[j] =3D=3D cdata[i].devaddr); > + devaddrs[j] =3D *(uint64_t *) (devaddrs[i] + sizes[j]); For x86_64-pc-linux-gnu '-m32' multilib: [...] [...]/source-gcc/libgomp/target.c: In function =E2=80=98gomp_target_rev= =E2=80=99: [...]/source-gcc/libgomp/target.c:3615:36: error: cast to pointer from = integer of different size [-Werror=3Dint-to-pointer-cast] 3615 | devaddrs[j] =3D *(uint64_t *) (devaddrs[i] = + sizes[j]); | ^ cc1: all warnings being treated as errors make[9]: *** [target.lo] Error 1 make[9]: Leaving directory `[...]/build-gcc/x86_64-pc-linux-gnu/32/libg= omp' [...] I suppose you'd do similar to what you already have a few lines above; that is, cast through 'uintptr_t': devaddrs[j] =3D *(uint64_t *) (uintptr_t) (devaddrs[i] + sizes[j]); Gr=C3=BC=C3=9Fe Thomas > + cdata[j].present =3D true; > cdata[j].devaddr =3D devaddrs[j]; > + if (devaddrs[j] =3D=3D 0) > + continue; > k =3D gomp_map_cdata_lookup (cdata, devaddrs, kinds, si= zes, j, > devaddrs[j], > devaddrs[j] + sizeof (void*)= , > diff --git a/libgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 b/li= bgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 > index ef7eb7bdd52..16810eb47de 100644 > --- a/libgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 > +++ b/libgomp/testsuite/libgomp.fortran/reverse-offload-5.f90 > @@ -24,7 +24,7 @@ s2 =3D 55 > > !$omp target map(to: A, A2, s1, s2) > block > - integer, allocatable :: ai(:), ai2(:), si1, si2 > + integer, allocatable :: ai(:), ai2(:), ai3(:), si1, si2, si3 > > a =3D a * 2 > a2 =3D a2 * 3 > @@ -38,7 +38,7 @@ block > > !$omp target device (ancestor:1) & > !$omp& map(to: A, s1, ai, si1) map(always, to: a2, s2) & > - !$omp& map(tofrom: ai2, si2) > + !$omp& map(tofrom: ai2, si2, ai3, si3) > if (shared_mem) then > if (any (a /=3D 2 * [1,2,3,4])) stop 1 > if (s1 /=3D 4 * 532) stop 2 > @@ -52,6 +52,7 @@ block > if (any (ai2 /=3D [8,4,7,1])) stop 8 > if (si1 /=3D 64) stop 9 > if (si2 /=3D 765) stop 10 > + if (allocated (ai3) .or. allocated(si3)) stop 26 > > a =3D a*3 > a2 =3D a2*7 > @@ -80,6 +81,7 @@ block > endif > if (any (ai2 /=3D 21 * [8,4,7,1])) stop 24 > if (si2 /=3D 31 * 765) stop 25 > + if (allocated (ai3) .or. allocated(si3)) stop 27 > > deallocate (ai, ai2, si1, si2) > end block ----------------- 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