This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gomp4 02/14] nvptx: emit pointers to OpenMP target region entry points
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Jakub Jelinek <jakub at redhat dot com>, Dmitry Melnik <dm at ispras dot ru>
- Date: Tue, 20 Oct 2015 21:34:24 +0300
- Subject: [gomp4 02/14] nvptx: emit pointers to OpenMP target region entry points
- Authentication-results: sourceware.org; auth=none
- References: <1445366076-16082-1-git-send-email-amonakov at ispras dot ru>
Note: this patch will have to be more complex if we go with 'approach 2'
described in a later patch, 07/14 "launch target functions via gomp_nvptx_main".
For OpenMP offloading, libgomp invokes 'gomp_nvptx_main' as the accelerator
kernel, passing it a pointer to outlined target region function. That
function needs to be a device function (.func rather than .kernel), unless we
want to bump the GPU requirement from sm_30 to sm_35. To retrieve the device
function pointer from the host side, we need to emit a global-visibility
pointer to that function in PTX. The naming scheme for deriving the pointer
name based on function name is an ABI item between the backend and libgomp
plugin.
* config/nvptx/nvptx.c: (write_libgomp_anchor): New. Use it...
(nvptx_declare_function_name): ...here to emit pointers for libgomp.
---
gcc/config/nvptx/nvptx.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index df7b61f..a619e4c 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -657,6 +657,26 @@ nvptx_init_axis_predicate (FILE *file, int regno, const char *name)
fprintf (file, "\t}\n");
}
+/* For function DECL outlined for an OpenMP 'target' region, emit a global
+ pointer: void *__ptr_NAME = NAME; to be used in libgomp nvptx plugin. */
+
+static void
+write_libgomp_anchor (std::stringstream &s, const char *name, const_tree decl)
+{
+ if (!lookup_attribute ("omp target entrypoint", DECL_ATTRIBUTES (decl)))
+ return;
+
+ /* OpenMP target regions are entered via gomp_nvptx_main. */
+ static bool gomp_nvptx_main_declared;
+ if (!gomp_nvptx_main_declared)
+ {
+ gomp_nvptx_main_declared = true;
+ s << "// BEGIN GLOBAL FUNCTION DECL: gomp_nvptx_main\n";
+ }
+ s << ".visible .global " << nvptx_ptx_type_from_mode (Pmode, false);
+ s << " __ptr_" << name << " = " << name << ";\n";
+}
+
/* Implement ASM_DECLARE_FUNCTION_NAME. Writes the start of a ptx
function, including local var decls and copies from the arguments to
local regs. */
@@ -671,6 +691,8 @@ nvptx_declare_function_name (FILE *file, const char *name, const_tree decl)
std::stringstream s;
write_function_decl_and_comment (s, name, decl);
+ if (flag_openmp)
+ write_libgomp_anchor (s, name, decl);
s << "// BEGIN";
if (TREE_PUBLIC (decl))
s << " GLOBAL";