-
Notifications
You must be signed in to change notification settings - Fork 10
/
nvidia-docker-installer.sh
97 lines (83 loc) · 2.46 KB
/
nvidia-docker-installer.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
set -o errexit
set -o pipefail
set -u
set -x
NVIDIA_DRIVER_VERSION="${NVIDIA_DRIVER_VERSION:-384.125}"
NVIDIA_DRIVER_DOWNLOAD_URL_DEFAULT="https://us.download.nvidia.com/tesla/${NVIDIA_DRIVER_VERSION}/NVIDIA-Linux-x86_64-${NVIDIA_DRIVER_VERSION}.run"
NVIDIA_DRIVER_DOWNLOAD_URL="${NVIDIA_DRIVER_DOWNLOAD_URL:-$NVIDIA_DRIVER_DOWNLOAD_URL_DEFAULT}"
NVIDIA_INSTALLER_RUNFILE="$(basename "${NVIDIA_DRIVER_DOWNLOAD_URL}")"
NVIDIA_INSTALL_DIR="${NVIDIA_INSTALL_DIR:-/tmp}"
set -x
RETCODE_SUCCESS=0
RETCODE_ERROR=1
RETRY_COUNT=5
download_kernel_src() {
echo "Downloading kernel sources..."
apt-get update
apt-get install -y linux-headers-$(uname -r)
apt-get install -y gcc libc-dev
echo "Downloading kernel sources... DONE."
}
download_nvidia_installer() {
echo "Downloading Nvidia installer..."
pushd "${NVIDIA_INSTALL_DIR}"
curl -L -S -f "${NVIDIA_DRIVER_DOWNLOAD_URL}" -o "${NVIDIA_INSTALLER_RUNFILE}"
popd
echo "Downloading Nvidia installer... DONE."
}
run_nvidia_installer() {
echo "Running Nvidia installer..."
pushd "${NVIDIA_INSTALL_DIR}"
sh "${NVIDIA_INSTALLER_RUNFILE}" \
--no-install-compat32-libs \
--log-file-name="${NVIDIA_INSTALL_DIR}/nvidia-installer.log" \
--no-drm \
--silent \
--accept-license
popd
echo "Running Nvidia installer... DONE."
}
configure_gpu() {
nvidia-smi -pm 1
nvidia-smi -acp 0
nvidia-smi --auto-boost-default=0
nvidia-smi --auto-boost-permission=0
nvidia-smi -ac 2505,875
}
verify_nvidia_installation() {
echo "Verifying Nvidia installation..."
nvidia-smi
nvidia-modprobe -c0 -u
echo "Verifying Nvidia installation... DONE."
}
install_nvidia_docker2() {
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | tee /etc/apt/sources.list.d/nvidia-docker.list
apt-get update
apt-get install -y nvidia-docker2=2.0.3+docker18.06.1-1 nvidia-container-runtime=2.0.0+docker18.06.1-1
}
set_nvidia_container_runtime() {
cat > /etc/docker/daemon.json <<EOL
{
"default-runtime": "nvidia",
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": []
}
}
}
EOL
}
main() {
download_kernel_src
download_nvidia_installer
run_nvidia_installer
configure_gpu
verify_nvidia_installation
install_nvidia_docker2
set_nvidia_container_runtime
}
main "$@"