public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-2565] GCN: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup
@ 2022-09-09 15:46 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2022-09-09 15:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dfd75bf7e9017e92b59be650fca97d2b4b331a82

commit r13-2565-gdfd75bf7e9017e92b59be650fca97d2b4b331a82
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Fri Sep 9 17:43:12 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.

Diff:
---
 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
@@ -553,6 +553,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;
@@ -577,7 +578,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/plugin/plugin-gcn.c b/libgomp/plugin/plugin-gcn.c
index 6c77f896f88..04b122f2a09 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)
     {
@@ -3525,6 +3525,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;
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-09-09 15:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 15:46 [gcc r13-2565] GCN: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).