Recent code uses OpenCL 1.2 more and more, which is a problem when wanting to use OpenCL 1.1 devices, or even 1.0 devices. Most times those computers have OpenCL 1.1 libraries installed. So what to do?
When you want to make code that runs on both on Nvidia, AMD and Intel, then you have two options:
- Use the OpenCL 1.2 library.
- Go back to OpenCL 1.1 (from 2010)
Below I’ll explain both option. Understand that the difference between 1.1 and 1.2 is not that big, and that this article is mostly here to get you started to prepare for 2.0.
Use the OpenCL 1.2 library
Not many people seem to know that you can just use OpenCL 1.2 libraries with 1.1 devices. So if you have opencl.dll or libOpenCL.so of version 1.2 and not use the new functions. The advantage is that you can use the 1.2 host-functionalities with the 1.2 devices. Else those were not really usable, except the kernel-functions. To get the version 1.2 of opencl.dll or libOpenCL.so, you need to install the drivers of AMD or Intel or just copy it from a friend.
You can go one step further: we have a wrapper that translates most 1.2 functions to 1.1, to port code to 1.1 more easily. This is a preparation for OpenCL 2.0, to keep partly backwards compatible – versioning is getting more important with each new version of OpenCL.
When distributing your code, you need to distribute the library too. Problem is that it’s not really allowed, and should be installed by the user – and that user installs OpenCL 1.1 when they have NVidia hardware. Khronos distributes the code of the library, but it doesn’t compile easily under Windows. Please read the license.txt well.
Go for OpenCL 1.1 completely
The advantage is that you avoid all kinds of problems, by giving up some progress in the standard. As OpenCL 1.0 libraries are not really out there anymore, you probably won’t need to distribute the library yourself. And it’s just what Nvidia wanted: keeping the competition back. Congrats, Nvidia!
A good reason would
Problems arise when using deprecated functions, or have libraries that have calls to deprecated functions. Those can usually be avoided, but not when coding. For instance the cl.hpp for OpenCL 1.1 (found here) gives loads of warnings when you have the 1.2 library. Luckily this can easily be solved by adding some pragmas (works with GCC 4.6 and higher).
#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" --> the contents of cl.hpp #pragma GCC diagnostic pop
The source of this trick has some more remarks when using GCC 4.5.
A word towards Linux distributions
OSX has OpenCL 1.2 by default for the host. Linux distributions have dependencies on OpenCL 1.1 for Nvidia-drivers, which is not needed – as explained above. They can easily go for a dependency on the OpenCL 1.2 library. The code provided by Khronos could be used.
Hi,
You mention wrappers for using OpenCL 1.2 code on OpenCL 1.1 devices. Where can one access them?
Regards,
Anup
We abandoned the internal project when NVidia moved to 1.2. There might be embedded projects where this code can be used. Also we can use the experience to implement missing functions in OpenCL 2.
Is it possible to have access these wrappers for an embedded systems project?
Commercially we can support such project. I’ve emailed you.