This page looks best with JavaScript enabled

How to Install GPU Drivers on CentOS

 ·  ☕ 5 min read

Using CentOS 7.7 and a Tesla P100 GPU as an example.

1. Preparing the Base Environment

  • Install the lspci command
1
yum install -y pciutils
  • Check whether the GPU supports CUDA
1
2
3
lspci | grep -i nvidia

00:09.0 3D controller: NVIDIA Corporation GP100GL [Tesla P100 PCIe 12GB] (rev a1)

List of CUDA-capable GPUs: https://developer.nvidia.com/cuda-gpus

  • Check whether the system supports CUDA
1
2
3
4
uname -m && cat /etc/redhat-release

x86_64
CentOS Linux release 7.7.1908 (Core)

List of CUDA-capable OSes: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements

  • Install system tooling packages
1
2
3
yum update -y
yum install -y wget vim gcc
yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
  • Install Docker

Version 19.03 or later is required, reference link .

Reference for installing Docker: Installing a Specific Docker Version .

2. Installing the GPU Driver & CUDA

2.1 Disabling the System’s Default nouveau Driver

Before blacklisting:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
lsmod | grep nouveau

nouveau              1898794  0
mxm_wmi                13021  1 nouveau
wmi                    21636  2 mxm_wmi,nouveau
video                  24538  1 nouveau
i2c_algo_bit           13413  1 nouveau
ttm                    96673  2 bochs_drm,nouveau
drm_kms_helper        186531  2 bochs_drm,nouveau
drm                   456166  5 ttm,bochs_drm,drm_kms_helper,nouveau

Disabling nouveau :

1
2
bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"

Rebuild the initramfs image

1
2
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
dracut /boot/initramfs-$(uname -r).img $(uname -r)

Reboot the system; after blacklisting:

1
2
3
lsmod | grep nouveau

(no output)

2.2 Installing the GPU Driver

There are two installation methods:

  • The first: install the kmod-nvidia driver

Add the repository

1
2
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

Install nvidia-detect :

1
yum install -y nvidia-detect

Check whether a matching kmod-nvidia version is available:

1
nvidia-detect -v

Install the kmod-nvidia driver:

1
yum install -y kmod-nvidia
  • The second: download the driver from the official site and install it

On the Nvidia official driver download page, find the GPU type shown by the lspci | grep -i nvidia command.

1
2
wget http://cn.download.nvidia.com/tesla/440.64.00/nvidia-driver-local-repo-rhel7-440.64.00-1.0-1.x86_64.rpm
rpm -Uvh nvidia-driver-local-repo-rhel7-440.64.00-1.0-1.x86_64.rpm

You can also download the Shell script to install

1
2
3
wget http://us.download.nvidia.com/tesla/440.33.01/NVIDIA-Linux-x86_64-440.64.00.run
chmod +x NVIDIA-Linux-x86_64-440.64.00.run
bash ./NVIDIA-Linux-x86_64-440.64.00.run

2.3 Installing CUDA

On the Nvidia developer cuda-toolkit-archive page, find the latest toolkit version. Following the page’s prompts, select your operating system; below are the installation commands obtained for CentOS 7.7:

1
2
3
4
5
wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-rhel7-10-2-local-10.2.89-440.33.01-1.0-1.x86_64.rpm
sudo rpm -i cuda-repo-rhel7-10-2-local-10.2.89-440.33.01-1.0-1.x86_64.rpm
sudo yum clean all
sudo yum -y install nvidia-driver-latest-dkms cuda
sudo yum -y install cuda-drivers

2.4 Verifying the Installation

After rebooting the machine, check whether Nvidia CUDA was installed successfully.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
nvidia-smi

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.82       Driver Version: 440.82       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  Tesla P100-PCIE...  Off  | 00000000:00:09.0 Off |                    0 |
| N/A   35C    P0    27W / 250W |      0MiB / 12198MiB |      6%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

3. Installing nvidia-docker

nvidia-docker provides support for using GPU acceleration inside Docker.

  • Install nvidia-docker
1
2
3
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo
yum install -y nvidia-container-runtime nvidia-container-toolkit nvidia-docker2
  • Add a new runtime

Edit the /etc/docker/daemon.json file and add the following content:

1
2
3
4
5
6
7
8
{
  "runtimes": {
    "nvidia": {
      "path": "/usr/bin/nvidia-container-runtime",
      "runtimeArgs": []
    }
  }
}
  • Restart Docker for the change to take effect
1
systemctl restart docker
  • Verify the installation
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
docker run --gpus all nvidia/cuda:10.0-base nvidia-smi

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.82       Driver Version: 440.82       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  Tesla P100-PCIE...  Off  | 00000000:00:09.0 Off |                    0 |
| N/A   36C    P0    26W / 250W |      0MiB / 12198MiB |      6%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
docker run --runtime=nvidia nvidia/cuda:10.0-base nvidia-smi

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.82       Driver Version: 440.82       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  Tesla P100-PCIE...  Off  | 00000000:00:09.0 Off |                    0 |
| N/A   36C    P0    26W / 250W |      0MiB / 12198MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
nvidia-docker run nvidia/cuda:10.0-base nvidia-smi

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.82       Driver Version: 440.82       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  Tesla P100-PCIE...  Off  | 00000000:00:09.0 Off |                    0 |
| N/A   35C    P0    26W / 250W |      0MiB / 12198MiB |      6%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

4. References


微信公众号
WRITTEN BY
微信公众号