-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathinstall.sh
More file actions
287 lines (239 loc) · 8.65 KB
/
install.sh
File metadata and controls
287 lines (239 loc) · 8.65 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#! /usr/bin/env bash
set -e
# Ensure we're in this feature's directory during build
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
# install global/common scripts
. ./common/install.sh;
check_packages \
jq \
gpg \
wget \
dirmngr \
gpg-agent \
apt-utils \
gettext-base \
ca-certificates \
bash-completion \
software-properties-common \
;
echo "Downloading CUDA keyring...";
export NVARCH="$(uname -p)";
export OSNAME="$(
. /etc/os-release;
major="$(cut -d'.' -f1 <<< "${VERSION_ID}")";
minor="$(cut -d'.' -f2 <<< "${VERSION_ID}")";
echo "$ID$((major - (major % 2)))${minor}";
)";
VERSION="${CUDA_VERSION:-${VERSION:-13.1.0}}";
if [[ "$NVARCH" == aarch64 ]]; then
NVARCH="sbsa";
fi
get_cuda_deb() {
local deb="$( \
wget --no-hsts -q -O- "${1}/Packages" \
| grep -P "^Filename: \./${2}(.*)\.deb$" \
| sort -Vr | head -n1 | cut -d' ' -f2 \
)";
if [ -z "$deb" ]; then
echo "Error: No matching .deb found for '${1}' and '${2}'" >&2
return 1
fi
wget --no-hsts -q -O "/tmp/${deb#./}" "${1}/${deb#./}";
echo -n "/tmp/${deb#./}";
}
# Add NVIDIA's keyring and apt repository
cuda_repo_base="https://developer.download.nvidia.com/compute/cuda/repos";
cuda_repo="${cuda_repo_base}/${OSNAME}/${NVARCH}";
if ! dpkg -s cuda-keyring; then
DEBIAN_FRONTEND=noninteractive \
apt install -y --no-install-recommends \
"$(get_cuda_deb "${cuda_repo}" cuda-keyring)" \
;
fi
if [[ "${OSNAME}" == "ubuntu1804" && "${NVARCH}" == "sbsa" ]]; then
ml_repo_base="https://developer.download.nvidia.com/compute/machine-learning/repos";
ml_repo="${ml_repo_base}/${OSNAME}/${NVARCH}";
apt-key adv --fetch-keys "${ml_repo}/7fa2af80.pub";
add-apt-repository -yn "deb ${ml_repo}/ /";
fi
apt-get update;
echo "Installing dev CUDA toolkit...";
export CUDA_HOME="/usr/local/cuda";
cuda_ver="${VERSION}";
cuda_ver=$(grep -Po '^[0-9]+\.[0-9]+' <<< "${cuda_ver}");
cuda_ver_major=$(grep -Po '^[0-9]+' <<< "${cuda_ver}");
cudapath="${CUDA_HOME}-${cuda_ver}";
cuda_tag="cuda${cuda_ver}";
cuda_ver="${cuda_ver/./-}";
dev_tag="";
if [ "${INSTALLDEVPACKAGES:-false}" = true ]; then
dev_tag="-dev";
fi
PKGS=();
if [ "${INSTALLCOMPILERS:-false}" = true ]; then
PKGS+=("cuda-nvml-dev-${cuda_ver}");
PKGS+=("cuda-compiler-${cuda_ver}");
PKGS+=("cuda-minimal-build-${cuda_ver}");
PKGS+=("cuda-command-line-tools-${cuda_ver}");
if [ "$NVARCH" = x86_64 ] && [ "$cuda_ver_major" -lt 13 ]; then
PKGS+=("cuda-nvprof-${cuda_ver}");
fi
fi
if [ "${INSTALLPROFILERS:-false}" = true ]; then
PKGS+=("cuda-nsight-compute-${cuda_ver}");
PKGS+=("cuda-nsight-systems-${cuda_ver}");
fi
if [ "${INSTALLCTKLIBRARIES:-false}" = true ]; then
INSTALLCUDARUNTIME=true;
INSTALLNVRTC=true;
INSTALLOPENCL=true;
INSTALLCUBLAS=true;
INSTALLCUSPARSE=true;
INSTALLCUFFT=true;
INSTALLCUFILE=true;
INSTALLCURAND=true;
INSTALLCUSOLVER=true;
INSTALLNPP=true;
INSTALLNVJPEG=true;
fi
if [ "${INSTALLCUDARUNTIME:-false}" = true ]; then
PKGS+=("cuda-cudart${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLNVRTC:-false}" = true ]; then
PKGS+=("cuda-nvrtc${dev_tag}-${cuda_ver}");
if test -n "$(apt-cache search "libnvjitlink${dev_tag}-${cuda_ver}" 2>/dev/null)"; then
PKGS+=("libnvjitlink${dev_tag}-${cuda_ver}");
fi
fi
if [ "${INSTALLOPENCL:-false}" = true ] \
&& test -n "$(apt-cache search "cuda-opencl${dev_tag}-${cuda_ver}" 2>/dev/null)"; then
PKGS+=("cuda-opencl${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLCUBLAS:-false}" = true ]; then
PKGS+=("libcublas${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLCUSPARSE:-false}" = true ]; then
PKGS+=("libcusparse${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLCUFFT:-false}" = true ]; then
PKGS+=("libcufft${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLCUFILE:-false}" = true ] \
&& test -n "$(apt-cache search "libcufile${dev_tag}-${cuda_ver}" 2>/dev/null)"; then
PKGS+=("libcufile${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLCURAND:-false}" = true ]; then
PKGS+=("libcurand${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLCUSOLVER:-false}" = true ]; then
PKGS+=("libcusolver${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLNPP:-false}" = true ]; then
PKGS+=("libnpp${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLNVJPEG:-false}" = true ]; then
PKGS+=("libnvjpeg${dev_tag}-${cuda_ver}");
fi
if [ "${INSTALLCUDNN:-false}" = true ]; then
CUDNNVERSION="${CUDNNVERSION:-8}";
if test "${CUDNNVERSION}" -le 8; then
if test -n "$(apt-cache search "libcudnn${CUDNNVERSION:-8}" 2>/dev/null)" \
&& apt-cache policy "libcudnn${CUDNNVERSION:-8}" 2>/dev/null | grep -q "+${cuda_tag}"; then
PKGS+=("libcudnn${CUDNNVERSION:-8}=*+${cuda_tag}");
if [ "${INSTALLDEVPACKAGES:-false}" = true ]; then
PKGS+=("libcudnn${CUDNNVERSION:-8}-dev=*+${cuda_tag}");
fi
fi
elif test -n "$(apt-cache search "libcudnn${CUDNNVERSION}-cuda-${cuda_ver_major}" 2>/dev/null)"; then
PKGS+=("libcudnn${CUDNNVERSION}-cuda-${cuda_ver_major}");
if [ "${INSTALLDEVPACKAGES:-false}" = true ]; then
PKGS+=("libcudnn${CUDNNVERSION}-dev-cuda-${cuda_ver_major}");
fi
fi
fi
if "${INSTALLCUDSS:-false}"; then
PKGS+=("cudss-cuda-${cuda_ver_major}");
fi
if [ "${INSTALLNCCL:-false}" = true ] \
&& test -n "$(apt-cache search libnccl2 2>/dev/null)" \
&& apt-cache policy libnccl2 2>/dev/null | grep -q "+${cuda_tag}"; then
PKGS+=("libnccl2=*+${cuda_tag}");
if [ "${INSTALLDEVPACKAGES:-false}" = true ]; then
PKGS+=("libnccl-dev=*+${cuda_tag}");
fi
fi
if [ "${INSTALLCUTENSOR:-false}" = true ]; then
# HACK: libcutensor-dev isn't currently in the ubuntu22.04 repo,
# but is in ubuntu20.04. Detect this and download the 20.04 deb.
if ! dpkg -s libcutensor-dev > /dev/null 2>&1; then
# If `libcutensor-deb` is available in the apt repo, install it
if ! dpkg -p libcutensor-dev 2>&1 | grep -q "not available" >/dev/null 2>&1; then
PKGS+=("libcutensor1");
if [ "${INSTALLDEVPACKAGES:-false}" = true ]; then
PKGS+=("libcutensor-dev");
fi
else
# If it's not in the apt repo for the current OS version, install it from the 20.04 repo
focal_cuda_repo="${cuda_repo_base}/ubuntu2004/${NVARCH}";
PKGS+=("$(get_cuda_deb "${focal_cuda_repo}" libcutensor1)");
if [ "${INSTALLDEVPACKAGES:-false}" = true ]; then
PKGS+=("$(get_cuda_deb "${focal_cuda_repo}" libcutensor-dev)");
fi
fi
fi
fi
check_packages "${PKGS[@]}";
apt autoremove -y;
if ! test -L "${CUDA_HOME}"; then
# Create /usr/local/cuda symlink
ln -s "${cudapath}" "${CUDA_HOME}";
fi
if ! test -n "${CUDA_VERSION:+x}"; then
if test -f "${CUDA_HOME}/include/cuda.h"; then
cuda_ver=$(grep "#define CUDA_VERSION" "${CUDA_HOME}/include/cuda.h" | cut -d' ' -f3);
CUDA_VERSION_MAJOR=$((cuda_ver / 1000));
CUDA_VERSION_MINOR=$((cuda_ver / 10 % 100));
CUDA_VERSION_PATCH=$((cuda_ver % 10));
CUDA_VERSION="$CUDA_VERSION_MAJOR.$CUDA_VERSION_MINOR.$CUDA_VERSION_PATCH";
else
CUDA_VERSION="${VERSION}";
CUDA_VERSION_MAJOR=$(cut -d'.' -f1 <<< "${VERSION}");
CUDA_VERSION_MINOR=$(cut -d'.' -f2 <<< "${VERSION}");
CUDA_VERSION_PATCH=$(cut -d'.' -f3 <<< "${VERSION}");
fi
fi
export CUDA_VERSION;
export CUDA_VERSION_MAJOR;
export CUDA_VERSION_MINOR;
export CUDA_VERSION_PATCH;
if [ "${INSTALLCUTENSOR:-false}" = true ]; then
# Remove extra libcutensor versions
source ./prune-extra-cutensor-libs.sh;
fi
vars_=();
vars_+=('$NVARCH');
vars_+=('$CUDA_HOME');
vars_+=('$CUDA_VERSION');
vars_+=('$CUDA_VERSION_MAJOR');
vars_+=('$CUDA_VERSION_MINOR');
vars_+=('$CUDA_VERSION_PATCH');
printf -v vars_ '%s,' "${vars_[@]}";
# export envvars in bashrc files
append_to_etc_bashrc "$(cat .bashrc | envsubst "${vars_%,}")";
append_to_all_bashrcs "$(cat .bashrc | envsubst "${vars_%,}")";
# export envvars in /etc/profile.d
add_etc_profile_d_script cuda "$(cat .bashrc | envsubst "${vars_%,}")";
# Required for nvidia-docker v1
cat <<EOF > /etc/ld.so.conf.d/nvidia.conf
/usr/local/nvidia/lib
/usr/local/nvidia/lib64
EOF
# Clean up
# rm -rf /tmp/*;
rm -rf /var/tmp/*;
rm -rf /var/cache/apt/*;
rm -rf /var/lib/apt/lists/*;
rm -rf /tmp/*.deb;
if [ "${PRUNESTATICLIBS:-false}" = true ]; then
source ./prune-static-libs.sh;
fi