[PATCH] OpenMP: Ensure that offloaded variables are public
Andrew Stubbs
ams@codesourcery.com
Tue Nov 16 11:49:18 GMT 2021
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
-------------- next part --------------
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;
}
More information about the Gcc-patches
mailing list