OpenCL on Debian Wheezy
OpenCL on x86 CPU Debian Wheezy
What is this article about?
OpenCL is a portable data processing system that can operate on GPU's as well as CPU's. This article lists the procedures I went through to try to get it up and running on my Linux box.
I am currently researching this subject for my own ends (never you mind...). But found I wasted a lot of time trying to get things working, so I am writing this as a quick how to to set up and run on an debian (wheezy) based system. I could not get my GPU to work with OpenCl since it is not recent enough so was limited to using the CPU.
My experienceFirst I read some documents at Part-OpenCL-Portable-Parallelism and Introductory-Tutorial-to-OpenCL which interested me greatly, this is where I started to get bogged down in jargon however and it took a while to work out exactly what was going on.
A brief synopsis of OpenClOpenCl is a library that enables a program to compile another program so that it can be run on various hardware be it a GPU or CPU on some system or other, it is designed to make use of parallel execution and optimize for the type of program i.e. data parallel or task parallel.
A typical example program uses the OpenCl library which needs to be installed on the compiling computer.
The program can check using the OpenCl library API which devices the host can supply, such as your graphics card or local cpu.
Each of these devices must have a driver installed which in effect maps the opencl program API to the native code on the GPU or CPU (or mixture of both depending on the capabilities of the devices). OpenCl also needs a loader to load these device drivers.
The program then loads the other program source which looks similar to C99 code, it generally has a .cl extension.
It then compiles this source code into a kernel for the devices that the host has available. It then queues the kernel to be run by the devices, and communicates with the devices or threads using events to send in data or receive data.
The problemsHere I list the problems I had whilst trying out various samples. I had opened synaptic package manager on my linux box:
Linux zelazny 3.2.0-4-686-pae #1 SMP Debian 3.2.57-3 i686 GNU/Linux Debian Wheezy version 7.5
and installed the following packages:
I then went through one of the example programs listed above. example
Before compiling I made sure I had the cl.hpp file referenced available here: http://www.khronos.org/registry/cl/
All ok so far.
- Compiling did not go as well.
#error \"SSE2 instruction set not enabled\"
So I added -msse2 to the gcc command line. This activated the SSE2 instructions set for my cpu in gcc. Problem solved. Next...
’ has no member named ‘resize’
At the top of the file with the define
#define __NO_STD_VECTORwe are telling the OpenCl to use it\'s own internal cl::vector not the std::vector that comes with the standard libraries.
The compiler is telling us that the vector we are attempting to use does not have the resize method defined.
Delving into the header file we find the following
#if !defined(__NO_STD_VECTOR) #include <vector> #endifand a bit further down
/*! \\class vector * \\brief Fixed sized vector implementation that mirroring * * \\note Deprecated. Please use std::vector as default or * re-define the vector class to match the std::vector * interface by defining VECTOR_CLASS * \\note Not recommended for use with custom objects as * current implementation will construct N elements * * std::vector functionality. * \\brief Fixed sized vector compatible with std::vector. * * \\note * This differs from std::vector<> not just in memory allocation, * but also in terms of when members are constructed, destroyed, * and assigned instead of being copy constructed. * * \\param T type of element contained in the vector. * * \\param N maximum size of the vector. */so it has been deprecated and we should use std::vector as default so remove the offending line at the top. Try recompiling...
error: ‘vector’ is not a member of ‘cl’So change the example references to cl::vector to std::vector.... and recompile...
Success!!!! Run the program ./hello
ERROR: cl::Platform::get (-1)Bringing me down to earth with a bump. After a quick internet search. it appears
02:00.0 VGA compatible controller: NVIDIA Corporation NV41 [Quadro FX 3450/4000 SDI] (rev a2)my graphics card will not work with opencl.
But I though it was supposed to work on CPU\'s as well as GPU\'s?? Well it does you just have to get the driver for the CPU you have.
So after a bit more delving around I found this amd-app which is only available for Linux® (openSUSE™ 11.*, Ubuntu® 10.0*, Red Hat® Enterprise Linux® 6.*) currently. It appears to have what you need to run kernels on both amd GPU\'s and CPU\'s.
I did not try to download it though (I may experiment in future) since I have been in dependancy hell before and didn\'t fancy a revisit.
After another few searches I found this OpenCLHowTo following the instructions under \"Installing the AMD ICD loader and CPU ICD (from the driver package--probably unsupported)\".
I went to the AMD driver site and downloaded a driver for Linux of a FirePro graphics card. I unzipped it. Ran the executable and searched for and copied the libamdocl32.so binary to my development folder. I noticed there was a 64-bit version there as well. Continuing to follow the instructions I added an icd file to /etc/OpenCL/vendors as amd.icd with the text \"/path/to/libamdoc32.so\" inside.
./hello Platform number is: 1 Platform is by: Advanced Micro Devices, Inc. Hello WorldSuccess!!! since the nvidia packages were doing \"not a lot\" I removed them recompiled and tested and all seemed to work.
The Distilled Steps
First install relevant packages.
- Get some example code (in fact there is some in the cl.hpp file) and compile it, in my case g++ -msse2 -o hello hello.cpp -lOpenCL
Get a recent driver for an AMD graphics card. Even if you don\'t have an AMD graphics card.
unpack the whole lot and find the libamdocl32.so file and copy it somewhere usefull.
- Create a file under /etc/opencl/vendors/ called amd.icd and edit it inserting the path to the libamdocl32.so file.
I hope this has been helpful to somebody, and thanks to the authors of the articles I link to for their help.
Back to work.......