I've been doing some Windows OpenCL stuff recently. One of the things that kind of annoyed me a lot was all the time spend to set things up. Installing Visual Studio (which takes quite some time), finding the proper SDK and praying that everything kind of works. Not realy my kind of fun. And all I wanted to do was to create a program that uses the systems
So how hard can that be? What do I really need for that? Common sense linking would suggest you only need the header files. With that the compiler knows how to generate code to call the DLL functions. So I gave it a try and it actually worked! (Which honestly surprises me most of the time.)
- I downloaded MinGW-w64 as standalone compiler. You can use the installer but a 50 MiB archive with a small
.cmd script to add it's
bin directory to the
%PATH% is just my type of thing. No external dependencies or funny setup stuff. Extract and go. As long as Microsoft doesn't break backward compatibility (unlikely) it will continue to work out of the box. No trouble if I want to pick it up again later on.
- All I really wanted from the OpenCL SDKs were the OpenCL header files. Well, you can get those directly from the Kronos Groups website. I actually only needed
cl_platform.h. The others (e.g.
cl_egl.h) are optional addons and are not included by
- The OpenCL runtime (
opencl.dll) is provided by recent AMD or nVidia drivers. No need for any SDK.
All that remains is to add the OpenCL headers to the compilers include path, compile an OpenCL program and link it against the systems
gcc -I. main.c C:\Windows\System32\OpenCL.dll -o main.exe
I've put the OpenCL header files into an
cl subdirectory. Then added the current directory to the include path. So the compiler will find
And that's it! MinGW-w64, two header files and a recent graphics driver is all you need. :)
I've tested this with OpenCL 1.1 on nVidia (one notebook) and AMD drivers (two different computers). There's so much interesting stuff in OpenCL 1.1. alone (e.g. combining out-of-order GPU and CPU command queues) that I haven't tested newer versions yet.
If you're curious you can find the minimal setup on GitHub. It's a small OpenCL application that takes the first GPU and transforms a hand full of characters on the GPU. Total waste of any processing time but enough to see if it works.