PyOpenCL in Ubuntu repositories

Ubuntu Maverick Meerkat (10.10) contains PyOpenCL packages for architectures amd64 and i386 in multiverse. Package is called python-pyopencl and depends on NVIDIA drivers.

For Ubuntu Lucid Lynx (10.04 LTS) there is PPA with backported python-pyopencl packages:

To be able to install PyOpenCL in Lucid Lynx you can:

Add ppa:fajran/opencl to the Software Sources

or add following lines to the software sources list /etc/apt/sources.list:

deb lucid main
deb-src lucid main

Installing PyOpenCL on Ubuntu

These instructions were originally written for Ubuntu 9.10 but have been updated for Ubuntu 11.04. Older versions work just like this, except for a changed boost version number. You may also look at the generic instructions if you'd like to install manually.

Step 0: Install OpenCL

There are many sources for the OpenCL SDK. Here we use the AMD source. Runs on any x86 64bit platform:

Download AMP APP from here after accepting licence and run

tar zxvf AMD-APP-SDK-v[version]-lnx64.tgz
sudo ./

(there may be ldconfig errors, they can be ignored)

Step 1: Install Boost and numpy

Use synaptic or apt-get to install python-setuptools python-numpy and libboost1.55-all-dev

sudo apt-get install python-setuptools python-numpy libboost1.55-all-dev

Step 2: Download and unpack PyOpenCL

Download PyOpenCL and unpack it:

$ tar xfz pyopencl-VERSION.tar.gz

Step 3: Build PyOpenCL

For the AMD Stream (64bit)

$ cd pyopencl-VERSION # if you're not there already
$ python \
  --boost-inc-dir=/usr/include/boost \
  --boost-lib-dir=/usr/lib \
  --no-use-shipped-boost \
  --boost-python-libname=boost_python-mt-py26 \
  --cl-inc-dir=/opt/AMDAPP/include \
  --cl-lib-dir=/opt/AMDAPP/lib/x86_64 \

If instead of the AMD SDK, you have the ATI Stream (64bit) beta4-implementation:

$ cd pyopencl-VERSION # if you're not there already
$ python \
  --boost-inc-dir=/usr/include/boost \
  --boost-lib-dir=/usr/lib \
  --no-use-shipped-boost \
  --boost-python-libname=boost_python-mt-py26 \
  --cl-inc-dir=/etc/ati-stream-sdk-v2.0-beta4-lnx64/include \
  --cl-lib-dir=/etc/ati-stream-sdk-v2.0-beta4-lnx64/lib/x86_64 \

If you want to compile in 32bit, change the cl-lib-dir from x86_64 to x86. You Should you also change -lnx64 to lnx32 in ati-stream-sdk-v2.0-beta4-lnx64.

The command converts the command line arguments in a configuration file. You can later edit it, if necessary. You should delete it if you want to run again.

Even writing the code above, some parameters are not always well taken into account on configuration file, you may need to edit it with your favourite text editor.

Now type:

$ make
$ sudo make install

Now you should be done with compiling and installing. You can test it with

cd examples

Putting it all together

Here is a complete script starting from scratch for downloading, configuring, and installing OpenCL and pyOpenCL, and running the examples. Tested a x86_64 Ubuntu 11.04:

tar zxvf AMD-APP-SDK-v2.6-lnx64.tgz
chmod +x
tar zxvf icd-registration.tgz
sudo cp -r etc/OpenCL/* /etc/OpenCL/
rm -r etc

sudo apt-get install python-numpy libboost1.40-all-dev python-setuptools

tar xfz pyopencl-2011.2.tar.gz
cd pyopencl-2011.2/
python                            \
   --boost-inc-dir=/usr/include/boost          \
   --boost-lib-dir=/usr/lib                    \
   --no-use-shipped-boost                      \
   --boost-python-libname=boost_python-mt-py26 \
   --cl-inc-dir=/opt/AMDAPP/include/           \
   --cl-lib-dir=/opt/AMDAPP/lib/x86_64         \
sudo make install
cd examples

Additional Notes (Dell Inspiron laptop with Intel and Nvidia cards)

I am using Ubuntu 12.04 on a Dell Inspiron laptop. I needed to install bumblebee in order to use the Nvidia graphics card. In order to run tests, I needed to do

optirun python examples/

which gave me the error

clRetainDevice, version OPENCL_1.2 not defined in file

It turns out optirun redefines my LD_LIBRARY_PATH so now I pick up from /usr/lib/nvidia-current/ where I want the one from /usr/lib/x86_64-linux-gnu/ Once I moved it, for example with

#mv /usr/lib/nvidia-current/{,.1}

running the benchmark (under optirun, don't forget) gave me

clGetPlatformIDs failed: platform not found khr

which was solved by

#echo >> /etc/OpenCL/vendors/nvidia.icd


PyOpenCL/Installation/Linux/Ubuntu (last edited 2015-06-22 09:21:05 by ::ffff:130)