Hi everyone
If any of you is interested, I wrote some code to dynamically link to the OpenCL runtime library. It looks for OpenCL.so on Linux, and OpenCLdll on Windows. I’ve only gotten the chance to test it with AMD’s implementation on 32-bit Linux (Fedora 12), but it works fine for me.
I used the CUDA driver API dynamic link code from the SDK samples as an example, so part of the credit goes to NVIDIA.
You can find the files(OpenCL_Dyn_Load.h/.c) here:
[url=“Google Code Archive - Long-term storage for Google Code Project Hosting.”]Google Code Archive - Long-term storage for Google Code Project Hosting.
NOTE: You need to call clLibLoad() and check thet it returns CL_SUCCESS before using any cl*() function.
Let me know what you think.
EDIT: Updated broken link
Hi, Mr Nuke,
Your code would be of great help, but the link seams to be dead.
could you post it again ?
–
RaF.
Oops, I changed a subfolder name. That’s why the link didn’t work. I’ve updated the link.
Ok it seams to work !
Thank’s.
–
RaF.
It’s me again. :">
Have you tried to install the latest drivers 197.13. They include OpenCL.dll so that you don’t need the SDK anymore.
The problem is that wilh this DLL, your dynamic link code crashes (dll loads fine, but crash occurs on the first cl* function call).
Anybody experiment the same problem ?
raf.
I’ll look into it once I get my hands on a Windows machine. Last I checked, it worked fine with AMD’s OpenCL on Fedora 12.
Is the crash a segfault (AKA access violation) ?
Alex
Yep,
Seg fault on the first call to clCreateContextFromType.
Thank’s
Raf.
What does clLibLoad() return?
If it’s not CL_SUCCESS, then something went wrong with loading the OpenCL Library, and using the cl* routines (which are just function pointers) is bound to make something bad happen.
It’s not documented, but
CL_DEVICE_NOT_FOUND - OpenCL.dll/libOpenCL.so not found
CL_DEVICE_NOT_AVAILABLE - one of the functions failed to load. If this is the case, you can step through the code and see which one fails. Since I’m five days away from a windows machine with NVIDIA GPU’s, I can’t test this myself at the moment.
Alex
Now I have no more seg faults,
I have updated the files in “CL/” directory on my project.
I thing the problem came from the definitions in CL/cl_platform.h
But now clCreateContextFromType returns CL_INVALID_PLATFORM, I will have to go a bit deeper, in the files that are included.
Thank’s Mr_Nuke.
If you’re looking for a (very rough an incomplete) example, in the same folder with the dynamic link code, there’s a file, “CL_Manager.cpp” I believe. If you’d like to do a bit of C++ hacking, you can look over it; I was able to retrieve platform info from NVIDIA cards with it. If I recall correctly, the function of interest is ScanDevices(). I never tried to create a context, but it should show how to cough initialize OpenCL.
Hope this helps.
Alex