Make sure you have installed Nvidia drivers and cuda toolkit on your system. Also follow caffe setup for preliminary setup of libraries.
Step 1: Install Dependencies
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev liblapack-dev gfortran git
Step 2: Now Install Theano
sudo pip install Theano
Step 3: Work around for a glibc bug
echo -e "\n[nvcc]\nflags=-D_FORCE_INLINES\n" >> ~/.theanorc
Step 4: ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.
Open file “gedit ~/.theanorc” add edit the path to CUDA root:
[nvcc] flags=-D_FORCE_INLINES [cuda] root = /usr/local/cuda-8.0
Step 5: Install Libgpuarry
Libgpuarry: Required for GPU/CPU code generation on CUDA and OpenCL devices
For the stable version of Theano you need a specific version of libgpuarray, that has been tagged
v0.6.2. Download it with:
git clone https://github.com/Theano/libgpuarray.git cd libgpuarray git checkout tags/v0.6.2 -b v0.6.2
mkdir Build cd Build # you can pass -DCMAKE_INSTALL_PREFIX=/path/to/somewhere to install to an alternate location cmake .. -DCMAKE_BUILD_TYPE=Release # or Debug if you are investigating a crash make sudo make install cd ..
# This must be done after libgpuarray is installed as per instructions above. python setup.py build sudo python setup.py install
If installed globally under Linux (in /usr/local), you might have to run:
Step 6: Testing Theano with GPU
Download this python script Theano Testing with GPU save it in a file called
Test Theano in GPU mode
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python TheanoGPU_Test.py
Optional if you want to compare GPU performanace against a regular CPU, you just need to adjust one parameter to measure the time this script takes when run on a CPU.
Test Theano in CPU mode
THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python TheanoGPU_Test.py
ERROR (theano.sandbox.gpuarray): pygpu was configured but could not be imported
Install libgpuarray and pygpu, as per this instructions provided above for libgpuarray.
Step 7: Install Keras
sudo pip install keras #Could it get any easier!! Thanks to developers of Keras!
- For learning how to use theano with GPU read this post
- Learn more about keras