Installing TensorFlow GPU on Ubuntu 16.04 with a Titan 1080 Graphics Card
In this detailed guide, we’ll walk through the process of installing the necessary components for running GPU-accelerated TensorFlow on an Ubuntu 16.04 system with a Titan 1080 graphics card. This setup is crucial for deep learning enthusiasts and professionals who need to leverage the power of their GPUs.
Prerequisites
- Operating System: Ubuntu 16.04
- Graphics Card: NVIDIA Titan 1080
- Drivers: CUDA 8.0, CUDNN 5.1
Step-by-Step Guide
1. Download CUDA
First, head over to the NVIDIA Developer website to download CUDA 8.0. Choose the “Runfile Local” option, as it’s more reliable than the .deb
format which can sometimes cause issues with apt-get
.
wget https://developer.download.nvidia.com/compute/cuda/8.0/Prod/local_installers/cuda_8.0.44_linux.run
2. Downgrade GCC and G++
CUDA does not fully support the latest versions of GCC and G++. To ensure compatibility, we need to downgrade to version 4.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.8 g++-4.8
3. Install the Graphics Driver
To ensure optimal performance, we need to install the appropriate NVIDIA graphics driver.
sudo apt-get install nvidia-367
4. Close Your Graphical Interface
To proceed with the installation of CUDA, you’ll need to close your graphical interface temporarily.
sudo service lightdm stop
At this point, your screen should turn black. Press Ctrl + Alt + F1
to enter the command line.
5. Install CUDA
Navigate to the directory where you downloaded the CUDA installer and run it.
sudo bash cuda_8.0.44_linux.run
You will be prompted to accept the EULA and install the NVIDIA Accelerated Graphics Driver. Accept the default options.
accept
no
no
Once the installation is complete, you can re-enable your graphical interface.
sudo service lightdm start
6. Set Up CUDA Environment Variables
Edit your .bashrc
file to include the necessary environment variables.
sudo vi ~/.bashrc
Add the following lines:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/extras/CUPTI/lib64
export CUDA_HOME=/usr/local/cuda-8.0
Save and exit, then source the .bashrc
file.
source ~/.bashrc
7. Install CUDNN
To install CUDNN, you have two options: downloading the .deb
package or using the .tar
file.
Option 1: Install CUDNN via .deb
Package
Register for an NVIDIA account and download the appropriate .deb
package.
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
Option 2: Install CUDNN via .tar
File
Alternatively, you can download the .tar
file and extract it.
wget https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v5.1/prod/8.0_20170120/cudnn-8.0-linux-x64-v5.1.tgz
tar -xzvf cudnn-8.0-linux-x64-v5.1.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64
sudo chmod a+r /usr/local/cuda-8.0/include/cudnn.h /usr/local/cuda-8.0/lib64/libcudnn*
8. Install TensorFlow
Now that all the prerequisites are in place, let’s install TensorFlow.
# Install Anaconda
bash ~/Downloads/Anaconda3-4.3.0-Linux-x86_64.sh
# During installation, select "Yes" to add Anaconda to your PATH
# Create a virtual environment
conda create -n tensorflow
source activate tensorflow
# Install TensorFlow GPU
conda install tensorflow-gpu
9. Test TensorFlow
Finally, let’s test our installation by running a simple TensorFlow script.
python -c "import tensorflow as tf; hello = tf.constant('Hello, TensorFlow!'); sess = tf.Session(); print(sess.run(hello)); a = tf.constant(10); b = tf.constant(32); print(sess.run(a + b))"
If everything runs smoothly and prints “Hello, TensorFlow!” followed by 42
, you’ve successfully set up TensorFlow GPU on your system.
Congratulations! You’ve now got a fully functional GPU-accelerated TensorFlow environment on your Ubuntu 16.04 system with a Titan 1080. Happy coding!
Original Source:
Under Ubuntu 16.04 for the TITAN 1080 graphics card installed driver (Cuda & CudNN) and Gpu version TensorFlow
Author: Jiangnan Summertime, Not Serious Data Scientist
Published on: 2018-02-28