Installing CUDA and Theano on Ubuntu 11.04 Natty Narwhal
Theano is a very interesting Python library developed mainly for deep learning, which can run calculations on some NVIDIA GPUs by using the CUDA library. Setting up Theano to use the GPU can be a little tricky and take a bit of work. However, Aaron Haviland has set up a CUDA 4.0 PPA, which makes the installation much simpler.
Install Theano
sudo apt-get install python-numpy libblas-dev liblapack-dev gfortran python-dev python-pip mercurial
sudo pip install --upgrade git+git://github.com/Theano/Theano.git
This will put Theano in /usr/local/lib/python2.7/dist-packages/theano
Install CUDA (requires downgrading gcc to 4.4)
sudo add-apt-repository ppa:aaron-haviland/cuda-4.0
sudo apt-get update sudo apt-get upgrade
sudo apt-get install nvidia-cuda-toolkit g++-4.4 gcc-4.4
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4
sudo update-alternatives --config gcc
Test it out
Now run the sample program under “Putting it all Together” in the Theano tutorial. It will hopefully tell you that it used your GPU.
A good benchmark to test out the speed of your setup is to run /usr/local/lib/python2.7/dist-packages/theano/misc/check_blas.py
Credits
Thanks to James Bergstra for the necessary Theano fix to make it work with the PPA as well as the rest of the Theano developers for providing this very cool library. And also to Andrew Ng, Samy Bengio, and the other Googlers who have been taking their time to teach the rest of us more machine learning concepts.