Documenting the steps how to setup Theano to run on GPU on Ubuntu 14.04 so I can refer to this in the future. With this successfully installed, you can run Keras, convnet, Theano, etc properly.
Have you ever met those painful issues just trying to setup your GPU for scientific programming:
-
Getting a blinking cursor after installing the “latest� Nvidia drivers?
-
Getting a blinking cursor after installing the “latest� CUDA toolkit?
-
Login loop in Ubuntu login screen?
-
NVRM: rm_init_adapter(0) failed?
-
NVIDIA: could not open the device file /dev/nvidia0 (input/output error)
-
…
If yes, then read on.
I cannot guarantee your OS does not break after running the steps below, so please backup everything, run as your own risk.
You may want to read the Things That Does Not Work For Me part below first before following the instructions.
My server has the following specifications:
-
OS: Ubuntu 14.04 LTS, X64
-
GPU: Nvidia Geforce GTX 780
-
Fresh install of Ubuntu 14.04 LTS
If you fail in the middle of any of this steps, you are advised to restart and follow the steps carefully again. Use common sense. and if you don’t know how to fix it, too bad,
-
Download latest (or very recent) Nvidia display driver for Linux:
-
Download latest (or very recent) CUDA Installation Run file for Ubuntu 14.04:
-
Get into recovery mode to install the files, because you cannot install your display driver with X server on.
Once you are in GRUB, select “Advanced Options for Ubuntu�.
In the recovery mode, select “network�, press yes. Once the networking has been enabled, this will also set your drive to read/write mode.
-
In the recovery mode, select “root� to get a root prompt.
-
Go to where you downloaded the previous files at, and run NVIDIA-Linux-x86_64-352.63.run.
For yes/no questions, take “yes�. For locations, press “enter� to take default values.
- Setup your environment variables.
Make sure your LD_LIBRARY_PATH, LIBRARY_PATH and PATH includes the places it needs to include:
Don’t forget to:
- Run nvidia-smi to confirm that your setup is correct.
nvidia-smi should be on your path already, so this should work. If it doesn’t:
-
You must have done something wrong, better go back to step 1. and do it all over again.
-
You can see if it’s at /usr/bin/nvidia-smi .
You should then see something similar to this:
- Go to where you downloaded the previous files at, and run cuda_7.5.18_linux.run .
For yes/no questions, take “yes�. For locations, press “enter� to take default values.
- Re-run nvidia-smi just to be sure everything is still working well.
You should then (again) see something similar to this:
-
Reboot now back to desktop.
-
Time to install Theano and python, basically the first part of this guide. Run the following commands:
-
Copy and paste the below code into check1.py. Now we need to make sure GPU is indeed working. I am copying the instructions from deeplearning.net.
-
Run the check1.py to confirm that Theano is working correctly with CPU.
This should give:
- Run the check.py to confirm that Theano is working correctly with GPU.
This should give:
Note that: computation time has decreased, and it is indeed using GPU now.
-
Done! If you reached here and did not meet any issues, I hope you can comment and confirm that this does help you, so others can trust this guide. If you have still spent hours/days, blame Linux. =]
-
Installing current nvidia drivers from apt-get.
Normally you would think apt-get install the latest nvidia drivers would be the best to go. Nope, after the installation 1) nvidia-smi does not work 2) I cannot get back into desktop 3) get error messages like RmInitAdapter failed in dmesg 4) no monitor found in /var/log/Xorg.0.log
- Install CUDA from apt-get.
The same as 1., equally disastrous: 1) nvidia-smi does not work 2) I cannot get back into desktop 3) get error messages like RmInitAdapter failed in dmesg 4) no monitor found in /var/log/Xorg.0.log
- Installing current nvidia from another “defacto� repository.
The same as 1., equally disastrous: 1) nvidia-smi does not work 2) I cannot get back into desktop 3) get error messages like RmInitAdapter failed in dmesg 4) no monitor found in /var/log/Xorg.0.log
- Anything about Bumblebee.
Not sure what this is, just not related. Forget about it.
-
Also, I don’t have advice trying to repair a broken Ubuntu if you did anything of the above. But maybe you can try removing nvidia drivers and reinstalling the desktop, but doesn’t work for me either.
-
Using any nvidia driver like 340 or 304 version. They do not work.
The only thing that works for me is a fresh reinstall of Ubuntu 14.04. Nothing else.
The installation guide from DeepLearning.net is very helpful, but it contains poison advice that messed up my display of my OS completely.
BTW, ever heard of “Linux is user-friendly but it is very selective of its friends.�? I know I am certainly not its friend… 😉