From patchwork Mon Dec 22 18:33:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 423479 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 792DA140082 for ; Tue, 23 Dec 2014 05:33:47 +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 :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; q=dns; s=default; b=sj/w7u6xmufvif1L XfNkK1vLNWak0HM34c7fgN8A4DxjRan/T3ANT6r+QMa5sXF99PkXyOXe2sVND81M zidk6LthdNjPky4QP1LjzY/BXAll8+L8jpYrhuC+tHc7No237kxcQYcni/gFpY0w M/b8+Qxqg3lr/IR5UlFOk4ivg9U= 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=z+eK5PVvTTXymSoovuFWmr 5kWxI=; b=CV1P3XA7eIrHHqWPJXz84P9yhtT1h8hLBqn3EeGih2gyNEHXbeCzwO PZwvp4Y1aNnHf4ZDlcQRoGkh8himyejtgODoG9UeKtKEZuoYvAP/3xPI+P2Nw3wG jO8QTproLXlguWwKF5mkp9kiTzaLPrAzMasQIEHG3WGCpIQC/P7PU= Received: (qmail 12808 invoked by alias); 22 Dec 2014 18:33:40 -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 12788 invoked by uid 89); 22 Dec 2014 18:33:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, 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; Mon, 22 Dec 2014 18:33:38 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1Y37nS-00067U-JM from Thomas_Schwinge@mentor.com ; Mon, 22 Dec 2014 10:33:35 -0800 Received: from feldtkeller.schwinge.homeip.net (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.181.6; Mon, 22 Dec 2014 18:33:32 +0000 From: Thomas Schwinge To: , Jakub Jelinek CC: Julian Brown Subject: Re: [PATCH 1/5] OpenACC 2.0 support for libgomp - OpenACC runtime, NVidia PTX/CUDA plugin (repost) In-Reply-To: <20141111135323.29e0f27b@octopus> References: <20140923191931.2177e60f@octopus> <20141111135323.29e0f27b@octopus> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/24.4.1 (i586-pc-linux-gnu) Date: Mon, 22 Dec 2014 19:33:28 +0100 Message-ID: <87egrry1on.fsf@kepler.schwinge.homeip.net> MIME-Version: 1.0 Hi! On Tue, 11 Nov 2014 13:53:23 +0000, Julian Brown wrote: > On Tue, 23 Sep 2014 19:19:31 +0100 > Julian Brown wrote: > > > This patch contains the bulk of the OpenACC 2.0 runtime support, > > building around, or on top of, the OpenMP 4.0 support (as previously > > posted or already extant upstream) where we could. [...] > > Here is a new version of the OpenACC support patch for libgomp, [...] > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -920,6 +1111,43 @@ gomp_target_init (void) > } > while (next); > > + /* Prefer a device with TARGET_CAP_OPENMP_400 for ICV default-device-var. */ > + if (num_devices > 1) > + { > + int d = gomp_icv (false)->default_device_var; > + > + if (!(devices[d].capabilities & TARGET_CAP_OPENMP_400)) > + { > + for (i = 0; i < num_devices; i++) > + { > + if (devices[i].capabilities & TARGET_CAP_OPENMP_400) > + { > + struct gomp_device_descr device_tmp = devices[d]; > + devices[d] = devices[i]; > + devices[d].id = d + 1; > + devices[i] = device_tmp; > + devices[i].id = i + 1; > + > + break; > + } > + } > + } > + } A thinko of mine; committed to gomp-4_0-branch in r219029: commit 806b4f5eed613a43bf52082816469268df0ed9a5 Author: tschwinge Date: Mon Dec 22 18:31:42 2014 +0000 libgomp: For OpenMP offloading, only publicize GOMP_OFFLOAD_CAP_OPENMP_400 devices. libgomp/ * target.c (num_devices_openmp): New variable. (gomp_get_num_devices): Use it. (gomp_target_init): Initialize it, and sort the devices array appropriately. With Intel MIC offloading (emulation), this fixes: FAIL: libgomp.c/examples-4/e.57.2.c execution test FAIL: libgomp.fortran/examples-4/e.57.2.f90 -O0 execution test FAIL: libgomp.fortran/examples-4/e.57.2.f90 -O1 execution test FAIL: libgomp.fortran/examples-4/e.57.2.f90 -O2 execution test FAIL: libgomp.fortran/examples-4/e.57.2.f90 -O3 -fomit-frame-pointer execution test FAIL: libgomp.fortran/examples-4/e.57.2.f90 -O3 -fomit-frame-pointer -funroll-loops execution test FAIL: libgomp.fortran/examples-4/e.57.2.f90 -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions execution test FAIL: libgomp.fortran/examples-4/e.57.2.f90 -O3 -g execution test FAIL: libgomp.fortran/examples-4/e.57.2.f90 -Os execution test git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@219029 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgomp/ChangeLog.gomp | 5 +++++ libgomp/target.c | 52 ++++++++++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 23 deletions(-) Grüße, Thomas diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp index eabf737..b9bd024 100644 --- libgomp/ChangeLog.gomp +++ libgomp/ChangeLog.gomp @@ -1,5 +1,10 @@ 2014-12-22 Thomas Schwinge + * target.c (num_devices_openmp): New variable. + (gomp_get_num_devices): Use it. + (gomp_target_init): Initialize it, and sort the devices array + appropriately. + * libgomp.h (struct gomp_device_descr): Remove id member. Update all users. diff --git libgomp/target.c libgomp/target.c index 226b95b..bf6edd2 100644 --- libgomp/target.c +++ libgomp/target.c @@ -67,6 +67,9 @@ static struct gomp_device_descr *devices; /* Total number of available devices. */ static int num_devices; +/* Number of GOMP_OFFLOAD_CAP_OPENMP_400 devices. */ +static int num_devices_openmp; + /* The comparison function. */ attribute_hidden int @@ -94,7 +97,7 @@ attribute_hidden int gomp_get_num_devices (void) { gomp_init_targets_once (); - return num_devices; + return num_devices_openmp; } static struct gomp_device_descr * @@ -1048,9 +1051,11 @@ gomp_register_image_for_device (struct gomp_device_descr *device, } /* This function initializes the runtime needed for offloading. - It parses the list of offload targets and tries to load the plugins for these - targets. Result of the function is properly initialized variable NUM_DEVICES - and array DEVICES, containing descriptors for corresponding devices. */ + It parses the list of offload targets and tries to load the plugins for + these targets. On return, the variables NUM_DEVICES and NUM_DEVICES_OPENMP + will be set, and the array DEVICES initialized, containing descriptors for + corresponding devices, first the GOMP_OFFLOAD_CAP_OPENMP_400 ones, follows + by the others. */ static void gomp_target_init (void) @@ -1089,6 +1094,8 @@ gomp_target_init (void) new_num_devices = current_device.get_num_devices_func (); if (new_num_devices >= 1) { + /* Augment DEVICES and NUM_DEVICES. */ + devices = realloc (devices, (num_devices + new_num_devices) * sizeof (struct gomp_device_descr)); if (!devices) @@ -1121,27 +1128,26 @@ gomp_target_init (void) } while (next); - /* Prefer a device with GOMP_OFFLOAD_CAP_OPENMP_400 for ICV - default-device-var. */ - if (num_devices > 1) + /* In DEVICES, sort the GOMP_OFFLOAD_CAP_OPENMP_400 ones first, and set + NUM_DEVICES_OPENMP. */ + struct gomp_device_descr *devices_s + = malloc (num_devices * sizeof (struct gomp_device_descr)); + if (!devices_s) { - int d = gomp_icv (false)->default_device_var; - - if (!(devices[d].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400)) - { - for (i = 0; i < num_devices; i++) - { - if (devices[i].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400) - { - struct gomp_device_descr device_tmp = devices[d]; - devices[d] = devices[i]; - devices[i] = device_tmp; - - break; - } - } - } + num_devices = 0; + free (devices); + devices = NULL; } + num_devices_openmp = 0; + for (i = 0; i < num_devices; i++) + if (devices[i].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400) + devices_s[num_devices_openmp++] = devices[i]; + int num_devices_after_openmp = num_devices_openmp; + for (i = 0; i < num_devices; i++) + if (!(devices[i].capabilities & GOMP_OFFLOAD_CAP_OPENMP_400)) + devices_s[num_devices_after_openmp++] = devices[i]; + free (devices); + devices = devices_s; for (i = 0; i < num_devices; i++) {