Skip to content

Instantly share code, notes, and snippets.

@ranr01
Last active March 22, 2021 15:12
Show Gist options
  • Save ranr01/46617b1fd289b5782138f78faf7a0bcd to your computer and use it in GitHub Desktop.
Save ranr01/46617b1fd289b5782138f78faf7a0bcd to your computer and use it in GitHub Desktop.
How to install TensorFlow with GPU support on a Ubuntu Dell Precision 5520

Here we will set up a Ubuntu Dell Precision 5520 with Ubuntu 18.04, and TensorFlow with GPU support.

Information collected from several sources cited below.

  1. Upgrade to Ubuntu 18.04

    1. Open a terminal and start with:

      $ sudo apt update
      $ sudo apt upgrade
      $ sudo apt dist-upgrade
      $ sudo apt-get autoremove
      $ sudo apt install update-manager-core  
      
    2. Make sure the last line in /etc/update-manager/release-upgrades is set to Prompt=LTS

    3. Finally do:

      $ sudo do-release-upgrade
      
  2. Install the NVIDIA driver.
    Here I will setup the driver to a headless mode, i.e. the driver will not handle the graphics of the computer (that will be left to the integrated Intel GPU), but one can still use the NVIDIA GPU for CUDA and TensorFlow.

    1. Download the NVIDIA driver as a run file and make it executable (chmod +x NVIDIA_installer.run)

    2. Remove everything nvidia with apt-get. Something like

      $ sudo apt-get purge nvidia
      

      (maybe a good idea to restart after this one to make sure the Intel graphics driver is working ok)

    3. To install we need to run with no x-server so we change to runlevel 3

      $ sudo init 3
      
    4. Log in to a console and install the driver

      $ sudo ./NVIDIA_installer.run --no-drm --no-opengl-files
      

      the ’no-drm’ makes the installer skip the automatic x-server config and the ’-no-opengl-files’ prevents the replacement of the system’s OpenGL files. If you want to use the driver for graphics you should remove those.
      The installer asks a bunch of questions and you should try and answer them as best you can. I could not get the driver to build using DKMS so I answered no to this question.

    5. Restart and test that you have the driver with

      $ nvidia-smi
      

      which should show you the status of your discrete GPU.

  3. Installing CUDA for Tensorflow

    1. Download the CUDA toolkit from NVIDIA as a run file (if update patches are available download them too). At the time of writing the right CUDA version for TensoFlow 1.10 was CUDA 9.0 for Ubuntu 17.04. It is important to use the CUDA version specified in the TensorFlow documentation (unless you want to build TF from source).

    2. Run:

      $ sudo chmod +x cuda_9.0.176_384.81_linux.run 
      $ ./cuda_9.0.176_384.81_linux.run --override
      

      say yes to installing with an unsupported configuration and no to Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81? (IMPORTANT!)

    3. After the CUDA installation finishes add the following lines to your ~/.bashrc file:

      export PATH=/usr/local/cuda-9.0/bin:${PATH} 
      export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH)
      
    4. run source ~/.bashrc to activate the installation

    5. If there are published patches run-files, run them as well.

    6. To test CUDA you can go into the code sample library and build and run the deviceQuery utility.

  4. Installing cuDNN

    1. Download the right version of cuDNN from Nvidia (as specified in the TensorFlow docs) and that is compatible with your CUDA version.

    2. Install with:

      $ tar -zxvf cudnn-9.0-linux-x64-v7.tgz
      $ sudo cp -P cuda/lib64/* /usr/local/cuda-9.0/lib64/ 
      $ sudo cp  cuda/include/* /usr/local/cuda-9.0/include/
      $ sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h
      
  5. Finally install libcupti with

    $ sudo apt-get install libcupti-dev
    
  6. Install python and TensorFlow.
    There are many ways to accomplish this. One of them is with miniconda:

    $ wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh 
    $ bash Miniconda3-latest-Linux-x86_64.sh
    # (accept the license and set a directory that works for you) 
    $ conda create --name tf python=3.6  
    # TF does not support python 3.7 at the time of writing
    $ source activate tf 
    (tf) $ pip install tensorflow-gpu
    

Sources

https://www.zdnet.com/article/how-to-upgrade-from-ubuntu-linux-16-04-to-18-04/

https://askubuntu.com/questions/1028949/why-am-i-not-getting-the-ubuntu-18-04-upgrade

https://medium.com/codezillas/step-by-step-guide-to-install-tensorflow-gpu-on-ubuntu-18-04-lts-6feceb0df5c0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment