forked from mikew-heavyai/heavyai-devstack
-
Notifications
You must be signed in to change notification settings - Fork 3
/
nvidiaRuntime2.sh
executable file
·42 lines (34 loc) · 1.4 KB
/
nvidiaRuntime2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Script to configure Nvidia drivers and set up Nvidia container toolkit
nvidia_docker_toolkit() {
# Add Nvidia GPG key for container toolkit using the recommended method
sudo mkdir -p /usr/share/keyrings
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit.gpg
# Determine the correct distribution version for the Nvidia repository
distribution=$(. /etc/os-release; echo $ID$VERSION_ID)
sudo curl -fsSL https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list > /dev/null
# Update package lists and install Nvidia container toolkit
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
# Configure Docker to use Nvidia container runtime
sudo nvidia-ctk runtime configure --runtime=docker --set-as-default
# Create or update Docker daemon.json
sudo bash -c 'cat > /etc/docker/daemon.json << EOF
{
"default-runtime": "nvidia",
"runtimes": {
"nvidia": {
"path": "nvidia-container-runtime",
"runtimeArgs": []
}
}
}
EOF'
# Restart Docker to apply changes
sudo systemctl restart docker
# Test the Nvidia container toolkit with a Docker container
sudo docker run --rm --gpus all ubuntu nvidia-smi
}
# Call the function
nvidia_docker_toolkit