CentOS Stream 8
Sponsored Link

Install NVIDIA Container Toolkit2021/04/13

 
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.
# confirm available images of Cuda

[root@dlp ~]#
curl -s https://registry.hub.docker.com/v1/repositories/nvidia/cuda/tags | sed "s/,/\n/g" | grep name

 "name": "10.0-base"}
 "name": "10.0-base-centos6"}
 "name": "10.0-base-centos7"}
 "name": "10.0-base-ubi7"}
 "name": "10.0-base-ubuntu14.04"}
 "name": "10.0-base-ubuntu16.04"}
 "name": "10.0-base-ubuntu18.04"}
.....
.....

# 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 Apr 13 05:04:42 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| 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    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                                                 |
+-----------------------------------------------------------------------------+

# connect to the interactive session and run [nvidia-smi]

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

root@39eec91a01d8:/#
nvidia-smi

Tue Apr 13 05:05:16 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| 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    18W / 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@39eec91a01d8:/# exit 

[root@dlp ~]#
podman images

REPOSITORY             TAG        IMAGE ID      CREATED       SIZE
docker.io/nvidia/cuda  11.0-base  2ec708416bb8  7 months ago  125 MB
Matched Content