Ubuntu18.04 view graphics card information and install NVDIA graphics driver driver + Cuda + Cudnn

Environment Setup 01-How to View Graphics Card Information and Install NVDIA Graphics Driver in Ubuntu

The original post is a bit old, here is an update, it can be regarded as a quick installation note!
https://blog.csdn.net/tanmx219/article/details/86553485

1. Check the graphics card model

Enter the following command:

lshw -c video

The following information will be displayed

WARNING: you should run this program as super-user.
  *-display                 
       description: VGA compatible controller
       product: GM107M [GeForce GTX 950M]
       vendor: NVIDIA Corporation
       physical id: 0
       bus info: pci@0000:04:00.0
       version: a2
       width: 64 bits
       clock: 33MHz
       capabilities: vga_controller bus_master cap_list rom
       configuration: driver=nouveau latency=0
       resources: irq:30 memory:fa000000-faffffff memory:d0000000-dfffffff memory:ce000000-cfffffff ioport:ec00(size=128) memory:c0000-dffff
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.

2. Find the driver of your graphics card

Use this command to view the drivers you can use:

ubuntu-drivers devices

The display results are as follows,

matth32@matth32-Thurley:~/下载$ ubuntu-drivers devices

== /sys/devices/pci0000:00/0000:00:07.0/0000:04:00.0 ==
modalias : pci:v000010DEd0000139Asv00001025sd0000091Bbc03sc00i00
vendor   : NVIDIA Corporation
model    : GM107M [GeForce GTX 950M]
driver   : nvidia-driver-440 - distro non-free recommended
driver   : nvidia-driver-390 - distro non-free
driver   : nvidia-driver-435 - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin

Go to the NVDIA driver search page to search for the driver model required by the graphics card and download it (as shown in the figure).

Choose the recommended driver,

nvidia-driver-440 - distro non-free recommended

Install after downloading

 sudo sh NVIDIA-Linux-x86_64-440.100.run

Appendix 1: How to uninstall Nouveau.

How to remove Nouveau kernel driver (fix Nvidia install error)

This is because, before the installation, Nouveau may have been started, so Nvidia cannot be installed successfully.

#---open a terminal---
sudo apt-get remove nvidia*
sudo apt autoremove
sudo apt-get install dkms build-essential linux-headers-generic
 
sudo vim /etc/modprobe.d/blacklist.conf
#---save the following info into file blacklist.conf---
blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
#---end of the info saved----
 
#---go back to the terminal---
echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
sudo update-initramfs -u
reboot
————————————————
参考链接:https://blog.csdn.net/tanmx219/java/article/details/86553485

Appendix 2: Problems encountered during installation

 The distribution-provided pre-install script failed!  Are you sure you want
  to continue?                                                                 
       
                 Continue installation      Abort installation       

----> Continue installation

Would you like to register the kernel module sources with DKMS? This will    
  allow DKMS to automatically build a new module, if you install a different   
  kernel later.

                          Yes                       No  
---->No

 The CC version check failed:

  The kernel was built with gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1), 
  but the current compiler version is cc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0.  

  This may lead to subtle problems; if you are not certain whether the         
  mismatched compiler will be compatible with your kernel, you may wish to     
  abort installation, set the CC environment variable to the name of the       
  compiler used to compile your kernel, and restart installation.

                Ignore CC version check     Abort installation         

----> select ignore

 WARNING: Ignoring CC version mismatch:

           The kernel was built with gcc version 7.4.0 (Ubuntu
           7.4.0-1ubuntu1~18.04.1), but the current compiler version is cc     
           (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0.

                                       OK  
----> OK

Install NVIDIA's 32-bit compatibility libraries?
                                                                               
                          Yes                       No   
----> No

 An incomplete installation of libglvnd was found. All of the essential       
  libglvnd libraries are present, but one or more optional components are      
  missing. Do you want to install a full copy of libglvnd? This will overwrite 
  any existing libglvnd libraries.

      Don't install  Install and overw          Abort installation.       

---->Install and overw

Would you like to run the nvidia-xconfig utility to automatically update
  your X configuration file so that the NVIDIA X driver will be used when you
  restart X?  Any pre-existing X configuration file will be backed up.         
                                                                      
                          Yes                       No                 
                          
---->Yes

Your X configuration file has been successfully updated.  Installation of    
  the NVIDIA Accelerated Graphics Driver for Linux-x86_64 (version: 440.100)   
  is now complete.

                                       OK  
----> OK

Three, check after installation

Check the NVIDIA version to check whether the installation is complete

$ nvidia-smi

Insert picture description here

Environment Build 02-Install cuda and cudnn on Ubuntu

Check the installed nvidia driver version number

nvidia-smi //第一行信息

~$ nvidia-smi
Fri Jul 24 11:55:29 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.100      Driver Version: 440.100      CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 950M    Off  | 00000000:04:00.0  On |                  N/A |
| N/A   35C    P8    N/A /  N/A |    189MiB /  4038MiB |      1%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1129      G   /usr/lib/xorg/Xorg                            12MiB |
|    0      1179      G   /usr/bin/gnome-shell                          47MiB |
|    0      3130      G   /usr/lib/xorg/Xorg                            59MiB |
|    0      3281      G   /usr/bin/gnome-shell                          62MiB |
|    0      3990      G   /usr/lib/firefox/firefox                       1MiB |
+-----------------------------------------------------------------------------+

You can see that the version is 10.2.

Select the installed CUDA version and download

Download
link NVIDIA's official cuda and driver correspondence

Find a button similar to DOWNLOAD-"LEGACY RELEASES, and finally find the version you need

10.2 cuda address

Install cuda

Use the installation method provided by the official website

Base Installer
Installation Instructions:

wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run
sudo sh cuda_10.2.89_440.33.01_linux.run

If the network is not good, it will be a bit slow, 2G more. Of course, you can also install it after downloading the tool.

During installation, you will be asked if you want to accept anything, enter accept and then press Enter to install.

Under normal circumstances, if the installation is successful, the following prompt words will be given

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

Driver:   Installed
Toolkit:  Installed in /usr/local/cuda-10.2/
Samples:  Installed in /home/matthew/, but missing recommended libraries

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

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-10.2/bin
To uninstall the NVIDIA Driver, run nvidia-uninstall

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.2/doc/pdf for detailed information on setting up CUDA.
Logfile is /var/log/cuda-installer.log

If the installation is unsuccessful, it is mostly because drm is enabled in the graphical interface. Use the following method to switch to text console mode, and then use the installation command

sudo sh cuda_10.2.89_440.33.01_linux.run

Of course, if you are using the character interface for the first time, it is best to set a password first, so as not to be unable to log in.

sudo passwd root

Then use the following method to install in the character interface. After installation, return to the graphical interface.

When an error is reported during installation-switch to the character interface

报错 ERROR: An NVIDIA kernel module ‘nvidia-drm’ appears to already be loaded in your kernel.

Close the graphical user interface

sudo systemctl set-default multi-user.target
sudo reboot

Open the graphical user interface

sudo systemctl set-default graphical.target
sudo reboot

Generally speaking, after switching to the character interface, there is no problem with the installation. If it is difficult to switch to the graphical interface, you can consider the following methods

(1)edit  /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="text"
GRUB_TERMINAL=console

(2)After saving changes you need to run:
sudo update-grub
sudo systemctl enable multi-user.target --force
sudo systemctl set-default multi-user.target

(3)Undoing text-mode
sudo systemctl enable graphical.target --force
sudo systemctl set-default graphical.target 

Configure Cuda environment variables after installation

After the installation is successful in the text console mode, there will be a prompt, we can configure it according to the prompt, here we configure it according to the practice of most people on the Internet,

sudo gedit ~/.bashrc is added
at the end of ~/.bashrc (a total of three additions have been seen online): the
first

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

The second

export PATH=/usr/local/cuda-10.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda10.2/lib64

The third type (* $PATH means adding to PATH)

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

After configuring the environment variable, you must update it, otherwise it will not take effect immediately. You can also restart the computer to make the environment variables take effect:
$source ~/.bashrc
or:
$source /etc/profile

source ~/.bashrc
nvcc --version

If the following text is displayed, the installation is successful:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

CUDNN installation

To download cuDNN,
first go to the official website to download cuDNN (https://developer.nvidia.com/cudnn), you need to be registered as a developer to download, and direct downloading may be very slow. Note the choice of version. For example, I chose
libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb
corresponding to
Download cuDNN v7.6.5 (November 18th, 2019), for CUDA 10.2
Library for Windows, Mac, Linux, Ubuntu and RedHat /Centos(x86_64architecture)
cuDNN Library for Windows 7
cuDNN Library for Windows 10
cuDNN Library for Linux
cuDNN Runtime Library for Ubuntu18.04 (Deb) ---> Select this package
cuDNN Developer Library for Ubuntu18.04 (Deb)
cuDNN Code Samples and User Guide for Ubuntu18.04 (Deb)
cuDNN Runtime Library for Ubuntu16.04 (Deb)
cuDNN Developer Library for Ubuntu16.04 (Deb)
cuDNN Code Samples and User Guide for Ubuntu16.04 (Deb)

After downloading, right click "open with software installation"-"install", and then OK.
Of course, you can also use the copy method to open the DEB package, there is a data package in it, and the files in it are all placed according to the path. The official installation method is

  1. Navigate to your directory containing the cuDNN Tar file.

  2. Unzip the cuDNN package.

    $ tar -xzvf cudnn-10.2-linux-x64-v7.6.5.32.tgz
    
  3. Copy the following files into the CUDA Toolkit directory, and change the file permissions.

    $ 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*
    

To repeat, it is mainly to decompress and then execute

sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/

Manual copy also needs to set permissions

sudo chmod a+r /usr/local/cuda/include/cudnn.h 
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

Check the cudnn version

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

If the following text is displayed, the installation is successful:

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

#include "driver_types.h"

Reference materials:

「1」:https://blog.csdn.net/qiancaobaicheng/article/details/95096354

Guess you like

Origin blog.csdn.net/tanmx219/article/details/107591416