CentOS 8
Sponsored Link

Install NVIDIA Container Toolkit2020/07/21

 
Install NVIDIA Container Toolkit to use GPU on your Computer from Containers.
[1]
[2]
[3] Install NVIDIA Container Toolkit.
[root@dlp ~]#
curl https://nvidia.github.io/nvidia-docker/centos8/nvidia-docker.repo > /etc/yum.repos.d/nvidia-docker.repo

[root@dlp ~]#
dnf -y install nvidia-container-toolkit

[4] If SELinux is enabled, change policy like follows.
[root@dlp ~]#
vi nvidiasmi.te
# create new

module nvidiasmi 1.0;

require {
        type container_runtime_tmpfs_t;
        type container_t;
        type xserver_misc_device_t;
        class file { open read };
        class chr_file { getattr ioctl open read write };
}

#============= container_t ==============
allow container_t container_runtime_tmpfs_t:file { open read };
allow container_t xserver_misc_device_t:chr_file { getattr ioctl open read write };

[root@dlp ~]#
checkmodule -m -M -o nvidiasmi.mod nvidiasmi.te

[root@dlp ~]#
semodule_package --outfile nvidiasmi.pp --module nvidiasmi.mod

[root@dlp ~]#
semodule -i nvidiasmi.pp

[5] This is how to use [nvidia-smi] from Containres.
# pull Cuda 11.0 image and run [nvidia-smi]

[root@dlp ~]#
podman run -e NVIDIA_VISIBLE_DEVICES=all nvidia/cuda:11.0-base nvidia-smi

Tue Jul 20 19:32:32 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.57       Driver Version: 450.57       CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070    Off  | 00000000:05:00.0 Off |                  N/A |
| 27%   35C    P5    27W / 180W |      0MiB /  8119MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

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

# pull Cuda 10.0 image and connect to the interactive session, then run [nvidia-smi]

[root@dlp ~]#
podman run -it -e NVIDIA_VISIBLE_DEVICES=all nvidia/cuda:10.0-base bash

root@81ccbb753393:/#
nvidia-smi

Tue Jul 20 19:37:10 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.57       Driver Version: 450.57       CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070    Off  | 00000000:05:00.0 Off |                  N/A |
| 27%   36C    P5    25W / 180W |      0MiB /  8119MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

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

root@81ccbb753393:/# exit 

[root@dlp ~]#
podman images

REPOSITORY              TAG         IMAGE ID       CREATED        SIZE
docker.io/nvidia/cuda   11.0-base   27c1a1745519   4 days ago     125 MB
docker.io/nvidia/cuda   10.0-base   841d44dd4b3c   7 months ago   113 MB
Matched Content