[PYTHON] [Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction

Introduction

index.png Tensorflow 2.0.0 has been released and integrated with keras, making it even more convenient. Therefore, I will write the procedure from installing the GPU driver to installing CUDA and cuDNN, and installing Tensorflow 2.0.0-gpu, which are necessary to install the GPU version of Tensorflow 2.0.0 on Ubuntu 18.04 LTS.

environment

OS:Ubuntu 18.04 LTS GPU:nvidia Geforce GTX1660

GPU driver installation

**-Update package information ** Get the package name, version, and dependencies from the package repository.

$ sudo apt update

** ・ Package update ** Just in case, update the package.

$ sudo apt upgrade

**-Display a list of available drivers **

$ ubuntu-drivers devices

The following results were displayed on the GTX 1660.

== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00002184sv00001462sd00008D91bc03sc00i00
vendor   : NVIDIA Corporation
driver   : nvidia-driver-435 - distro non-free recommended
driver   : nvidia-driver-430 - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin

Install the recommended driver, nvidia-driver-435.

**-Driver installation **

$ sudo apt install nvidia-driver-435

·Reboot

$ sudo reboot

Activate the installed driver by rebooting.

CUDA installation

Install CUDA-10.0 which is compatible with Tensorflow 2.0.0.

**-Download CUDA Toolkit ** Download the .run file for CUDA Toolkit 10.0 from the nvidia page below.  CUDA Toolkit 10.0 Archive  https://developer.nvidia.com/cuda-10.0-download-archive Screenshot from 2019-12-23 17-40-47.png **-Installing CUDA Toolkit ** To install CUDA, you need to download and install the Base Installer. Since there is also a patch this time, after downloading the Base Installer and Patch, move to the directory where the Base Installer and Patch are saved.

$cd saved directory

First, run the Base Installer.

/Saved directory$ sudo sh cuda_10.0.130_410.48_linux.run

Press the D key to proceed and answer the question. This time, the driver is installed first, so set the driver installation to no. If you need a CUDA sample, answer yes to the last question.

-----------------
Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
(y)es/(n)o/(q)uit: n

Install the CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-10.0 ]: /usr/local/cuda-10.0

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 10.0 Samples?
(y)es/(n)o/(q)uit: n

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-10.0
Samples:  Not Selected

Then install Patch.

/\ Saved directory$ sudo sh cuda_10.0.130.1_linux.run

As before, press the D key to proceed and answer the question.

Do you accept the previously read EULA?
accept/decline/quit: accept    

Enter CUDA Toolkit installation directory
 [ default is /usr/local/cuda-10.0 ]: /usr/local/cuda-10.0

Installation complete!
Installation directory: /usr/local/cuda-10.0

** ・ Pass through CUDA's PATH ** Enter the following command.

$ echo -e "\n## CUDA and cuDNN PATHS" >> ~/.bashrc
$ echo "export PATH=/usr/local/cuda-10.0/bin:${PATH}" >> ~/.bashrc
$ echo "export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:${LD_LIBRARY_PATH}" >> ~/.bashrc
$ source ~/.bashrc

** ・ Confirmation of CUDA installation ** Check if CUDA of the following command is installed correctly.

$ nvcc -V

result

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130

You can confirm that CUDA 10.0 has been installed.

cuDNN installation

Install cuDNN7.6 which is compatible with Tensorflow 2.0.0. ** ・ Installation of cuDNN ** Download the cuDNN7.6 .deb file from the nvidia page below. Membership registration is required to download.  Download cuDNN v7.6.0 (May 20, 2019), for CUDA 10.0  https://developer.nvidia.com/rdp/cudnn-archive Screenshot from 2019-12-23 18-15-22.png After downloading both the cuDNN Runtime Library for Ubuntu18.04 (Deb) and the cuDNN Developer Library for Ubuntu18.04 (Deb), move to the saved directory.

$cd saved directory

First install the runtime library.

/Saved directory$ sudo dpkg -i libcudnn7_7.6.0.64-1+cuda10.0_amd64.deb

Then install the developer library.

/Saved directory$ sudo dpkg -i libcudnn7-dev_7.6.0.64-1+cuda10.0_amd64.deb

** ・ Confirm cuDNN installation ** Enter the following command

$ cat /usr/include/cudnn.h | grep CUDNN_MAJOR -A 2

result

#define CUDNN_MAJOR 7
#define CUDNN_MINOR 6
#define CUDNN_PATCHLEVEL 0
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)

#include "driver_types.h"

If you see the above, cuDNN is installed normally.

Install Tensorflow

Install pip to install Tensorflow. If you already have the latest version of pip installed, you can skip the curl and pip installations. **-Install curl command ** Install the curl command that allows you to specify a URL and install files on the web.

$ sudo apt install curl

** ・ Install pip ** Install the Python package management tool pip. If you have installed Ubuntu18.04LTS with the minimum configuration, you do not need to install pip3 because Python2 system is not installed. Pip needs to be the latest version to install Tensorflow 2.0.0, but if the Python 2 environment coexists with the Python 3 environment, an error occurs after updating pip 3 installed with apt with pip 3. Therefore, it is easier to install Tensorflow in a Python 3 only environment. Download the Python code to install pip with the following command and run the program.

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ sudo python3 get-pip.py

This completes the installation of pip. You can check the version of pip with the command below.

$ pip -V
pip 19.3.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

If the version of pip is less than 19.0, enter the following command.

$ pip install --upgrade pip

**-Upgrade setuptools ** Upgrade setuptools with the command below.

$ pip install setuptools --upgrade

**-Tensorflow 2.0.0-GPU installation ** Tensorflow 2.0.0-Install GPU. Enter the following command.

$ pip install tensorflow-gpu==2.0.0

This completes the installation of tensorflow-gpu == 2.0.0.

**Thank you for your hard work! !! Send us a fun Tensorflow 2.0.0-GPU life! ** **

Recommended Posts

[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
Ubuntu14.04 + GPU + TensorFlow environment construction
Python environment construction and TensorFlow
[Tensorflow] Tensorflow environment construction on Windows 10
[Environment construction] @anaconda that runs keras / tensorflow on GPU
Python environment construction (pyenv, anaconda, tensorflow)
From Ubuntu 20.04 introduction to environment construction
Python3 TensorFlow for Mac environment construction
Ubuntu Desktop 20.04 development environment construction memo
Environment construction of "Tello_Video" on Ubuntu
OpenCV3 & Python3 environment construction on Ubuntu
Django environment construction
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
DeepIE3D environment construction
Emacs-based environment construction
Linux environment construction
Python environment construction
Environment construction of Tensorflow and Chainer by Window with CUDA (with GPU)
Environment construction (python)
django environment construction
I installed TensorFlow (GPU version) on Ubuntu
CodeIgniter environment construction
python environment construction
Python --Environment construction
Environment construction procedure: Ubuntu + Apache2 + Python + Pyramid
Python environment construction
Golang environment construction
python environment construction
Word2vec environment construction
Until the Deep Learning environment (TensorFlow) using GPU is prepared for Ubuntu 14.04
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
[0] TensorFlow-GPU environment construction built with Anaconda on Ubuntu
Python 3.x environment construction by Pyenv (CentOS, Ubuntu)
Install TensorFlow on Ubuntu
Environment construction: GCP + Docker
Django project environment construction
python windows environment construction
Go language environment construction
ConoHa environment construction memo
homebrew python environment construction
PyData related environment construction
Anaconda-4.2.0-python3 environment construction (Mac)
Python development environment construction
YOLO v4 environment construction ①
Enable GPU for tensorflow
pyenv + fish environment construction
Ubuntu (18.04.3) Web server construction
python2.7 development environment construction
BigGorilla environment construction memo
grip environment construction onCentOS6.5
Anaconda environment construction memo
Golang environment construction [goenv]
Mac environment construction Python
Pyxel environment construction (Mac)
Python environment construction @ Win7
Building a TensorFlow environment that uses GPU on Windows 10
[Introduction to RasPi4] Environment construction; OpenCV / Tensorflow, Japanese input ♪
Python + Anaconda + Pycharm environment construction
About Linux environment construction (CentOS)
PyTorch C ++ (LibTorch) environment construction
Anaconda environment construction on CentOS7