8

I'm writing a small hello world OpenCL program using Khronos Group's cl.hpp for OpenCL 1.2 and nVidia's openCL libraries. The drivers and ICD I have support OpenCL 1.1. Since the nVidia side doesn't support 1.2 yet, I get some errors on functions required on OpenCL 1.2.

On the other side, cl.hpp for OpenCL 1.2 has a flag, CL_VERSION_1_1 to be exact, to run the header in 1.1 mode, but it's not working. Anybody has similar experience or solution?

Note: cl.hpp for version 1.1 works but, generates many warnings during compilation. This is why I'm trying to use 1.2 version.

bayindirh
  • 425
  • 6
  • 21
  • I had the same problem and just used the 1.1 header. Copy it into the cuda/include/CL directory and let it there forever. It seems Nvidia will never support OpenCL 1.2. Strangely the 1.1 headers work for me without warnings. Centos 6.2 with gcc 4.8.1. – Michael Haidl Oct 16 '13 at 14:21

5 Answers5

8

Unfortunately NVIDIA distributes an old version of the OpenCL ICD (the library that dispatches API calls to the appropriate driver). Your best options are to either

  • Get hold of a more up to date version of the ICD (if you're using Linux, this is libOpenCL.so, and you can find a newer copy in AMD's APP SDK). The downside is that if you distribute your compiled code, it will also require the 1.2 ICD.
  • Use the OpenCL 1.1 header files, except that you can use the latest cl.hpp. It should (in theory) detect that it is being combined with OpenCL 1.1 headers and disable all the OpenCL 1.2 code (that doesn't get tested much though). The advantage of using the latest cl.hpp is that there are a lot of bug fixes that don't get back-ported to the 1.1 version of cl.hpp.
  • You can do this:

    #include <CL/cl.h>
    #undef CL_VERSION_1_2
    #include <CL/cl.hpp>
    

    I've just implemented that in my code and it seems to do the trick.

Bruce Merry
  • 751
  • 3
  • 11
  • You'll still need to define CL_USE_DEPRECATED_OPENCL_1_1_APIS as in Erik's answer. – Bruce Merry Oct 22 '13 at 15:19
  • 1
    It is a pity that nVIDIA is trying to kill so desperate OpenCL, instead of giving a proper support. For example, now their tools do not even profile or log the OpenCL kernels... – DarkZeros Oct 23 '13 at 09:55
  • It works! Nvidia is very silent and has nothing to say about OpenCL. Intel goes with GPU OpenCL support to MSWIndows. Bad luck for them! AMD with OpenCL 2.0 support is very promising technology under linux, though I have not got any of their cards yet. – 42n4 Feb 09 '15 at 10:12
  • In my case I did `#undef CL_VERSION_2_0` and now everything works. Thanks! I still had to add the `CL_USE_DEPRECATED_OPENCL_X_X_APIS` defines. – Z boson Oct 08 '15 at 11:35
6

You can define the flag CL_USE_DEPRECATED_OPENCL_1_1_APIS which will make the 1.2 hpp file 1.1 compatible.

#define CL_USE_DEPRECATED_OPENCL_1_1_APIS

This is what I have done on NVIDIA and AMD. Works like a charm

Erik Smistad
  • 1,009
  • 8
  • 7
  • I'll try it as soon as I got to my other computer, where the source is. The compiling error was about `clRetainDevice`and `clReleaseDevice`, which both are OpenCL 1.2 related functions. When I analyzed the code, looked like they can be disabled by `CL_VERSION_1_1` but I'll try the flag you suggested too. – bayindirh Oct 18 '13 at 15:00
  • Unfortunately no, setting the flag didn't prevent the header try to link to `clRetainDevice()` and `clReleaseDevice()`. I'll investigate it further though. – bayindirh Oct 21 '13 at 11:25
4

I was fed up with downloading several GB OpenCL SDK's by Intel, Nvidia, and AMD with different issues:

  • Intel requires registration and has a temporary license.
  • Nvidia SDK does not support OpenCL 2.0 and you have to download cl.hpp anyway.
  • AMDs cl.hpp file defines min and max macros which can conflict with MSVC's min and max macros (I spend too much time figuring out how to fix this with e.g. NOMINMAX). The header is not even the same as the one defined by Khronos (which does not have the min/max problem).

Therefore, I downloaded the source code and includes from Khronos as suggested by this SO answer and compiled the OpenCL.lib file myself. The includes and OpenCL.lib files are a couple of MB. That's a lot smaller than all the extra stuff in the Intel/Nvidia/AMD SDKs! I can include the OpenCL includes and OpenCL.lib files in my project and no longer have to tell others to download an SDK.

The includes for OpenCL 2.0 from the Khronos registry has a new C++ binding file cl2.hpp. Looking at this file I have determined that the correct way to support the deprecated functions with the OpenCL 2.0 is something like this.

#define CL_HPP_MINIMUM_OPENCL_VERSION 110
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_CL_1_2_DEFAULT_BUILD
#include "CL/cl2.hpp"

This is because the cl2.hpp file has this code

#if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
# define CL_USE_DEPRECATED_OPENCL_1_0_APIS
#endif
#if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
# define CL_USE_DEPRECATED_OPENCL_1_1_APIS
#endif
#if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
# define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#endif
#if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
# define CL_USE_DEPRECATED_OPENCL_2_0_APIS
#endif

Notice that you no longer need to (and should not) include <CL/opencl.h> anymore.

Lastly, after #include "CL/cl2.hpp" in order to get my code to work with Boost/Compute I had to add

#undef CL_VERSION_2_0

My own OpenCL code works without this but Boost/Compute does not. It appears I'm not the only one having this issue. My GPU does not support OpenCL 2.0.

Community
  • 1
  • 1
Z boson
  • 32,619
  • 11
  • 123
  • 226
1

Looks like the only way is to use the OpenCL 1.1 headers while working with 1.1 capable devices.

bayindirh
  • 425
  • 6
  • 21
  • 2
    My reaction: oh well, too bad for nVidia card owners. I would much rather use an open, portable, well-understood technology like OpenCL than a dead-end, proprietary framework like CUDA. – Thomas Nov 25 '13 at 06:37
1

You can call can set the options of clBuildProgram as follows

const char options[] = "-cl-std=CL1.1";

clBuildProgram( program, 1, &devices, options, NULL, NULL );

This forces the compiler to use OpenCL 1.1 no matter which version is supported by your device

Michele
  • 366
  • 2
  • 13