Installing PyCUDA on Ubuntu Linux

These instructions were written for Ubuntu 9.04 and also work for Ubuntu 10.04, 10.10 and 11.04. Ubuntu 8.10 works 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.

../Debian generally is very similar to Ubuntu, so those instructions might work, too. Bonus: There are pre-built binary packages on that page.

Step 0: Ensure that CUDA is installed and settings are correct

You'll need $CUDA_ROOT set to the root of the CUDA install directory, and $CUDA_ROOT/bin on $PATH.

Step 0: Install gcc4.3 (for Ubuntu 9.10 and 10.04) or gcc4.4 (Ubuntu 11.04)

Ubuntu 9.10 comes with gcc4.4 by default. CUDA 2.3 and 3.0 are incompatible with this version. You'll need to install gcc4.3.

Note that CUDA 3.2/4.0 are compatible with gcc 4.4, so downgrading to gcc 4.3 is not necessary anymore with that CUDA version.

NOTE: For Ubuntu 11.04, the default gcc is gcc 4.5, so you need to install gcc4.4 to work with CUDA 3.2.

$ sudo apt-get install build-essential gcc-4.3 g++-4.3
$ cd /usr/bin
$ sudo ln -sf gcc-4.3 gcc

These instructions were written for Ubuntu 9.04 and also work for Ubuntu 10.04, 10.10 and 11.04. Ubuntu 8.10 works 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.

../Debian generally is very similar to Ubuntu, so those instructions might work, too. Bonus: There are pre-built binary packages on that page.

Step 0: Install gcc4.3 (for Ubuntu 9.10 and 10.04) or gcc4.4 (Ubuntu 11.04)

Ubuntu 9.10 comes with gcc4.4 by default. CUDA 2.3 and 3.0 are incompatible with this version. You'll need to install gcc4.3.

Note that CUDA 3.2 is compatible with gcc 4.4, so downgrading to gcc 4.3 is not necessary anymore with that CUDA version.

NOTE: For Ubuntu 11.04, the default gcc is gcc 4.5, so you need to install gcc4.4 to work with CUDA 3.2.

$ sudo apt-get install build-essential gcc-4.3 g++-4.3
$ cd /usr/bin
$ sudo ln -sf gcc-4.3 gcc

Step 1: Install numpy

You may use Ubuntu's built-in numpy package by typing

$ sudo apt-get install python-numpy -y

or you may install from source if you're aiming for peak (CPU) performance.

Step 2: Download, unpack and install PyCUDA

Install the necessary libraries:

$ sudo apt-get install build-essential python-dev python-setuptools libboost-python-dev libboost-thread-dev -y

Download PyCUDA and unpack it:

$ tar xzvf pycuda-VERSION.tar.gz

Configure, make and install PyCUDA:

$ cd pycuda-VERSION
$ ./configure.py --cuda-root=/usr/local/cuda --cudadrv-lib-dir=/usr/lib --boost-inc-dir=/usr/include --boost-lib-dir=/usr/lib --boost-python-libname=boost_python-mt --boost-thread-libname=boost_thread-mt --no-use-shipped-boost
$ make -j 4
$ sudo python setup.py install

Configure, make and install PyCUDA using Python3.2 (on Ubuntu 12.04): (Note that boost_python-mt becomes boost_python-mt-py32)

$ cd pycuda-VERSION
$ ./configure.py --python-exe=/usr/bin/python3 --cuda-root=/usr/local/cuda --cudadrv-lib-dir=/usr/lib --boost-inc-dir=/usr/include --boost-lib-dir=/usr/lib --boost-python-libname=boost_python-mt-py32 --boost-thread-libname=boost_thread-mt --no-use-shipped-boost
$ make -j 4
$ sudo python3 setup.py install

Some notes:

  1. If you are not installing PyCUDA 0.93 or above, remove the --boost-thread-libname=boost_thread-mt

  2. Modify --cuda-root=/usr/local/cuda if cuda is not installed in /usr/local/cuda .

  3. If you get errors about not being able to find -lboost_python-mt or -lboost_thread-mt, but you know they are in /usr/lib or wherever, make sure the symlinks to those files exist. For example, on Ubuntu 9.10, you might need to make a link libboost_python-mt to libboost_python-mt-py26 (alternatively you can just use --boost-python-libname=boost_python-mt-py26:

    • $ sudo ln -s /usr/lib/libboost_python-mt-py26 /usr/lib/libboost_python-mt
  4. On ubuntu releases using the 'nvidia-current' package (e.g. ubuntu 10.04 Lucid Lynx), you will need to add the following link:
    • $ ln -sf /usr/lib/nvidia-current/libcuda.so /usr/lib/libcuda.so
  5. On ubuntu releases using the 'cuda3.1' package ( ubuntu 10.04 Lucid Lynx), you will need to add the following link:
    • $ sudo ln -s /usr/lib/libboost_python-mt-py26.so /usr/lib/libboost_python-mt.so
  6. When executing: sudo python setup.py install If you got the following error: *** CUDA_ROOT not set, and nvcc not in path. Giving up., sudo might have different PATH value, try the following to resolve: sudo env PATH=$PATH python setup.py install

(Instructions by Nicolas Pinto and Vincent Favre-Nicolin. Please go to the ../../../MailingList for support.)


CategoryPyCuda CategoryPyCuda