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.
source share