Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to set up tensorflow with CUDA 8 cuDNN 5.1 in virtualenv with Python 3.5 on Ubuntu 16.04 http://ksopyla.com/2017/02/tensorflow-gpu-virtualenv-python3/
# This is shorthened version of blog post
# http://ksopyla.com/2017/02/tensorflow-gpu-virtualenv-python3/
# update packages
sudo apt-get update
sudo apt-get upgrade
#Add the ppa repo for NVIDIA graphics driver
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
#Install the recommended driver (currently nvidia-378)
sudo ubuntu-drivers autoinstall
sudo reboot
#check if drivers were installed
nvidia-smi
#############################################
# Instal CUDA Toolkit 8.0 for x64 Ubuntu 16.04
wget -O cuda_8_linux.run https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
sudo chmod +x cuda_8_linux.run
./cuda_8.0.61_375.26_linux.run
#Do you accept the previously read EULA?
#accept
#Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?
#n (we installed drivers previously)
#Install the CUDA 8.0 Toolkit?
#y
#Enter Toolkit Location:
#/usr/local/cuda-8.0 (enter)
#Do you wish to run the installation with ‚sudo’?
#y
#Do you want to install a symbolic link at /usr/local/cuda?
#y
#Install the CUDA 8.0 Samples?
#y
#Enter CUDA Samples Location:
#enter
# Install cuDNN
# go to website and download cudnn-8 https://developer.nvidia.com/cudnn
tar -zxvf cudnn-8.0-linux-x64-v5.1.tgz
# copy libs to /usr/local/cuda folder
sudo cp -P cuda/include/cudnn.h /usr/local/cuda/include
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
# isntall python 3 and virtual env
sudo apt install python3-pip
sudo apt install python3-venv
# create virtual environment for tensorflow
python3 -m venv tfenv
source tfenv/bin/activate
# Instal tensorflow package with gpu support
(tfenv)$ pip install tensorflow-gpu
#or CPU version
(tfenv)$ pip install tensorflow
# check installation, run simple python scipt from console
$ python
import tensorflow as tf
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally
tf_session = tf.Session()
x = tf.constant(1)
y = tf.constant(1)
print(tf_session.run(x + y))
@facundoq

This comment has been minimized.

Show comment
Hide comment
@facundoq

facundoq Aug 9, 2017

I think you should add that CUDA_HOME should be set and LD_LIBRARY_PATH modified for TF to find the libraries.

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda

You can add those lines to ~/.bashrc so that they are executed each time you open as shell.

facundoq commented Aug 9, 2017

I think you should add that CUDA_HOME should be set and LD_LIBRARY_PATH modified for TF to find the libraries.

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda

You can add those lines to ~/.bashrc so that they are executed each time you open as shell.

@seogi1004

This comment has been minimized.

Show comment
Hide comment
@seogi1004

seogi1004 Aug 25, 2017

You should run the following command before upgrading the driver automatically.
"sudo apt-get install ubuntu-drivers-common"

You should run the following command before upgrading the driver automatically.
"sudo apt-get install ubuntu-drivers-common"

@seogi1004

This comment has been minimized.

Show comment
Hide comment
@seogi1004

seogi1004 Aug 25, 2017

It is recommended to use cudnn version 6.0 to use the latest version of the tensorflow-gpu library.

It is recommended to use cudnn version 6.0 to use the latest version of the tensorflow-gpu library.

@seogi1004

This comment has been minimized.

Show comment
Hide comment
@seogi1004

seogi1004 Aug 25, 2017

There were some difficulties, but it was easy to install.
Thank you very much.

There were some difficulties, but it was easy to install.
Thank you very much.

@isalirezag

This comment has been minimized.

Show comment
Hide comment
@isalirezag

isalirezag Aug 28, 2017

I have a stupid question.
How to know what the link in wget -O cuda_8_linux.run https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run should be? where we get that from?
also any specific reason you didnot use sudo sh .... comand?

isalirezag commented Aug 28, 2017

I have a stupid question.
How to know what the link in wget -O cuda_8_linux.run https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run should be? where we get that from?
also any specific reason you didnot use sudo sh .... comand?

@TarrySingh

This comment has been minimized.

Show comment
Hide comment
@TarrySingh

TarrySingh Sep 4, 2017

@isalirazeg:
0. Register a developer on Nvidia (its free of charge)

  1. Go to https://developer.nvidia.com/cuda-downloads
  2. Select your cuda version (normally about 1.4 - 1.9G)
  3. right-click to get the url link
  4. paste it to your terminal to download on your server

@isalirazeg:
0. Register a developer on Nvidia (its free of charge)

  1. Go to https://developer.nvidia.com/cuda-downloads
  2. Select your cuda version (normally about 1.4 - 1.9G)
  3. right-click to get the url link
  4. paste it to your terminal to download on your server
@yaroslavvb

This comment has been minimized.

Show comment
Hide comment
@yaroslavvb

yaroslavvb Oct 5, 2017

Is reboot necessary?

Is reboot necessary?

@yaroslavvb

This comment has been minimized.

Show comment
Hide comment
@yaroslavvb

yaroslavvb Oct 5, 2017

btw, the updated driver, didn't work for me ("modprobe: ERROR: could not insert 'nvidia_387_uvm': Unknown symbol in module, or unknown parameter (see dmesg)") , I had to yes | sudo apt-get remove nvidia-387

btw, the updated driver, didn't work for me ("modprobe: ERROR: could not insert 'nvidia_387_uvm': Unknown symbol in module, or unknown parameter (see dmesg)") , I had to yes | sudo apt-get remove nvidia-387

@andrasmolnar

This comment has been minimized.

Show comment
Hide comment
@andrasmolnar

andrasmolnar Oct 15, 2017

Up and running configuration for me:

Ubuntu 16.04.3 LTS
GeForce GTX 1080 Ti
TensorFlow: 1.3.0
Python: 3.5.2
nvidia driver: nvidia-387
CUDA: cuda_8.0.61_375.26 + cuda_8.0.61.2
cuDNN: cudnn-8.0-linux-x64-v6.0

Up and running configuration for me:

Ubuntu 16.04.3 LTS
GeForce GTX 1080 Ti
TensorFlow: 1.3.0
Python: 3.5.2
nvidia driver: nvidia-387
CUDA: cuda_8.0.61_375.26 + cuda_8.0.61.2
cuDNN: cudnn-8.0-linux-x64-v6.0

@saikishor

This comment has been minimized.

Show comment
Hide comment
@saikishor

saikishor Oct 18, 2017

Will I only be able to run CUDA & CuDNN in python3?. I am not able to see the above lines that in my machine. In fact after i import nothing happens. Any clue?
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally

Will I only be able to run CUDA & CuDNN in python3?. I am not able to see the above lines that in my machine. In fact after i import nothing happens. Any clue?
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally

@Aquakor

This comment has been minimized.

Show comment
Hide comment
@Aquakor

Aquakor Oct 22, 2017

@saikishor
Tensorflow supports python 2.7, 3.4, 3.5, 3.6. I don't know the answer for the second problem.

Aquakor commented Oct 22, 2017

@saikishor
Tensorflow supports python 2.7, 3.4, 3.5, 3.6. I don't know the answer for the second problem.

@harpone

This comment has been minimized.

Show comment
Hide comment
@harpone

harpone Nov 8, 2017

it would be nice to add this wget method to get the cudnn file:
https://gist.github.com/mjdietzx/0ff77af5ae60622ce6ed8c4d9b419f45

harpone commented Nov 8, 2017

it would be nice to add this wget method to get the cudnn file:
https://gist.github.com/mjdietzx/0ff77af5ae60622ce6ed8c4d9b419f45

@nusynergi

This comment has been minimized.

Show comment
Hide comment
@nusynergi

nusynergi Jan 14, 2018

Can you tell us what virtual env you got this working in. Trying to do something similar with ESXI.
Keep hitting an issue logging back into the Ubuntu UI when I install the NVIDIA graphics driver with specific version. i.e. sudo apt install nvidia-381 . The UI Accepts the user/password, but then just kicks me back to login. To fix it I run sudo apt-get purge nvidia*

It seems to accept sudo ubuntu-drivers autoinstall and allows me to log in. However the nvidia-smi command isn't found. Any ideas, pointers welcomed.

nusynergi commented Jan 14, 2018

Can you tell us what virtual env you got this working in. Trying to do something similar with ESXI.
Keep hitting an issue logging back into the Ubuntu UI when I install the NVIDIA graphics driver with specific version. i.e. sudo apt install nvidia-381 . The UI Accepts the user/password, but then just kicks me back to login. To fix it I run sudo apt-get purge nvidia*

It seems to accept sudo ubuntu-drivers autoinstall and allows me to log in. However the nvidia-smi command isn't found. Any ideas, pointers welcomed.

@ti994a

This comment has been minimized.

Show comment
Hide comment
@ti994a

ti994a Jan 31, 2018

Thanks for these instructions. Unfortunately I was unable to get this to work, seems like the versions of the software are a moving target. Here are steps that worked for me yesterday (1/30/18): http://www.sixthdoor.com/deep-learning-setup-tensorflow-gpu-1-4-on-ubuntu-16-04/

ti994a commented Jan 31, 2018

Thanks for these instructions. Unfortunately I was unable to get this to work, seems like the versions of the software are a moving target. Here are steps that worked for me yesterday (1/30/18): http://www.sixthdoor.com/deep-learning-setup-tensorflow-gpu-1-4-on-ubuntu-16-04/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment