Go Back   nV News Forums > Linux Support Forums > NVIDIA Linux

Newegg Daily Deals

Reply
 
Thread Tools
Old 01-24-11, 11:31 PM   #1
maxtothemax
Registered User
 
Join Date: Jan 2011
Posts: 7
Default Attempting to write my own OpenCL ICD Loader-- libcuda.so doesn't export OpenCL API

This isn't a user question, it's a developer question. I already know that OpenCL works fine on my system because I've successfully run some simple test apps. I'm just having trouble writing my own OpenCL code using nVidia's drivers. Dunno if this is the right place to go for developer help, but I'll ask here anyway so I don't get flamed if I ask on the Knronos forums.

I am trying to implement my own OpenCL ICD Loader (implementing this spec.) The use case is that it will be statically linked with an application and will detect any OpenCL ICDs installed on the system.

According to the spec (at least, as I understand it,) /etc/OpenCL/vendors/*.icd is a file with the name of a .so; the .so will provide an OpenCL implementation which the ICD Loader will load. In this case, I have /etc/OpenCl/vendors/nvidia.icd, which references "libcuda.so," which I can open just fine with dlopen(). I can get clGetExtensionFunctionAddress and clGetPlatformInfo from libcuda.so using dlsym(), and I can then use clGetExtensionFunctionAddress to retrieve clIcdGetPlatformIDsKHR. I can then use clIcdGetPlatformIDsKHR and clGetPlatformInfo to query all platforms provided by the driver (all one of them) and verify that they all support the cl_khr_icd extension. So far it's going exactly like the spec says it should.

However, libcuda.so does not seem to export *any* of the rest of the OpenCL API- clGetDeviceIDs, clGetDeviceInfo, etc. etc. etc.-- dlsym fails on all of them.

Am I misunderstanding the spec? Should I be looking elsewhere for these functions? If any nVidia developers are reading this, would they mind disclosing how nVidia's ICD loader does this?

Ceremonial information:
  • 32-bit Linux Mint 9 (Ubuntu 10.04)
  • Driver 195.36.24 from nvidia-current package

Attached files:
  • [s]clicd.tar.gz - My source code.[/s] (Removed- see post below for newer version.) Pure ANSI C, includes Makefile, no dependencies. "make" to compile it, then "./clicd_test" to run it. The file you are probably most interested in is clicd_locateicd_unix.c, which contains main() and all the code being talked about in this post.
  • nvidia-bug-report.log.gz - Probably not relevent but hey why not?
Attached Files
File Type: gz nvidia-bug-report.log.gz (68.7 KB, 160 views)

Last edited by maxtothemax; 01-26-11 at 05:50 AM.
maxtothemax is offline   Reply With Quote
Old 01-25-11, 11:39 PM   #2
Thunderbird
 
Join Date: Jul 2002
Location: Netherlands, Europe
Posts: 2,105
Default Re: Attempting to write my own OpenCL ICD Loader-- libcuda.so doesn't export OpenCL A

What happens if you use clGetExtensionFunctionAddress to get those missing calls? It is typically the recommended way of doing things also on OpenGL because a lot of calls are not exported through the default symbol tables.
Thunderbird is offline   Reply With Quote
Old 01-26-11, 12:17 AM   #3
maxtothemax
Registered User
 
Join Date: Jan 2011
Posts: 7
Default Re: Attempting to write my own OpenCL ICD Loader-- libcuda.so doesn't export OpenCL A

You can try that (and I have, sorry I forgot to mention) by changing this:
Code:
#define IGNORE_SFATAL 0 /* Option for testing, DO NOT ENABLE */
#define SFATAL 1    /* If API is missing then the ICD is no good. */
#define SEXT 2      /* API is an extension and might not be a "symbol" */
To this:
Code:
#define IGNORE_SFATAL 0 /* Option for testing, DO NOT ENABLE */
#define SFATAL 3    /* If API is missing then the ICD is no good. */
#define SEXT 2      /* API is an extension and might not be a "symbol" */
This causes anything marked as SFATAL (required) to be marked as SEXT (should be tried with clGetExtensionFunctionAddress as well as dlsym.) You can also define IGNORE_SFATAL 1 to try all of them instead of giving up when one is missing. Result:
Code:
Trying libcuda.so
Successfully loaded clGetExtensionFunctionAddress (0xb6f9c770)
Successfully loaded clIcdGetPlatformIDsKHR (0xb6f8a020)
Successfully loaded clGetPlatformInfo (0xb6f8a040)
Name: NVIDIA CUDA	Vendor: NVIDIA Corporation
Extensions cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll 
ICD Suffix NV
Failed to load clGetPlatformIDs (non-fatal)
Failed to load clGetDeviceIDs (non-fatal)
Failed to load clGetDeviceInfo (non-fatal)
Failed to load clCreateContext (non-fatal)
Failed to load clCreateContextFromType (non-fatal)
Failed to load clRetainContext (non-fatal)
Failed to load clReleaseContext (non-fatal)
Failed to load clGetContextInfo (non-fatal)
Failed to load clCreateCommandQueue (non-fatal)
Failed to load clRetainCommandQueue (non-fatal)
Failed to load clReleaseCommandQueue (non-fatal)
Failed to load clGetCommandQueueInfo (non-fatal)
Failed to load clSetCommandQueueProperty (non-fatal)
Failed to load clCreateBuffer (non-fatal)
Failed to load clCreateImage2D (non-fatal)
Failed to load clCreateImage3D (non-fatal)
Failed to load clRetainMemObject (non-fatal)
Failed to load clReleaseMemObject (non-fatal)
Failed to load clGetSupportedImageFormats (non-fatal)
Failed to load clGetMemObjectInfo (non-fatal)
Failed to load clGetImageInfo (non-fatal)
Failed to load clCreateSampler (non-fatal)
Failed to load clRetainSampler (non-fatal)
Failed to load clReleaseSampler (non-fatal)
Failed to load clGetSamplerInfo (non-fatal)
Failed to load clCreateProgramWithSource (non-fatal)
Failed to load clCreateProgramWithBinary (non-fatal)
Failed to load clRetainProgram (non-fatal)
Failed to load clReleaseProgram (non-fatal)
Failed to load clBuildProgram (non-fatal)
Failed to load clUnloadCompiler (non-fatal)
Failed to load clGetProgramInfo (non-fatal)
Failed to load clGetProgramBuildInfo (non-fatal)
Failed to load clCreateKernel (non-fatal)
Failed to load clCreateKernelsInProgram (non-fatal)
Failed to load clRetainKernel (non-fatal)
Failed to load clReleaseKernel (non-fatal)
Failed to load clSetKernelArg (non-fatal)
Failed to load clGetKernelInfo (non-fatal)
Failed to load clGetKernelWorkGroupInfo (non-fatal)
Failed to load clWaitForEvents (non-fatal)
Failed to load clGetEventInfo (non-fatal)
Failed to load clRetainEvent (non-fatal)
Failed to load clReleaseEvent (non-fatal)
Failed to load clGetEventProfilingInfo (non-fatal)
Failed to load clFlush (non-fatal)
Failed to load clFinish (non-fatal)
Failed to load clEnqueueReadBuffer (non-fatal)
Failed to load clEnqueueWriteBuffer (non-fatal)
Failed to load clEnqueueCopyBuffer (non-fatal)
Failed to load clEnqueueReadImage (non-fatal)
Failed to load clEnqueueWriteImage (non-fatal)
Failed to load clEnqueueCopyImage (non-fatal)
Failed to load clEnqueueCopyImageToBuffer (non-fatal)
Failed to load clEnqueueCopyBufferToImage (non-fatal)
Failed to load clEnqueueMapBuffer (non-fatal)
Failed to load clEnqueueMapImage (non-fatal)
Failed to load clEnqueueUnmapMemObject (non-fatal)
Failed to load clEnqueueNDRangeKernel (non-fatal)
Failed to load clEnqueueTask (non-fatal)
Failed to load clEnqueueNativeKernel (non-fatal)
Failed to load clEnqueueMarker (non-fatal)
Failed to load clEnqueueWaitForEvents (non-fatal)
Failed to load clEnqueueBarrier (non-fatal)
(EDIT: Removed mention of second problem I had, I figured that one out. My first question still stands.)

Attached-- newer version of my code which attempts to fall back on libOpenCL.so and also tries to test all located drivers.
Attached Files
File Type: gz clicd.tar.gz (26.8 KB, 130 views)

Last edited by maxtothemax; 01-27-11 at 02:36 PM.
maxtothemax is offline   Reply With Quote
Old 01-31-11, 11:01 AM   #4
Stephen Warren
Moderator
 
Stephen Warren's Avatar
 
Join Date: Aug 2005
Posts: 1,327
Default Re: Attempting to write my own OpenCL ICD Loader-- libcuda.so doesn't export OpenCL A

For CUDA issues, NVIDIA's own "cuda zone" forums are probably the best place to ask; it's much more concentrated specifically on CUDA and OpenCL issues, and I think some CUDA support people read those forums.
Stephen Warren is offline   Reply With Quote
Old 01-31-11, 06:32 PM   #5
maxtothemax
Registered User
 
Join Date: Jan 2011
Posts: 7
Default Re: Attempting to write my own OpenCL ICD Loader-- libcuda.so doesn't export OpenCL A

Thanks for the pointer!
maxtothemax is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:49 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.