forked from Spartee/RedisAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_deps.sh
executable file
·330 lines (268 loc) · 7.72 KB
/
get_deps.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
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/usr/bin/env bash
error() {
echo "There are errors."
exit 1
}
trap error ERR
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
if [[ $1 == --help || $1 == help ]]; then
cat <<-END
[ARGVARS...] get_deps.sh [cpu|gpu] [--help|help]
Argument variables:
CPU=1 Get CPU dependencies
GPU=1 Get GPU dependencies
JETSON=1 Get Jetson Nano dependencies
VERBOSE=1 Print commands
FORCE=1 Download even if present
WITH_DLPACK=0 Skip dlpack
WITH_TF=0|S3 Skip Tensorflow or download from S3 repo
WITH_TFLITE=0|S3 Skip TensorflowLite or download from S3 repo
WITH_PT=0|S3 Skip PyTorch or download from S3 repo
WITH_ORT=0|S3 Skip OnnxRuntime or download from S3 repo
END
exit 0
fi
set -e
[[ $VERBOSE == 1 ]] && set -x
if [[ "$1" == "cpu" || $CPU == 1 ]]; then
GPU=0
DEVICE=cpu
elif [[ "$1" == "gpu" || $GPU == 1 ]]; then
GPU=1
DEVICE=gpu
else
GPU=${GPU:-0}
if [[ $GPU == 1 ]]; then
DEVICE=gpu
else
DEVICE=cpu
fi
fi
git submodule update --init --recursive || true
OS=$(python3 $HERE/opt/readies/bin/platform --os)
ARCH=$(python3 $HERE/opt/readies/bin/platform --arch)
# avoid wget warnings on macOS
[[ $OS == macos ]] && export LC_ALL=en_US.UTF-8
DEPS_DIR=$HERE/deps/$OS-$ARCH-$DEVICE
mkdir -p ${DEPS_DIR}
cd ${DEPS_DIR}
# PREFIX=${DEPS_DIR}/install
# mkdir -p ${PREFIX}
DLPACK=dlpack
LIBTENSORFLOW=libtensorflow
LIBTFLITE=libtensorflow-lite
LIBTORCH=libtorch
MKL=mkl
ONNXRUNTIME=onnxruntime
######################################################################################## DLPACK
DLPACK_VERSION="v0.4"
if [[ $WITH_DLPACK != 0 ]]; then
[[ $FORCE == 1 ]] && rm -rf $DLPACK
if [[ ! -d $DLPACK ]]; then
echo "Cloning dlpack ..."
git clone --depth 1 --branch $DLPACK_VERSION https://github.com/dmlc/dlpack.git $DLPACK
echo "Done."
else
echo "dlpack is in place."
fi
else
echo "Skipping dlpack."
fi
################################################################################# LIBTENSORFLOW
TF_VERSION="2.4.0"
if [[ $WITH_TF != 0 ]]; then
[[ $FORCE == 1 ]] && rm -rf $LIBTENSORFLOW
if [[ ! -d $LIBTENSORFLOW ]]; then
echo "Installing TensorFlow ..."
if [[ $OS == linux ]]; then
TF_OS="linux"
if [[ $GPU != 1 ]]; then
TF_BUILD="cpu"
else
TF_BUILD="gpu"
fi
if [[ $ARCH == x64 ]]; then
TF_ARCH=x86_64
LIBTF_URL_BASE=https://storage.googleapis.com/tensorflow/libtensorflow
elif [[ $ARCH == arm64v8 ]]; then
TF_ARCH=arm64
if [[ $JETSON == 1 ]]; then
TF_BUILD="gpu-jetson"
fi
LIBTF_URL_BASE=https://s3.amazonaws.com/redismodules/tensorflow
elif [[ $ARCH == arm32v7 ]]; then
TF_ARCH=arm
LIBTF_URL_BASE=https://s3.amazonaws.com/redismodules/tensorflow
fi
elif [[ $OS == macos ]]; then
TF_OS=darwin
TF_BUILD=cpu
TF_ARCH=x86_64
if [[ $WITH_TF == S3 ]]; then
LIBTF_URL_BASE=https://s3.amazonaws.com/redismodules/tensorflow
else
LIBTF_URL_BASE=https://storage.googleapis.com/tensorflow/libtensorflow
fi
fi
LIBTF_ARCHIVE=libtensorflow-${TF_BUILD}-${TF_OS}-${TF_ARCH}-${TF_VERSION}.tar.gz
[[ ! -f $LIBTF_ARCHIVE || $FORCE == 1 ]] && wget -q $LIBTF_URL_BASE/$LIBTF_ARCHIVE
rm -rf $LIBTENSORFLOW.x
mkdir $LIBTENSORFLOW.x
tar xf $LIBTF_ARCHIVE --no-same-owner -C $LIBTENSORFLOW.x
mv $LIBTENSORFLOW.x $LIBTENSORFLOW
echo "Done."
else
echo "TensorFlow is in place."
fi
else
echo "Skipping TensorFlow."
fi # WITH_TF
################################################################################# LIBTFLITE
TFLITE_VERSION="2.0.0"
if [[ $WITH_TFLITE != 0 ]]; then
[[ $FORCE == 1 ]] && rm -rf $LIBTFLITE
if [[ ! -d $LIBTFLITE ]]; then
echo "Installing TensorFlow Lite ..."
LIBTF_URL_BASE=https://s3.amazonaws.com/redismodules/tensorflow
if [[ $OS == linux ]]; then
TFLITE_OS="linux"
# if [[ $GPU != 1 ]]; then
# TFLITE_BUILD="cpu"
# else
# TFLITE_BUILD="gpu"
# fi
if [[ $ARCH == x64 ]]; then
TFLITE_ARCH=x86_64
elif [[ $ARCH == arm64v8 ]]; then
TFLITE_ARCH=arm64
elif [[ $ARCH == arm32v7 ]]; then
TFLITE_ARCH=arm
fi
elif [[ $OS == macos ]]; then
TFLITE_OS=darwin
# TFLITE_BUILD=cpu
TFLITE_ARCH=x86_64
fi
LIBTFLITE_ARCHIVE=libtensorflowlite-${TFLITE_OS}-${TFLITE_ARCH}-${TFLITE_VERSION}.tar.gz
[[ ! -f $LIBTFLITE_ARCHIVE || $FORCE == 1 ]] && wget -q $LIBTF_URL_BASE/$LIBTFLITE_ARCHIVE
rm -rf $LIBTFLITE.x
mkdir $LIBTFLITE.x
tar xf $LIBTFLITE_ARCHIVE --no-same-owner -C $LIBTFLITE.x
mv $LIBTFLITE.x $LIBTFLITE
echo "Done."
else
echo "TensorFlow Lite is in place."
fi
else
echo "Skipping TensorFlow Lite."
fi # WITH_TFLITE
###################################################################################### LIBTORCH
PT_VERSION="1.7.1"
if [[ $WITH_PT != 0 ]]; then
[[ $FORCE == 1 ]] && rm -rf $LIBTORCH
if [[ ! -d $LIBTORCH ]]; then
echo "Installing libtorch ..."
PT_REPACK=0
if [[ $OS == linux ]]; then
PT_OS=linux
if [[ $GPU != 1 ]]; then
PT_BUILD=cpu
else
if [[ $JETSON == 1 ]]; then
PT_BUILD=cu102-jetson
else
PT_BUILD=cu110
fi
fi
if [[ $ARCH == x64 ]]; then
PT_ARCH=x86_64
PT_REPACK=1
elif [[ $ARCH == arm64v8 ]]; then
PT_ARCH=arm64
elif [[ $ARCH == arm32v7 ]]; then
PT_ARCH=arm
fi
elif [[ $OS == macos ]]; then
PT_OS=macos
PT_ARCH=x86_64
PT_BUILD=cpu
PT_REPACK=1
fi
[[ $PT_VERSION == latest ]] && PT_BUILD=nightly/${PT_BUILD}
LIBTORCH_ARCHIVE=libtorch-${PT_BUILD}-${PT_OS}-${PT_ARCH}-${PT_VERSION}.tar.gz
if [[ $PT_REPACK == 1 ]]; then
PT_VERSION=$PT_VERSION GPU=$GPU $HERE/opt/build/libtorch/repack.sh
else
LIBTORCH_URL=https://s3.amazonaws.com/redismodules/pytorch/$LIBTORCH_ARCHIVE
[[ ! -f $LIBTORCH_ARCHIVE || $FORCE == 1 ]] && wget -q $LIBTORCH_URL
fi
rm -rf $LIBTORCH.x
mkdir $LIBTORCH.x
tar xf $LIBTORCH_ARCHIVE --no-same-owner -C $LIBTORCH.x
mv $LIBTORCH.x/libtorch $LIBTORCH
rmdir $LIBTORCH.x
echo "Done."
else
echo "libtorch is in place."
fi
else
echo "SKipping libtorch."
fi # WITH_PT
########################################################################################### MKL
if [[ ! -d mkl ]]; then
MKL_VERSION=0.18
MKL_BUNDLE_VER=2019.0.3.20190220
if [[ $OS == macos ]]; then
echo "Installing MKL ..."
MKL_OS=mac
MKL_ARCHIVE=mklml_${MKL_OS}_${MKL_BUNDLE_VER}.tgz
[[ ! -e ${MKL_ARCHIVE} ]] && wget -q https://github.com/intel/mkl-dnn/releases/download/v${MKL_VERSION}/${MKL_ARCHIVE}
rm -rf $MKL.x
mkdir $MKL.x
tar xzf ${MKL_ARCHIVE} --no-same-owner --strip-components=1 -C $MKL.x
mv $MKL.x $MKL
echo "Done."
fi
else
echo "mkl is in place."
fi
################################################################################### ONNXRUNTIME
ORT_VERSION="1.7.1"
if [[ $WITH_ORT != 0 ]]; then
[[ $FORCE == 1 ]] && rm -rf $ONNXRUNTIME
if [[ ! -d $ONNXRUNTIME ]]; then
echo "Installing ONNXRuntime ..."
if [[ $OS == linux ]]; then
ORT_OS=linux
if [[ $GPU != 1 ]]; then
ORT_BUILD=""
else
ORT_BUILD="-gpu"
fi
ORT_URL_BASE=https://s3.amazonaws.com/redismodules/onnxruntime
if [[ $ARCH == x64 ]]; then
ORT_ARCH=x64
elif [[ $ARCH == arm64v8 ]]; then
ORT_ARCH=arm64
elif [[ $ARCH == arm32v7 ]]; then
ORT_ARCH=arm
fi
elif [[ $OS == macos ]]; then
ORT_OS=osx
ORT_ARCH=x64
ORT_BUILD=""
ORT_URL_BASE=https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}
fi
ORT_ARCHIVE=onnxruntime-${ORT_OS}-${ORT_ARCH}${ORT_BUILD}-${ORT_VERSION}.tgz
[[ ! -e ${ORT_ARCHIVE} ]] && wget -q $ORT_URL_BASE/${ORT_ARCHIVE}
rm -rf $ONNXRUNTIME.x
mkdir $ONNXRUNTIME.x
tar xzf ${ORT_ARCHIVE} --no-same-owner --strip-components=1 -C $ONNXRUNTIME.x
mv $ONNXRUNTIME.x $ONNXRUNTIME
echo "Done."
else
echo "ONNXRuntime is in place."
fi
else
echo "Skipping ONNXRuntime."
fi # WITH_ORT