aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/config/nvptx/mkoffload.c28
-rw-r--r--libgomp/ChangeLog8
-rw-r--r--libgomp/plugin/plugin-nvptx.c46
4 files changed, 58 insertions, 29 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a7949ece..9506686 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2015-07-16 Nathan Sidwell <nathan@codesourcery.com>
+
+ * config/nvptx/mkoffload.c (process): Constify mapping variables.
+ Define target data struct and initialize it.
+
2015-07-16 Vladimir Makarov <vmakarov@redhat.com>
PR rtl-optimization/66626
diff --git a/gcc/config/nvptx/mkoffload.c b/gcc/config/nvptx/mkoffload.c
index 42cce3b..ca13e09 100644
--- a/gcc/config/nvptx/mkoffload.c
+++ b/gcc/config/nvptx/mkoffload.c
@@ -842,7 +842,6 @@ process (FILE *in, FILE *out)
{
const char *input = read_file (in);
Token *tok = tokenize (input);
- unsigned int nvars = 0, nfuncs = 0;
do
tok = parse_file (tok);
@@ -853,19 +852,30 @@ process (FILE *in, FILE *out)
write_stmts (out, rev_stmts (vars));
write_stmts (out, rev_stmts (fns));
fprintf (out, ";\n\n");
- fprintf (out, "static const char *var_mappings[] = {\n");
- for (id_map *id = var_ids; id; id = id->next, nvars++)
+
+ fprintf (out, "static const char *const var_mappings[] = {\n");
+ for (id_map *id = var_ids; id; id = id->next)
fprintf (out, "\t\"%s\"%s\n", id->ptx_name, id->next ? "," : "");
fprintf (out, "};\n\n");
- fprintf (out, "static const char *func_mappings[] = {\n");
- for (id_map *id = func_ids; id; id = id->next, nfuncs++)
+ fprintf (out, "static const char *const func_mappings[] = {\n");
+ for (id_map *id = func_ids; id; id = id->next)
fprintf (out, "\t\"%s\"%s\n", id->ptx_name, id->next ? "," : "");
fprintf (out, "};\n\n");
- fprintf (out, "static const void *target_data[] = {\n");
- fprintf (out, " ptx_code, (void*) %u, var_mappings, (void*) %u, "
- "func_mappings\n", nvars, nfuncs);
- fprintf (out, "};\n\n");
+ fprintf (out,
+ "static struct nvptx_tdata {\n"
+ " const char *ptx_src;\n"
+ " const char *const *var_names;\n"
+ " __SIZE_TYPE__ var_num;\n"
+ " const char *const *fn_names;\n"
+ " __SIZE_TYPE__ fn_num;\n"
+ "} target_data = {\n"
+ " ptx_code,\n"
+ " var_mappings,"
+ " sizeof (var_mappings) / sizeof (var_mappings[0]),\n"
+ " func_mappings,"
+ " sizeof (func_mappings) / sizeof (func_mappings[0])\n"
+ "};\n\n");
fprintf (out, "#ifdef __cplusplus\n"
"extern \"C\" {\n"
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 161c5bc..6b15776 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,11 @@
+2015-07-16 Nathan Sidwell <nathan@codesourcery.com>
+
+ * plugin/plugin-nvptx.c (link_ptx): Constify string argument.
+ Workaround driver library const error.
+ (struct nvptx_tdata, nvptx_tdata_t): New.
+ (GOMP_OFFLOAD_load_image): Use struct for target_data's real
+ type.
+
2015-07-15 Maxim Blumenthal <maxim.blumenthal@intel.com>
* testsuite/libgomp.fortran/examples-4/simd-8.f90: (main): Change type
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index b67d301..cfb143b 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -804,7 +804,7 @@ nvptx_get_num_devices (void)
static void
-link_ptx (CUmodule *module, char *ptx_code)
+link_ptx (CUmodule *module, const char *ptx_code)
{
CUjit_option opts[7];
void *optvals[7];
@@ -874,7 +874,8 @@ link_ptx (CUmodule *module, char *ptx_code)
cuda_error (r));
}
- r = cuLinkAddData (linkstate, CU_JIT_INPUT_PTX, ptx_code,
+ /* cuLinkAddData's 'data' argument erroneously omits the const qualifier. */
+ r = cuLinkAddData (linkstate, CU_JIT_INPUT_PTX, (char *)ptx_code,
strlen (ptx_code) + 1, 0, 0, 0, 0);
if (r != CUDA_SUCCESS)
{
@@ -1618,23 +1619,36 @@ GOMP_OFFLOAD_fini_device (int n)
pthread_mutex_unlock (&ptx_dev_lock);
}
+/* Data emitted by mkoffload. */
+
+typedef struct nvptx_tdata
+{
+ const char *ptx_src;
+
+ const char *const *var_names;
+ size_t var_num;
+
+ const char *const *fn_names;
+ size_t fn_num;
+} nvptx_tdata_t;
+
int
GOMP_OFFLOAD_load_image (int ord, void *target_data,
struct addr_pair **target_table)
{
CUmodule module;
- char **fn_names, **var_names;
+ const char *const *fn_names, *const *var_names;
unsigned int fn_entries, var_entries, i, j;
CUresult r;
struct targ_fn_descriptor *targ_fns;
- void **img_header = (void **) target_data;
+ nvptx_tdata_t const *img_header = (nvptx_tdata_t const *) target_data;
struct ptx_image_data *new_image;
GOMP_OFFLOAD_init_device (ord);
nvptx_attach_host_thread_to_device (ord);
- link_ptx (&module, img_header[0]);
+ link_ptx (&module, img_header->ptx_src);
pthread_mutex_lock (&ptx_image_lock);
new_image = GOMP_PLUGIN_malloc (sizeof (struct ptx_image_data));
@@ -1644,22 +1658,14 @@ GOMP_OFFLOAD_load_image (int ord, void *target_data,
ptx_images = new_image;
pthread_mutex_unlock (&ptx_image_lock);
- /* The mkoffload utility emits a table of pointers/integers at the start of
- each offload image:
-
- img_header[0] -> ptx code
- img_header[1] -> number of variables
- img_header[2] -> array of variable names (pointers to strings)
- img_header[3] -> number of kernels
- img_header[4] -> array of kernel names (pointers to strings)
-
- The array of kernel names and the functions addresses form a
- one-to-one correspondence. */
+ /* The mkoffload utility emits a struct of pointers/integers at the
+ start of each offload image. The array of kernel names and the
+ functions addresses form a one-to-one correspondence. */
- var_entries = (uintptr_t) img_header[1];
- var_names = (char **) img_header[2];
- fn_entries = (uintptr_t) img_header[3];
- fn_names = (char **) img_header[4];
+ var_entries = img_header->var_num;
+ var_names = img_header->var_names;
+ fn_entries = img_header->fn_num;
+ fn_names = img_header->fn_names;
*target_table = GOMP_PLUGIN_malloc (sizeof (struct addr_pair)
* (fn_entries + var_entries));