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
create OpenCL project in Visual Studio 2010
The CUDA Toolkit 5.0 contains the headers in include\CL and the libraries lib\\OpenCL.lib. The same includes and library are available from AMD, Intel, Khronos, ... In the tutorial you are following simply replace Step 2 substeps 1,2,3 with the paths I mentioned.
OpenCL configuration settings
This error indicates that the compiler is not able to find the CL/cl.h header file. Find out where the OpenCL SDK you are using is installed and the directory that contains the OpenCL header files inside it.
On my computer for example, the Intel OpenCL SDK header files are in: C:\Program Files (x86)\Intel\OpenCL SDK\1.5\include\CL
And the NVIDIA OpenCL header files are in: C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.1\include\CL
To compile with the Intel OpenCL SDK, I would add C:\Program Files (x86)\Intel\OpenCL SDK\1.5\include
to the Visual Studio project. That is, add this path to Project -> Properties -> C/C++ -> General -> Additional Include Directories
NVIDIA OpenCL Device Version
According to the clGetDeviceInfo
specification:
CL_DEVICE_OPENCL_C_VERSION
is the highest OpenCL C language version that the compiler supports for this device.
CL_DEVICE_VERSION
is the OpenCL version supported by the device.
So even though your MX150 supports OpenCL 3.0, you can only compile OpenCL 1.2 code. Note that OpenCL 3.0 basically is identical to OpenCL 1.2 but with better support for optional OpenCL 2.x features. With the lates driver Nvidia has added a few new OpenCL 2.x features, but still has no full 2.x support.
Related Topics
How to Programmatically Gain Root Privileges
How to Define a Template Function Within a Template Class Outside of the Class Definition
Template Tuple - Calling a Function on Each Element
How Does C++ Stl Unordered_Map Resolve Collisions
How to Check What Shared Libraries Are Loaded at Run Time for a Given Process
How to Get a Random Element from a C++ Container
How to Read File Content into Istringstream
When Is Overloading Pass by Reference (L-Value and R-Value) Preferred to Pass-By-Value
What Is the Best Encryption Library in C/C++
Sharing a Global/Static Variable Between a Process and Dll
How Is a Vector's Data Aligned
C++ Sort Keeping Track of Indices
Cancelling a Thread Using Pthread_Cancel:Good Practice or Bad
What's Faster, Iterating an Stl Vector with Vector::Iterator or with At()
Shared-Memory Ipc Synchronization (Lock-Free)
How to Make C++ Cout Not Use Scientific Notation
Why Does Std::Array Not Have an Constructor That Takes a Value for the Array to Be Filled With