]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[libgomp, nvptx] Handle CUDA_ONE_CALL_MAYBE_NULL
authorvries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Aug 2018 22:13:56 +0000 (22:13 +0000)
committervries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Aug 2018 22:13:56 +0000 (22:13 +0000)
This patch adds handling of functions that may not be present in the cuda
driver.

Such a function can be declared using CUDA_ONE_CALL_MAYBE_NULL in cuda-lib.def,
it can be called with the usual convenience macros, but before calling its
presence needs to be tested using new macro CUDA_CALL_EXISTS.

When using the dlopen interface (PLUGIN_NVPTX_DYNAMIC == 1), we allow
non-present functions by allowing dlsym to return NULL.  Otherwise
(PLUGIN_NVPTX_DYNAMIC == 0) we declare the non-present function to be weak.

Build and reg-tested libgomp on x86_64 with nvidia accelerator, with and without
--disable-cuda-driver, in combination with a trigger patch that adds a
non-existing function foo to cuda-lib.def:
...
CUDA_ONE_CALL_MAYBE_NULL (foo)
...
and declares it in plugin-nvptx.c:
...
CUresult foo (void);
...
and then uses it in nvptx_init after the init_cuda_lib call:
...
  if (CUDA_CALL_EXISTS (foo))
    CUDA_CALL (foo);
...

Also build and reg-tested on x86_64 with nvidia accelerator, with and without
--disable-cuda-driver, in combination with a trigger patch that replaces all
CUDA_ONE_CALLs in cuda-lib.def with CUDA_ONE_CALL_MAYBE_NULL, and guards two
CUDA_CALLs with CUDA_CALL_EXISTS, one for a regular fn, and one for a fn that is
a define in cuda/cuda.h.

2018-08-07  Tom de Vries  <tdevries@suse.de>

* plugin/plugin-nvptx.c (DO_PRAGMA): Define.
(struct cuda_lib_s): Add def/undef of CUDA_ONE_CALL_MAYBE_NULL.
(init_cuda_lib): Add new param to CUDA_ONE_CALL_1.  Add arg to
corresponding call in CUDA_ONE_CALL.  Add def/undef of
CUDA_ONE_CALL_MAYBE_NULL.
(CUDA_CALL_EXISTS): Define.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263346 138bc75d-0d04-0410-961f-82ee72b054a4

libgomp/ChangeLog
libgomp/plugin/plugin-nvptx.c

index d96ab1f35f8e633c62732e8cb8cab27bc94866f9..e3b92a707df87924207b817b3444b9bde57b9221 100644 (file)
@@ -1,3 +1,12 @@
+2018-08-07  Tom de Vries  <tdevries@suse.de>
+
+       * plugin/plugin-nvptx.c (DO_PRAGMA): Define.
+       (struct cuda_lib_s): Add def/undef of CUDA_ONE_CALL_MAYBE_NULL.
+       (init_cuda_lib): Add new param to CUDA_ONE_CALL_1.  Add arg to
+       corresponding call in CUDA_ONE_CALL.  Add def/undef of
+       CUDA_ONE_CALL_MAYBE_NULL.
+       (CUDA_CALL_EXISTS): Define.
+
 2018-08-07  Tom de Vries  <tdevries@suse.de>
 
        * plugin/plugin-nvptx.c (struct cuda_lib_s, init_cuda_lib): Put
index 2e72a6379eb91599a86eb104ede9143e91a81a2a..825470adce3e6f4370fcc3a110c6b2a8495e199b 100644 (file)
@@ -49,6 +49,8 @@
 #include <assert.h>
 #include <errno.h>
 
+#define DO_PRAGMA(x) _Pragma (#x)
+
 #if PLUGIN_NVPTX_DYNAMIC
 # include <dlfcn.h>
 
@@ -56,8 +58,11 @@ struct cuda_lib_s {
 
 # define CUDA_ONE_CALL(call)                   \
   __typeof (call) *call;
+# define CUDA_ONE_CALL_MAYBE_NULL(call)                \
+  CUDA_ONE_CALL (call)
 #include "cuda-lib.def"
 # undef CUDA_ONE_CALL
+# undef CUDA_ONE_CALL_MAYBE_NULL
 
 } cuda_lib;
 
@@ -78,20 +83,29 @@ init_cuda_lib (void)
   if (h == NULL)
     return false;
 
-# define CUDA_ONE_CALL(call) CUDA_ONE_CALL_1 (call)
-# define CUDA_ONE_CALL_1(call) \
+# define CUDA_ONE_CALL(call) CUDA_ONE_CALL_1 (call, false)
+# define CUDA_ONE_CALL_MAYBE_NULL(call) CUDA_ONE_CALL_1 (call, true)
+# define CUDA_ONE_CALL_1(call, allow_null)             \
   cuda_lib.call = dlsym (h, #call);    \
-  if (cuda_lib.call == NULL)           \
+  if (!allow_null && cuda_lib.call == NULL)            \
     return false;
 #include "cuda-lib.def"
 # undef CUDA_ONE_CALL
 # undef CUDA_ONE_CALL_1
+# undef CUDA_ONE_CALL_MAYBE_NULL
 
   cuda_lib_inited = true;
   return true;
 }
 # define CUDA_CALL_PREFIX cuda_lib.
 #else
+
+# define CUDA_ONE_CALL(call)
+# define CUDA_ONE_CALL_MAYBE_NULL(call) DO_PRAGMA (weak call)
+#include "cuda-lib.def"
+#undef CUDA_ONE_CALL_MAYBE_NULL
+#undef CUDA_ONE_CALL
+
 # define CUDA_CALL_PREFIX
 # define init_cuda_lib() true
 #endif
@@ -136,6 +150,9 @@ init_cuda_lib (void)
 #define CUDA_CALL_NOCHECK(FN, ...)             \
   CUDA_CALL_PREFIX FN (__VA_ARGS__)
 
+#define CUDA_CALL_EXISTS(FN)                   \
+  CUDA_CALL_PREFIX FN
+
 static const char *
 cuda_error (CUresult r)
 {