diff mbox

[6/4] Handle GOMP_OPENACC_NVPTX_JIT=-arch=<n> in libgomp nvptx plugin

Message ID b8b93537-70b4-e065-fd0f-bdfb2d999603@mentor.com
State New
Headers show

Commit Message

Tom de Vries June 30, 2017, 4:06 p.m. UTC
[ was: Re: [PATCH, 0/4] Handle 
GOMP_OPENACC_NVPTX_{DISASM,SAVE_TEMPS,JIT} in libgomp nvptx plugin ]
On 06/26/2017 01:24 PM, Tom de Vries wrote:
> Hi,
> 
> I've written a patch series to facilitate debugging libgomp openacc 
> testcase failures on the nvptx accelerator.
> 
> 
> When running an openacc test-case on an nvptx accelerator, the following 
> happens:
> - the plugin obtains the ptx assembly for the acceleration kernels
> - it calls the cuda jit to compile and link the ptx into a module
> - it loads the module
> - it starts an acceleration kernel
> 

This patch adds handling of GOMP_OPENACC_NVPTX_JIT=-arch=<n> in libgomp 
nvptx plugin.

F.i. GOMP_OPENACC_NVPTX_JIT=-arch=60 for sm_60.

Thanks,
- Tom
diff mbox

Patch

libgomp/ChangeLog:

2017-06-30  Tom de Vries  <tom@codesourcery.com>

	* plugin/plugin-nvptx.c (parse_number):
	(process_GOMP_OPENACC_NVPTX_JIT):
	(link_ptx):


Handle GOMP_OPENACC_NVPTX_JIT=-arch=<n> in libgomp nvptx plugin

---
 libgomp/plugin/plugin-nvptx.c | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index 365c787..4cca0c7 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -983,9 +983,24 @@  debug_linkout (void *linkout, size_t linkoutsize)
     }
 }
 
+static bool
+parse_number (const char *c, unsigned long* resp, char **end)
+{
+  unsigned long res;
+
+  errno = 0;
+  res = strtoul (c, end, 10);
+  if (errno)
+    return false;
+
+  *resp = res;
+  return true;
+}
+
 static void
 process_GOMP_OPENACC_NVPTX_JIT (intptr_t *gomp_openacc_nvptx_o,
-				intptr_t *gomp_openacc_nvptx_ori)
+				intptr_t *gomp_openacc_nvptx_ori,
+				uintptr_t *gomp_openacc_nvptx_target)
 {
   const char *var_name = "GOMP_OPENACC_NVPTX_JIT";
   const char *env_var = getenv (var_name);
@@ -1019,6 +1034,19 @@  process_GOMP_OPENACC_NVPTX_JIT (intptr_t *gomp_openacc_nvptx_o,
 	  continue;
 	}
 
+      if (c[0] == '-' && c[1] == 'a' && c[2] == 'r' && c[3] == 'c'
+	  && c[4] == 'h' && c[5] == '=')
+	{
+	  const char *end;
+	  unsigned long val;
+	  if (parse_number (&c[6], &val, (char**)&end))
+	    {
+	      *gomp_openacc_nvptx_target = val;
+	      c = end;
+	      continue;
+	    }
+	}
+
       GOMP_PLUGIN_error ("Error parsing %s", var_name);
       break;
     }
@@ -1183,9 +1211,11 @@  link_ptx (CUmodule *module, const struct targ_ptx_obj *ptx_objs,
 
   static intptr_t gomp_openacc_nvptx_o = -1;
   static intptr_t gomp_openacc_nvptx_ori = -1;
+  static uintptr_t gomp_openacc_nvptx_target = 0;
   if (gomp_openacc_nvptx_o == -1)
     process_GOMP_OPENACC_NVPTX_JIT (&gomp_openacc_nvptx_o,
-				    &gomp_openacc_nvptx_ori);
+				    &gomp_openacc_nvptx_ori,
+				    &gomp_openacc_nvptx_target);
 
   opts[6] = CU_JIT_OPTIMIZATION_LEVEL;
   optvals[6] = (void *) gomp_openacc_nvptx_o;
@@ -1197,6 +1227,12 @@  link_ptx (CUmodule *module, const struct targ_ptx_obj *ptx_objs,
       optvals[nopts] = (void *) gomp_openacc_nvptx_ori;
       nopts++;
     }
+  if (gomp_openacc_nvptx_target)
+    {
+      opts[nopts] = CU_JIT_TARGET;
+      optvals[nopts] = (void *) gomp_openacc_nvptx_target;
+      nopts++;
+    }
 
   CUDA_CALL (cuLinkCreate, nopts, opts, optvals, &linkstate);