Sunday, 16 October 2016

Setting up theano in Ubuntu 14.04 with CUDA

This blog deals with setting up theano in Ubuntu 14.04 with cuda 7.5(latest version is 8.0 presently) .

Requirements :

The gcc version should be 4.8.x and kernel should be 4.2.x. If your gcc is greater than 4.8.X or your kernel is less than 4.2.X, you will face errors while installation or running the code.

To check gcc version : $ gcc -v
To check kernel version : $ uname -r

To check your display drivers use the following command in ubuntu terminal .
$ cat /etc/X11/default-display-manager
Ubuntu Unity has lightdm display managers and gdm display managers .

Your result will be like /usr/sbin/<name of display manager>

1) Download CUDA 7.5 Version from archives . Note download the .run version.

2) check if /etc/X11/xorg.conf exists or not. If yes then delete it
$ sudo rm -rf /etc/X11/xorg.cong

3) Go and Create /etc/modprobe.d/blacklist-nouveau.conf file

$ sudo gedit /etc/modprobe.d/blacklist-nouveau.conf

Copy paste these lines and save it

blacklist nouveau
options nouveau modeset=0

4) sudo update-initramfs -u

5) Reboot your computer and on login screen click ALT+CTRL+F1 . Login in tty1 wih your id.

6) I will assume you have downloaded the cuda in DOWNLOAD folder.

$ chmod a+x ~/Downloads/cuda<version>.run . Name will be according to the download

$ sudo service gdm stop . (you might get a delay of 1-2 minutes)
In case you are using Ubuntu Unity version , use lightdm instead of gdm .

$ sudo bash cuda<version>.run --no-opengl-libs.

Note : You dont have to install opengl-libs .

7)Accept EULA conditions
 Say YES to installing the NVIDIA driver
 SAY YES to installing CUDA Toolkit + Driver
 Say YES to installing CUDA Samples
 Note : Say NO rebuilding any Xserver configurations with Nvidia.

8)Just run the command.
$ sudo modprobe nvidia

9)add lines to environment variables
$ sudo nano ~/.bashrc and add these line at last

export PATH=/usr/local/cuda-7.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH

10)install build-essential
$ sudo apt-get install build-essential

11) Verify DRIVER version and cuda version
$ cat /proc/driver/nvidia/version
$ nvcc -V

12) Now you can switch back to gdm
$ sudo service gdm start
Now you wont be facing any login issues .

13) Log into your system and go to your NVIDIA_CUDA-7.5_Samples folder. If you want to work with examples then you need to make your files . This will take a lot of time and I will suggest everyone to do this in free time. Moreover it is not necessary to do this step .

$ cd path to samples/
$ make
Ideally you shouldn't be getting any errors . Incase you get any errors , google it for solution .

In many cases your will get an error that X library was not found . The best solution is to try sudo apt-get install X . Incase that doesn't works try combinations of X using the TABS button .

PS : If you get lglut cannot be found . Then just install freeglut3-dev to solve the issue .
$ sudo apt-get install freeglut3-dev

14) You can check your installation by running  ./deviceQuery and ./bandwidthTest. This will work if your have completed the 13th step .

$ cd NVIDIA_CUDA-7.5_Samples/bin/x86_64/linux/release/
$ sudo ./deviceQuery

$ sudo ./bandwidthTest
Your GPU should pass these two test.

15) Installation of files for theano .
$ sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ git

16) Install OpenBlas .
$ sudo apt-get install libopenblas-dev

17) Install Theano
$ sudo pip install Theano

18) Create .theanorc File
$ sudo gedit ~/.theanorc
Note: The .theanorc file should contain


fastmath = True

ldflags = -lopenblas

root = /usr/local/cuda-7.5

This is sufficient to work with theano. In case you want to use more tags, you are free to edit the .theanorc file .

Edit 1 :
I tried to install CUDA 8.0 in Ubuntu 14.04 and it installed successfully .

Enjoy Deep Learning
Cheers !

Credits :

1 comment:

  1. I appreciate you taking the time and effort to share your knowledge. This material proved to be really efficient and beneficial to me. Thank you very much for providing this information. Continue to write your blog.

    Data Engineering Services 

    Artificial Intelligence Solutions

    Data Analytics Services

    Data Modernization Services