Install CUDA10.1 + cuDNN7.6.5 + tensorflow-2.3.0 on Ubuntu 18.04

Introduction

In this post, I will install NVIDIA's GPU driver, CUDA10.1, cuDNN7.6.5, tensorflow 2.3.0 in ubuntu 18.04 environment. The environment is as follows. GPU : GTX1060 OS : Ubuntu18.04 Python : 3.6.9

** The following reference procedure is an example, so please use it as a reference and at your own risk. ** ** Also, since I am not an engineer, there are some notations that are difficult to read, but please forgive me.

About machine learning frameworks

I used to study with tensorflow1.xx + keras, but I was also interested in tensorflow2 and decided to move to tensorflow2 considering the future. As an aside, the GPU in use will be replaced with the Ampere generation in the future. CUDA11 and cuDNN8 are required in the Ampere generation, and as of November 2020, it is said that operation has been confirmed with tensorflow-nightly (2.4.0rc), but it seems that it is not supported in the official version.

Dependencies between Tensorflow version and CUDA, cuDNN

If you want to use GPU to speed up learning, you have to be careful about the versions of tensorflow, CUDA and cuDNN. See Tensorflow Official Site. When installing tensorflow 2.3.0 as shown below, cuDNN must be 7.6 and CUDA must be 10.1. Note in particular that CUDA must be 10.1, not 10.1 or higher. tensorflow_cuda_cudnn.PNG

NVIDIA driver installation

References

This item is based on the following. -How to install / reinstall NVIDIA driver on Ubuntu

-If the NVIDIA driver and CUDA are installed, delete them with the following command.

sudo apt --purge remove nvidia-* sudo apt --purge remove cuda-*

-NVIDIA's GPU driver can be installed using apt with the following command. In my environment, the installation was successful without disabling the ubuntu default driver called nouveau. sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt update ubuntu-drivers devices Here you will see a list of installable versions on the console. As of November 2020, nvidia-driver-455 was recommended in my environment. sudo apt install nvidia-driver-<version> (Note: For , enter the version displayed on the console)

Confirm driver installation

Enter nvidia-smi and if the specified version is displayed, it is successful.

NVIDIA-SMI.PNG

Installation of CUDA 10.1

Download the CUDA deb file from NVIDIA site To do. After moving to the downloaded directory, install it with the following command. ** The last command is the point! (The reason will be explained later) **

sudo dpkg -i cuda-repo-ubuntu1804-10-1-local-10.1.105-418.39_1.0-1_amd64.deb sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub sudo apt-get update sudo apt-get install cuda-toolkit-<version>

The NVIDIA official website says sudo apt-get install cuda, but if you do this, the GPU driver version will not change, and you may end up with an unintended environment.

PATH in CUDA

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

Confirm CUDA installation

Enter nvcc -V on the console and it will be displayed as shown below.

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Fri_Feb__8_19:08:17_PST_2019
Cuda compilation tools, release 10.1, V10.1.105

CUDA displayed by nvidia -smi and nvcc -V are different, but there is no problem

It seems that CUDA has two APIs, runtime and driver API, and it doesn't matter if the CUDA versions displayed by nvidia -smi and nvcc -V are different. I have had the experience of repeating the installation in order to actually match these versions, but in the end I found that there is no problem in using tensorflow even if the versions are different. (Please tell me if the recognition is different.)

cuDNN installation

If all goes well, it's almost over. You can download cuDNN for free, but you must register as a member on the NVIDIA site before downloading. Click Archived cuDNN Releases to find the previous cuDNN. This time, download the cuDNN 7.6.5 Runtime Library, Developer Library, and Code Samples Deb files for Ubuntu 18.04. CuDNN.png Execute the following in the downloaded directory. sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.1_amd64.deb sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb sudo dpkg -i libcudnn7-doc_7.6.5.32-1+cuda10.1_amd64.deb

cuDNN test

Execute one of the code samples, and if there are no errors, it's OK. cp -r /usr/src/cudnn_samples_v7/ $HOME cd $HOME/cudnn_samples_v7/mnistCUDNN make clean && make ./mnistCUDNN

Install Tensorflow

Another breath. Tensorflow2 requires an upgrade of pip3. python3 -m pip install --upgrade pip Install Tensorflow. If you do not specify the version, an unintended version will be installed. Replace the part with a version such as 2.3.0 and enter it. python3 -m pip install tensorflow==<version>

Check if you can import tensorflow in python environment

import tensorflow as tf tf.__version__ If the intended version is displayed, it is successful.

in conclusion

We have built an environment for learning using GPU by Gtensorflow on Ubuntu 18.04. I would like to update this article again after replacing it with the Ampere generation RTX30 series. Since the engineer is not my main business, there are many points that I cannot reach, but I hope it will be helpful.

Recommended Posts

Install CUDA10.1 + cuDNN7.6.5 + tensorflow-2.3.0 on Ubuntu 18.04
Install TensorFlow on Ubuntu
Install the latest Cuda + CuDNN on Ubuntu 18.04 @ Spring 2020
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Install Tensorflow on Mac
Install PySide2 on Ubuntu
Install JModelica on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Install Theano on Ubuntu 12.04
Install angr on Ubuntu 18.04
Install pip / pip3 on Ubuntu
Install GoLand IDE on Ubuntu
Install OpenCV on Ubuntu + python
wsl Install PostgreSQL on Ubuntu 18.04
Introducing TensorFlow on Ubuntu + Python 2.7
[ROS] Install ROS (melodic) on Ubuntu (18.04)
Install Caffe on Ubuntu 14.04 (GPU)
Install Docker on WSL Ubuntu 18.04
Install TensorFlow 1.15.0 on Raspberry Pi
Install NVIDIA-driver (GeForce RTX 2070 SUPER), cuda 10.1, cudnn 7.6 on Ubuntu 18.04.3 LTS + python environment construction
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Install Caffe on Ubuntu 14.04 (CPU mode)
Install Mecab and mecab-python3 on Ubuntu 14.04
Install and run dropbox on Ubuntu 20.04
Install OpenCV and Chainer on Ubuntu
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Install CUDA on Linux Mint Mate 20
How to install TensorFlow on CentOS 7
Set up AWS (Ubuntu 14.04) for Deep Learning (install CUDA, cuDNN)
Install fabric on Ubuntu and try
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install confluent-kafka for Python on Ubuntu
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
How to install Go on Ubuntu
ROS study # 1 Install ros-noetic on ubuntu 20.04
Steps to install Python environment on Ubuntu
I installed TensorFlow (GPU version) on Ubuntu
Install Pleasant on Ubuntu 20.04 (.NetCore3.1 / PostgreSQL version)
Install ubuntu on 32bit UEFI Ultra Notebook
Install Caffe running 3D-CNN on clean Ubuntu 14.04
Install Puppet Master and Client on Ubuntu 16.04
How to install php7.4 on Linux (Ubuntu)
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Shebang on Ubuntu 20.04
Install tensorflow. (Only!)
I can't install Dask with pip on Ubuntu
Install python package in personal environment on Ubuntu
[Procedure memo] Install Python3 + OpenSSL locally on Ubuntu
[Note] Install wxPython 3.x on Linux Mint (Ubuntu)
Build procedure for TensorFlow 2.4.0 (Windows10, CUDA11.1.1, cuDNN 8.0.5, Python 3.8.6)
Build procedure of TensorFlow 2.2.0-rc0 (CUDA10.2 + cuDNN7.6.5) --Windows10
Notes for using TensorFlow on Bash on Ubuntu on Windows
Install MongoDB on Ubuntu 16.04 and operate via python
Install Ubuntu 20.04 LTS (Server) 64bit version on RaspberryPi3B +
Install the machine learning library TensorFlow on fedora23
How to force build TensorFlow 2.3.0 for CUDA11 + cuDNN8
Install mecab on Marvericks
Install python on WSL
Install Faiss on CentOS 7
Install pyenv on mac
Install pip on Mavericks