Ai
1 Star 0 Fork 1

周司南/pytorch-github

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
libtorch.rst 2.03 KB
一键复制 编辑 原始数据 按行查看 历史
Lee Newberg 提交于 2020-10-22 05:27 +08:00 . DOC: Building libtorch using CMake (#44196)

libtorch (C++-only)

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 using Python

You can use a python script/module located in tools package to build libtorch

cd <pytorch_root>

# Make a new folder to build in to avoid polluting the source directories
mkdir build_libtorch && cd build_libtorch

# You might need to export some required environment variables here.
Normally setup.py sets good default env variables, but you'll have to do
that manually.
python ../tools/build_libtorch.py

Alternatively, you can call setup.py normally and then copy the built cpp libraries. This method may have side effects to your active Python installation.

cd <pytorch_root>
python setup.py build

ls torch/lib/tmp_install # output is produced here
ls torch/lib/tmp_install/lib/libtorch.so # of particular interest

To produce libtorch.a rather than libtorch.so, set the environment variable BUILD_SHARED_LIBS=OFF.

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.

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhou_sinan/pytorch-github.git
git@gitee.com:zhou_sinan/pytorch-github.git
zhou_sinan
pytorch-github
pytorch-github
master

搜索帮助