-
Notifications
You must be signed in to change notification settings - Fork 618
Expand file tree
/
Copy pathinstall.sh
More file actions
172 lines (145 loc) · 5.74 KB
/
Copy pathinstall.sh
File metadata and controls
172 lines (145 loc) · 5.74 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
set -e
# Clean up
rm -rf /var/lib/apt/lists/*
INSTALL_CUDNN=${INSTALLCUDNN}
INSTALL_CUDNNDEV=${INSTALLCUDNNDEV}
INSTALL_NVTX=${INSTALLNVTX}
INSTALL_TOOLKIT=${INSTALLTOOLKIT}
CUDA_VERSION=${CUDAVERSION}
CUDNN_VERSION=${CUDNNVERSION}
. /etc/os-release
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
apt_get_update()
{
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
}
# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update
apt-get -y install --no-install-recommends "$@"
fi
}
if [ $VERSION_CODENAME = "bookworm" ] || [ $VERSION_CODENAME = "jammy" ] && [ $CUDA_VERSION \< 11.7 ]; then
echo "(!) Unsupported distribution version '${VERSION_CODENAME}' for CUDA < 11.7"
exit 1
fi
export DEBIAN_FRONTEND=noninteractive
check_packages wget ca-certificates
# Determine system architecture and set NVIDIA repository URL accordingly
ARCH=$(uname -m)
case $ARCH in
x86_64)
NVIDIA_ARCH="x86_64"
;;
aarch64 | arm64)
NVIDIA_ARCH="arm64"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
# Add NVIDIA's package repository to apt so that we can download packages
# Updating the repo to ubuntu2204 as ubuntu 20.04 is going out of support.
NVIDIA_REPO_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/$NVIDIA_ARCH"
if [ "${ID}" = "debian" ] && [ "${VERSION_CODENAME}" = "trixie" ]; then
echo "(!) Temporary workaround on debian:trixie: bypassing NVIDIA repo signature checks"
cat > /etc/apt/sources.list.d/cuda.list <<EOF
deb [trusted=yes] ${NVIDIA_REPO_URL}/ /
EOF
apt-get -o Acquire::AllowInsecureRepositories=true \
-o Acquire::AllowDowngradeToInsecureRepositories=true \
update -yq
else
KEYRING_PACKAGE="cuda-keyring_1.0-1_all.deb"
KEYRING_PACKAGE_URL="$NVIDIA_REPO_URL/$KEYRING_PACKAGE"
KEYRING_PACKAGE_PATH="$(mktemp -d)"
KEYRING_PACKAGE_FILE="$KEYRING_PACKAGE_PATH/$KEYRING_PACKAGE"
wget -O "$KEYRING_PACKAGE_FILE" "$KEYRING_PACKAGE_URL"
apt-get install -yq "$KEYRING_PACKAGE_FILE"
apt-get update -yq
fi
# Ensure that the requested version of CUDA is available
cuda_pkg="cuda-libraries-${CUDA_VERSION/./-}"
nvtx_pkg="cuda-nvtx-${CUDA_VERSION/./-}"
toolkit_pkg="cuda-toolkit-${CUDA_VERSION/./-}"
if ! apt-cache show "$cuda_pkg"; then
echo "The requested version of CUDA is not available: CUDA $CUDA_VERSION"
if [ "$NVIDIA_ARCH" = "arm64" ]; then
echo "Note: arm64 supports limited CUDA versions. Please check available versions:"
echo "https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/arm64"
fi
exit 1
fi
echo "Installing CUDA libraries..."
apt-get install -yq "$cuda_pkg"
apt-get update -yq --fix-missing
# auto find recent cudnn version
major_cuda_version=$(echo "${CUDA_VERSION}" | cut -d '.' -f 1)
if [ "$CUDNN_VERSION" = "automatic" ]; then
if [[ "$CUDA_VERSION" < "12.3" ]]; then
CUDNN_VERSION=$(apt-cache policy libcudnn8 | grep "$CUDA_VERSION" | grep -Eo '^[^-1+]*' | sort -V | tail -n1 | xargs)
else
CUDNN_VERSION=$(apt-cache policy libcudnn9-cuda-$major_cuda_version | grep "Candidate" | awk '{print $2}' | grep -Eo '^[^-+]*')
fi
fi
major_cudnn_version=$(echo "${CUDNN_VERSION}" | cut -d '.' -f 1)
if [ "$INSTALL_CUDNN" = "true" ]; then
# Ensure that the requested version of cuDNN is available AND compatible
#if major cudnn version is 9, then we need to install libcudnn9-cuda-<major_cuda_version>_<CUDNN_VERSION>-1 package
#else we need to install libcudnn8_<CUDNN_VERSION>-1+cuda<CUDA_VERSION>" package
if [[ $major_cudnn_version -ge "9" ]]
then
cudnn_pkg_version="libcudnn9-cuda-${major_cuda_version}=${CUDNN_VERSION}-1"
else
cudnn_pkg_version="libcudnn8=${CUDNN_VERSION}-1+cuda${CUDA_VERSION}"
fi
if ! apt-cache show "$cudnn_pkg_version"; then
echo "The requested version of cuDNN is not available: cuDNN $CUDNN_VERSION for CUDA $CUDA_VERSION"
if [ "$NVIDIA_ARCH" = "arm64" ]; then
echo "Note: arm64 has limited cuDNN package availability"
fi
exit 1
fi
echo "Installing cuDNN libraries..."
apt-get install -yq "$cudnn_pkg_version"
fi
if [ "$INSTALL_CUDNNDEV" = "true" ]; then
# Ensure that the requested version of cuDNN development package is available AND compatible
#if major cudnn version is 9, then we need to install libcudnn9-dev-cuda-<major_cuda_version>_<CUDNN_VERSION>-1 package
#else we need to install libcudnn8-dev_<CUDNN_VERSION>-1+cuda<CUDA_VERSION>" package
if [[ $major_cudnn_version -ge "9" ]]
then
cudnn_dev_pkg_version="libcudnn9-dev-cuda-${major_cuda_version}=${CUDNN_VERSION}-1"
else
cudnn_dev_pkg_version="libcudnn8-dev=${CUDNN_VERSION}-1+cuda${CUDA_VERSION}"
fi
if ! apt-cache show "$cudnn_dev_pkg_version"; then
echo "The requested version of cuDNN development package is not available: cuDNN $CUDNN_VERSION for CUDA $CUDA_VERSION"
if [ "$NVIDIA_ARCH" = "arm64" ]; then
echo "Note: arm64 has limited cuDNN development package availability"
fi
exit 1
fi
echo "Installing cuDNN dev libraries..."
apt-get install -yq "$cudnn_dev_pkg_version"
fi
if [ "$INSTALL_NVTX" = "true" ]; then
echo "Installing NVTX..."
apt-get install -yq "$nvtx_pkg"
fi
if [ "$INSTALL_TOOLKIT" = "true" ]; then
echo "Installing CUDA Toolkit..."
apt-get install -yq "$toolkit_pkg"
fi
# Clean up
rm -rf /var/lib/apt/lists/*
echo "Done!"