-
Notifications
You must be signed in to change notification settings - Fork 44
/
setup-libtorch.sh
43 lines (35 loc) · 1.39 KB
/
setup-libtorch.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
#!/bin/bash
LIBTORCH_VERSION="${LIBTORCH_VER:-2.1.0}"
CUDA_VERSION="${CUDA_VER:-11.8}"
if [ "${CUDA_VERSION}" == "cpu" ]; then
CU_VERSION="cpu"
else
CU_VERSION="cu${CUDA_VERSION//./}"
fi
# Libtorch paths
LIBTORCH_PATH="/usr/local/lib"
GOTCH_LIBTORCH="$LIBRARY_PATH/libtorch"
LIBRARY_PATH="$LIBRARY_PATH:$GOTCH_LIBTORCH/lib"
CPATH="$CPATH:$GOTCH_LIBTORCH/lib:$GOTCH_LIBTORCH/include:$GOTCH_LIBTORCH/include/torch/csrc/api/include"
if [[ "${CUDA_VERSION}" == "cpu" ]]; then
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$GOTCH_LIBTORCH/lib"
else
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$GOTCH_LIBTORCH/lib:/usr/lib64-nvidia:/usr/local/cuda-${CUDA_VERSION}/lib64"
fi
# Update current shell environment variables for newly installed Libtorch
export GOTCH_LIBTORCH=$GOTCH_LIBTORCH
export LIBRARY_PATH=$LIBRARY_PATH
export CPATH=$CPATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
# Install Libtorch
#=================
LIBTORCH_ZIP="libtorch-cxx11-abi-shared-with-deps-${LIBTORCH_VERSION}%2B${CU_VERSION}.zip"
LIBTORCH_URL="https://download.pytorch.org/libtorch/${CU_VERSION}/${LIBTORCH_ZIP}"
echo $LIBTORCH_URL
sudo wget -q --show-progress --progress=bar:force:noscroll -O "/tmp/$LIBTORCH_ZIP" "$LIBTORCH_URL"
sudo rm -rf $GOTCH_LIBTORCH # delete old libtorch if exisitng
sudo unzip "/tmp/$LIBTORCH_ZIP" -d $LIBTORCH_PATH
sudo rm "/tmp/$LIBTORCH_ZIP"
sudo ldconfig
# refresh environment for all next opening shells.
exec "$BASH"