Installing Tensorflow GPU on Ubuntu 18.04 LTS

I wanted to detail here what I did to get tensorflow-gpu working with my fresh Ubuntu 18.04 LTS install. NVIDIA doesn’t have any official downloads for Ubuntu 18.04 yet, but you can get things to work with the available files for Ubuntu 17.04.

Check your NVIDIA driver version

You can check what graphics driver you have installed with thenvidia-smicommand. You should see some output like the following:

The driver version you have installed is near the top left next to “NVIDIA-SMI”. I’ve got nvidia-390 installed.

If you don’t have a proper driver installed, go do that now.

Install CUDA Toolkit 9.0

Runfile download page. Grab the file from the Base Installer link.

Once you’ve got that file, navigate to where the file was downloaded in your terminal and do

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

Accept the terms and conditions, say yes to installing with an unsupported configuration, and no to “Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?”. Make sure you don’t agree to install the new driver. In my experience, doing so often leads to system instability issues. Follow the prompts to install the toolkit using the default install locations.

Install CUDNN 7.0

There are lots of options on the archive downloads page for CUDNN. Get the Library for Linux file for CUDA 9.0.

Once downloaded, unpack the archive and move it the contents into the directory where you install CUDA 9.0:

# Unpack the archive
tar -zxvf cudnn-9.0-linux-x64-v7.tgz
# Move the unpacked contents to your CUDA directory
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64/
sudo cp cuda/include/cudnn.h /usr/local/cuda-9.0/include/
# Give read access to all users
sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Install libcupti

sudo apt-get install libcupti-dev

Do the CUDA post-install actions

export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Restart your terminal before proceeding to the next step.

Install Tensorflow GPU

pip install --upgrade tensorflow-gpu

I recommend installing tensorflow in a virtualenv to prevent having to muck around with your system Python packages. The official Tensorflow install instructions give various options, so you can choose what works best for you. If you choose the virtualenv route, I highly recommend using virtualenvwrapper, which makes using virtualenv far easier.

You can now test everything worked by opening a new python interpreter with python and running the following commands:

from tensorflow.python.client import device_lib

device_lib.list_local_devices()

If everything worked fine, you’ll see your GPU listed as part of the output like so:

[{
name: "/device:CPU:0",
device_type: "CPU",
memory_limit: 268435456,
locality {},
incarnation: 12584189039274141042
},{
name: "/device:GPU:0",
device_type: "GPU",
memory_limit: 3252486144,
locality {
bus_id: 1,
links {}
},
incarnation: 16344452236433767630,
physical_device_desc: "device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1"
]

That’s it! Good luck!

--

--

Machine Learning Masters Student at University of Waterloo. I’m interested in generative models, anomaly detection, and machine learning safety.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Taylor Denouden

Machine Learning Masters Student at University of Waterloo. I’m interested in generative models, anomaly detection, and machine learning safety.