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 6E7433858D35 for ; Fri, 16 Jun 2023 20:43:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E7433858D35 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="6.00,248,1681200000"; d="scan'208";a="10133365" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 16 Jun 2023 12:42:59 -0800 IronPort-SDR: V2oRabkWlJW02twNuEchL11E3I6po5UDPuUMusOmGwO7obihk1cPhf9iLy9LV4P9Wnh8twyWrs kr2Q7UZ6Crqh4T1skrqWZZisGrCgxKgsAyxu3UCU/hHSotR2Q5woguoAreeTSRH2u/nhO/ek+E LuE+7AMMy+eG1Ql9hO2R9sg/ObrY7T/XT5oXyVAxJAJs5fM0nlYWvD4GXCwnoigeZUUnG8r0bO fllQn2Me9a4DR7IglMOm7lif2mwSFFfNle5Dw/si17UfS7rYMyRnUQf1lCAhh2sPTJACIIPmqc SpQ= From: Thomas Schwinge To: Tobias Burnus CC: Subject: Re: [committed] libgomp: Fix OMP_TARGET_OFFLOAD=mandatory In-Reply-To: <91bb9136-f8a4-e516-3f42-ed6d66dc8ce0@codesourcery.com> References: <1487d7d4-8611-0d78-6bf2-9bffdd4daa64@codesourcery.com> <91bb9136-f8a4-e516-3f42-ed6d66dc8ce0@codesourcery.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Fri, 16 Jun 2023 22:42:35 +0200 Message-ID: <87cz1vf8as.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-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,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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-06-16T17:57:10+0200, Tobias Burnus wrote: > Found an order problem caused by my r14-1801-g18c8b56c7d67a9 due to > ordering issues related to the offloading initialization > (gomp_init_targets_once). > > The testsuite did test various ways but only code such paths that > initialized the library before ... > > Committed as Rev. r14-1893-g8216ca85037be9. > commit 8216ca85037be9f4d5c20540522a22a4a93b660e > Author: Tobias Burnus > Date: Fri Jun 16 17:21:59 2023 +0200 > > libgomp: Fix OMP_TARGET_OFFLOAD=3Dmandatory > > It turned out that gomp_init_targets_once() was not run when directly > calling 'omp target' or 'omp target (enter/exit) data' causing an > abort with OMP_TARGET_OFFLOAD=3Dmandatory wrongly claiming that no > device is available. It was called a tiny bit later but few lines too > late for updating the default-device-var. > > libgomp/ChangeLog: > > * target.c (resolve_device): Call gomp_get_num_devices early = to ensure > gomp_init_targets_once was called before using default-device= -var. > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -138,6 +138,10 @@ gomp_get_num_devices (void) > static struct gomp_device_descr * > resolve_device (int device_id, bool remapped) > { > + /* Get number of devices and thus ensure that 'gomp_init_targets_once'= was > + called, which must be done before using default_device_var. */ > + int num_devices =3D gomp_get_num_devices (); > + > if (remapped && device_id =3D=3D GOMP_DEVICE_ICV) > { > struct gomp_task_icv *icv =3D gomp_icv (false); > @@ -151,7 +155,7 @@ resolve_device (int device_id, bool remapped) > : omp_initial_device)) > return NULL; > if (gomp_target_offload_var =3D=3D GOMP_TARGET_OFFLOAD_MANDATORY > - && gomp_get_num_devices () =3D=3D 0) > + && num_devices =3D=3D 0) > gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, " > "but only the host device is available"); > else if (device_id =3D=3D omp_invalid_device) > @@ -162,10 +166,10 @@ resolve_device (int device_id, bool remapped) > > return NULL; > } > - else if (device_id >=3D gomp_get_num_devices ()) > + else if (device_id >=3D num_devices) > { > if (gomp_target_offload_var =3D=3D GOMP_TARGET_OFFLOAD_MANDATORY > - && device_id !=3D num_devices_openmp) > + && device_id !=3D num_devices) > gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, " > "but device not found"); I see the new tests PASS, but with offloading enabled (nvptx) also see: PASS: libgomp.c/target-51.c (test for excess errors) PASS: libgomp.c/target-51.c execution test [-PASS:-]{+FAIL:+} libgomp.c/target-51.c output pattern test ... due to: Output was: libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY, but device cannot be u= sed for offloading Should match: .*libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY, but device not found= .* Gr=C3=BC=C3=9Fe Thomas > diff --git a/libgomp/testsuite/libgomp.c/target-55.c b/libgomp/testsuite/= libgomp.c/target-55.c > new file mode 100644 > index 00000000000..1314b3c6963 > --- /dev/null > +++ b/libgomp/testsuite/libgomp.c/target-55.c > @@ -0,0 +1,20 @@ > +/* { dg-do run { target { offload_device } } } */ > +/* { dg-set-target-env-var OMP_TARGET_OFFLOAD "mandatory" } */ > + > +/* Should pass - see target-55a.c for !offload_device */ > + > +/* Check OMP_TARGET_OFFLOAD - it shall run on systems with offloading > + devices available and fail otherwise. Note that this did always > + fail - as the device handling wasn't initialized before doing the > + mandatory checking. */ > + > +int > +main () > +{ > + int x =3D 1; > + #pragma omp target map(tofrom: x) > + x =3D 5; > + if (x !=3D 5) > + __builtin_abort (); > + return 0; > +} > diff --git a/libgomp/testsuite/libgomp.c/target-55a.c b/libgomp/testsuite= /libgomp.c/target-55a.c > new file mode 100644 > index 00000000000..53978c3f405 > --- /dev/null > +++ b/libgomp/testsuite/libgomp.c/target-55a.c > @@ -0,0 +1,23 @@ > +/* { dg-do run { target { ! offload_device } } } */ > +/* { dg-set-target-env-var OMP_TARGET_OFFLOAD "mandatory" } */ > + > +/* Should fail - see target-55a.c for offload_device */ > + > +/* { dg-shouldfail "omp_invalid_device" } */ > +/* { dg-output ".*libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY, but o= nly the host device is available.*" } */ > + > +/* Check OMP_TARGET_OFFLOAD - it shall run on systems with offloading > + devices available and fail otherwise. Note that this did always > + fail - as the device handling wasn't initialized before doing the > + mandatory checking. */ > + > +int > +main () > +{ > + int x =3D 1; > + #pragma omp target map(tofrom: x) > + x =3D 5; > + if (x !=3D 5) > + __builtin_abort (); > + return 0; > +} ----------------- 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