How to install Tensorflow GPU with CUDA 10.0 for python on Ubuntu

This tutorial is for building tensorflow 1.12 GPU from source along with CUDA 10 and cuDNN 7.3.1

This is going to be a tutorial on how to install tensorflow 1.12 GPU version. We will also be installing CUDA 10.0 and cuDNN 7.3.1 along with the GPU version of tensorflow 1.12. At the time of writing this blog post, the latest version of tensorflow is 1.12. This tutorial is for building tensorflow from source. If you want to use the official pre-built pip package instead, I recommend another post, How to install Tensorflow using official pip package.

Tensorflow is an open source software library developed and used by Google that is fairly common among students, researchers, and developers for deep learning applications such as neural networks. It has both the CPU as well as GPU version available and although the CPU version works quite well, realistically, if you are going for deep learning, you will need GPU. In order to use the GPU version of TensorFlow, you will need an NVIDIA GPU with a compute capability > 3.0

Using latest version of Tensorflow provides you latest features and optimization, using latest CUDA Toolkit provides you speed improvement with latest gpu support and using latest CUDNN greatly improves deep learing training time.

There must be 64-bit python installed tensorflow does not work on 32-bit python installation.

Step 1: Update and Upgrade your system:

sudo apt-get update 
sudo apt-get upgrade

Step 2: Verify You Have a CUDA-Capable GPU:

lspci | grep -i nvidia

Note GPU model. eg. GeForce 840M

If you do not see any settings, update the PCI hardware database that Linux maintains by entering update-pciids (generally found in /sbin) at the command line and rerun the previous lspci command.

If your graphics card is from NVIDIA then goto and verify if listed in CUDA enabled gpu list.

Note down its Compute Capability. eg. GeForce 840M 5.0

Step 3: Verify You Have a Supported Version of Linux:

To determine which distribution and release number you’re running, type the following at the command line:

uname -m && cat /etc/*release

The x86_64 line indicates you are running on a 64-bit system which is supported by cuda 9.1

Step 4: Install Dependencies:

Required to compile from source:

sudo apt-get install build-essential 
sudo apt-get install cmake git unzip zip
sudo apt-get install python-dev python3-dev python-pip python3-pip

Step 5: Install linux kernel header:

Goto terminal and type:

uname -r

You can get like “4.15.0-36-generic”. Note down linux kernel version.

To install linux header supported by your linux kernel do following:

sudo apt-get install linux-headers-$(uname -r)

Step 6: Install NVIDIA CUDA 10.0:

Remove previous cuda installation:

sudo apt-get purge nvidia*
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /usr/local/cuda*

Install cuda :

For Ubuntu 16.04 :

sudo apt-key adv --fetch-keys
echo "deb /" | sudo tee /etc/apt/sources.list.d/cuda.list

For Ubuntu 18.04 :

sudo apt-key adv --fetch-keys
echo "deb /" | sudo tee /etc/apt/sources.list.d/cuda.list

For Both Options:

sudo apt-get update 
sudo apt-get -o Dpkg::Options::="--force-overwrite" install cuda-10-0 cuda-drivers

You can also install cuda toolkit following instructions from here and it is recommended to use deb[network].

Step 7: Reboot the system to load the NVIDIA drivers.

Step 8: Go to terminal and type:

echo 'export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc
source ~/.bashrc
sudo ldconfig

Check driver version probably Driver Version: 396.26

(not likely) If you got nvidia-smi is not found then you have unsupported linux kernel installed. Comment your linux kernel version noted in step 5.

You can check your cuda installation using following sample: ~
cd ~/NVIDIA_CUDA-10.0_Samples/5_Simulations/nbody

8 Comments on How to install Tensorflow GPU with CUDA 10.0 for python on Ubuntu

  1. Hi Arun,

    I tried to install the .whl on my computer(Ubuntu 18.04), but encountered a problem like this:
    Ignoring visible gpu device (device: 0, name: GeForce GT 730, pci bus id: 0000:01:00.0, compute capability: 3.5) with Cuda compute capability 3.5. The minimum required Cuda capability is 5.0.

    I understand my GPU is too old, but is there any method to solve this problem?

  2. Hello and thank you for this post. I cannot find targets/x86_64-linux/. I can only find this folder “/usr/local/cuda-10.0/NsightCompute-1.0/target/”. Did I do anything wrong? should I start again?

  3. Is it possible to install a headless version without installing xserver? Which packages are the minimum necessary in step 6?

    • I have not tried but you can try run file to setup nvidia driver and then setup cuda, it may ask to install xserver if it requires. Also you may delete xserver later but don’t know the driver will work afterwards.

  4. Will I be able to configure TensorFlow if I have a GPU with only 3.0 compute capability?

    ==============NVSMI LOG==============

    Timestamp : Tue Nov 27 07:52:36 2018
    Driver Version : 410.72
    CUDA Version : 10.0

    Attached GPUs : 1
    GPU 00000000:01:00.0
    Product Name : GeForce GTX 760
    Product Brand : GeForce
    Display Mode : N/A

    • I have not tried, you can try to build. Also official gpu builds does not support this compute capability.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.