Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile OpenCL application using 1.2 headers in 1.1 version

Tags:

c++

nvidia

opencl

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.

like image 232
bayindirh Avatar asked Oct 16 '13 14:10

bayindirh


4 Answers

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.

like image 136
Bruce Merry Avatar answered Oct 20 '22 01:10

Bruce Merry


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

like image 21
Erik Smistad Avatar answered Oct 19 '22 23:10

Erik Smistad


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.

like image 37
Z boson Avatar answered Oct 20 '22 01:10

Z boson


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

like image 41
bayindirh Avatar answered Oct 20 '22 01:10

bayindirh