Getting your Windows machine ready for OpenCL is rather straightforward. In short, you only need the latest drivers for your OpenCL device(s) and you’re ready to go. Of course, you will need to add an OpenCL SDK in case you want to develop OpenCL applications but that’s equally easy.
Before we start, a few notes:
If you want to know more about OpenCL and you are looking for simple examples to get started, check the Tutorials section on this webpage.
If you only need to run an OpenCL application without getting into development stuff then most probably everything already works.
If OpenCL applications fail to launch, then you need to have a closer look to the drivers and hardware installed on your machine:
GPU Caps Viewer- Check that you have a device that supports OpenCL. All graphics cards and CPUs from 2011 and later support OpenCL. If your computer is from 2010 or before, check this page. You can also find a list with OpenCL conformant products on Khronos webpage.
Here is where you can download drivers manually:
In addition, it is always a good idea to check for any other special requirements that the OpenCL application may have. Look for device type and OpenCL version in particular. For example, the application may run only on OpenCL CPUs, or conversely, on OpenCL GPUs. Or it may require a certain OpenCL version that your device does not support.
A great tool that will allow you to retrieve the details for the OpenCL devices in your system is Caps Viewer.
Now it’s time to put the pedal to the metal and start developing some proper OpenCL applications.
The basic steps would be the following:
Ok, so let’s have a look into each of these.
For OpenCL headers and libraries the main options you can choose from are:
As long as you pay attention to the OpenCL version and the OpenCL features supported by your device, you can use the OpenCL headers and libraries from any of these three vendors.
Let’s assume that we are developing a 64bit C/C++ application using Visual Studio 2013. To begin with, we need to check how many OpenCL platforms are available in the system:
[raw]
#include<stdio.h>
#include<CL/cl.h>
int main(void)
{
cl_int err;
cl_uint numPlatforms;
err = clGetPlatformIDs(0, NULL, &numPlatforms);
if (CL_SUCCESS == err)
printf("\nDetected OpenCL platforms: %d", numPlatforms);
else
printf("\nError calling clGetPlatformIDs. Error code: %d", err);
return 0;
}
[/raw]
We need to specify where the OpenCL headers are located by adding the path to the OpenCL “CL” is in the same location as the other CUDA include files, that is, CUDA_INC_PATH. On a x64 Windows 8.1 machine with CUDA 6.5 the environment variable CUDA_INC_PATH is defined as “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include”
If you’re using the AMD SDK, you need to replace “$(CUDA_INC_PATH)” with “$(AMDAPPSDKROOT)/include” or, for Intel SDK, with “$(INTELOCLSDKROOT)/include“.
Similarly, we need to let the linker know about the OpenCL libraries. Firstly, add OpenCL.lib to the list of Additional Dependencies:
Secondly, specify the OpenCL.lib location in Additional Library Directories:
As in the case of the includes, If you’re using the AMD SDK, replace “$(CUDA_LIB_PATH)” with “$(AMDAPPSDKROOT)/lib/x86_64” , or in the case of Intel with “$(INTELOCLSDKROOT)/lib/x64“.
And you’re good to go! The application should now build and run. Now, just how difficult was it? Happy OpenCL-coding on Windows!
If you have any question or suggestion, just leave a comment.