cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

jirmik
Adept I

Redistributing OpenCL library / detection of OpenCL devices

Hi, what is correct way of distributing OpenCL runtime with our application?

We'd like to achieve following: when launched on any target machine, we want our application to detect any OpenCL AMD GPU devices and use them, or (if no devices are present) fall back to slower C++ implementation. Is it possible to distribute OpenCL dynamic library with the application just for case that there is no OpenCL installed on target system? We have already tried to compile our application with libOpenCL.so from APP SDK and move the application together with the library to other machine. However, there were weird problems with deadlocks when throwing C++ exceptions anywhere in application if it was linked with the libOpenCL.so and moved to other machines.

How can we achieve correct and safe automatic detection of OpenCL devices in unknown environment of target machines? I'm interested in solution for Linux and Windows.

Thanks,

Martin

0 Likes
1 Solution

You cannot distribute the OpenCL dynamic library, just as how you cannot distribute the OpenGL library on the system. Each library contains the OpenCL implementation specific to the device/platform its running on. The job of the ICD loader is to enumerate each platform and shunt calls to the correct one. Instead of statically linking your app to OpenCL, try dynamically loading the library ( failure to load the library, would indicate that the OpenCL implementation cannot be found, may be missing or in the wrong location, in either case you would use the C++ implementation ).

View solution in original post

0 Likes
6 Replies
ginquo
Adept II

Maybe take a look at the cl_khr_icd extension spec and the ICD loader in the OpenCL registry. This should allow you to enumerate installed OpenCL implementations and to add your own local library to the available platforms.

0 Likes

You cannot distribute the OpenCL dynamic library, just as how you cannot distribute the OpenGL library on the system. Each library contains the OpenCL implementation specific to the device/platform its running on. The job of the ICD loader is to enumerate each platform and shunt calls to the correct one. Instead of statically linking your app to OpenCL, try dynamically loading the library ( failure to load the library, would indicate that the OpenCL implementation cannot be found, may be missing or in the wrong location, in either case you would use the C++ implementation ).

0 Likes

Couldn't you distribute a portable CPU implementation of OpenCL like for instance pocl with your code?

0 Likes

Hi, we were doing some experiments with POCL, but most of our kernels didn't work. Anyway, we already have working CPU version so we can easily utilize the CPU without OpenCL. The key is the safe detection of OpenCL. Currently, we are happy with cgrant's solution.

0 Likes

Thanks for confirmation of our thoughts. We have created simple dispatch wrappers for all OpenCL functionality which we needed and a code for detection of OpenCL dynamic library in the system. The wrapper functions have also solved our problems with deprecated OpenCL functions, as we can emulate the deprecated functions with newer ones, based on available OpenCL version.

0 Likes

Thats really good to hear. Good luck

0 Likes