With Linux (Ubuntu)

Linux and AI go together such as natural complements. When you talk to Google Assistant on your Android phone, talk to Cortana on your Windows device, or wonder how Watson won a round at Jeopardy on TV, it's all based on Linux.

When we talk about Linux in this chapter, we'll be talking about a particular distribution called Ubuntu, one of the most popular distributions of the Linux operating system. It's recommended that you stick with an older, more stable version of Ubuntu (Version 14.04), as although it will do wonders for your AI applications; it's certainly not as stable as your standard Windows OS. 

If you'd like to use Ubuntu on your local machine, check out Ubuntu's tutorials for installing on a Windows machine (https://tutorials.ubuntu.com/tutorial/tutorial-ubuntu-on-windows#0). If you don't have a PC or you'd like to set up a virtual instance, AWS has a great tutorial (https://aws.amazon.com/getting-started/tutorials/launch-a-virtual-machine/) to walk you through the steps:

  1. To get started with deep learning for GPUs on Ubuntu, we first have to install the GPU's driver. In this example, we're going to utilize wget and chmod to retrieve and set up read/write access: 
wget http://us.download.nvidia.com/XFree86/Linuxx86_64/367.44/NVIDIA-Linux-x86_64-367.44.run

sudo chmod +x NVIDIA-Linux-x86_64-367.35.run
./NVIDIA-Linux-x86_64-367.35.run --silent
  1. Once the installation finishes, you can check if it was intalled correctly with a simple nvidia-smi command.
  2. Next, let's install NVIDIA CUDA. CUDA is a NVIDIA package that allows us to run TensorFlow models on our GPUs: 
wget"http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.44-1_amd64.deb"
## Install the drivers
sudo chmod +x cuda_7.5.18_linux.run
./cuda_7.5.18_linux.run --driver --silent
./cuda_7.5.18_linux.run --toolkit --silent
./cuda_7.5.18_linux.run --samples --silent
  1. Next, let's add the library to our system path:
echo ‘export LD_LIBRARY_PATH=”$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"’ >> ~/.bashrc
  1. Lastly, we need to install a higher-level package called cuNN, which is a specific library that sits on top of CUDA and provides highly-tuned procedures for typical deep learning operations:
sudo scp cudnn-7.0-linux-x64-v4.0-prod.tgz
  1. One last step to move the files to the correct place:
tar -xzvf cudnn-7.0-linux-x64-v4.0-prod.tgz
cp cuda/lib64/* /usr/local/cuda/lib64/
cp cuda/include/cudnn.h /usr/local/cuda/include/
  1. And there you are, we're set up on Ubuntu for GPU acceleration. Our last step is to simply install the GPU-enabled version of TensorFlow with Python 3:
pip3 install tensorflow-gpu