Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Theano to use the GPU

I am having quite a bit of trouble setting up Theano to work with my graphics card - I hope you guys can give me a hand.

I have used CUDA before and it is properly installed as would be necessary to run Nvidia Nsight. However, I now want to use it with PyDev and am having several problems following the 'Using the GPU' part of the tutorial at http://deeplearning.net/software/theano/install.html#gpu-linux

The first is quite basic, and that is how to set up the environment variables. It says I should 'Define a $CUDA_ROOT environment variable'. Several sources have said to create a new '.pam_environment' file in my home directory. I have done this and written the following:

CUDA_ROOT = /usr/local/cuda-5.5/bin
LD_LIBRARY_PATH = /usr/local/cuda-5.5/lib64/lib

I am not sure if this is exactly the way it has to be written - apologies if this is a basic question. If I could get confirmation that this is indeed the correct place to have written it, too, that would be helpful.

The second problem is in the following part of the tutorial. It says to 'change the device option to name the GPU device in your computer'. Apparently this has something to do with THEANO_FLAGS and .theanorc, but nowhere am I able to find out what these are: are they files? If so where do I find them? The tutorial seems to be assuming some knowledge that I don't have!

Thanks for taking the time to read this: any and all answers are greatly appreciated - I am very much completely stuck at the moment!

like image 376
Boyentenbi Avatar asked Aug 10 '13 18:08

Boyentenbi


2 Answers

On Linux/OSX:

Edit or create the file ~/.theanorc. The file should contain:

[global]
floatX = float32
device = gpu0

[nvcc]
fastmath = True

[cuda]
root=/usr/local/cuda-5.5/  
# On a mac, this will probably be /Developer/NVIDIA/CUDA-5.5/

You need to add cuda to the $LD_LIBRARY_PATH variable. If you're running eclipse, you can go to Project properties > Interpreters > Configure and interpreter ... > Environment, and then add an LD_LIBRARY_PATH variable that points to your cuda lib folder (probably /Developer/NVIDIA/CUDA-5.5/lib64)

Now when you import theano it should print a message about finding the gpu. You can run the test code at http://deeplearning.net/software/theano/tutorial/using_gpu.html to see if it's using the gpu.

like image 63
Peter Avatar answered Sep 21 '22 11:09

Peter


THEANO_FLAGS is an environment variable and .theanorc is a configuration file. You can use both mechanism to configure Theano. This is described here.

I never heard of the .pam_environment file. Also, you shouldn't just override the value of LD_LIBRARY_PATH, but append/prepend to it like this:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-5.5/lib64/lib

For Theano, if you define CUDA_ROOT, you don't need to modify LD_LIBRARY_PATH, so I would just remove the last line.

Normally, if your shell is bash, people define the env variable CUDA_ROOT in the .bashrc file like this:

export CUDA_ROOT=/usr/local/cuda-5.5/bin

The change to .bashrc will only be used if you log out and log it again.

like image 37
nouiz Avatar answered Sep 20 '22 11:09

nouiz