From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127131 invoked by alias); 3 Aug 2015 23:52:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 127115 invoked by uid 89); 3 Aug 2015 23:52:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_20,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Aug 2015 23:52:37 +0000 Received: from svr-orw-fem-04.mgc.mentorg.com ([147.34.97.41]) by relay1.mentorg.com with esmtp id 1ZMPX0-0005vJ-Ag from Nathan_Sidwell@mentor.com for gcc-patches@gcc.gnu.org; Mon, 03 Aug 2015 16:52:34 -0700 Received: from [127.0.0.1] (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.3.224.2; Mon, 3 Aug 2015 16:52:33 -0700 To: GCC Patches From: Nathan Sidwell Subject: [gomp4] Remove superfluous code Message-ID: <55BFFEC0.4050406@mentor.com> Date: Mon, 03 Aug 2015 23:52:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080109090809020609090301" X-SW-Source: 2015-08/txt/msg00134.txt.bz2 --------------080109090809020609090301 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 246 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 --------------080109090809020609090301 Content-Type: text/x-patch; name="gomp4-plugin.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gomp4-plugin.patch" Content-length: 3588 2015-08-03 Nathan Sidwell 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 #include #include -#include #include #include #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)); --------------080109090809020609090301--