]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
GCN: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup
authorTobias Burnus <tobias@codesourcery.com>
Mon, 12 Sep 2022 07:14:50 +0000 (09:14 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Mon, 12 Sep 2022 07:14:50 +0000 (09:14 +0200)
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)

gcc/ChangeLog.omp
gcc/config/gcn/mkoffload.cc
libgomp/ChangeLog.omp
libgomp/plugin/plugin-gcn.c

index 0ad8f78103c5b95bb2cf470cbc1a6b278b0b0113..a0d14efef57b6662f8486d146d7bd3156efc6c8b 100644 (file)
@@ -1,3 +1,11 @@
+2022-09-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-09-09  Tobias Burnus  <tobias@codesourcery.com>
+
+       * config/gcn/mkoffload.cc (process_asm): Create .offload_func_table,
+       similar to pre-existing .offload_var_table.
+
 2022-09-09  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index 2f9ee883022a68989060b23b78f20590fd6f7550..2c7a1feafd275a9c40cb4e35d9376908d81187a3 100644 (file)
@@ -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;
index 943e872aecfa904c34113ce517583547fa295b6f..93e288a2e0cd3c42722de650e48bc74f549a791a 100644 (file)
@@ -1,3 +1,11 @@
+2022-09-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from mainline:
+       2022-09-09  Tobias Burnus  <tobias@codesourcery.com>
+
+       * plugin/plugin-gcn.c (GOMP_OFFLOAD_load_image): Read
+       .offload_func_table to populate rev_fn_table when requested.
+
 2022-09-12  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from mainline:
index a051c2a9b2b645b8bd94ff90f55411f38af774a1..dd493f63912542e2d97d0168d6af8b22ea7664c9 100644 (file)
@@ -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;
 }