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.