From patchwork Thu Feb 13 08:04:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederik Harwath X-Patchwork-Id: 1237338 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519458-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=bGg++AH2; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48J8F96PYgz9s1x for ; Thu, 13 Feb 2020 19:05:00 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=rPMshk5VUnXVH9Jeb NUttyWGtXLbjrMsMAC2xCnvTL9+ynuX+3gOKRSObRtWzVSPyzcw58qIeYahguMe5 NEj1qlDVYQB8wrzLn9a0Z6KmPywKveI+Yb+eVVJLu+cJOG26UBswVUz2j1SXW0YJ keAsTVfkRLpYj8JZAGw3KrTPLs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=cH6C7fDs6Pka5XDSgOXkJZN z7Rk=; b=bGg++AH2b0Bo/EdkK0YQv+aiLRZYhGKrcIodrnnIoznhykDyQJdXHet F6ljRuV78QEFngfimxm6h3tchOdzyycMf0b2So157mBCbWxYZbHvf7j6Up66BZ4v hRlrLlgpaiRO3Cr/6NGMjwP8ZFmBdDfrqgQ6lhuNw0pW4sEuNDcU= Received: (qmail 130057 invoked by alias); 13 Feb 2020 08:04:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 130045 invoked by uid 89); 13 Feb 2020 08:04:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=observed X-HELO: esa2.mentor.iphmx.com Received: from esa2.mentor.iphmx.com (HELO esa2.mentor.iphmx.com) (68.232.141.98) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Feb 2020 08:04:50 +0000 IronPort-SDR: wvI6B4ILKU2wxUtMJiJrminIm5+dgb/BOMTt8eCNBgs9ixzr1VktqEtREZjYXVsG0iY9jeEPG+ YMT3Lq874mfE7hBvwNufVpek71mTBteXa5iylbdYD47uTzU61iosu1EphCa+lRSbpPV4fFCVER GuIonQJ/j3K5NqpP1ZZZ3qxwdPObQ5V0qYdLNm0V6Y6GlhmfyeyT/Syu82F86dCigSC4674kVa 4hkRMXhM76bG+pERkwI3EbfTcaC6eG9w5ia3th0Fjmn8f0VrkXiTDg+YKb5dCfYGyb5Bey7DXB OFU= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 13 Feb 2020 00:04:48 -0800 IronPort-SDR: W5VVE/ODOc63qHhhmJe9FPcyW9Zn9Bfbe5FaSTe40EbUsQfKzr6/8ZI3EvMOBdxuF8y80RJ06T 1Q36DgFyV2Ug/lPmHbgRl61WehcMhYgSGAZ0Tvslxro/q9FHADONSwfA407UqP69WWrmZez3Wi fZ2yMW3gyAfxT/KmZS3cfrrzq4VtukUkJgTozpAyPGHDVnChHW1gNngsysMYtGpfPPD6JQFyD7 TvdB6a+c2A8cz4dBCPXGnP/NHpjplK1PVn/XXfjmJIHBAJRX6m2m5IcdYMPqurt5YX5IGubS0/ 91Q= From: "Harwath, Frederik" Subject: [PATCH] openmp: ignore nowait if async execution is unsupported [PR93481] To: Jakub Jelinek CC: GCC Patches , References: <1ea4c14f-f975-5170-46ac-ada4588c4969@codesourcery.com> <20200207152929.GU17695@tucnak> <6df464fe-2a2d-2809-ebfa-cc239b406019@codesourcery.com> X-Pep-Version: 2.0 Message-ID: <3b2c0707-cc23-c3e7-82ad-de885abe85d5@codesourcery.com> Date: Thu, 13 Feb 2020 09:04:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <6df464fe-2a2d-2809-ebfa-cc239b406019@codesourcery.com> X-IsSubscribed: yes Hi Jakub, On 10.02.20 08:49, Harwath, Frederik wrote: >> There has been even in some PR a suggestion that instead of failing >> in nvptx async_run we should just ignore the nowait clause if the plugin >> doesn't implement it properly. > > This must be https://gcc.gnu.org/PR93481. The attached patch implements the behavior that has been suggested in the PR. It makes GOMP_OFFLOAD_async_run optional, removes the stub which produces the error described in the PR from the nvptx plugin, and changes the nowait-handling to ignore the clause if GOMP_OFFLOAD_async_run is not available for the executing device's plugin. I have tested the patch by running the full libgomp testsuite with nvptx-none offloading on x86_64-linux-gnu. I have observed no regressions. Ok to push the commit to master? For the record: Someone should implement GOMP_OFFLOAD_async_run properly in the nvtpx plugin. Best regards, Frederik From 1258f713be317870e9171281e3f7c3a174773aa1 Mon Sep 17 00:00:00 2001 From: Frederik Harwath Date: Thu, 13 Feb 2020 07:30:16 +0100 Subject: [PATCH] openmp: ignore nowait if async execution is unsupported [PR93481] An OpenMP "nowait" clause on a target construct currently leads to a call to GOMP_OFFLOAD_async_run in the plugin that is used for offloading at execution time. The nvptx plugin contains only a stub of this function that always produces a fatal error if called. This commit changes the "nowait" implementation to ignore the clause if the executing device's plugin does not implement GOMP_OFFLOAD_async_run. The stub in the nvptx plugin is removed which effectively means that programs containing "nowait" can now be executed with nvptx offloading as if the clause had not been used. This behavior is consistent with the OpenMP specification which says that "[...] execution of the target task *may* be deferred" (emphasis added), cf. OpenMP 5.0, page 172. libgomp/ * plugin/plugin-nvptx.c: Remove GOMP_OFFLOAD_async_run stub. * target.c (gomp_load_plugin_for_device): Make "async_run" loading optional. (gomp_target_task_fn): Assert "devicep->async_run_func". (clear_unsupported_flags): New function to remove unsupported flags (right now only GOMP_TARGET_FLAG_NOWAIT) that can be be ignored. (GOMP_target_ext): Apply clear_unsupported_flags to flags. (GOMP_target_update_ext): Likewise. (GOMP_target_enter_exit_data): Likewise. * testsuite/libgomp.c/target-33.c: Remove xfail for offload_target_nvptx. * testsuite/libgomp.c/target-34.c: Likewise. --- libgomp/plugin/plugin-nvptx.c | 7 +------ libgomp/target.c | 19 ++++++++++++++++++- libgomp/testsuite/libgomp.c/target-33.c | 3 --- libgomp/testsuite/libgomp.c/target-34.c | 3 --- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index 6033c71a9db..ec103a2f40b 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -1931,9 +1931,4 @@ GOMP_OFFLOAD_run (int ord, void *tgt_fn, void *tgt_vars, void **args) nvptx_stacks_free (stacks, teams * threads); } -void -GOMP_OFFLOAD_async_run (int ord, void *tgt_fn, void *tgt_vars, void **args, - void *async_data) -{ - GOMP_PLUGIN_fatal ("GOMP_OFFLOAD_async_run unimplemented"); -} +/* TODO: Implement GOMP_OFFLOAD_async_run. */ diff --git a/libgomp/target.c b/libgomp/target.c index 3df007283f4..4fbf963f305 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -2022,6 +2022,16 @@ GOMP_target (int device, void (*fn) (void *), const void *unused, gomp_unmap_vars (tgt_vars, true); } +static unsigned int +clear_unsupported_flags (struct gomp_device_descr *devicep, unsigned int flags) +{ + /* If we cannot run asynchronously, simply ignore nowait. */ + if (devicep != NULL && devicep->async_run_func == NULL) + flags &= ~GOMP_TARGET_FLAG_NOWAIT; + + return flags; +} + /* Like GOMP_target, but KINDS is 16-bit, UNUSED is no longer present, and several arguments have been added: FLAGS is a bitmask, see GOMP_TARGET_FLAG_* in gomp-constants.h. @@ -2054,6 +2064,8 @@ GOMP_target_ext (int device, void (*fn) (void *), size_t mapnum, size_t tgt_align = 0, tgt_size = 0; bool fpc_done = false; + flags = clear_unsupported_flags (devicep, flags); + if (flags & GOMP_TARGET_FLAG_NOWAIT) { struct gomp_thread *thr = gomp_thread (); @@ -2257,6 +2269,8 @@ GOMP_target_update_ext (int device, size_t mapnum, void **hostaddrs, { struct gomp_device_descr *devicep = resolve_device (device); + flags = clear_unsupported_flags (devicep, flags); + /* If there are depend clauses, but nowait is not present, block the parent task until the dependencies are resolved and then just continue with the rest of the function as if it @@ -2398,6 +2412,8 @@ GOMP_target_enter_exit_data (int device, size_t mapnum, void **hostaddrs, { struct gomp_device_descr *devicep = resolve_device (device); + flags = clear_unsupported_flags (devicep, flags); + /* If there are depend clauses, but nowait is not present, block the parent task until the dependencies are resolved and then just continue with the rest of the function as if it @@ -2524,6 +2540,7 @@ gomp_target_task_fn (void *data) } ttask->state = GOMP_TARGET_TASK_READY_TO_RUN; + assert (devicep->async_run_func); devicep->async_run_func (devicep->target_id, fn_addr, actual_arguments, ttask->args, (void *) ttask); return true; @@ -3040,7 +3057,7 @@ gomp_load_plugin_for_device (struct gomp_device_descr *device, if (device->capabilities & GOMP_OFFLOAD_CAP_OPENMP_400) { DLSYM (run); - DLSYM (async_run); + DLSYM_OPT (async_run, async_run); DLSYM_OPT (can_run, can_run); DLSYM (dev2dev); } diff --git a/libgomp/testsuite/libgomp.c/target-33.c b/libgomp/testsuite/libgomp.c/target-33.c index 15d2d7e38ab..1bed4b6bc67 100644 --- a/libgomp/testsuite/libgomp.c/target-33.c +++ b/libgomp/testsuite/libgomp.c/target-33.c @@ -1,6 +1,3 @@ -/* { dg-xfail-run-if "GOMP_OFFLOAD_async_run not implemented" { offload_target_nvptx } } - Cf. https://gcc.gnu.org/PR81688. */ - extern void abort (void); int diff --git a/libgomp/testsuite/libgomp.c/target-34.c b/libgomp/testsuite/libgomp.c/target-34.c index 5a3596424d8..66d9f54202b 100644 --- a/libgomp/testsuite/libgomp.c/target-34.c +++ b/libgomp/testsuite/libgomp.c/target-34.c @@ -1,6 +1,3 @@ -/* { dg-xfail-run-if "GOMP_OFFLOAD_async_run not implemented" { offload_target_nvptx } } - Cf. https://gcc.gnu.org/PR81688. */ - extern void abort (void); int -- 2.17.1