Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
313 views
Welcome To Ask or Share your Answers For Others

1 Answer

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://drive.google.com/file/d/1-yHaWWG7XfOarWPD817_ugeLCVLBtSCr/view?usp=sharing

Unzip 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:pathoyourprojectsourceOpenCLinclude. Then, in "Project Properties -> Linker -> All Options -> Additional Dependencies" add OpenCL.lib; and in "Project Properties -> Linker -> All Options -> Additional Library Directories" add C:pathoyourprojectsourceOpenCLlib.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...