Unable to compile OpenCL application using 1.2 headers in version 1.1

I am writing a small OpenCL welcome program using Khronos Group cl.hpp for OpenCL 1.2 and nVidia openCL libraries. Drivers and ICDs have support for OpenCL 1.1. Since the nVidia side does not yet support 1.2, I get some errors regarding the features required for OpenCL 1.2.

On the other hand, cl.hpp for OpenCL 1.2 has the CL_VERSION_1_1 flag, to be precise, to run the header in mode 1.1, but it does not work. Does anyone have a similar experience or solution?

Note: cl.hpp for version 1.1 works, but generates many warnings at compile time. This is why I am trying to use version 1.2.

+6
source share
5 answers

Unfortunately, NVIDIA is distributing an old version of OpenCL ICD (a library that sends API calls to the appropriate driver). Your best options are either

  • Get a more modern version of ICD (if you are using Linux, this is libOpenCL.so and you can find a newer copy in the AMD APP SDK). The downside is that if you distribute your compiled code, it will also require 1.2 ICD.
  • Use the OpenCL 1.1 header files, except that you can use the latest cl.hpp. It should (theoretically) detect that it combines with the OpenCL 1.1 headers and disables all OpenCL 1.2 code (which is not tested, though). The advantage of using the latest cl.hpp is that there are many bug fixes that do not return to version 1.1 of cl.hpp.
  • You can do it:

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

    I just implemented this in my code and it seems to have done the trick.

+7
source

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

 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS 

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

+6
source

I'm tired of downloading several GB OpenCL SDKs from Intel, Nvidia and AMD with various problems:

  • Intel requires registration and has a temporary license.
  • The Nvidia SDK does not support OpenCL 2.0, and you still need to download cl.hpp.
  • The AMD cl.hpp defines the min and max macros, which may conflict with the MSVC min and max masks (I spend too much time figuring out how to fix this, for example, NOMINMAX ). The header does not match the one set by Khronos (which does not have a min / max problem).

So I downloaded the source code and included it from Khronos as suggested by fooobar.com/questions/204277 / ... and compiled the OpenCL.lib file. The include and OpenCL.lib files are a couple of MB. This is much less than all the additional materials in the Intel / Nvidia / AMD SDK! I can include OpenCL and OpenCL.lib files in my project and no longer have to tell others to download the SDK.

The inclusion for OpenCL 2.0 from the Khronos registry contains a new C ++ binding file cl2.hpp . Looking at this file, I decided that the correct way to support legacy functions with OpenCL 2.0 looks 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 

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

Finally, after #include "CL/cl2.hpp" , to make my code 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 work. Looks like I'm not the only one who has this problem . My GPU does not support OpenCL 2.0.

+4
source

It seems like the only way to use OpenCL 1.1 headers when working with devices that support 1.1.

+1
source

You can call to set clBuildProgram parameters 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.

+1
source

Source: https://habr.com/ru/post/956093/


All Articles