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](PyCuda/Installation/Linux) if you'd like to install manually. [../Debian](PyCuda/Installation/Linux/Debian) generally is very similar to Ubuntu, so those instructions might work, too. Bonus: There are pre-built binary packages on that page.
Ubuntu 16.04 comes with CUDA support through the repositories: install nvidia-cuda-toolkit, nvidia-cuda-dev and python-pycuda using apt-get.

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 1: 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](PyCuda/Installation/Linux) if you'd like to install manually. [../Debian](PyCuda/Installation/Linux/Debian) generally is very similar to Ubuntu, so those instructions might work, too. Bonus: There are pre-built binary packages on that page.

Step 2: Install Boost C++ libraries

You may use Ubuntu's built-in Boost C++ library packages by typing


$ sudo apt-get install libboost-all-dev

Boost.Python has supported both Python 2.x and 3.x since 2009.

Step 3: 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 4: 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

[[!PyPi pycuda desc="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-py27 --boost-thread-libname=boost_thread
$ make -j 4
$ sudo python setup.py install
$ sudo pip install .

On Ubuntu 14.04 64bit version the command should be (boost lib folder and files changed) # For Python 2.x $ ./configure.py --cuda-root=/usr/local/cuda --cudadrv-lib-dir=/usr/lib/x86_64-linux-gnu --boost-inc-dir=/usr/include --boost-lib-dir=/usr/lib --boost-python-libname=boost_python --boost-thread-libname=boost_thread --no-use-shipped-boost (if still not works try to locate boost library files and change accordingly, libraries start with lib and end with .so e.g libboost_python.so but they should not be specified in the name) # For Python 3.4 $ ./configure.py --python-exe=/usr/bin/python3 --cuda-root=/usr/local/cuda --cudadrv-lib-dir=/usr/lib/x86_64-linux-gnu --boost-inc-dir=/usr/include --boost-lib-dir=/usr/lib --boost-python-libname=boost_python-py34 --boost-thread-libname=boost_thread --no-use-shipped-boost The -mt suffix after boost_python had been removed because the installed Boost libraries are multi-threading safe.

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: * If you are not installing PyCUDA 0.93 or above, remove the ```--boost-thread-libname=boost_thread-mt``` * Modify ```--cuda-root=/usr/local/cuda``` if cuda is not installed in ```/usr/local/cuda``` . * 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 * 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 * 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 * 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``` * Don't forget to include the cuda library directories '${CUDA_ROOT}/lib', '${CUDA_ROOT}/lib64' to LD_LIBRARY_PATH variable.

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


CategoryPyCuda CategoryPyCuda CategoryPyCuda