PyTorch C++ API¶
The following installation procedure describes how to install and link the library libTorch that contains C++ APIs used to load PyTorch models in some SLOTH applications.
The procedure focuses on the CPU-only libTorch
Getting libTorch¶
The library libTorch can be downloaded either from the PyTorch website or by running the following instructions in a terminal:
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
unzip libtorch-shared-with-deps-latest.zip
This will result in an uncompressed folder named libtorch that can be linked to SLOTH during the configuration of the project.
Linking SLOTH and libTorch¶
To link SLOTH with libTorch, the user must run the envSloth.sh script file with the --libtorch option:
where LIBTORCH_PATH is an environment variable containing the path toward the libtorch folder previously uncompressed and [OPTIONS] are:
--release Build with Release compiler options
--optim Build with Optim compiler options
--debug Build with Debug compiler options
--coverage Build with Coverage compiler options
--minsizerel Build with MinSizeRel compiler options
--relwithdebinfo Build with RelWithDebInfo compiler options
--external Build SLOTH with an external package
--shared Build a shared library for Sloth
--install Specify the installation path for Sloth
(default: a "SlothInstallation" directory at the same level as the repository)
--np Specify the number of CPUs to use for compilation (default: 4)