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:
- The steps described herein have been tested on Windows 8.1 only, but should also apply for Windows 7 and Windows 8.
- We will not discuss how to write an actual OpenCL program or kernel, but focus on how to get everything installed and ready for OpenCL on a Windows machine. This is because writing efficient OpenCL kernels is almost entirely OS independent.
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.
Running an OpenCL application
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:
- 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.
- Make sure your OpenCL device driver is up to date, especially if you’re not using the latest and greatest hardware. With certain older devices OpenCL support wasn’t initially included in the drivers.
Here is where you can download drivers manually:
- Intel has hidden them a bit, but you can find them here with support for OpenCL 2.0.
- AMD’s GPU-drivers include the OpenCL-drivers for CPUs, APUs and GPUs, version 2.0.
- NVIDIA’s GPU-drivers mention mostly CUDA, but the drivers for OpenCL
1.11.2 are there too.
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.
Developing OpenCL applications
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:
- Make sure you have a machine which supports OpenCL, as described above.
- Get the OpenCL headers and libraries included in the OpenCL SDK from your favourite vendor.
- Start writing OpenCL code. That’s the difficult part.
- Tell the compiler where the OpenCL headers are located.
- Tell the linker where to find the OpenCL .lib files.
- Build the fabulous application.
- Run and prepare to be awed in amazement.
Ok, so let’s have a look into each of these.
OpenCL SDKs
For OpenCL headers and libraries the main options you can choose from are:
- NVIDIA – CUDA Toolkit. You can grab the OpenCL samples here.
- AMD –
AMD APP SDK. Also works with Intel’s CPUs.- Headers and OpenCL.lib are here: https://github.com/GPUOpen-LibrariesAndSDKs/OCL-SDK/releases
- Samples are here: https://github.com/OpenCL/AMD_APP_samples
- Math libraries are here: https://github.com/clMathLibraries
- Intel – the previous Intel SDK for OpenCL is now integrated into Intel’s new tools, such as Intel INDE (which has a free starters edition) or Intel Media Server Studio. Grab any of these in order to have everything ready for building OpenCL code.
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.
OpenCL headers
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“.
OpenCL libraries
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.
Very interesting post, thanks Anca!
Pingback: OpenCL Links vom 22.03.2015 - OpenCL-Blog
NVIDIA’s drivers support OpenCL 1.2 on their recent hardware.
Yes it is a big mess since they have removed the OpenCL SDK separately from the main GPU computing tool kit and only OpenCL.lib file exists. Also there are separate OpenCL samples instead of one single ocl_releasevs2010.sln I ran my OpenCL 1.2 code on NVIDIA GeForce 840M
Pingback: clGetPlatformID error when running OpenCL program. »
The problem is that you are providing a NULL pointer to clGetPlatformIDs.
Try to change this line:
cl_uint* numPlatforms = NULL;
to
cl_uint numPlatforms = 0;
And call clGetPlaformIDs like this:
clGetPlatformIDs(0, NULL, &numPlatforms);
You are now saying to clGetPlatformsIDs: “Hey, I’m sending you the address of my variable numPlatforms, please write there the number of OpenCL platforms”.
Please let us know if this change works for you.
Just wanna say a very big thank you to you, i was able to successfully install and run my first OpenCL program. wish u all the best..cheers
Good to hear! You’re very welcome!
please tell me how to get that 1st window OPENCL LIBRARIES.i dont know about any of these step.
and i downloaded all the required downloads, but there is no exe file to open.all there was a bunch of useless dll etc files and folders.I have AMD gpu and INTEL cpu.
”Start writing OpenCL code. That’s the difficult part.” where to write, how can i get in to this step.
Hi, guys. Tell me, please, how to activate OpenCL 1.1 for Intel Core 2 Quad Q9550 if OS Windows 10 – 64 bit?
Install Intel’s OpenCL drivers from https://software.intel.com/en-us/articles/opencl-drivers
Very thanx, my friend! It works at Win 10 WOW64, but Intel OpenCL compiler not work (freeze) at pure 64-bit.
WoW64 stands for “Windows 32-bit on Windows 64-bit”, so W32oW64 would be a better name. You need to use the opencl.lib from C:Program Files (x86)IntelOpenCL SDKlibx64, not the x86-version.
Thanks for the tutorial, but i got these errors :
any suggestion?
Be sure to check if $(CUDA_INC_PATH) is set in the Windows environment.
If the OpenCL includes were not in NVidia’s CUDA SDK, then look at the downloads at the bottom of https://streamhpc.com/blog/2012-09-10/nvidias-industry-leading-support-for-opencl/
Already set sir, but still can’t build. Btw, I already using those CUDA SDK4.2 even I’ve tried the latest version of CUDA SDK (7.5). I’m using Win10, 64bit, and by using this link https://streamhpc.com/blog/2011-12-29/opencl-hardware-support/ that my hardware is support openCL. And already followed the instruction above still cant build. Is there any issues beside all of this? I’d really appreciate. thanks
please tell me how to get that 1st window OPENCL LIBRARIES.i dont know about any of these step.
and i downloaded all the required downloads, but there is no exe file to open.all there was a bunch of files.I have AMD gpu and INTEL cpu.
”Start writing OpenCL code. That’s the difficult part.” where to write, how can i get in to this step.
You need the AMD GPU drivers and then install the AMD APP SDK. The SDK is indeed no simple executable you can run, as it is for developers.
We offer trainings in OpenCL. You can also read one of the OpenCL books.
http://amd-dev.wpengine.netdna-cdn.com/app-sdk/installers/APPSDKInstaller/3.0.130.135-GA/full/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x64.exe
http://amd-dev.wpengine.netdna-cdn.com/app-sdk/installers/APPSDKInstaller/3.0.130.135-GA/full/AMD-APP-SDKInstaller-v3.0.130.135-GA-windows-F-x86.exe
Direct links for Windows.