From: Nathan Sidwell <nathan_sidwell@mentor.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [gomp4] Remove superfluous code
Date: Mon, 03 Aug 2015 23:52:00 -0000 [thread overview]
Message-ID: <55BFFEC0.4050406@mentor.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 246 bytes --]
I've committed this to gomp4 branch. It tidies up the error message processing
and removes some code that shows a remarkable confusion about how shared
libraries work.
nathan
--
Nathan Sidwell - Director, Sourcery Services - Mentor Embedded
[-- Attachment #2: gomp4-plugin.patch --]
[-- Type: text/x-patch, Size: 3588 bytes --]
2015-08-03 Nathan Sidwell <nathan@codesourcery.com>
libgomp/
* plugin/plugin-nvptx.c: Don't include dlfcn.h.
(cuda_errlist): Constify.
(errmsg): Move into ...
(cuda_error): ... here. Make smaller.
(_XSTR, _STR): Delete.
(cuda_synames): Delete.
(verify_device_library): Delete.
(nvptx_init): Don't call it.
Index: libgomp/plugin/plugin-nvptx.c
===================================================================
--- libgomp/plugin/plugin-nvptx.c (revision 226533)
+++ libgomp/plugin/plugin-nvptx.c (working copy)
@@ -43,16 +43,15 @@
#include <stdint.h>
#include <string.h>
#include <stdio.h>
-#include <dlfcn.h>
#include <unistd.h>
#include <assert.h>
#define ARRAYSIZE(X) (sizeof (X) / sizeof ((X)[0]))
-static struct
+static const struct
{
CUresult r;
- char *m;
+ const char *m;
} cuda_errlist[]=
{
{ CUDA_ERROR_INVALID_VALUE, "invalid value" },
@@ -109,9 +108,7 @@ static struct
{ CUDA_ERROR_UNKNOWN, "unknown" }
};
-static char errmsg[128];
-
-static char *
+static const char *
cuda_error (CUresult r)
{
int i;
@@ -119,12 +116,14 @@ cuda_error (CUresult r)
for (i = 0; i < ARRAYSIZE (cuda_errlist); i++)
{
if (cuda_errlist[i].r == r)
- return &cuda_errlist[i].m[0];
+ return cuda_errlist[i].m;
}
- sprintf (&errmsg[0], "unknown result code: %5d", r);
+ static char errmsg[30];
+
+ snprintf (errmsg, sizeof (errmsg), "unknown error code: %d", r);
- return &errmsg[0];
+ return errmsg;
}
static unsigned int instantiated_devices = 0;
@@ -383,74 +382,6 @@ static struct ptx_event *ptx_events;
static struct ptx_device **ptx_devices;
-#define _XSTR(s) _STR(s)
-#define _STR(s) #s
-
-static struct _synames
-{
- char *n;
-} cuda_symnames[] =
-{
- { _XSTR (cuCtxCreate) },
- { _XSTR (cuCtxDestroy) },
- { _XSTR (cuCtxGetCurrent) },
- { _XSTR (cuCtxPushCurrent) },
- { _XSTR (cuCtxSynchronize) },
- { _XSTR (cuDeviceGet) },
- { _XSTR (cuDeviceGetAttribute) },
- { _XSTR (cuDeviceGetCount) },
- { _XSTR (cuEventCreate) },
- { _XSTR (cuEventDestroy) },
- { _XSTR (cuEventQuery) },
- { _XSTR (cuEventRecord) },
- { _XSTR (cuInit) },
- { _XSTR (cuLaunchKernel) },
- { _XSTR (cuLinkAddData) },
- { _XSTR (cuLinkComplete) },
- { _XSTR (cuLinkCreate) },
- { _XSTR (cuMemAlloc) },
- { _XSTR (cuMemAllocHost) },
- { _XSTR (cuMemcpy) },
- { _XSTR (cuMemcpyDtoH) },
- { _XSTR (cuMemcpyDtoHAsync) },
- { _XSTR (cuMemcpyHtoD) },
- { _XSTR (cuMemcpyHtoDAsync) },
- { _XSTR (cuMemFree) },
- { _XSTR (cuMemFreeHost) },
- { _XSTR (cuMemGetAddressRange) },
- { _XSTR (cuMemHostGetDevicePointer) },
- { _XSTR (cuMemHostRegister) },
- { _XSTR (cuMemHostUnregister) },
- { _XSTR (cuModuleGetFunction) },
- { _XSTR (cuModuleLoadData) },
- { _XSTR (cuStreamDestroy) },
- { _XSTR (cuStreamQuery) },
- { _XSTR (cuStreamSynchronize) },
- { _XSTR (cuStreamWaitEvent) }
-};
-
-static int
-verify_device_library (void)
-{
- int i;
- void *dh, *ds;
-
- dh = dlopen ("libcuda.so", RTLD_LAZY);
- if (!dh)
- return -1;
-
- for (i = 0; i < ARRAYSIZE (cuda_symnames); i++)
- {
- ds = dlsym (dh, cuda_symnames[i].n);
- if (!ds)
- return -1;
- }
-
- dlclose (dh);
-
- return 0;
-}
-
static inline struct nvptx_thread *
nvptx_thread (void)
{
@@ -631,16 +562,11 @@ static bool
nvptx_init (void)
{
CUresult r;
- int rc;
int ndevs;
if (instantiated_devices != 0)
return true;
- rc = verify_device_library ();
- if (rc < 0)
- return false;
-
r = cuInit (0);
if (r != CUDA_SUCCESS)
GOMP_PLUGIN_fatal ("cuInit error: %s", cuda_error (r));
next reply other threads:[~2015-08-03 23:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-03 23:52 Nathan Sidwell [this message]
2015-08-04 0:41 ` Nathan Sidwell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55BFFEC0.4050406@mentor.com \
--to=nathan_sidwell@mentor.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).