Brad Barrows home

Installing OpenCL and PyOpenCL on Ubuntu 12.10

The hassle of Intel OpenCL Dev

Trying to mine some damn bitcoin

Fueled by the ridiculous BitCoin bubble and yes, I know, late to the game I decided I might as well start a bitcoin miner on an extra computer or two.

What I didnt expect is the huge pain in the ass that was installing the Intel OpenCL libs/headers..

Ill try to sum this up as quickly as possible:

I started with this guys blog entry on installing OpenCL on ubuntu which

This is directly from his site, slightly modified:


  1. Download the Intel SDK for OpenCL Applications from Intel’s web site. The download options are not easy to spot in the messy page, they are on the top right bo. After downloading, you will end with a .tgz file with an RPM inside (crazy, I know).

The guy who I stole this walk through from says he got the file : intel_sdk_for_ocl_applications_2012_x64.tgz. NOTE!! I actually didnt see this option I downloaded the option with all the check marks for the beta that supported RedHat Linux. I got this file: intel_sdk_for_ocl_applications_2013_xe_beta_sdk_3.0.56860_x64.tgz

  1. Extract the RPM from the .tgz file: $ tar zxvf intel_sdk_for_ocl_applications_2012_x64.tgz

This will extract the intel_ocl_sdk_2012_x64.rpm file.

  1. Convert the RPM file to .deb format and install: $ sudo apt-get install -y rpm alien libnuma1 # In case you don’t have these packages $ fakeroot alien –to-deb intel_ocl_sdk_2012_x64.rpm

The guy says to run:

$ sudo dpkg -i intel-ocl-sdk_2.0-31361_amd64.deb

However you will probably have 4 diff debs. I just ran the following to install them all: sudo dpkg -i .deb

  1. Now the SDK and libraries will be installed to /usr/lib64, while Ubuntu expects them to be in /usr/lib. No problem, just make a symlink and update the library cache: $ sudo ln -s /usr/lib64/libOpenCL.so /usr/lib/libOpenCL.so $ sudo ldconfig

That’s it! OpenCL should be installed now. Let’s try with a test program to see the device capabilities.

#include <iostream>
#include <CL/cl.hpp>
#include <boost/foreach.hpp>

int main(int, char**) {
 std::vector<cl::Platform> platforms;
 cl::Platform::get(&platforms);
 BOOST_FOREACH(cl::Platform platform, platforms) {
     std::cout << "Platform: " << platform.getInfo<CL_PLATFORM_NAME>() << std::endl;
     std::vector<cl::Device> devices;
     platform.getDevices(CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_CPU, &devices);
     BOOST_FOREACH(cl::Device device, devices) {
         std::cout << "Device: " << device.getInfo<CL_DEVICE_TYPE>();
         std::cout << " (" << CL_DEVICE_TYPE_GPU << " means GPU, " << CL_DEVICE_TYPE_CPU << " means CPU)" << std::endl;
     }
 }
}

Save this snippet into opencl.cpp, compile and run: $ g++ opencl.cpp -lOpenCL -o opencl && ./opencl Platform: Intel(R) OpenCL Device: 2 (4 means GPU, 2 means CPU) This shows that this particular machine has one OpenCL-capable Intel CPU.


So continuing on I basically kep trying to compile his example until it succesfully compiled and ran.

So along with installing the libs I needed the headers to do this I made the following dir:

sudo mkdir -p /usr/local/cuda/include/CL
cd /usr/local/cuda/include/CL
sudo wget http://www.khronos.org/registry/cl/api/1.1/cl.hpp
sudo wget http://www.khronos.org/registry/cl/api/1.1/cl.h
sudo wget http://www.khronos.org/registry/cl/api/1.1/opencl.h
sudo wget http://www.khronos.org/registry/cl/api/1.1/cl_platform.h
sudo wget http://www.khronos.org/registry/cl/api/1.1/cl_gl.h
sudo wget http://www.khronos.org/registry/cl/api/1.1/cl_gl_ext.h
sudo wget http://www.khronos.org/registry/cl/api/1.1/cl_ext.h
sudo chmod -R a+r /usr/local/cuda

If you are missing any other headers try looking for the file under the http://www.khronos.org/registry/cl/api/1.1/ directory..

I also installed:

sudo apt-get install libboost-all-dev python-setuptools python-numpy

I actually installed numpy with pip but that should work too..

I downloaded PyOpenCL and ran sudo python setup.py install however it couldnt find the headers.

I actually just added the following line to setup.py, right before the line: INCLUDE_DIRS = conf“BOOST_INC_DIR” + conf“CL_INC_DIR” I added: conf“CL_INC_DIR” = ‘/usr/local/cuda/include/’, ‘/usr/local/cuda/include/CL’

althouh you prob only need that first one..

then running: sudo python setup.py install worked great..

Previous Post: Implementing exception logging in Python - Next Post: Python string bit iterator