4.6 KiB
title | layout |
---|---|
How to Install TensorFlow on Ubuntu 16.04 with GPU Support | post |
I found the tensorflow documentation rather lacking for installation instructions, especially in regards to getting GPU support. I'm going to write down my notes from wrangling with the installation here for future reference and hopefully this helps someone else too.
This will invariably go out-of-date at some point, so be mindful of the publish date of this post. Make sure to cross-reference other documentation that has more up-to-date information.
Assumptions
These instructions are very specific to my environment, so this is what I am assuming:
- You are running Ubuntu 16.04. (I have 16.04.1)
- You can check this in the output of
uname -a
- You can check this in the output of
- You have a 64 bit machine.
- You can check this with
uname -m
. (should sayx86_64
)
- You can check this with
- You have an NVIDIA GPU that has CUDA Compute Capability 3.0 or higher.
[NVIDIA documentation] has a full table of cards and their Compute Capabilities.
(I have a GeForce GTX 980 Ti)
- You can check what card you have in Settings > Details under the label "Graphics"
- You can also check by verifying there is any output when you run
lspci | grep -i nvidia
- You have a linux kernel version 4.4.0 or higher. (I have 4.8.0)
- You can check this by running
uname -r
- You can check this by running
- You have gcc version 5.3.1 or higher installed. (I have 5.4.0)
- You can check this by running
gcc --version
- You can check this by running
- You have the latest proprietary NVIDIA
drivers installed.
- You can check this and install it if you haven't in the "Additional
Drivers" tab in the "Software & Updates" application (
update-manager
). (I have version 375.66 installed)
- You can check this and install it if you haven't in the "Additional
Drivers" tab in the "Software & Updates" application (
- You have the kernel headers installed.
- Just run
sudo apt-get install linux-headers-$(uname -r)
to install them if you don't have them installed already.
- Just run
- You have Python installed. The exact version shouldn't matter, but for the
rest of this post I'm going to assume you have
python3
installed.- You can install
python3
by runningsudo apt-get install python3
. This will install Python 3.5. - Bonus points: you can install Python 3.6 by following this answer, but Python 3.5 should be fine.
- You can install
Install the CUDA Toolkit 8.0
NVIDIA has a big scary documentation page on this, but I will summarize the only the parts you need to know here.
Go to the CUDA Toolkit Download page. Click Linux > x86_64 > Ubuntu > 16.04 > deb (network).
Click download and then follow the instructions, copied here:
sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
This will install CUDA 8.0. It installed it to the directory
/usr/local/cuda-8.0/
on my machine.
There are some post-install actions we must follow:
- Edit your
~/.bashrc
- Use your favorite editor
gedit ~/.bashrc
,nano ~/.bashrc
,vim ~/.bashrc
, whatever.
- Use your favorite editor
- Add the following lines to the end of the file:
# CUDA 8.0 (nvidia) paths
export CUDA_HOME=/usr/local/cuda-8.0
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
- Save and exit.
- Run
source ~/.bashrc
. - Install writable samples by running the script
cuda-install-samples-8.0.sh ~/
.- If the script cannot be found, the above steps didn't work :(
- I don't actually know if the samples are absolutely required for what I'm
using CUDA for, but it's recommended according to NVIDIA, and compiling
them will output a nifty
deviceQuery
binary which can be ran to test if everything is working properly.
- Make sure
nvcc -V
outputs something.- If an error, the above steps 1-4 didn't work :(
cd ~/NVIDIA_CUDA-8.0_Samples
, cross your fingers, and runmake
- The compile will take a while
- My compile actually errored near the end with an error about
/usr/bin/ld: cannot find -lcudart
. I think that doesn't really matter because the binary files where still output.
- Try running
~/NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release/deviceQuery
to see if you get any output. Hopefully you will see your GPU listed.