This CMakeLists.txt manages the building of a minimal libtorch from PyTorch 1.6 by setting environment variables and calling pytorch/tools/build_libtorch.py
PyTorch is working on eliminating tools/build_pytorch_libs.sh in favor of a unified cmake build source. Builders should use pytorch_setup instead.
- Clone PyTorch 1.6 and adjust the CMakeLists.txt variable
PYTORCH_SRC_DIRto point to the local repository, for exampleset(PYTORCH_SRC_DIR ../pytorch) - Install the PyTorch prerequisites
cd pytorch
git restore :/
git clean -dfx
export DEBUG=1
export BUILD_TEST=0
export USE_CUDA=0
export USE_DISTRIBUTED=0
export USE_MKLDNN=0
export USE_FBGEMM=0
export USE_NNPACK=0
export USE_QNNPACK=0
export USE_XNNPACK=0
export BUILD_PYTHON=0
export BUILD_CAFFE2_OPS=0
python tools/build_libtorch.py
cmake -S . -B build
Restore and clean the PyTorch source working tree from HEAD.
The build generates a shared library by default. This can be disabled by passing the option -D NO_BUILD_SHARED_LIBS=1.
The build does not use static dispatch for ATen operators by default. This can be enabled by passing the option -D USE_STATIC_DISPATCH=1.
The default buid type is Release. For a debug build pass option -D CMAKE_BUILD_TYPE=Debug
-Og enables optimizations that do not interfere with debugging
cmake -DRESET=1 -DCMAKE_CXX_FLAGS=-Og -DCMAKE_BUILD_TYPE=Debug -S . -B build
pytorch/build/lib
rm build/CMakeCache.txt
rm -rf build
del build/CMakeCache.txt
rmdir /s /q build
mklink /d build d:\build
git clean -dfx