From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 42ED3384D148; Mon, 12 Sep 2022 07:22:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42ED3384D148 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662967337; bh=9zTmBLDNEHwKx8sXLxe5EGBhdGEEJhAlpbPyTcz9hXM=; h=From:To:Subject:Date:From; b=mJnK8hVC8kz4V3GZ5GHdF51B2yEjJSEuYo5l6sjsON5nWchITnYNbB5zHq62z5cmB V7Vebyxbw0YCn7Oj2Vc48T3tk4wJrtklUeZOaVkMGiGvswRdM/zlA7p0fBUGMhFWs/ dsq3L45UOpCiNnNiea5U4IXJ6jBqJLkVL3AYOUss= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] GCN: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup X-Act-Checkin: gcc X-Git-Author: Tobias Burnus X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: fd867dd6cc71abaed4afe3bb029b3abc7177421e X-Git-Newrev: b2e6dfc8090a957155a9242e720d50dd0d90ba03 Message-Id: <20220912072217.42ED3384D148@sourceware.org> Date: Mon, 12 Sep 2022 07:22:17 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b2e6dfc8090a957155a9242e720d50dd0d90ba03 commit b2e6dfc8090a957155a9242e720d50dd0d90ba03 Author: Tobias Burnus Date: Mon Sep 12 09:14:50 2022 +0200 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. (cherry picked from commit dfd75bf7e9017e92b59be650fca97d2b4b331a82) Diff: --- gcc/ChangeLog.omp | 8 ++++++++ gcc/config/gcn/mkoffload.cc | 11 ++++++++++- libgomp/ChangeLog.omp | 8 ++++++++ libgomp/plugin/plugin-gcn.c | 26 +++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 0ad8f78103c..a0d14efef57 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-09-12 Tobias Burnus + + Backport from mainline: + 2022-09-09 Tobias Burnus + + * config/gcn/mkoffload.cc (process_asm): Create .offload_func_table, + similar to pre-existing .offload_var_table. + 2022-09-09 Tobias Burnus Backport from mainline: diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index 2f9ee883022..2c7a1feafd2 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -564,6 +564,7 @@ process_asm (FILE *in, FILE *out, FILE *cfile) char *funcname; if (sscanf (buf, "\t.8byte\t%ms\n", &funcname)) { + fputs (buf, out); obstack_ptr_grow (&fns_os, funcname); fn_count++; continue; @@ -587,7 +588,15 @@ process_asm (FILE *in, FILE *out, FILE *cfile) 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; diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index 943e872aecf..93e288a2e0c 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,11 @@ +2022-09-12 Tobias Burnus + + Backport from mainline: + 2022-09-09 Tobias Burnus + + * plugin/plugin-gcn.c (GOMP_OFFLOAD_load_image): Read + .offload_func_table to populate rev_fn_table when requested. + 2022-09-12 Tobias Burnus Backport from mainline: diff --git a/libgomp/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c index a051c2a9b2b..dd493f63912 100644 --- a/libgomp/plugin/plugin-gcn.c +++ b/libgomp/plugin/plugin-gcn.c @@ -3355,7 +3355,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) { @@ -3527,6 +3527,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; }