gotch/setup-libtorch.sh

44 lines
1.4 KiB
Bash
Raw Normal View History

2020-12-30 01:05:27 +00:00
#!/bin/bash
2023-10-11 04:53:35 +01:00
LIBTORCH_VERSION="${LIBTORCH_VER:-2.1.0}"
2023-10-11 02:31:45 +01:00
CUDA_VERSION="${CUDA_VER:-11.8}"
2020-12-30 01:05:27 +00:00
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"
2021-04-11 02:07:03 +01:00
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
2021-04-11 02:07:03 +01:00
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$GOTCH_LIBTORCH/lib"
else
2021-04-11 02:07:03 +01:00
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$GOTCH_LIBTORCH/lib:/usr/lib64-nvidia:/usr/local/cuda-${CUDA_VERSION}/lib64"
fi
2020-12-30 01:05:27 +00:00
# Update current shell environment variables for newly installed Libtorch
2021-04-11 02:07:03 +01:00
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}"
2021-04-11 03:21:24 +01:00
echo $LIBTORCH_URL
sudo wget -q --show-progress --progress=bar:force:noscroll -O "/tmp/$LIBTORCH_ZIP" "$LIBTORCH_URL"
2021-04-11 02:07:03 +01:00
sudo rm -rf $GOTCH_LIBTORCH # delete old libtorch if exisitng
sudo unzip "/tmp/$LIBTORCH_ZIP" -d $LIBTORCH_PATH
sudo rm "/tmp/$LIBTORCH_ZIP"
2021-04-11 02:07:03 +01:00
sudo ldconfig
2020-12-30 01:05:27 +00:00
# refresh environment for all next opening shells.
exec "$BASH"