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.
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.
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.
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 nvidia-smi
and if the specified version is displayed, it is successful.
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.
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"
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
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.)
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.
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
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
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 2.3.0
and enter it.
python3 -m pip install tensorflow==<version>
import tensorflow as tf
tf.__version__
If the intended version is displayed, it is successful.
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