From patchwork Wed Jun 14 08:09:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 1794844 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qgykk1Ykcz20QH for ; Wed, 14 Jun 2023 18:09:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EAE243858414 for ; Wed, 14 Jun 2023 08:09:30 +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 E32173858CDA for ; Wed, 14 Jun 2023 08:09:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E32173858CDA 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,242,1681200000"; d="scan'208,223";a="9786065" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 14 Jun 2023 00:09:17 -0800 IronPort-SDR: g9QFRDTNcYX8UfJpMzdjrLtGOf4BMbg3QE3i9uu6uSYibGb7CJlqdwTyfBuG5CfguGVWWwGyH9 Y2kdeUB/dKinR21pakkct8KbPTfDlQ1zl+cU2uqQRJMI8A1xYJSkbM9Y1H8x/n+4jBVis41dmz OmsXseT77wJCIrukZDFeuJ2GWmT0SQhj0BO7Ixgqzsperla8qGek+hG855BsfJZDLWqjxYLEPl oI1kyMX5DzZ4DAjMuztFrr+ZN6ik/O+3y94W0cIpwNHtskikeSZl+4KqDZVZzjpou+mikbSv2m pzE= From: Thomas Schwinge To: Tobias Burnus , Subject: Fix typo in 'libgomp.c/target-51.c' (was: [patch] OpenMP: Set default-device-var with OMP_TARGET_OFFLOAD=mandatory) In-Reply-To: <1487d7d4-8611-0d78-6bf2-9bffdd4daa64@codesourcery.com> References: <1487d7d4-8611-0d78-6bf2-9bffdd4daa64@codesourcery.com> User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Wed, 14 Jun 2023 10:09:09 +0200 Message-ID: <87pm5y31p6.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) 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_SHORT, 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 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! On 2023-06-13T20:44:39+0200, Tobias Burnus wrote: > I intent to commit this tomorrow, unless there are comments. I'm sorry I'm late. ;-P > It does as it says (see commit log): It initializes default-device-var > to the value using the algorithm described in OpenMP 5.2, which > depends on whether OMP_TARGET_OFFLOAD=mandatory was set. > > NOTE: With -foffload=disable there is no binary code but still > devices get found - such that default-device-var == 0 (= first > nonhost device). Thus, in that case, libgomp runs the code on that > device but as no binary data is available, host fallback is used. > (Even if there would be executable code for another device on > the system.) > With mandatory, this unintended host fallback is detected and an > error is diagnosed. One can argue whether keeping the devices > makes sense (e.g. because in a dynamic library device code will > be loaded later) or not (don't list if no code is available). This reminds me of the (unresolved) "Means to determine at runtime foffload targets specified at compile time". > Note that TR11 (future OpenMP 6.0) extends OMP_DEFAULT_DEVICE and > adds OMP_AVAILABLE_DEVICES which permit a finer-grained control about > the device, including OMP_DEFAULT_DEVICE=initial (and 'invalid') which > the current scheme does not permit. (Well, there is > OMP_TARGET_OFFLOAD=disabled, but that's a too big hammer.) > PS: DejaGNU testing was done without offloading configured > and with remote testing on a system having an offload device, > which which does not support setting environment variables. > Manual testing was done with offloading enabled and depending > on the testcase, running on a system with and/or without offloading > hardware. > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -150,7 +150,11 @@ resolve_device (int device_id, bool remapped) > if (device_id == (remapped ? GOMP_DEVICE_HOST_FALLBACK > : omp_initial_device)) > return NULL; > - if (device_id == omp_invalid_device) > + if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY > + && gomp_get_num_devices () == 0) > + gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY but only the host " > + "device is available"); > + else if (device_id == omp_invalid_device) > gomp_fatal ("omp_invalid_device encountered"); > else if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY) > gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, " | "but device not found"); | | return NULL; | } | else if (device_id >= gomp_get_num_devices ()) | { | if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY | && device_id != num_devices_openmp) | gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, " | "but device not found"); | | return NULL; | } | | gomp_mutex_lock (&devices[device_id].lock); | if (devices[device_id].state == GOMP_DEVICE_UNINITIALIZED) | gomp_init_device (&devices[device_id]); | else if (devices[device_id].state == GOMP_DEVICE_FINALIZED) | { | gomp_mutex_unlock (&devices[device_id].lock); | | if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY) | gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, " | "but device is finalized"); | | return NULL; | } | gomp_mutex_unlock (&devices[device_id].lock); | | return &devices[device_id]; | } > --- /dev/null > +++ b/libgomp/testsuite/libgomp.c/target-51.c > @@ -0,0 +1,24 @@ > +/* Check OMP_TARGET_OFFLOAD on systems with no available non-host devices, > + which is enforced by using -foffload=disable. */ > + > +/* { dg-do run } */ > +/* { dg-additional-options "-foffload=disable" } */ > +/* { dg-set-target-env-var OMP_TARGET_OFFLOAD "mandatory" } */ > + > +/* { dg-shouldfail "OMP_TARGET_OFFLOAD=mandatory and no available device" } */ > + > +/* See comment in target-50.c/target-50.c for why the output differs. */ > + > +/* { dg-output ".*libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY but only the host device is available.*" { target { ! offload_device } } } */ > +/* { dg-output ".*libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY but device not found.*" { target offload_device } } */ I intend to push the attached "Fix typo in 'libgomp.c/target-51.c'" after testing. Let me know if I should also adjust the new 'target { ! offload_device }' diagnostic "[...] MANDATORY but only the host device is available" to include a comma before 'but', for consistency with the other existing diagnostics (cited above)? Grüße Thomas > + > +int > +main () > +{ > + int x; > + #pragma omp target map(tofrom:x) > + x = 5; > + if (x != 5) > + __builtin_abort (); > + return 0; > +} ----------------- 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 2464d87db542b87a1d276637f334e9c6eb35be64 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Wed, 14 Jun 2023 09:25:15 +0200 Subject: [PATCH] Fix typo in 'libgomp.c/target-51.c' ..., and therefore, given 'target offload_device': PASS: libgomp.c/target-51.c (test for excess errors) PASS: libgomp.c/target-51.c execution test [-FAIL:-]{+PASS:+} libgomp.c/target-51.c output pattern test Fix-up for recent commit 18c8b56c7d67a9e37acf28822587786f0fc0efbc "OpenMP: Set default-device-var with OMP_TARGET_OFFLOAD=mandatory". libgomp/ * testsuite/libgomp.c/target-51.c: Fix typo. --- libgomp/testsuite/libgomp.c/target-51.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgomp/testsuite/libgomp.c/target-51.c b/libgomp/testsuite/libgomp.c/target-51.c index 7d09bceacd58..cf9e690263e9 100644 --- a/libgomp/testsuite/libgomp.c/target-51.c +++ b/libgomp/testsuite/libgomp.c/target-51.c @@ -10,7 +10,7 @@ /* See comment in target-50.c/target-50.c for why the output differs. */ /* { dg-output ".*libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY but only the host device is available.*" { target { ! offload_device } } } */ -/* { dg-output ".*libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY but device not found.*" { target offload_device } } */ +/* { dg-output ".*libgomp: OMP_TARGET_OFFLOAD is set to MANDATORY, but device not found.*" { target offload_device } } */ int main () -- 2.39.2