From patchwork Tue Jul 14 20:15:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 495229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 8927A1402BD for ; Wed, 15 Jul 2015 06:15:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=cW2y8A6C; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; q=dns; s=default; b=Y7HHCvc3CejHvHdx w0kvkpqZOz42DTvaZ0C31qlR7BiF7dQ8oD5N/SNRtBpHVPSk183BYxuBilTM+vwv hF4HWSCRwPpe/LdXqS9dEkzXTplCYb5DUMX1q2JtPKEigi6oGHThJ81i5chDEONC W04XBORGfJ/ZtORYr22F5fxe55k= 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 :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; s=default; bh=4KXDMzmuC7um1xZL44/Zfr P+UTY=; b=cW2y8A6CmtAQ2IIn0Swl3lEo10D6IU0vbBz/C76A7rwVuVk+GFGicK 8gVBSOsLf4vGcHNmIj9RjUxXUefN2pzSCnMFXFO7OAjHFB9RAyOTCCcDMi+Eo1xo 5JKcIBUd0/FcwLn4NpWLA6B2LZHB2BM2ph1yRolzfmFf0TDGoNfes= Received: (qmail 62333 invoked by alias); 14 Jul 2015 20:15:47 -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 62315 invoked by uid 89); 14 Jul 2015 20:15:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Jul 2015 20:15:44 +0000 Received: from svr-orw-fem-03.mgc.mentorg.com ([147.34.97.39]) by relay1.mentorg.com with esmtp id 1ZF6c8-0005O9-R8 from Thomas_Schwinge@mentor.com ; Tue, 14 Jul 2015 13:15:40 -0700 Received: from tftp-cs (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.3.224.2; Tue, 14 Jul 2015 13:15:40 -0700 Received: by tftp-cs (Postfix, from userid 49978) id DB6C1C23CF; Tue, 14 Jul 2015 13:15:39 -0700 (PDT) From: Thomas Schwinge To: Richard Biener CC: Subject: PR65742: OpenACC acc_on_device fixes In-Reply-To: <20150507193226.6aee40c5@octopus> References: <20150331235328.GC623@msticlxl57.ims.intel.com> <20150401052147.GG19273@tucnak.redhat.com> <20150401131405.GD623@msticlxl57.ims.intel.com> <20150401132025.GM19273@tucnak.redhat.com> <20150406124557.GA5541@msticlxl57.ims.intel.com> <20150407152645.GJ19273@tucnak.redhat.com> <20150408153142.128b97b9@octopus> <20150408145856.GA19410@msticlxl57.ims.intel.com> <20150414151502.5ca882a4@octopus> <87pp76zpep.fsf@schwinge.name> <20150417131619.GP1725@tucnak.redhat.com> <20150507193226.6aee40c5@octopus> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/24.4.1 (i586-pc-linux-gnu) Date: Tue, 14 Jul 2015 22:15:30 +0200 Message-ID: <87zj2yxzq5.fsf@kepler.schwinge.homeip.net> MIME-Version: 1.0 Hi! Per your request in , »can you please fix the gcc 5 branch«, I'm planning to apply the following to gcc-5-branch tomorrow (but wanted to give you a chance to veto, given that your backport request pre-dates the branch freeze by a week): commit b73b9881a781f8e5572ce6c6a38f51696fc09b83 Author: Thomas Schwinge Date: Tue Jul 14 15:27:49 2015 +0200 OpenACC acc_on_device fixes Backport trunk r223801: PR libgomp/65742 gcc/ * builtins.c (expand_builtin_acc_on_device): Don't use open-coded sequence for !ACCEL_COMPILER. libgomp/ * oacc-init.c (plugin/plugin-host.h): Include. (acc_on_device): Check whether we're in an offloaded region for host_nonshm plugin. Don't use __builtin_acc_on_device. * plugin/plugin-host.c (GOMP_OFFLOAD_openacc_parallel): Set nonshm_exec flag in thread-local data. (GOMP_OFFLOAD_openacc_create_thread_data): Allocate thread-local data for host_nonshm plugin. (GOMP_OFFLOAD_openacc_destroy_thread_data): Free thread-local data for host_nonshm plugin. * plugin/plugin-host.h: New. Mark parameters with ATTRIBUTE_UNUSED Backport trunk r223805: * builtins.c (expand_builtin_acc_on_device): Mark parameters with ATTRIBUTE_UNUSED. [PR libgomp/65742, PR middle-end/66332] XFAIL acc_on_device compile-time evaluation The OpenACC 2.0a specification mandates differently, but we currently do get a library call in the host code. Backport trunk r224028: PR libgomp/65742 PR middle-end/66332 gcc/testsuite/ * c-c++-common/goacc/acc_on_device-2.c: XFAIL for C, too. --- gcc/builtins.c | 12 +++---- gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c | 10 +++++- libgomp/oacc-init.c | 14 ++++++-- libgomp/plugin/plugin-host.c | 21 +++++++++-- libgomp/plugin/plugin-host.h | 37 ++++++++++++++++++++ 8 files changed, 127 insertions(+), 12 deletions(-) Grüße, Thomas diff --git gcc/builtins.c gcc/builtins.c index 9263777..bcbc11d 100644 --- gcc/builtins.c +++ gcc/builtins.c @@ -5915,8 +5915,10 @@ expand_stack_save (void) acceleration device (ACCEL_COMPILER conditional). */ static rtx -expand_builtin_acc_on_device (tree exp, rtx target) +expand_builtin_acc_on_device (tree exp ATTRIBUTE_UNUSED, + rtx target ATTRIBUTE_UNUSED) { +#ifdef ACCEL_COMPILER if (!validate_arglist (exp, INTEGER_TYPE, VOID_TYPE)) return NULL_RTX; @@ -5925,13 +5927,8 @@ expand_builtin_acc_on_device (tree exp, rtx target) /* Return (arg == v1 || arg == v2) ? 1 : 0. */ machine_mode v_mode = TYPE_MODE (TREE_TYPE (arg)); rtx v = expand_normal (arg), v1, v2; -#ifdef ACCEL_COMPILER v1 = GEN_INT (GOMP_DEVICE_NOT_HOST); v2 = GEN_INT (ACCEL_COMPILER_acc_device); -#else - v1 = GEN_INT (GOMP_DEVICE_NONE); - v2 = GEN_INT (GOMP_DEVICE_HOST); -#endif machine_mode target_mode = TYPE_MODE (integer_type_node); if (!target || !register_operand (target, target_mode)) target = gen_reg_rtx (target_mode); @@ -5945,6 +5942,9 @@ expand_builtin_acc_on_device (tree exp, rtx target) emit_label (done_label); return target; +#else + return NULL; +#endif } diff --git gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c index 2f4ee2b..7fe4e4e 100644 --- gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c +++ gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c @@ -20,10 +20,18 @@ f (void) } /* With -fopenacc, we're expecting the builtin to be expanded, so no calls. + TODO: in C++, even under extern "C", the use of enum for acc_device_t perturbs expansion as a builtin, which expects an int parameter. It's fine when changing acc_device_t to plain int, but that's not what we're doing in . - { dg-final { scan-rtl-dump-times "\\\(call \[^\\n\]* acc_on_device" 0 "expand" { xfail c++ } } } */ + + TODO: given that we can't expand acc_on_device in + gcc/builtins.c:expand_builtin_acc_on_device for in the !ACCEL_COMPILER case + (because at that point we don't know whether we're acc_device_host or + acc_device_host_nonshm), we'll (erroneously) get a library call in the host + code. + + { dg-final { scan-rtl-dump-times "\\\(call \[^\\n\]* acc_on_device" 0 "expand" { xfail { c || c++ } } } } */ /* { dg-final { cleanup-rtl-dump "expand" } } */ diff --git libgomp/oacc-init.c libgomp/oacc-init.c index dc40fb6..a7c2e0d 100644 --- libgomp/oacc-init.c +++ libgomp/oacc-init.c @@ -29,6 +29,7 @@ #include "libgomp.h" #include "oacc-int.h" #include "openacc.h" +#include "plugin/plugin-host.h" #include #include #include @@ -548,11 +549,18 @@ ialias (acc_set_device_num) int acc_on_device (acc_device_t dev) { - if (acc_get_device_type () == acc_device_host_nonshm) + struct goacc_thread *thr = goacc_thread (); + + /* We only want to appear to be the "host_nonshm" plugin from "offloaded" + code -- i.e. within a parallel region. Test a flag set by the + openacc_parallel hook of the host_nonshm plugin to determine that. */ + if (acc_get_device_type () == acc_device_host_nonshm + && thr && thr->target_tls + && ((struct nonshm_thread *)thr->target_tls)->nonshm_exec) return dev == acc_device_host_nonshm || dev == acc_device_not_host; - /* Just rely on the compiler builtin. */ - return __builtin_acc_on_device (dev); + /* For OpenACC, libgomp is only built for the host, so this is sufficient. */ + return dev == acc_device_host || dev == acc_device_none; } ialias (acc_on_device) diff --git libgomp/plugin/plugin-host.c libgomp/plugin/plugin-host.c index 1faf5bc..3cb4dab 100644 --- libgomp/plugin/plugin-host.c +++ libgomp/plugin/plugin-host.c @@ -44,6 +44,7 @@ #include #include #include +#include #ifdef HOST_NONSHM_PLUGIN #define STATIC @@ -55,6 +56,10 @@ #define SELF "host: " #endif +#ifdef HOST_NONSHM_PLUGIN +#include "plugin-host.h" +#endif + STATIC const char * GOMP_OFFLOAD_get_name (void) { @@ -174,7 +179,10 @@ GOMP_OFFLOAD_openacc_parallel (void (*fn) (void *), void *targ_mem_desc __attribute__ ((unused))) { #ifdef HOST_NONSHM_PLUGIN + struct nonshm_thread *thd = GOMP_PLUGIN_acc_thread (); + thd->nonshm_exec = true; fn (devaddrs); + thd->nonshm_exec = false; #else fn (hostaddrs); #endif @@ -232,11 +240,20 @@ STATIC void * GOMP_OFFLOAD_openacc_create_thread_data (int ord __attribute__ ((unused))) { +#ifdef HOST_NONSHM_PLUGIN + struct nonshm_thread *thd + = GOMP_PLUGIN_malloc (sizeof (struct nonshm_thread)); + thd->nonshm_exec = false; + return thd; +#else return NULL; +#endif } STATIC void -GOMP_OFFLOAD_openacc_destroy_thread_data (void *tls_data - __attribute__ ((unused))) +GOMP_OFFLOAD_openacc_destroy_thread_data (void *tls_data) { +#ifdef HOST_NONSHM_PLUGIN + free (tls_data); +#endif } diff --git libgomp/plugin/plugin-host.h libgomp/plugin/plugin-host.h new file mode 100644 index 0000000..96955d1 --- /dev/null +++ libgomp/plugin/plugin-host.h @@ -0,0 +1,37 @@ +/* OpenACC Runtime Library: acc_device_host, acc_device_host_nonshm. + + Copyright (C) 2015 Free Software Foundation, Inc. + + Contributed by Mentor Embedded. + + This file is part of the GNU Offloading and Multi Processing Library + (libgomp). + + Libgomp is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + . */ + +#ifndef PLUGIN_HOST_H +#define PLUGIN_HOST_H + +struct nonshm_thread +{ + bool nonshm_exec; +}; + +#endif