From patchwork Fri Jun 16 15:57:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1796019 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4QjP1m6QF5z20ZB for ; Sat, 17 Jun 2023 01:57:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 772A7385771A for ; Fri, 16 Jun 2023 15:57: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 287463858D35 for ; Fri, 16 Jun 2023 15:57:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 287463858D35 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,247,1681200000"; d="diff'?scan'208";a="10076761" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 16 Jun 2023 07:57:15 -0800 IronPort-SDR: bCzIwoc6rcNax2yo5E8n6D5bp2joPypZjrWEsyY+ZLi2zgsF/Zq4B9ZI/OdYUOPCV7b1Jdtrns yUt6l1zqbyzF/95Tc6Q6/mqI/wrQ6dWS+/w1U7ccX7Sra4UeO249reuzp9nBGSl2k9VREX6Wou YLUh/TFAKDQoJ1Df4rkCQtFnkmVPNxPalaDK/hwgsuKRyI69nzZbrKXTG4Aj0kIBPfZUEWWJUn 1QZ9Y7ULzIZgwUMFKlgYgKmtWLcdzFZbfb1QhP8XGhntbGOm6pHvr2V3zOZIOae0Oulc21tnbB +Yg= Message-ID: <91bb9136-f8a4-e516-3f42-ed6d66dc8ce0@codesourcery.com> Date: Fri, 16 Jun 2023 17:57:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US To: gcc-patches From: Tobias Burnus Subject: [committed] libgomp: Fix OMP_TARGET_OFFLOAD=mandatory X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.3 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 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" 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. Tobias ----------------- 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 commit 8216ca85037be9f4d5c20540522a22a4a93b660e Author: Tobias Burnus Date: Fri Jun 16 17:21:59 2023 +0200 libgomp: Fix OMP_TARGET_OFFLOAD=mandatory 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=mandatory 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. * testsuite/libgomp.c/target-55.c: New test. * testsuite/libgomp.c/target-55a.c: New test. --- libgomp/target.c | 10 +++++++--- libgomp/testsuite/libgomp.c/target-55.c | 20 ++++++++++++++++++++ libgomp/testsuite/libgomp.c/target-55a.c | 23 +++++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/libgomp/target.c b/libgomp/target.c index e39ef8f6e82..b6a7214ab4f 100644 --- 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 = gomp_get_num_devices (); + if (remapped && device_id == GOMP_DEVICE_ICV) { struct gomp_task_icv *icv = gomp_icv (false); @@ -151,7 +155,7 @@ resolve_device (int device_id, bool remapped) : omp_initial_device)) return NULL; if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY - && gomp_get_num_devices () == 0) + && 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) @@ -162,10 +166,10 @@ resolve_device (int device_id, bool remapped) return NULL; } - else if (device_id >= gomp_get_num_devices ()) + else if (device_id >= num_devices) { if (gomp_target_offload_var == GOMP_TARGET_OFFLOAD_MANDATORY - && device_id != num_devices_openmp) + && device_id != num_devices) gomp_fatal ("OMP_TARGET_OFFLOAD is set to MANDATORY, " "but device not found"); 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 = 1; + #pragma omp target map(tofrom: x) + x = 5; + if (x != 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 only 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 = 1; + #pragma omp target map(tofrom: x) + x = 5; + if (x != 5) + __builtin_abort (); + return 0; +}