Zekhire
Zekhire

Reputation: 115

How to create NVIDIA OpenCL project

I want to write application in NVIDIA OpenCL in Visual Studio 2017 but don't know how to create project for this purpose.

I have GPU from NVIDIA (GeForce 940M) and Intel (HD Graphics 5500) and already managed to open and run Intel example programs for OpenCL but they have almost one thousand lines of code, so I decided to try NVIDIA OpenCL but don't know how. On some forums they say that I should download CUDA toolkit and it install OpenCL, others say that I should download driver that supports OpenCL but I don't know which driver will be proper. I have already installed CUDA and driver from https://www.nvidia.pl/Download/index.aspx?lang=pl but still I have not possibility to create NVIDIA project in OpenCL in Visual Studio.

Upvotes: 5

Views: 19582

Answers (1)

ProjectPhysX
ProjectPhysX

Reputation: 5746

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

Upvotes: 11

Related Questions