Stefano Cappellini

I teach machines how to learn – ML, DeepLearning, AI, Math lover, BCompSc

Deep Learning: How to install an Ubuntu machine with a GTX 1080 Ti

Written on

Hi there! Last month I finally completed my first Deep Learning, TensorFlow machine (an old pc pimped with Ubuntu, some ram and a fantastic GTX 1080 Ti). The installation is substantially easy, if you know what you are doing. However there are some steps that for a Mac user like me could be troublesome. So, here is how to do a completely clean install.

Some important notes

  • This is not a guide, it is more like a set of tips I write here for future reference and to help. I do not know if this is the best way to install all this stuff. Some initial steps could differ if you are not a mac user.
  • I am going to consider TensorFlow 1.2 which requires CuDNN version 5 (sadly!). Soon TensorFlow 1.3 will be released and that one will use CuDNN 6!

Edit history

  • 03-Ago-2017: created
  • 06-Ago-2017: big changes. Version numbers are clearly stated, the steps order is changed and code is easier to read

Sections

Let's begin! Ubuntu installation

  1. First of all, let's download Ubuntu.  At the time of writing there are two versions available: 16.04LTS and 17.04. I suggest the 16.04LTS. LTS stands for Long Term Support, which in short means that you will not have to worry about updating your machine too soon, you will receive all the necessary security and bug-fixing updates. This version is the best if, like me, you are building an hard-working, pragmatic machine. So, go here and pick the LTS version
  2. Now let's create a bootable usb stick. Here the best thing to do is to follow this guide (there are also guides for Windows and for Ubuntu too)
  3. Connect the usb stick to the fully-mounted pc and turn it on, booting from the usb device you created before. Now, the first problem: if you try to start Ubuntu you will end up with a terrible "pink" screen. What the heck? This is due to Ubuntu that is trying to load video driver too early at kernel level. Sadly this does not work with our 1080Ti. Here is the work-around
    1. In the UNetbootin boot menu, press the TAB key
    2. Add nomodeset before quiet splash - - -, obtaining
      nomodeset quiet splash - - -
  4. Now, complete the Ubuntu installation. The computer will reboot
  5. During the startup, press the SHIFT key, to enter in the GRUB menu
  6. Now press the "e" key to edit the launch configuration. In the text displayed, find again the "quiet splash" string and add nomodeset before it, obtaining
    nomodeset quiet splash 
    Then start Ubuntu. Everything should work fine

Fix the nomodeset forever

  1. Open the grub configuration file:
    sudo nano /etc/default/grub
  2. Add nomodeset to the GRUB_CMDLINE_LINUX_DEFAULT, obtaining:
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"
  3. Save (CTRL + O) and exit (CTRL + X)
  4. Then run
    sudo update-grub
  5. Restart the computer
  6. Done!!! Thanks to this answer

Nvidia driver

  1. Now the fun stuff. First thing, download the Nvidia driver for the 1080Ti (from here). It is a .run file.
  2. Make the downloaded file executable, with the command
    chmod +x <filename>
  3. Now, stop the X serve (the GUI) using the command:
    sudo service lightdm stop
  4. Wow, the screen is completely black. Now you have to open a shell. Try CTRL + ALT + [a key from F1 to F7]. A shell should appear. Do the login
  5. Now, using the shell locate the downloaded Nvidia file and run it (if you are in the same directory, do
    sudo ./<filename>
  6. Choose to update the X configuration
  7. When finished, relaunch the X serve:
    sudo service lightdm start

CUDA Toolkit

  1. Now, download Cuda version 8 from Nvidia: choose your system type and then Ubuntu. It should be a .run file
  2. Make again the file executable with the command
    chmod +x <filename>
  3. Run it. Again, if you are in the same directory, do
    sudo ./<filename>
  4. DO NOT INSTALL the drivers (we have installed them before). Install just the CUDA toolkit. Leave all the settings to their default. Add symlinks. Do not install examples

The Deep Learning library: CuDNN

  1. Download CuDNN from Nvidia. A registration is required.
  2. Attention: download the linux file (not the Ubuntu one!!!!!)
  3. Attention: download the 5.1 version
  4. Locate the downloaded file (should be a .tgz).
  5. Let's extract it:
    tar -xvzf <filename>
  6. Now, let's copy the extracted files:
  7. sudo cp -P cuda/include/cudnn.h /usr/local/cuda/include
    sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
    sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
    

Anaconda

  1. Download Anaconda for Linux (a .sh file) from here
  2. Execute it WITHOUT USING THE SUDO COMMAND: 
    bash <filename>.sh
  3. Done!!! Please note that Anaconda is not strictly required in order to do some Deep Learning stuff. However, I think< it is worth trying because it makes the life so easy by managing all the packages behind the scene./li>

TensorFlow

To install tensorflow-gpu, simply follow the guide here. To summarize:

  1. First grab here the last Tensorflow GPU version (1.2 for this guide) url. At the moment of writing the url is this one
  2. Do:
    pip install --ignore-installed --upgrade <here the url>
  3. Note: there are so many good Deep Learning frameworks. Here I have considered only TensorFlow, but everything should work well even with other frameworks

Path and other

Now, the last edit.
  1. Do:
    pico ~/.bashrc
  2. Go to the end of the file and locate the comment line "# added by Anaconda3 ..."
  3. Immediately after this line add this new line:
    export CUDA_HOME=/usr/local/cuda
  4. After this new line, there is a single line like this:
    export PATH="/home/username/anaconda3/bin:$PATH"
  5. Edit this line to obtain (be careful with the various colons!!!!):
    export PATH="/home/username/anaconda3/bin:$CUDA_HOME:$PATH"
  6. After this line add another line:
    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$CUDA_HOME/lib64"
  7. The final result should be:
    
    export CUDA_HOME=/usr/local/cuda
    export PATH="/home/username/anaconda3/bin:$CUDA_HOME:$PATH"
    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$CUDA_HOME/lib64"
    
  8. Remember: you have to open a new Terminal window in order to see these edits

A tip

Sometimes numpy can give problems. A good thing to do before start playing with TensorFlow is to update it:

conda update numpy

Let's try it

Everything should work like a charm! To check if everything is working open a Terminal and start an Ipython session. Then type this:


import tensorflow as tf
tf.Session().run(tf.constant(2))

Everything should work fine!

And that is it! Everything should work fine! Now you can do some Deep Learning stuff :) This post will be updated to improve its quality and to add everything useful I will discover in this long run. Have fun!

comments powered by Disqus