DOC: Building libtorch using CMake (#44196)

Summary:
I am adding documentation for building the C++-only libtorch.so without invoking Python in the build and install process.  This works on my Ubuntu 20.04 system and is designed to be operating system agnostic.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/44196

Reviewed By: zou3519

Differential Revision: D24421066

Pulled By: malfet

fbshipit-source-id: e77c222703353ff7f7383fb88f7bce705f88b7bf
This commit is contained in:
Lee Newberg 2020-10-21 14:27:27 -07:00 committed by Facebook GitHub Bot
parent ff0e20b384
commit e02a3e190e

View File

@ -5,8 +5,8 @@ The core of pytorch does not depend on Python. A
CMake-based build system compiles the C++ source code into a shared
object, libtorch.so.
Building libtorch
-----------------
Building libtorch using Python
------------------------------
You can use a python script/module located in tools package to build libtorch
::
@ -34,3 +34,16 @@ To produce libtorch.a rather than libtorch.so, set the environment variable `BUI
To use ninja rather than make, set `CMAKE_GENERATOR="-GNinja" CMAKE_INSTALL="ninja install"`.
Note that we are working on eliminating tools/build_pytorch_libs.sh in favor of a unified cmake build.
Building libtorch using CMake
--------------------------------------
You can build C++ libtorch.so directly with cmake. For example, to build a Release version from the master branch and install it in the directory specified by CMAKE_INSTALL_PREFIX below, you can use
::
git clone -b master --recurse-submodule https://github.com/pytorch/pytorch.git
mkdir pytorch-build
cd pytorch-build
cmake -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=Release -DPYTHON_EXECUTABLE:PATH=`which python3` -DCMAKE_INSTALL_PREFIX:PATH=../pytorch-install ../pytorch
cmake --build . --target install
To use release branch v1.6.0, for example, replace ``master`` with ``v1.6.0``. You will get errors if you do not have needed dependencies such as Python3's PyYAML package.