I tried to follow the instructions on Easy Installation of an Optimized Theano on Current Ubuntu but it doesn't work: whenever I run a Theano script using GPU, it gives me the error message:
CUDA is installed, but device gpu is not available (error: Unable to get the number of gpus available: no CUDA-capable device is detected)
More specifically, following the instructions in the linked webpage, I executed the following steps:
# Install Theano
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
sudo pip install Theano
# Install Nvidia drivers and CUDA
sudo apt-get install nvidia-current
sudo apt-get install nvidia-cuda-toolkit
Then I rebooted and tried running:
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python gpu_test.py # gpu_test.py comes from http://deeplearning.net/software/theano/tutorial/using_gpu.html
But I get:
f@f-Aurora-R4:~$ THEANO_FLAGS=’mode=FAST_RUN,device=gpu,floatX=float32,cuda.root=/usr/lib/nvidia-cuda-toolkit’ python gpu_test.py WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available (error: Unable to get the number of gpus available: no CUDA-capable device is detected) [Elemwise{exp,no_inplace}(<TensorType(float32, vector)>)] Looping 1000 times took 2.199992 seconds Result is [ 1.23178029 1.61879337 1.52278066 ..., 2.20771813 2.29967761 1.62323284] Used the cpu
(I tested the following on Ubuntu 14.04.4 LTS x64 and Kubuntu 14.04.4 LTS x64, I guess it should work on most Ubuntu variants)
Installing Theano and configuring the GPU (CUDA)
The instructions on the official website are outdated. Instead you can use the following instructions (assume a freshly installed Kubuntu 14.04 LTS x64):
At that point, running
nvidia-smi
should work, but runningnvcc
won't work.At that point, both
nvidia-smi
andnvcc
should work.To test whether Theano is able to use the GPU:
Copy-paste the following in
gpu_test.py
:and run it:
which should return:
To know your CUDA version:
Example:
Adding cuDNN
To add cuDNN (instructions from http://deeplearning.net/software/theano/library/sandbox/cuda/dnn.html):
tar -xvf cudnn-7.0-linux-x64-v3.0-prod.tgz
Option 1: Copy the
*.h
files toCUDA_ROOT/include
and the*.so*
files toCUDA_ROOT/lib64
(by default,CUDA_ROOT
is/usr/local/cuda
on Linux).Option 2:
By default, Theano will detect if it can use cuDNN. If so, it will use it. If not, Theano optimizations will not introduce cuDNN ops. So Theano will still work if the user did not introduce them manually.
To get an error if Theano can not use cuDNN, use this Theano flag:
optimizer_including=cudnn
.Example:
To know your cuDNN version:
Adding CNMeM
The CNMeM library is a "Simple library to help the Deep Learning frameworks manage CUDA memory.".
To use with Theano, you need to add the
lib.cnmem
flag. Example:The first output of the script should be:
lib.cnmem=0.8
means that it can use up to 80% of the GPU.CNMeM has been reported to give some interesting speed improvements, and is supported by Theano, Torch, and Caffee.
Theano - source 1:
Theano - source 2:
Running Theano on multiple CPU cores
As a side note, you can run Theano on multiple CPU cores with the
OMP_NUM_THREADS=[number_of_cpu_cores]
flag. Example:The script
theano/misc/check_blas.py
outputs information regarding which BLAS is used:To run Theano's test suite:
or
Common issues: