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: 761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp278758wro; Thu, 25 Aug 2022 07:55:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR7kMwZ/CfEw4gH7SrCjJX3Ie4XtIvR38oQcz0lsLq+G0kX+f6pjHO3ru6jDAVLreYq/tE2t X-Received: by 2002:a17:906:d7a9:b0:731:2189:4f58 with SMTP id pk9-20020a170906d7a900b0073121894f58mr2808504ejb.471.1661439355066; Thu, 25 Aug 2022 07:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661439355; cv=none; d=google.com; s=arc-20160816; b=pnLtReTnIez+yedbuyywk1bh4+KMAMElPaZYuJgzQaO7ORawVpp4MXTARGM0L0xaY8 6TLADvtrM1Ax3GKCHmhEEpbIm03CkUSlyp1AB+S4CZxlYZkiylRX07w2+CqJafYk/HE0 X1muKOFa8ldabVALsB5SX+4q4vd6ZrqiaaxOTE6BxF/i3w0SUeQ+f7yO9wgYm6x9StbP dbAuaicJ6CqMSgz2twnZ/c304Y0cKUrBEvylkdg6YspIW+i9y4zSFSiGA5bz/W+K71Y2 KfuQwt7evXznoJ4/EFKxQ1EiXdjkrk7/Vlfn2CUZPotVq0vwYcomJAQ/EiWXeW6o969U GF6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:from:to :content-language:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=NHNNjg9JJrbHzJmuVEIx3/5FVOrPDUfuoA4vdmuLhqI=; b=Gzob5w8wtEinFv3FmUKXbaS6rk2m8eGI8ggSkp3Yd2ONkXP6Ik+ygU8tDGuHIKebQE tSl/OhiLTgvgEHYArAg7DmPsFL/Hpd/axQVNc21EMCULGAN2YNZUuLRdoi+zjwu3F8dk zosJlrWEiwzqxlnaE5BUx9EAr6MdvA4Y2cW1KBy7tu8eouTetCYl69G0ob40at4hv2DY iSHRoxPUDDJrNunEK4F96mKwon6YjnWdvcN7APlQQtzUJna86dWLWu3BpclxUEeIqQxZ NO2klx6d5qchcJXqLFnOdkpg7boTQQD3Jhp1zxv4k4II7DdkT8Wf3EyAhR4dxuWQ0FS5 hAXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v2-20020aa7d642000000b0043be773a90dsi314497edr.45.2022.08.25.07.55.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 07:55:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61AE23851AA2 for ; Thu, 25 Aug 2022 14:55:32 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742145433412275436?= X-GMAIL-MSGID: =?utf-8?q?1742145433412275436?= 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); From patchwork Thu Aug 25 15:38:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp299199wro; Thu, 25 Aug 2022 08:39:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR5WFNvETxXmjaxmo/8mjPpYyJsNzp1YnfDzl5FMslRHIr/JXqHP/kI8pxte1xW/rj52H8mA X-Received: by 2002:a17:907:7da0:b0:734:9bc0:6203 with SMTP id oz32-20020a1709077da000b007349bc06203mr2856999ejc.637.1661441980462; Thu, 25 Aug 2022 08:39:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661441980; cv=none; d=google.com; s=arc-20160816; b=pRDpCVzsIezqNRXtb40jRh12TYs9hrVlkpYxyYdzFX/j2fXTVlZokR+XKr6RMFU6+D tEAyQdJyA0s6AJCNXhpthWF5vUEbYRm2kIrrxeKAhBmdpmxKnLvQZalgv6JOf57sapSM ZFYaJg5Eg2GAqN/JU5XP6xJHU/MyCR93QdYLOJ+SquovFP3g1tZ82GWc408GFUIzYLSv yJXpEM4kPrgXAFQAJuIBi4OlkDzcXjCDpe0Ks/Ef4hF/66cy6JJd6xa0lX7rJJ661F9K fw+mZW0mzOzVbukg/tRXKbQawnm2cgOriZp7WojNxgyofpos/pv4o3pwEj/Azq/OyqBG hK4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=V+5G34QW/6jD3/molT81juf7714emfYaAQI7RZ/1tP4=; b=v3uZ7xJMpuoUUjYoARkHv6qbhWRqwq5UhRxxN90AQ+dMfwkdBL3k/SqFWARpjmwEM4 IzAF1N2erdheUvpbou59+kVFC4HdyHPjvZtp9r1QzH8ZqpGvFLpjYCBepFNeIdUYyH/x RRTZ4rFe3rFVpcR8etuXKHNjqHKroAoXFua1bkcuxR3H7M9a+YpmQVogPbUGprPJHz1O twyH30Frg0L1zHXBdQZOhwSLS3RyKsbB+ShiuMGYXhc0JjhVqZCYjTQ+4RRBbPvAPtH+ n/QnKEMWSs+pDBP5jvP1NAdyN6DEqmoJIAAHC3rGl0rkFg4TkPHnzYXnxc/UcmGjdr7P wB+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hu9-20020a170907a08900b007316cc1113asi4301269ejc.910.2022.08.25.08.39.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 08:39:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3723038515C2 for ; Thu, 25 Aug 2022 15:39:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 5FCE13858C2F for ; Thu, 25 Aug 2022 15:39:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5FCE13858C2F 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="81811447" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 25 Aug 2022 07:39:05 -0800 IronPort-SDR: 2Q/PcFk1ylukeB16pGTGS9Vve5Ui2jhWnJF4Yjvi1T/Zt3Fe3EChmTmhXAcL4KE4GmcbpkntUX LiykHMtFpb4q4u4fjkmRwLSVZSJyn3wWghE9OT9cUTc++D7O5BmaJfJRsnniR0EDDeyntQhx5/ tN5nuaYDf/OnRjdtRNMVS6kqGxiBMfTSJwCk7kgEUe0bt16YWLF72yaIRrFK49JGzqQfuCGQ0h Tu71eJD1al42VZ/blKpwqtLYCt7Ci9/dZuPCW9Z7IaxbjCgkMx55SKIySM0AafSmFRjiTURah3 yaU= Message-ID: <9b367f13-dad2-5151-45a6-ae5dbc7950aa@codesourcery.com> Date: Thu, 25 Aug 2022 17:38:58 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: [Patch][2/3] GCN: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup Content-Language: en-US From: Tobias Burnus To: gcc-patches , Jakub Jelinek , Andrew Stubbs References: <40563a1c-49ef-a185-3c01-9f717cd48fc5@codesourcery.com> In-Reply-To: <40563a1c-49ef-a185-3c01-9f717cd48fc5@codesourcery.com> X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE, KAM_DMARC_STATUS, KAM_STOCKGEN, SPF_HELO_PASS, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742148186233635561?= X-GMAIL-MSGID: =?utf-8?q?1742148186233635561?= On 25.08.22 16:54, Tobias Burnus wrote: The attached patch prepare for reverse-offload device->host function-address lookup by requesting (if needed) the on-device address. This patch adds the actual implementation for GCN. A variant would be to only generate .offload_func_table inside mkoffload when OMP_REQUIRES_REVERSE_OFFLOAD has been requested. This is currently effectively a no op as with [1/3] patch, always NULL is passed and as GOMP_OFFLOAD_get_num_devices returns <= 0 as soon as 'omp requires reverse_offload' has been specified. 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 GCN: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup Add support to GCN for reverse lookup of function name to prepare for 'omp target device(ancestor:1)'. gcc/ChangeLog: * config/gcn/mkoffload.cc (process_asm): Create .offload_func_table, similar to pre-existing .offload_var_table. libgomp/ChangeLog: * plugin/plugin-gcn.c (GOMP_OFFLOAD_load_image): Read .offload_func_table to populate rev_fn_table when requested. gcc/config/gcn/mkoffload.cc | 11 ++++++++++- libgomp/plugin/plugin-gcn.c | 26 +++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 4206448703a..24d327355e3 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -537,63 +537,72 @@ process_asm (FILE *in, FILE *out, FILE *cfile) case IN_VARS: { char *varname; unsigned varsize; if (sscanf (buf, " .8byte %ms\n", &varname)) { fputs (buf, out); fgets (buf, sizeof (buf), in); if (!sscanf (buf, " .8byte %u\n", &varsize)) abort (); var_count++; } break; } case IN_FUNCS: { char *funcname; if (sscanf (buf, "\t.8byte\t%ms\n", &funcname)) { + fputs (buf, out); obstack_ptr_grow (&fns_os, funcname); fn_count++; continue; } break; } } char dummy; if (sscanf (buf, " .section .gnu.offload_vars%c", &dummy) > 0) { state = IN_VARS; /* Add a global symbol to allow plugin-gcn.c to locate the table at runtime. It can't use the "offload_var_table.N" emitted by the compiler because a) they're not global, and b) there's one for each input file combined into the binary. */ fputs (buf, out); fputs ("\t.global .offload_var_table\n" "\t.type .offload_var_table, @object\n" ".offload_var_table:\n", out); } else if (sscanf (buf, " .section .gnu.offload_funcs%c", &dummy) > 0) - state = IN_FUNCS; + { + state = IN_FUNCS; + /* Likewise for .gnu.offload_vars; used for reverse offload. */ + fputs (buf, out); + fputs ("\t.global .offload_func_table\n" + "\t.type .offload_func_table, @object\n" + ".offload_func_table:\n", + out); + } else if (sscanf (buf, " .amdgpu_metadata%c", &dummy) > 0) { state = IN_METADATA; regcount.kernel_name = NULL; regcount.sgpr_count = regcount.vgpr_count = -1; } else if (sscanf (buf, " .section %c", &dummy) > 0 || sscanf (buf, " .text%c", &dummy) > 0 || sscanf (buf, " .bss%c", &dummy) > 0 || sscanf (buf, " .data%c", &dummy) > 0 || sscanf (buf, " .ident %c", &dummy) > 0) state = IN_CODE; else if (sscanf (buf, " .end_amdgpu_metadata%c", &dummy) > 0) { state = IN_CODE; gcc_assert (regcount.kernel_name != NULL && regcount.sgpr_count >= 0 && regcount.vgpr_count >= 0); obstack_grow (®counts_os, ®count, sizeof (regcount)); diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c index 363e2950649..00603981866 100644 --- a/libgomp/plugin/plugin-gcn.c +++ b/libgomp/plugin/plugin-gcn.c @@ -3353,7 +3353,7 @@ GOMP_OFFLOAD_init_device (int n) int GOMP_OFFLOAD_load_image (int ord, unsigned version, const void *target_data, struct addr_pair **target_table, - uint64_t **rev_fn_table __attribute__((unused))) + uint64_t **rev_fn_table) { if (GOMP_VERSION_DEV (version) != GOMP_VERSION_GCN) { @@ -3520,6 +3520,30 @@ GOMP_OFFLOAD_load_image (int ord, unsigned version, const void *target_data, if (module->fini_array_func) kernel_count--; + if (rev_fn_table != NULL && kernel_count == 0) + *rev_fn_table = NULL; + else if (rev_fn_table != NULL) + { + hsa_status_t status; + hsa_executable_symbol_t var_symbol; + status = hsa_fns.hsa_executable_get_symbol_fn (agent->executable, NULL, + ".offload_func_table", + agent->id, 0, &var_symbol); + if (status != HSA_STATUS_SUCCESS) + hsa_fatal ("Could not find symbol for variable in the code object", + status); + uint64_t fn_table_addr; + status = hsa_fns.hsa_executable_symbol_get_info_fn + (var_symbol, HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_ADDRESS, + &fn_table_addr); + if (status != HSA_STATUS_SUCCESS) + hsa_fatal ("Could not extract a variable from its symbol", status); + *rev_fn_table = GOMP_PLUGIN_malloc (kernel_count * sizeof (uint64_t)); + GOMP_OFFLOAD_dev2host (agent->device_id, *rev_fn_table, + (void*) fn_table_addr, + kernel_count * sizeof (uint64_t)); + } + return kernel_count + var_count + other_count; }