Installing PyCUDA on Linux

You're looking at the generic, distribution-independent instructions for installing PyCUDA. You may be able to save a fair bit of work by using these distribution-specific instructions:

This tutorial will walk you through the process of building PyCUDA. To follow, you really only need four basic things:

Step 1: Download and unpack PyCUDA

Download PyCUDA and unpack it:

$ tar xfz pycuda-VERSION.tar.gz

Step 2: Install Numpy

PyCUDA is designed to work in conjunction with numpy, Python's array package. Here's an easy way to install it, if you do not have it already:

$ cd pycuda-VERSION
$ su -c "python distribute_setup.py" # this will install distribute
$ su -c "easy_install numpy" # this will install numpy using distribute

(If you're not sure, repeating these commands will not hurt.)

Step 3: Build PyCUDA

Next, just type:

$ cd pycuda-VERSION # if you're not there already
$ python configure.py --cuda-root=/where/ever/you/installed/cuda
$ su -c "make install"

Also note that you will (probably) have to change the value of :option:--cuda-root. If you want to install PyCUDA to your home folder, you need to edit the setup.py call in the Makefile by appending for example "--home=/home/username/local" to the line after the install directive. Make sure that the lib/python folder under the folder you specified is also in PYTHONPATH.

Once that works, congratulations! You've successfully built PyCUDA.

Note that this step may automatically look for and, if necessary, install a number of Python packages from the Python package index. These packages are listed under install_requires in PyCUDA's install control file.

Step 4: Test PyCUDA

If you'd like to be extra-careful, you can run PyCUDA's unit tests:

$ cd pycuda-VERSION/test
$ python test_driver.py

If it says "OK" at the end, that means your installation of PyCUDA was successful. Reward yourself by checking out the tutorial.

Optional: Boost C++ Libraries

As of version 0.94, the Boost C++ libraries are no longer a dependency of PyCUDA.

If you would like to use multiple packages that use Boost.Python (e.g. both PyCUDA and PyOpenCL), you can still build PyCUDA against a separate Boost installation. If so, follow the BoostInstallationHowto. Continue here when you're done.

$ cd pycuda-VERSION # if you're not there already
$ python configure.py \
  --boost-inc-dir=$HOME/pool/include/boost-1_35 \
  --boost-lib-dir=$HOME/pool/lib \
  --boost-python-libname=boost_python-gcc42-mt \
  --boost-thread-libname=boost_thread-gcc42-mt (0.93 and above only) \
  --cuda-root=/where/ever/you/installed/cuda
$ su -c "make install"

Note that gcc42 is a compiler tag that depends on the compiler with which you built boost. Check the contents of your boost library directory to find out what the correct tag is.

Contributed Helper Script

A simple script do deal with: * a littlesome ambiguity in the names and directory locations * beware cuda does not accept gcc-4.5, get and symlink to v4.4

rm siteconf.py
./configure.py \
        --boost-inc-dir=/usr/include/boost \
        --boost-lib-dir=/usr/lib64 \
        --boost-python-libname=boost_python-mt \
        --cudadrv-lib-dir=/usr/lib64 \
        --cudart-lib-dir=/usr/local/cuda/lib64 \
        --cudart-libname=cudart \
        --cuda-root=/usr/local/cuda \
        --boost-thread-libname=boost_thread-mt \
        --no-cuda-enable-curand

* Also note how the library names do not have eithe rh the usual prefix "lib" nor any extension whatsoever * It simply could not find curand ... effectiveness of the --cuda-root (which is where it is most usually, along with libcudart) doubted.


CategoryPyCuda