From patchwork Thu Aug 25 14:54:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1670300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MD5cF1xm3z1yhN for ; Fri, 26 Aug 2022 00:55:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 23E283851164 for ; Thu, 25 Aug 2022 14:55:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 2C89B385275A for ; Thu, 25 Aug 2022 14:55:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2C89B385275A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,263,1654588800"; d="diff'?scan'208,217";a="81946237" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 25 Aug 2022 06:55:05 -0800 IronPort-SDR: esjQv+j40v9joCbyJHmhcrfT2iKuGoHN/fCUVuAksrHA6xTFPI1QV6YNA8AcO4T3mBhpZdFPEd keaL5bXD/v3e3uVTuDRlR8haZWuYNfdbr02KjLvlE98+yxIi0UkeUcwcTteMyfHAroJF5375eW Q0UyGZPWyvZCOjIvkDbKZu8gVn30NWn++AXcpbTE8yg1uApAP2XM7XSe/yPpV9srn/lVdyOWrg oWGP/qeNTc/DSkSfeLqx2epRV00ojSv51xT8Pw5SlbNo0QdrN5S23BUZcDXzD0oJXYTj+BeQCe ZJo= Message-ID: <40563a1c-49ef-a185-3c01-9f717cd48fc5@codesourcery.com> Date: Thu, 25 Aug 2022 16:54:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Content-Language: en-US To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch][1/3] libgomp: Prepare for reverse offload fn lookup X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Technically, this patch is stand alone, but conceptually it based on the submitted but not reviewed patch: "[Patch] OpenMP: Support reverse offload (middle end part)" https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598662.html With that patch, for reverse offloads ('omp target device(ancestor:1)'), calls like the following are added: GOMP_target_ext (-2 /* initial device */, omp_fn.1 where 'omp_fn.1' on nonhost devices a stub function just required for looking up the host function pointer via the offload_funcs table. The attached patch prepare for reverse-offload device->host function-address lookup by requesting (if needed) the on-device address. OK for mainline? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 libgomp: Prepare for reverse offload fn lookup Prepare for reverse-offloading function-pointer lookup by passing a rev_fn_table argument to GOMP_OFFLOAD_load_image. The argument will be NULL, unless GOMP_REQUIRES_REVERSE_OFFLOAD is requested and devices not supported it, are filtered out. (Up to and including this commit, no non-host device claims such support and the caller currently always passes NULL.) libgomp/ChangeLog: * libgomp-plugin.h (GOMP_OFFLOAD_load_image): Add 'uint64_t **rev_fn_table' argument. * oacc-host.c (host_load_image): Likewise. * plugin/plugin-gcn.c (GOMP_OFFLOAD_load_image): Likewise; currently unused. * plugin/plugin-nvptx.c (GOMP_OFFLOAD_load_image): Likewise. * target.c (gomp_load_image_to_device): Update call but pass NULL for now. liboffloadmic/ChangeLog: * plugin/libgomp-plugin-intelmic.cpp (GOMP_OFFLOAD_load_image): Add (unused) uint64_t **rev_fn_table argument. libgomp/libgomp-plugin.h | 2 +- libgomp/oacc-host.c | 3 ++- libgomp/plugin/plugin-gcn.c | 7 +++++-- libgomp/plugin/plugin-nvptx.c | 7 +++++-- libgomp/target.c | 2 +- liboffloadmic/plugin/libgomp-plugin-intelmic.cpp | 3 ++- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/libgomp/libgomp-plugin.h b/libgomp/libgomp-plugin.h index ab3ed638475..57309303e66 100644 --- a/libgomp/libgomp-plugin.h +++ b/libgomp/libgomp-plugin.h @@ -130,7 +130,7 @@ extern bool GOMP_OFFLOAD_init_device (int); extern bool GOMP_OFFLOAD_fini_device (int); extern unsigned GOMP_OFFLOAD_version (void); extern int GOMP_OFFLOAD_load_image (int, unsigned, const void *, - struct addr_pair **); + struct addr_pair **, uint64_t **); extern bool GOMP_OFFLOAD_unload_image (int, unsigned, const void *); extern void *GOMP_OFFLOAD_alloc (int, size_t); extern bool GOMP_OFFLOAD_free (int, void *); diff --git a/libgomp/oacc-host.c b/libgomp/oacc-host.c index eb11b9cf16a..4e3971ae1a9 100644 --- a/libgomp/oacc-host.c +++ b/libgomp/oacc-host.c @@ -81,7 +81,8 @@ static int host_load_image (int n __attribute__ ((unused)), unsigned v __attribute__ ((unused)), const void *t __attribute__ ((unused)), - struct addr_pair **r __attribute__ ((unused))) + struct addr_pair **r __attribute__ ((unused)), + uint64_t **f __attribute__ ((unused))) { return 0; } diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c index ea327bf2ca0..363e2950649 100644 --- a/libgomp/plugin/plugin-gcn.c +++ b/libgomp/plugin/plugin-gcn.c @@ -3346,11 +3346,14 @@ GOMP_OFFLOAD_init_device (int n) /* Load GCN object-code module described by struct gcn_image_desc in TARGET_DATA and return references to kernel descriptors in TARGET_TABLE. - If there are any constructors then run them. */ + If there are any constructors then run them. If not NULL, REV_FN_TABLE will + contain the on-device addresses of the functions for reverse offload. To be + freed by the caller. */ int GOMP_OFFLOAD_load_image (int ord, unsigned version, const void *target_data, - struct addr_pair **target_table) + struct addr_pair **target_table, + uint64_t **rev_fn_table __attribute__((unused))) { if (GOMP_VERSION_DEV (version) != GOMP_VERSION_GCN) { diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index bc63e274cdf..d130665ed19 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -1266,11 +1266,14 @@ nvptx_set_clocktick (CUmodule module, struct ptx_device *dev) } /* Load the (partial) program described by TARGET_DATA to device - number ORD. Allocate and return TARGET_TABLE. */ + number ORD. Allocate and return TARGET_TABLE. If not NULL, REV_FN_TABLE + will contain the on-device addresses of the functions for reverse offload. + To be freed by the caller. */ int GOMP_OFFLOAD_load_image (int ord, unsigned version, const void *target_data, - struct addr_pair **target_table) + struct addr_pair **target_table, + uint64_t **rev_fn_table __attribute__((unused))) { CUmodule module; const char *const *var_names; diff --git a/libgomp/target.c b/libgomp/target.c index 135db1d88ab..da907a2fb48 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -2137,7 +2137,7 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version, num_target_entries = devicep->load_image_func (devicep->target_id, version, - target_data, &target_table); + target_data, &target_table, NULL); if (num_target_entries != num_funcs + num_vars /* Others (device_num) are included as trailing entries in pair list. */ diff --git a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp index 33bae0650b4..7be27f0459d 100644 --- a/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp +++ b/liboffloadmic/plugin/libgomp-plugin-intelmic.cpp @@ -349,7 +349,8 @@ GOMP_OFFLOAD_version (void) extern "C" int GOMP_OFFLOAD_load_image (int device, const unsigned version, - const void *target_image, addr_pair **result) + const void *target_image, addr_pair **result, + uint64_t ** /* rev_fn_table */) { TRACE ("(device = %d, target_image = %p)", device, target_image);