5

I downloaded the AMD APP 3.0 SDK and as soon as I include #include <CL/cl.hpp> into my cpp it throws deprecation warnings:

1>c:\program files (x86)\amd app sdk\3.0\include\cl\cl.hpp(4240): warning 
     C4996: 'clCreateSampler': was declared deprecated

and many more.

Am I doing something wrong? I feel uncomfortable starting to play with openCL having so many warnings already before writing a single line of useful code.

NOhs
  • 2,780
  • 3
  • 25
  • 59

1 Answers1

8

The issue here is that cl.hpp is for OpenCL 1.X platforms, but the rest of AMD's SDK supports OpenCL 2.0. The clCreateSampler function was deprecated in OpenCL 2.0.

Khronos have released an OpenCL 2.X version of the C++ bindings - cl2.hpp - which is what you should use if you wish to target OpenCL 2.0 devices using the C++ API. It may not have propagated to the vendor SDKs yet, but you can get the latest version directly from Khronos. To target OpenCL 2.0 with this header, you would include it like this:

#define CL_HPP_TARGET_OPENCL_VERSION 200
#include <CL/cl2.hpp>

If you wish to target OpenCL 1.2 platforms instead, you just need to change the value of the CL_HPP_TARGET_OPENCL_VERSION_MACRO:

#define CL_HPP_TARGET_OPENCL_VERSION 120
#include <CL/cl2.hpp>

(this will suppress the deprecation warnings that you previously received)

You could still use the 1.X header (cl.hpp) for 1.X platforms; you just need to make it clear that the deprecation warnings are not an issue for you:

#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.hpp>
jprice
  • 9,755
  • 1
  • 28
  • 32
  • Switching from `cl.hpp` to `cl2.hpp` header opened a `LNK2005` error on my Intel OpenCL SDK: `enum cl::QueueProperties __cdecl cl::operator|(enum cl::QueueProperties,enum cl::QueueProperties) ...... already defined in opencl_ops-tester.obj` – Patrizio Bertoni May 13 '16 at 09:19
  • @PatrizioBertoni This issue should have been fixed a few months ago, are you using the latest cl2.hpp available here? https://github.com/KhronosGroup/OpenCL-CLHPP/releases/tag/v2.0.9 – jprice May 13 '16 at 12:26