Sep 29, 2016 - Building PC For Deep Learning - Software

Software

This is a continuation of my previous post on setting up a home PC for deep learning.
Below are some software installation instructions which might help you to get started.

OS

The OS of choice for deep learning is Linux. And of many Linux distributions, the easiest one to get started is probably Ubuntu. Hence, I’ve installed desktop version of Ubuntu 16.06. Installing Ubuntu in Virtual Machine will not make sense if you plan on using GPU, so it has to be “real” Ubuntu installation.

GPU driver

Go to GeForce Drivers and select your particular OS and GPU card. In my case - GTX 1080 and Linux 64. The driver I got (as of 2016-09-29) has version 367.44.

Installing the driver.

  • Press Ctrl+Alt+F3 and then login with your credentials
  • Stop lightdm service like this:
    $ sudo service lightdm stop
    
  • Start driver installer. (When prompted, I skipped installing 32 bit compatibility)
    $ sudo ~/Downloads/NVIDIA-Linux-x86_64-367.44.run
    
  • After reboot, you can check that the driver is installed and working if everything looks pretty, and the following command finds your card and shows correct driver version:
    $ nvidia-smi
    

CUDA

Go to CUDA HOMEPAGE and download the latest (at the time of this writing 8.0) version of CUDA for your architecture and distribution. I chose “runfile” as installer type.

  • Once download is done, do:
$ sudo sh ~/Downloads/cuda_8.0.44_linux.run

When asked, you can choose to skip driver installation in case you’ve installed it during previous step. If you do chose to install driver, the installation might fail if you did not stop lightdm before.

  • Modify ~/.bashrc to include the following at the end:
export PATH=/usr/local/cuda-8.0/bin:$PATH  
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64/$LD_LIBRARY_PATH

Then do $ source ~/.bashrc

  • To verify that it worked type $ nvcc

CuDNN

To get cuDNN, you’ll need to register in Accelerated Computing Developer Program. It is free, and once you’ve registered, you can download it. cuDNN. You need to get version 5.1 for Linux and CUDA 8.0.

  • Once download is done, do:
$ tar -xvf cudnn-8.0-linux-x64-v5.1.tgz  
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include  
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64  
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

(That’s it - it is just few files which need to be downloaded and copied to appropriate location)

Tensorflow

Tensorflow is a very flexible machine learning framework from Google. Below are the steps I followed to build it from sources. This is mainly following these instructions.

  • Install some Python libraries
    $ sudo apt-get update
    $ sudo apt-get upgrade
    $ sudo apt-get install python-pip
    $ sudo apt-get install python-numpy swig python-dev python-wheel
    
  • Installing Bazel - open-source version of Google’s build system
    $ sudo add-apt-repository ppa:webupd8team/java
    $ sudo apt-get update
    $ sudo apt-get install oracle-java8-installer
    $ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
    $ curl https://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg | sudo apt-key add -
    $ sudo apt-get update && sudo apt-get install bazel
    $ sudo apt-get upgrade bazel
    
  • Install Git and clone Tensorflow’s repository
    $ sudo apt-get install git
    $ git clone https://github.com/tensorflow/tensorflow
    
  • Configure by going to tensorflow’s folder and running
    $ ./configure
    

    Here I configured without Google cloud and Hadoop Filesystem support but with GPU support. Specify CUDA’s version as 8.0 when asked and for GTX 1080, compute capability of 6.0

  • Run build (this will take some time - in my case it took 1031 seconds!):
    $ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
    

    Technically, master branch might be broken or just not work with your configuration for whatever reason. Try switching to more stable “version” branch instead.

  • Setup for development
    $ mkdir _python_build
    $ cd _python_build
    $ ln -s ../bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .
    $ ln -s ../tensorflow/tools/pip_package/* .
    $ sudo python setup.py develop
    

    Now you should be able to run some models. Test it with MNIST by going to tensorflow/tensorflow/models/image/mnist and running $ python convolutional.py. It’ll first download some data and then should run really fast. You can check using nvidia-smi that your GPU usage goes up.