How to create NVIDIA OpenCL project

The OpenCL Runtime is already included in the Nvidia graphics drivers. You only need the OpenCL C++ header files, the OpenCL.lib file and on Linux also the libOpenCL.so file. These come with the CUDA toolkit, but there is no need to install it only to get the 9 necessary files.

Here are the OpenCL C++ header files and the lib file from CUDA toolkit 10.1:
https://github.com/ProjectPhysX/OpenCL-Wrapper/tree/master/src/OpenCL

Download the OpenCL folder and copy it into your project source folder.
Then in your Visual Studio Project, go to “Project Properties -> C/C++ -> General -> Additional Include Directories” and add C:\path\to\your\project\src\OpenCL\include. Then, in “Project Properties -> Linker -> All Options -> Additional Dependencies” add OpenCL.lib; and in “Project Properties -> Linker -> All Options -> Additional Library Directories” add C:\path\to\your\project\src\OpenCL\lib.

Finally, in your .cpp source file, include the headers with #include <CL/cl.hpp>.

This also works for AMD/Intel GPUs and CPUs. It also works on Linux if you compile with:

g++ *.cpp -o Test.exe -I./OpenCL/include -L./OpenCL/lib -lOpenCL

For an easy start with OpenCL, I created a wrapper that vastly simplifies the OpenCL C++ bindings and eliminates the entire code overhead that comes with it. This includes the OpenCL headers and all Visual Studio project settings; no additional setup required:
https://github.com/ProjectPhysX/OpenCL-Wrapper

Leave a Comment