From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E5C15383D5E6 for ; Thu, 15 Dec 2022 17:49:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5C15383D5E6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671126575; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=tYn+64f799ey5xI27Nm7u+Izmrsl2shqXHNgZcqD7EA=; b=FJKGbfHSXIu7FUT/GDTDVsbdsyFdY2v1qOkYYeBA3X+UNvdEaLjP8ysKLzIvgnt8VQxYRx G5wNzqh+nYeL5wGJgJip1lPnXSBmbjmC3KYWudcxiPKw5Chefe9l8NqHmx9pUwQd6g/h9k r3y4/fE0P3N3p37SiXt7IXD3AIgjZRE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-50-Jw4AW5_4MTeJDOFVpVmkkw-1; Thu, 15 Dec 2022 12:49:33 -0500 X-MC-Unique: Jw4AW5_4MTeJDOFVpVmkkw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9679785CBE1; Thu, 15 Dec 2022 17:49:33 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 55B8E1121314; Thu, 15 Dec 2022 17:49:33 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2BFHnSAk3330316 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 15 Dec 2022 18:49:28 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BFHnRFE3330315; Thu, 15 Dec 2022 18:49:27 +0100 Date: Thu, 15 Dec 2022 18:49:26 +0100 From: Jakub Jelinek To: Thomas Schwinge Cc: Tobias Burnus , gcc-patches@gcc.gnu.org Subject: Re: [Patch] libgomp: Handle OpenMP's reverse offloads Message-ID: Reply-To: Jakub Jelinek References: <0567b7c6-fede-72b8-63d1-1fc10dca36a0@codesourcery.com> <87ilicfu55.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 In-Reply-To: <87ilicfu55.fsf@euler.schwinge.homeip.net> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Dec 15, 2022 at 06:34:30PM +0100, Thomas Schwinge wrote: > --- a/libgomp/libgomp-plugin.c > +++ b/libgomp/libgomp-plugin.c > @@ -82,9 +82,9 @@ GOMP_PLUGIN_fatal (const char *msg, ...) > void > GOMP_PLUGIN_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr, > uint64_t sizes_ptr, uint64_t kinds_ptr, int dev_num, > - void (*dev_to_host_cpy) (void *, const void *, size_t, > + bool (*dev_to_host_cpy) (void *, const void *, size_t, > void *), > - void (*host_to_dev_cpy) (void *, const void *, size_t, > + bool (*host_to_dev_cpy) (void *, const void *, size_t, > void *), void *token) > { > gomp_target_rev (fn_ptr, mapnum, devaddrs_ptr, sizes_ptr, kinds_ptr, dev_num, > diff --git a/libgomp/libgomp-plugin.h b/libgomp/libgomp-plugin.h > index ac3878289506..fb533164bf9b 100644 > --- a/libgomp/libgomp-plugin.h > +++ b/libgomp/libgomp-plugin.h > @@ -122,9 +122,9 @@ extern void GOMP_PLUGIN_fatal (const char *, ...) > > extern void GOMP_PLUGIN_target_rev (uint64_t, uint64_t, uint64_t, uint64_t, > uint64_t, int, > - void (*) (void *, const void *, size_t, > + bool (*) (void *, const void *, size_t, > void *), > - void (*) (void *, const void *, size_t, > + bool (*) (void *, const void *, size_t, > void *), void *); > > /* Prototypes for functions implemented by libgomp plugins. */ > --- a/libgomp/libgomp.h > +++ b/libgomp/libgomp.h > @@ -1130,8 +1130,8 @@ extern int gomp_get_num_devices (void); > extern bool gomp_target_task_fn (void *); > extern void gomp_target_rev (uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, > int, > - void (*) (void *, const void *, size_t, void *), > - void (*) (void *, const void *, size_t, void *), > + bool (*) (void *, const void *, size_t, void *), > + bool (*) (void *, const void *, size_t, void *), > void *); > > /* Splay tree definitions. */ I think returning bool from those is fine. > --- a/libgomp/plugin/plugin-nvptx.c > +++ b/libgomp/plugin/plugin-nvptx.c > @@ -1,3 +1,5 @@ > +#pragma GCC optimize "O0" But the pragmas are not. > --- a/libgomp/target.c > +++ b/libgomp/target.c > @@ -1,3 +1,5 @@ > +#pragma GCC optimize "O0" Neither here. > @@ -3340,12 +3342,21 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr, > kinds = (unsigned short *) gomp_malloc (mapnum * sizeof (unsigned short)); > if (dev_to_host_cpy) > { > - dev_to_host_cpy (devaddrs, (const void *) (uintptr_t) devaddrs_ptr, > - mapnum * sizeof (uint64_t), token); > - dev_to_host_cpy (sizes, (const void *) (uintptr_t) sizes_ptr, > - mapnum * sizeof (uint64_t), token); > - dev_to_host_cpy (kinds, (const void *) (uintptr_t) kinds_ptr, > - mapnum * sizeof (unsigned short), token); > + bool ok = true; > + ok = ok && dev_to_host_cpy (devaddrs, > + (const void *) (uintptr_t) devaddrs_ptr, > + mapnum * sizeof (uint64_t), token); > + ok = ok && dev_to_host_cpy (sizes, > + (const void *) (uintptr_t) sizes_ptr, > + mapnum * sizeof (uint64_t), token); > + ok = ok && dev_to_host_cpy (kinds, > + (const void *) (uintptr_t) kinds_ptr, > + mapnum * sizeof (unsigned short), token); Why not just if (!dev_to_host_cpy (...) || !dev_to_host_cpy (...) || !dev_to_host_cpy (...)) ? > + if (!ok) > + { > + /*TODO gomp_mutex_unlock (&devicep->lock); */ Why the comment? That makes no sense, devicep->lock isn't locked here. > else if (dev_to_host_cpy) > - dev_to_host_cpy (tgt + tgt_size, (void *) (uintptr_t) devaddrs[i], > - (size_t) sizes[i], token); > + { > + if (!dev_to_host_cpy (tgt + tgt_size, > + (void *) (uintptr_t) devaddrs[i], > + (size_t) sizes[i], token)) > + { > + /*TODO gomp_mutex_unlock (&devicep->lock); */ Neither here. > @@ -3662,9 +3692,15 @@ gomp_target_rev (uint64_t fn_ptr, uint64_t mapnum, uint64_t devaddrs_ptr, > case GOMP_MAP_FROM: > case GOMP_MAP_TOFROM: > if (copy && host_to_dev_cpy) > - host_to_dev_cpy ((void *) (uintptr_t) cdata[i].devaddr, > - (void *) (uintptr_t) devaddrs[i], > - sizes[i], token); > + { > + if (!host_to_dev_cpy ((void *) (uintptr_t) cdata[i].devaddr, > + (void *) (uintptr_t) devaddrs[i], > + sizes[i], token)) > + { > + /*TODO gomp_mutex_unlock (&devicep->lock); */ And neither here. > + exit (EXIT_FAILURE); > + } > + } Jakub