public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] OpenMP: Ensure that offloaded variables are public
@ 2021-11-16 11:49 Andrew Stubbs
  2021-11-30 16:24 ` Jakub Jelinek
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Stubbs @ 2021-11-16 11:49 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 750 bytes --]

Hi,

This patch is needed for AMD GCN offloading when we use the assembler 
from LLVM 13+.

The GCN runtime (libgomp+ROCm) requires that the location of all 
variables in the offloaded variables table are discoverable at runtime 
(using the "hsa_executable_symbol_get_info" API), and this only works 
when the symbols are exported from the binary. Previously we solved this 
by having mkoffload insert ".global" directives into the assembler text, 
but newer LLVM assemblers emit an error if we do this when then variable 
was previously declared ".local" (which happens when a variable is 
zero-initialized and placed in the BSS).

Since we can no longer easily fix them up after the fact, this patch 
fixes them up during OMP lowering.

OK?

Andrew

[-- Attachment #2: 211116-openmp-global-vars.patch --]
[-- Type: text/plain, Size: 1551 bytes --]

OpenMP: Ensure that offloaded variables are public

The AMD GCN runtime loader requires that variables in the offload table are
exported (public) so that it can locate the load address and do the mapping.

gcc/ChangeLog:

	* config/gcn/mkoffload.c (process_asm): Don't add .global directives.
	* omp-offload.c (pass_omp_target_link::execute): Make offload_vars
	public.

diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index b2e71ea5aa00..5b130cc6de71 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -573,10 +573,6 @@ process_asm (FILE *in, FILE *out, FILE *cfile)
 		  abort ();
 		obstack_int_grow (&varsizes_os, varsize);
 		var_count++;
-
-		/* The HSA Runtime cannot locate the symbol if it is not
-		   exported from the kernel.  */
-		fprintf (out, "\t.global %s\n", varname);
 	      }
 	    break;
 	  }
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index 833f7ddea58f..c6fb87a5dee2 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -2799,6 +2799,18 @@ pass_omp_target_link::execute (function *fun)
 	}
     }
 
+  /* Variables in the offload table may need to be public for the runtime
+     loader to be able to locate them.  (This is true for at least amdgcn.)  */
+  if (offload_vars)
+    for (auto it = offload_vars->begin (); it != offload_vars->end (); it++)
+    if (!TREE_PUBLIC (*it))
+      {
+	TREE_PUBLIC (*it) = 1;
+
+	if (dump_enabled_p () && dump_flags & TDF_DETAILS)
+	  dump_printf (MSG_NOTE, "Make offload var public: %T\n", *it);
+      }
+
   return 0;
 }
 

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-12-22 13:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 11:49 [PATCH] OpenMP: Ensure that offloaded variables are public Andrew Stubbs
2021-11-30 16:24 ` Jakub Jelinek
2021-11-30 16:54   ` Jakub Jelinek
2021-12-02 12:36     ` Andrew Stubbs
2021-12-02 12:58       ` Jakub Jelinek
2021-12-02 16:05         ` Andrew Stubbs
2021-12-02 16:31           ` Andrew Stubbs
2021-12-02 16:43             ` Jakub Jelinek
2021-12-09 11:41               ` Andrew Stubbs
2021-12-09 12:34                 ` Jakub Jelinek
2021-12-22 13:01                 ` [OG11][PATCH] " Andrew Stubbs

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).