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: https://launchpad.net/~fajran/+archive/opencl

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 http://ppa.launchpad.net/fajran/opencl/ubuntu lucid main
deb-src http://ppa.launchpad.net/fajran/opencl/ubuntu 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:

wget http://developer.amd.com/Downloads/AMD-APP-SDK-v2.6-lnx64.tgz
tar zxvf AMD-APP-SDK-v2.6-lnx64.tgz
chmod +x Install-AMD-APP.sh
./Install-AMD-APP.sh
tar zxvf icd-registration.tgz
sudo cp -r etc/OpenCL/* /etc/OpenCL/

(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 libboost1.38-dev or libboost1.40-all-dev

sudo apt-get install python-setuptools python-numpy libboost1.40-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 configure.py \
  --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 \
  --cl-libname=OpenCL

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

$ cd pyopencl-VERSION # if you're not there already
$ python configure.py \
  --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 \
  --cl-libname=OpenCL

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 configure.py command converts the command line arguments in a siteconfig.py configuration file. You can later edit it, if necessary. You should delete it if you want to run configure.py again.

Now type:

$ make
$ sudo make install

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

cd examples
python demo.py

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:

wget http://developer.amd.com/Downloads/AMD-APP-SDK-v2.6-lnx64.tgz
tar zxvf AMD-APP-SDK-v2.6-lnx64.tgz
chmod +x Install-AMD-APP.sh
./Install-AMD-APP.sh
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

wget http://pypi.python.org/packages/source/p/pyopencl/pyopencl-2011.2.tar.gz
tar xfz pyopencl-2011.2.tar.gz
cd pyopencl-2011.2/
python configure.py                            \
   --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         \
   --cl-libname=OpenCL
make
sudo make install
cd examples
python demo.py

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/benchmark.py

which gave me the error

clRetainDevice, version OPENCL_1.2 not defined in file libOpenCL.so.1

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

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

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

clGetPlatformIDs failed: platform not found khr

which was solved by

#echo libnvidia-opencl.so.1 >> /etc/OpenCL/vendors/nvidia.icd


CategoryPyOpenCl

PyOpenCL/Installation/Linux/Ubuntu (last edited 2014-01-19 15:04:03 by AndreasKloeckner)