Hand handle Ubuntu 16.04+cuda9.0+cudnn 7.1+Anaconda+tensorflow-gpu+keras


It's all tear and blood. Notes after reinstalling the system (Note that I didn't check it, the graphics card settings can refer to other posts)

Install CUDA

Download address, official website or Baidu cloud, Baidu cloud address



Official website download failed, not to mention for the moment.


Enter the directory where the deb file is located, command line operation

sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
sudo apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda

Click yes.. runfile installed before is probably whether to install the nvidia driver, anyway, I did not install the nvidia driver, so all the way yes. If the nvidia driver is installed beforehand, select no as the driver option.
Add some libraries

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev



command line

ls /dev/nvidia*

If there is uvm, the installation is successful.

Setting environment variables

sudo gedit /etc/profile

If something goes wrong, see the next post.

End plus

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

source /etc/profile

Check whether the environment variable was set successfully

Verify Driven Version

cat /proc/driver/nvidia/version

Verify the cuda toolkit

nvcc -V

Test sample
Compile sample:

cd /usr/local/cuda-9.0/samples
sudo make

Waiting... (More than 10 minutes)

Compile binary files

cd bin/x86_64/linux/release

result = pass success

Finally, check the connection between the system and CUDA-Capable device:



Install cudnn 7.1

Download the cloud disk address as above

Enter the file directory

command line

tar -xzvf cudnn-9.0-linux-x64-v7.1.tgz 
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Installation of Anaconda

After downloading, you need to install anaconda, enter the anaconda storage directory, and use the command

bash Anaconda3-4.2.0-Linux-x86_64.sh 

Keep in mind that sudo bash command is not allowed here

Tensorflow and keras installation

Use the command CONDA create-n tensorflow-gpu python = 3.5 to create a python 3.5 environment named tensorflow-gpu. Pay attention to writing the python version.  

Activation of conda environment

source activate tensorflow-gpu activates tensorflow-gpu environment

After activating the environment

pip install tensorflow-gpu==1.11

Test code

import tensorflow as tf
# Creates a graph.
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.

Install Keras

pip install keras


Keywords: sudo Linux Anaconda Python

Added by wafawj on Fri, 17 May 2019 03:09:42 +0300