From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 36107 invoked by alias); 14 Dec 2018 14:17:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 36087 invoked by uid 89); 14 Dec 2018 14:17:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=sk:gomp_de 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; Fri, 14 Dec 2018 14:17:18 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-01.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1gXoHE-0001sC-6T from Thomas_Schwinge@mentor.com for gcc-patches@gcc.gnu.org; Fri, 14 Dec 2018 06:17:16 -0800 Received: from hertz.schwinge.homeip.net (137.202.0.90) by svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Fri, 14 Dec 2018 14:17:12 +0000 From: Thomas Schwinge To: Chung-Lin Tang CC: Subject: Re: [PATCH 2/6, OpenACC, libgomp] Async re-work, oacc-* parts In-Reply-To: <12319572-dd02-c946-f2b9-9d047be9c707@mentor.com> References: <12319572-dd02-c946-f2b9-9d047be9c707@mentor.com> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/25.2.2 (x86_64-pc-linux-gnu) Date: Fri, 14 Dec 2018 14:17:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2018-12/txt/msg01056.txt.bz2 Hi Chung-Lin! On Tue, 25 Sep 2018 21:10:47 +0800, Chung-Lin Tang wrote: > --- a/libgomp/oacc-async.c > +++ b/libgomp/oacc-async.c > +attribute_hidden struct goacc_asyncqueue * > +lookup_goacc_asyncqueue (struct goacc_thread *thr, bool create, int asyn= c) > +{ > + /* The special value acc_async_noval (-1) maps to the thread-specific > + default async stream. */ > + if (async =3D=3D acc_async_noval) > + async =3D thr->default_async; > + > + if (async =3D=3D acc_async_sync) > + return NULL; > + > + if (async < 0) > + gomp_fatal ("bad async %d", async); To make this "resolve" part more obvious, that is, the translation from the "async" argument to an "asyncqueue" array index: > + if (!create > + && (async >=3D dev->openacc.async.nasyncqueue > + || !dev->openacc.async.asyncqueue[async])) > + return NULL; > +[...] ..., I propose adding a "async2id" function for that, and then rename all "asyncqueue[async]" to "asyncqueue[id]". And, this also restores the current trunk behavior, so that "acc_async_noval" gets its own, separate "asyncqueue". commit e0d10cd744906c031af536bbf523ed6607370bf7 Author: Thomas Schwinge Date: Wed Dec 12 15:22:29 2018 +0100 into async re-work: libgomp/oacc-async.c:async2id --- libgomp/oacc-async.c | 58 +++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git libgomp/oacc-async.c libgomp/oacc-async.c index c9b134ac3380..b091ba2460ac 100644 --- libgomp/oacc-async.c +++ libgomp/oacc-async.c @@ -54,53 +54,73 @@ get_goacc_thread_device (void) return thr->dev; } =20 -attribute_hidden struct goacc_asyncqueue * -lookup_goacc_asyncqueue (struct goacc_thread *thr, bool create, int async) +/* Translate from an OpenACC async-argument to an internal asyncqueue ID, = or -1 + if no asyncqueue is to be used. */ + +static int +async2id (int async) { - /* The special value acc_async_noval (-1) maps to the thread-specific - default async stream. */ - if (async =3D=3D acc_async_noval) - async =3D 0; //TODO thr->default_async; + if (!async_valid_p (async)) + gomp_fatal ("invalid async-argument: %d", async); =20 if (async =3D=3D acc_async_sync) + return -1; + else if (async =3D=3D acc_async_noval) + return 0; + else if (async >=3D 0) + return 1 + async; + else + __builtin_unreachable (); +} + +/* Return the asyncqueue to be used for OpenACC async-argument ASYNC. This + might return NULL if no asyncqueue is to be used. Otherwise, if CREATE, + create the asyncqueue if it doesn't exist yet. */ + +attribute_hidden struct goacc_asyncqueue * +lookup_goacc_asyncqueue (struct goacc_thread *thr, bool create, int async) +{ + int id =3D async2id (async); + if (id < 0) return NULL; =20 - if (async < 0) - gomp_fatal ("bad async %d", async); - struct gomp_device_descr *dev =3D thr->dev; =20 if (!create - && (async >=3D dev->openacc.async.nasyncqueue - || !dev->openacc.async.asyncqueue[async])) + && (id >=3D dev->openacc.async.nasyncqueue + || !dev->openacc.async.asyncqueue[id])) return NULL; =20 gomp_mutex_lock (&dev->openacc.async.lock); - if (async >=3D dev->openacc.async.nasyncqueue) + if (id >=3D dev->openacc.async.nasyncqueue) { - int diff =3D async + 1 - dev->openacc.async.nasyncqueue; + int diff =3D id + 1 - dev->openacc.async.nasyncqueue; dev->openacc.async.asyncqueue =3D gomp_realloc (dev->openacc.async.asyncqueue, - sizeof (goacc_aq) * (async + 1)); + sizeof (goacc_aq) * (id + 1)); memset (dev->openacc.async.asyncqueue + dev->openacc.async.nasyncque= ue, 0, sizeof (goacc_aq) * diff); - dev->openacc.async.nasyncqueue =3D async + 1; + dev->openacc.async.nasyncqueue =3D id + 1; } =20 - if (!dev->openacc.async.asyncqueue[async]) + if (!dev->openacc.async.asyncqueue[id]) { - dev->openacc.async.asyncqueue[async] =3D dev->openacc.async.construc= t_func (); + dev->openacc.async.asyncqueue[id] =3D dev->openacc.async.construct_f= unc (); =20 /* Link new async queue into active list. */ goacc_aq_list n =3D gomp_malloc (sizeof (struct goacc_asyncqueue_lis= t)); - n->aq =3D dev->openacc.async.asyncqueue[async]; + n->aq =3D dev->openacc.async.asyncqueue[id]; n->next =3D dev->openacc.async.active; dev->openacc.async.active =3D n; } gomp_mutex_unlock (&dev->openacc.async.lock); - return dev->openacc.async.asyncqueue[async]; + return dev->openacc.async.asyncqueue[id]; } =20 +/* Return the asyncqueue to be used for OpenACC async-argument ASYNC. This + might return NULL if no asyncqueue is to be used. Otherwise, create the + asyncqueue if it doesn't exist yet. */ + attribute_hidden struct goacc_asyncqueue * get_goacc_asyncqueue (int async) { Gr=C3=BC=C3=9Fe Thomas