Install gpu driver cuda cuDNN unbuntu16.04

Article directory

    • 1.Install NVIDIA Graphics Driver via runfile
      • 1.1 Uninstall the old version before:
      • 1.2 Download cuda Driver
      • 1.3 Disable Nouveau Driver
      • 1.4 Close x-server related services
      • 1.5 execute run file
    • 2. install cuda
      • 2.1 Specific operation steps
      • 2.2 Configure the runtime library
      • 2.3 Solve nvcc -V does not work
    • 3. install cuDnn
      • 3.1 Go to the official website to download and select the corresponding version. Note that there are three packages:
      • 3.2 Execute the installation command
      • 3.3 Entry compilation test:
    • 4. Official reference documents

1.Install NVIDIA Graphics Driver via runfile

Reference: https://gist.github.com/wangruohui/df039f0dc434d6486f5d4d098aa52d07#install-nvidia-graphics-driver-via-runfile

1.1 Uninstall the old version before:

zutnlp@YQ2:/opt/nvidia$ sudo apt-get purge nvidia*

1.2 Download cuda Driver

https://www.nvidia.com/Download/index.aspx?lang=en-us
Find the corresponding version
It should be because the machine has already downloaded it before, just need to scp it:

zutnlp@YQ1:~/.ssh$ sudo scp [email protected]:~/Downloads/NVIDIA-Linux-x86_64-418.87.01.run [email protected]:/opt/nvidia

If you encounter scp permission problems, please modify the permission of the prompt file to 777:

zutnlp@YQ2:/opt$ sudo chmod 777 nvidia/
[sudo] password for zutnlp:

1.3 Disable Nouveau Driver

Because it has been set up before, almost no operation is required. If it is not in the following form, please use vim to edit and add the content as follows.

zutnlp@YQ2:~$ cat /etc/modprobe.d/blacklist-nouveau.conf
blacklist nouveau
options nouveau modset=0

1.4 Close x-server related services

sudo service lightdm stop

1.5 execute run file

I don’t know why -dkms reports an error, but if you don’t add this parameter -dkms, the driver will fail after the kenel update, and you need to reinstall the driver. Finally, the problem is found, which is caused by the lack of dependencies:

zutnlp@YQ2:/opt/nvidia$ sudo sh NVIDIA-Linux-x86_64-418.87.01.run -s --dkms --no-opengl-files
Verifying archive integrity...OK
Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 418.87.01................................... ................................................... ................................................... ................................................... ................................................... ................................................... ................................................... ................................................... ................................................... ................................................... ...................................................

ERROR: Failed to find dkms on the system!
ERROR: Failed to install the kernel module through DKMS. No kernel module was
       installed; please try installing again without DKMS, or check the DKMS
       logs for more information.


ERROR: Installation has failed. Please see the file
       '/var/log/nvidia-installer.log' for details. You may find suggestions
       on fixing installation problems in the README available on the Linux
       driver download page at www.nvidia.com.

Finally, I learned that some dependencies are missing, so I added some dependent libraries as follows for insurance purposes:

 sudo apt-get update
 sudo apt-get install dkms build-essential linux-headers-generic
 sudo apt-get install gcc-multilib xorg-dev
 sudo apt-get install freeglut3-dev libx11-dev libxmu-dev install libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

Then it succeeds after re-executing:

zutnlp@YQ2:/opt/nvidia$ sudo sh NVIDIA-Linux-x86_64-418.87.01.run -s --dkms --no-opengl-files
parameter description:
--no-opengl-files: Indicates that only the driver files are installed, and the OpenGL files are not installed. This parameter cannot be omitted, otherwise it will lead to an infinite loop in the login interface, which is generally called "login loop" or "stuck in login" in English. **Required parameter explanation**: Because the NVIDIA driver will install OpenGL by default, and the Ubuntu kernel itself also has OpenGL, which is closely related to the GUI display. Once the NVIDIA driver overrides OpenGL, when the GUI needs to dynamically link to the OpenGL library cause problems.
–no-x-check: Indicates that the X service is not checked when installing the driver. It is not necessary, and we have disabled the graphical interface.
–no-nouveau-check: Indicates that nouveau is not checked when installing the driver. It is not necessary, and we have disabled the driver.
-Z, --disable-nouveau: disable nouveau. This parameter is not required because nouveau was manually disabled earlier.
-A: View more advanced options.
-dkms (recommended) Installs the driver into the module when the kernel updates itself, preventing the driver from being reinstalled. ** During a kernel update, dkms triggers driver recompilation to the new kernel module stack.
-s is used for silent installation which should be used for batch installation. For installation on a single computer, this option should be turned off for more installtion information.

The following proves that the driver installation is successful:

zutnlp@YQ2:/opt/nvidia$ nvidia-smi
Sun Nov 17 18:47:07 2019
 + ------------------------------------------------- ---------------------------- +
| NVIDIA-SMI 418.87.01 Driver Version: 418.87.01 CUDA Version: 10.1 |
|------------------------------- + ----------------- ----- + ---------------------- +
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|=================================+ ================== ===== + =======================|
| 0 Tesla P100-PCIE... Off | 00000000:04:00.0 Off | 0 |
| N/A 34C P0 29W / 250W | 0MiB / 12198MiB | 0% Default |
 + ------------------------------- + ----------------- ----- + ---------------------- +
| 1 Tesla P100-PCIE... Off | 00000000:82:00.0 Off | 0 |
| N/A 35C P0 24W / 250W | 0MiB / 12198MiB | 6% Default |
 + ------------------------------- + ----------------- ----- + ---------------------- +
                                                                               
 + ------------------------------------------------- ---------------------------- +
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|==================================================== ===============================|
| No running processes found |
 + ------------------------------------------------- ---------------------------- +

2.install cuda

2.1 Specific operation steps

https://developer.nvidia.com/cuda-downloads
cuda installation is relatively simple, just execute the run script:
Choose the installation method

wget http://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.243_418.87.00_linux.run
sudo sh cuda_10.1.243_418.87.00_linux.run

It should be because the file is relatively large, so it is recommended to copy from Public Opinion 1 to this machine faster:

zutnlp@YQ1:~/.ssh$ scp /usr/local/cuda_10.1.243_418.87.00_linux.run [email protected]:/opt/nvidia

Here’s the process:

─────────────────────────────────────────────── ─────────────────────────────────────────┐
│ End User License Agreement │
│ -------------------------- │
│ │
│ │
│ Preface │
│ ------- │
│ │
│ The Software License Agreement in Chapter 1 and the Supplement │
│ in Chapter 2 contain license terms and conditions that govern │
│ the use of NVIDIA software. By accepting this agreement, you │
│ agree to comply with all the terms and conditions applicable │
│ to the product(s) included herein. │
│ │
│ │
│ NVIDIA Driver │
│ │
│ │
│ Description │
│ │
│ This package contains the operating system driver and │
│───────────────────────────────────────────────────────────────────────────────────────── ────────────────────────────────────────────────────────────────────────────────────────│
│ Do you accept the above EULA? (accept/decline/quit): │
│ accept │

Select the space, and there is an x in front of it to indicate selection. Here, only cuda toolkit can be selected:

│CUDA Installer│
│ - [ ] Driver │
│ [ ] 418.87.00 │
│ + [X] CUDA Toolkit 10.1 │
│ [ ] CUDA Samples 10.1 │
│ [ ] CUDA Demo Suite 10.1 │
│ [ ] CUDA Documentation 10.1 │
│ Options │
│ Install

select yes

─────────────────────────────────────────────── ────────────────────────────────────────────┐
│ A symlink already exists at /usr/local/cuda. Update to this installation? │
│ Yes │
│No

Wait for a while and the following will appear to indicate that the installation is complete:

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

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

Please make sure that
 - PATH includes /usr/local/cuda-10.1/bin
 - LD_LIBRARY_PATH includes /usr/local/cuda-10.1/lib64, or, add /usr/local/cuda-10.1/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-10.1/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.1/doc/pdf for detailed information on setting up CUDA.
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 418.00 is required for CUDA 10.1 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run --silent --driver

Logfile is /var/log/cuda-installer.log

Enter the following command to verify success:

zutnlp@YQ2:/opt/nvidia$ cat /usr/local/cuda/version.txt
CUDA Version 10.1.243

2.2 Configure runtime library

sudo bash -c "echo /usr/local/cuda/lib64/ > /etc/ld.so.conf.d/cuda.conf"
sudo ldconfig

Add /usr/local/cuda/bin to the environment variable path of the system, use the following command:

zutnlp@YQ2:/opt/nvidia$ vim /etc/environment
zutnlp@YQ2:/opt/nvidia$ sudo vim /etc/environment
zutnlp@YQ2:/opt/nvidia$ source /etc/environment

2.3 Solve nvcc -V does not work

Found that cuda has been upgraded but nvcc still shows the previous cuda 9.0:

zutnlp@YQ2:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

Therefore, the following code needs to be added to the end of /etc/profile. After the operation is completed, it is as follows:

export PATH=/usr/local/cuda/bin${PATH: + :${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH: + :${LD_LIBRARY_PATH}}

After the operation is complete, you can view the following:

zutnlp@YQ2:~$ cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] & amp; & amp; [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      ./etc/bash.bashrc
    the fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='#'
    else
      PS1='$'
    the fi
  the fi
the fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      .$i
    the fi
  done
  unset i
the fi

xrandr --newmode 1920x1080 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync + vsync
xrandr --addmode VGA-1 1920x1080
xrandr --output VGA-1 --mode 1920x1080

export PYTHONPATH=/home/yuqing/data/tf/models:/home/zutnlp/quanyou.chang/models/tf/slim
export PATH=/usr/local/cuda/bin${PATH: + :${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH: + :${LD_LIBRARY_PATH}}

The operation steps are as follows:

zutnlp@YQ2:~$ vim /etc/profile
zutnlp@YQ2:~$ sudo vim /etc/profile
[sudo] password for zutnlp:
zutnlp@YQ2:~$ source /etc/profile
Can't open display
Can't open display
Can't open display

At this time, you can test whether the configuration is successful as follows:

zutnlp@YQ2:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

3.install cuDnn

Citing the install cuDNN part of this article: https://medium.com/repro-repo/install-cuda-and-cudnn-for-tensorflow-gpu-on-ubuntu-79306e4ac04e

3.1 Go to the official website to download and select the corresponding version. Note that there are three packages:

https://developer.nvidia.com/rdp/cudnn-download

Official Website

zutnlp@YQ1:~/wueryong/nvidia/cuDNNN$ ll
total 336524
drwxrwxr-x 2 zutnlp zutnlp 4096 Nov 17 15:50 ./
drwxrwxr-x 3 zutnlp zutnlp 4096 Nov 17 15:50 ../
-rw-r--r-- 1 zutnlp zutnlp 180962466 Nov 16 21:19 libcudnn7_7.6.5.32-1+cuda10.1_amd64.deb
-rw-r--r-- 1 zutnlp zutnlp 159185716 Nov 16 21:18 libcudnn7-dev_7.6.5.32-1+cuda10.1_amd64.deb
-rw-r--r-- 1 zutnlp zutnlp 4428908 Nov 16 21:03 libcudnn7-doc_7.6.5.32-1+cuda10.1_amd64.deb

3.2 Execute the installation command

zutnlp@YQ1:~/wueryong/nvidia/cuDNNN$ sudo dpkg -i libcudnn7_7.6.5.32-1 + cuda10.1_amd64.deb
Selecting previously unselected package libcudnn7.
(Reading database ... 351236 files and directories currently installed.)
Preparing to unpack libcudnn7_7.6.5.32-1 + cuda10.1_amd64.deb...
Unpacking libcudnn7 (7.6.5.32-1 + cuda10.1)...
Setting up libcudnn7 (7.6.5.32-1 + cuda10.1)...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
zutnlp@YQ1:~/wueryong/nvidia/cuDNNN$ sudo dpkg -i libcudnn7-dev_7.6.5.32-1 + cuda10.1_amd64.deb
Selecting previously unselected package libcudnn7-dev.
(Reading database ... 351242 files and directories currently installed.)
Preparing to unpack libcudnn7-dev_7.6.5.32-1 + cuda10.1_amd64.deb...
Unpacking libcudnn7-dev (7.6.5.32-1 + cuda10.1)...
Setting up libcudnn7-dev (7.6.5.32-1 + cuda10.1)...
update-alternatives: using /usr/include/x86_64-linux-gnu/cudnn_v7.h to provide /usr/include/cudnn.h (libcudnn) in auto mode
zutnlp@YQ1:~/wueryong/nvidia/cuDNNN$ sudo dpkg -i libcudnn7-doc_7.6.5.32-1 + cuda10.1_amd64.deb
Selecting previously unselected package libcudnn7-doc.
(Reading database ... 351248 files and directories currently installed.)
Preparing to unpack libcudnn7-doc_7.6.5.32-1 + cuda10.1_amd64.deb...
Unpacking libcudnn7-doc (7.6.5.32-1 + cuda10.1)...
Setting up libcudnn7-doc (7.6.5.32-1 + cuda10.1)...

3.3 Entry compilation test:

zutnlp@YQ1:/usr/src/nvidia-418.87.01$ cp -r /usr/src/cudnn_samples_v7/ ~
zutnlp@YQ1:/usr/src/nvidia-418.87.01$ cd ~/cudnn_samples_v7/mnistCUDNN
zutnlp@YQ1:~/cudnn_samples_v7/mnistCUDNN$ make clean & amp; & amp; make
rm -rf *o
rm -rf mnistCUDNN
Linking again cublasLt = true
CUDA VERSION: 10010
TARGET ARCH: x86_64
HOST_ARCH: x86_64
TARGET OS: linux
SMS: 30 35 50 53 60 61 62 70 72 75
/usr/local/cuda/bin/nvcc -ccbin g++ -I/usr/local/cuda/include -I/usr/local/cuda/include -IFreeImage/include -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_62 ,code=sm_62 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_72,code=sm_72 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o fp16_dev.o -c fp16_dev.cu
g++ -I/usr/local/cuda/include -I/usr/local/cuda/include -IFreeImage/include -o fp16_emu.o -c fp16_emu.cpp
g++ -I/usr/local/cuda/include -I/usr/local/cuda/include -IFreeImage/include -o mnistCUDNN.o -c mnistCUDNN.cpp
/usr/local/cuda/bin/nvcc -ccbin g + + -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53, code=sm_53 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_62,code=sm_62 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_72,code=sm_72 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o mnistCUDNN fp16_dev.o fp16_emu.o mnistCUDNN.o -I/usr/local/cuda/include -I/usr/local/cuda/include -IFreImage /include -L/usr/local/cuda/lib64 -L/usr/local/cuda/lib64 -lcublasLt -LFreeImage/lib/linux/x86_64 -LFreeImage/lib/linux -lcudart -lcublas -lcudnn -lfreeimage -lstdc++ -lm

zutnlp@YQ1:~/cudnn_samples_v7/mnistCUDNN$ ./mnistCUDNN
cudnnGetVersion() : 7605 , CUDNN_VERSION from cudnn.h : 7605 (7.6.5)
Host compiler version: GCC 4.9.4
There are 2 CUDA capable devices on your machine:
device 0 : sms 56 Capabilities 6.0, SmClock 1328.5 Mhz, MemSize (Mb) 12198, MemClock 715.0 Mhz, Ecc=1, boardGroupID=0
device 1 : sms 56 Capabilities 6.0, SmClock 1328.5 Mhz, MemSize (Mb) 12198, MemClock 715.0 Mhz, Ecc=1, boardGroupID=1
Using device 0

Testing single precision
Loading image data/one_28x28.pgm
Performing forward propagation... ?
Testing cudnnGetConvolutionForwardAlgorithm...
Fastest algorithm is Algo 1
Testing cudnnFindConvolutionForwardAlgorithm...
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.031264 time requiring 0 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.068768 time requiring 3464 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.079424 time requiring 57600 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 5: 0.095104 time requiring 203008 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.101568 time requiring 2057744 memory
Resulting weights from Softmax:
0.0000000 0.9999399 0.0000000 0.0000000 0.0000561 0.0000000 0.0000012 0.0000017 0.0000010 0.0000000
Loading image data/three_28x28.pgm
Performing forward propagation... ?
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 0.9999288 0.0000000 0.0000711 0.0000000 0.0000000 0.0000000 0.0000000
Loading image data/five_28x28.pgm
Performing forward propagation... ?
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 0.9999820 0.0000154 0.0000000 0.0000012 0.0000006

Result of classification: 1 3 5

Test passed!

Testing half precision (math in single precision)
Loading image data/one_28x28.pgm
Performing forward propagation... ?
Testing cudnnGetConvolutionForwardAlgorithm...
Fastest algorithm is Algo 1
Testing cudnnFindConvolutionForwardAlgorithm...
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.024544 time requiring 0 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.059488 time requiring 3464 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.068256 time requiring 28800 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 5: 0.076192 time requiring 203008 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.090816 time requiring 2057744 memory
Resulting weights from Softmax:
0.0000001 1.0000000 0.0000001 0.0000000 0.0000563 0.0000001 0.0000012 0.0000017 0.0000010 0.0000001
Loading image data/three_28x28.pgm
Performing forward propagation... ?
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000714 0.0000000 0.0000000 0.0000000 0.0000000
Loading image data/five_28x28.pgm
Performing forward propagation... ?
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 1.0000000 0.0000154 0.0000000 0.0000012 0.0000006

Result of classification: 1 3 5

Test passed!

4. Official reference documents

Official documentation: https://docs.nvidia.com/deeplearning/sdk/cudnn-install/