Re: [PATCH, openacc, PR85411] Move GOMP_OPENACC_DIM parsing out of nvptx plugin

2018-04-16 Thread Jakub Jelinek
On Mon, Apr 16, 2018 at 11:41:35AM +0200, Tom de Vries wrote:
> Hi,
> 
> this patch moves the parsing of the GOMP_OPENACC_DIM environment variable
> from the nvptx target plugin to the libgomp library.
> 
> The variable is not part of the OpenACC standard, but it is specific for the
> gcc implementation of OpenACC, so it makes sense to share the part handling
> the parsing, rather than having each target plugin duplicate it.
> 
> Build on x86_64 with nvptx accelerator and reg-tested libgomp.
> 
> OK for stage1?

Ok.

> [openacc] Move GOMP_OPENACC_DIM parsing out of nvptx plugin
> 
> 2018-04-15  Tom de Vries  
> 
>   PR libgomp/85411
>   * plugin/plugin-nvptx.c (notify_var): Remove no longer used function.
>   (nvptx_exec): Move parsing of
>   GOMP_OPENACC_DIM ...
>   * env.c (parse_gomp_openacc_dim): ... here.  New function.
>   (initialize_env): Call parse_gomp_openacc_dim.
>   (goacc_default_dims): Define.
>   * libgomp.h (goacc_default_dims): Declare.
>   * oacc-plugin.c (GOMP_PLUGIN_acc_default_dim): New function.
>   * oacc-plugin.h (GOMP_PLUGIN_acc_default_dim): Declare.
>   * libgomp.map: New version "GOMP_PLUGIN_1.2". Add
>   GOMP_PLUGIN_acc_default_dim.
>   * testsuite/libgomp.oacc-c-c++-common/loop-default-runtime.c: New test.
>   * testsuite/libgomp.oacc-c-c++-common/loop-default.h: New test.

Jakub


[PATCH, openacc, PR85411] Move GOMP_OPENACC_DIM parsing out of nvptx plugin

2018-04-16 Thread Tom de Vries

Hi,

this patch moves the parsing of the GOMP_OPENACC_DIM environment 
variable from the nvptx target plugin to the libgomp library.


The variable is not part of the OpenACC standard, but it is specific for 
the gcc implementation of OpenACC, so it makes sense to share the part 
handling the parsing, rather than having each target plugin duplicate it.


Build on x86_64 with nvptx accelerator and reg-tested libgomp.

OK for stage1?

Thanks,
- Tom
[openacc] Move GOMP_OPENACC_DIM parsing out of nvptx plugin

2018-04-15  Tom de Vries  

	PR libgomp/85411
	* plugin/plugin-nvptx.c (notify_var): Remove no longer used function.
	(nvptx_exec): Move parsing of
	GOMP_OPENACC_DIM ...
	* env.c (parse_gomp_openacc_dim): ... here.  New function.
	(initialize_env): Call parse_gomp_openacc_dim.
	(goacc_default_dims): Define.
	* libgomp.h (goacc_default_dims): Declare.
	* oacc-plugin.c (GOMP_PLUGIN_acc_default_dim): New function.
	* oacc-plugin.h (GOMP_PLUGIN_acc_default_dim): Declare.
	* libgomp.map: New version "GOMP_PLUGIN_1.2". Add
	GOMP_PLUGIN_acc_default_dim.
	* testsuite/libgomp.oacc-c-c++-common/loop-default-runtime.c: New test.
	* testsuite/libgomp.oacc-c-c++-common/loop-default.h: New test.

---
 libgomp/env.c  |  32 +
 libgomp/libgomp.h  |   2 +
 libgomp/libgomp.map|   5 +
 libgomp/oacc-plugin.c  |  11 ++
 libgomp/oacc-plugin.h  |   1 +
 libgomp/plugin/plugin-nvptx.c  |  38 +-
 .../loop-default-runtime.c |  16 +++
 .../libgomp.oacc-c-c++-common/loop-default.h   | 144 +
 8 files changed, 213 insertions(+), 36 deletions(-)

diff --git a/libgomp/env.c b/libgomp/env.c
index 871a3e4..18c90bb 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -90,6 +90,7 @@ int gomp_debug_var;
 unsigned int gomp_num_teams_var;
 char *goacc_device_type;
 int goacc_device_num;
+int goacc_default_dims[GOMP_DIM_MAX];
 
 #ifndef LIBGOMP_OFFLOADED_ONLY
 
@@ -1066,6 +1067,36 @@ parse_acc_device_type (void)
 }
 
 static void
+parse_gomp_openacc_dim (void)
+{
+  /* The syntax is the same as for the -fopenacc-dim compilation option.  */
+  const char *var_name = "GOMP_OPENACC_DIM";
+  const char *env_var = getenv (var_name);
+  if (!env_var)
+return;
+
+  const char *pos = env_var;
+  int i;
+  for (i = 0; *pos && i != GOMP_DIM_MAX; i++)
+{
+  if (i && *pos++ != ':')
+	break;
+
+  if (*pos == ':')
+	continue;
+
+  const char *eptr;
+  errno = 0;
+  long val = strtol (pos, (char **), 10);
+  if (errno || val < 0 || (unsigned)val != val)
+	break;
+
+  goacc_default_dims[i] = (int)val;
+  pos = eptr;
+}
+}
+
+static void
 handle_omp_display_env (unsigned long stacksize, int wait_policy)
 {
   const char *env;
@@ -1336,6 +1367,7 @@ initialize_env (void)
 goacc_device_num = 0;
 
   parse_acc_device_type ();
+  parse_gomp_openacc_dim ();
 
   goacc_runtime_initialize ();
 }
diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index d659cd2..10ea894 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -44,6 +44,7 @@
 #include "config.h"
 #include "gstdint.h"
 #include "libgomp-plugin.h"
+#include "gomp-constants.h"
 
 #ifdef HAVE_PTHREAD_H
 #include 
@@ -367,6 +368,7 @@ extern unsigned int gomp_num_teams_var;
 extern int gomp_debug_var;
 extern int goacc_device_num;
 extern char *goacc_device_type;
+extern int goacc_default_dims[GOMP_DIM_MAX];
 
 enum gomp_task_kind
 {
diff --git a/libgomp/libgomp.map b/libgomp/libgomp.map
index f9044ae..8752348 100644
--- a/libgomp/libgomp.map
+++ b/libgomp/libgomp.map
@@ -420,3 +420,8 @@ GOMP_PLUGIN_1.1 {
   global:
 	GOMP_PLUGIN_target_task_completion;
 } GOMP_PLUGIN_1.0;
+
+GOMP_PLUGIN_1.2 {
+  global:
+	GOMP_PLUGIN_acc_default_dim;
+} GOMP_PLUGIN_1.1;
diff --git a/libgomp/oacc-plugin.c b/libgomp/oacc-plugin.c
index 475f357..c04db90 100644
--- a/libgomp/oacc-plugin.c
+++ b/libgomp/oacc-plugin.c
@@ -49,3 +49,14 @@ GOMP_PLUGIN_acc_thread (void)
   struct goacc_thread *thr = goacc_thread ();
   return thr ? thr->target_tls : NULL;
 }
+
+int
+GOMP_PLUGIN_acc_default_dim (unsigned int i)
+{
+  if (i >= GOMP_DIM_MAX)
+{
+  gomp_fatal ("invalid dimension argument: %d", i);
+  return -1;
+}
+  return goacc_default_dims[i];
+}
diff --git a/libgomp/oacc-plugin.h b/libgomp/oacc-plugin.h
index ae152aa..0a183bb 100644
--- a/libgomp/oacc-plugin.h
+++ b/libgomp/oacc-plugin.h
@@ -29,5 +29,6 @@
 
 extern void GOMP_PLUGIN_async_unmap_vars (void *, int);
 extern void *GOMP_PLUGIN_acc_thread (void);
+extern int GOMP_PLUGIN_acc_default_dim (unsigned int);
 
 #endif
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index 9ae6095..365b45e 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -867,15 +867,6 @@ nvptx_get_num_devices (void)
   return n;
 }
 
-static void