1

Hi I'm building Libtorch from source. I'm using Conan, so that I'm able to have same version of dependencies in my project and in Libtorch. Build works just fine but after including Libtorch in my project I get immediately exception even before program gets to main() function.

I created minimal example, for easy reproduction. I would be glad If someone could tell me what the problem is. I found very much same problem on stack: libtorch throws c10::error after build on Windows 10 (VS2019) but unresolved.

Here is the source to reproduce: https://github.com/TheMejky/reproduceLibtorchBug.git

Steps:

Open powershell and install Conan package manager:

pip install conan

Put these setting to C:/Users/<user>/.conan/profiles/default

[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=Visual Studio
compiler.runtime=MD
compiler.toolset=v143
compiler.version=17
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
CONAN_DISABLE_STRICT_MODE=1

git clone https://github.com/TheMejky/reproduceLibtorchBug.git

cd reproduceLibtorchBug

conan create . -b -s build_type=Debug

This can take a while - On AMD Ryzen 7 5800x approxiamtely one hour

Then navigate to folder minimal project and run commands:

cd minimal_project

conan install . --install-folder=install_folder -s build_type=Debug

conan build . -sf=source_folder -bf=build_folder -if=install_folder

Now you go tu build_folder and open MinimalExampleProject.sln and launch it, then you get exception immediately when program starts

Exception image

Here is call stack:

Call stack image

I've tried different versions - 1.13.0, 1.13.1 and current master. I also played with the options of Libtorch CMake, but nothing lead to successful run of my test project.

TheMejky
  • 11
  • 2
  • If this is more a report than a question, then better submitting it to https://github.com/conan-io/conan/issues – drodri Mar 13 '23 at 11:00

1 Answers1

0

I solve the problem using the cmake + Ninja + x64 Native Tools Command Prompt for VS 2019. Here is the full record of my solution. Hope that helps!

Building libtorch (2.0.0) using CMake (Ninja)

Visit the official guide for more information.

Download pytorch (v2.0.0)

git clone https://github.com/pytorch/pytorch.git
cd pytorch
git checkout tags/v2.0.0
git submodule sync
git submodule update --init --recursive

Note: All submodules(in path /pytorch/third_party) must be not empty, i.e., no error in cli

Cmake Command line (must using x64 Native Tools Command Prompt for VS 2019)

cmake -B "E:/package/pytorch/build2" ^
-S "E:/package/pytorch/source/2.0.0/pytorch" ^
-G "Ninja" ^
-D USE_TENSORPIPE:BOOL="0" ^
-D ONNX_ML:BOOL="0" ^
-D USE_MKLDNN:BOOL="0" ^
-D CMAKE_CUDA_ARCHITECTURES:STRING="75" ^
-D USE_CUDNN:BOOL="0" ^
-D USE_EXPERIMENTAL_CUDNN_V8_API:BOOL="0" ^
-D BUILD_PYTHON:BOOL="0" ^
-D CMAKE_BUILD_TYPE:STRING=Release ^
-D CMAKE_INSTALL_PREFIX:PATH="E:/package/pytorch/install2" ^
-D CMAKE_CONFIGURATION_TYPES:STRING="Debug;Release"

cd /d E:/package/pytorch/build2

cmake --build . --target install --parallel 20

Note: All the following configurations didn't work for me

  1. Cmake GUI (configurate something and generate) -> open MSVC project -> choose x64/release or x64/debug -> ALL BUILD -> INSTALL
  2. Cmake CLI + CMD(open by the shotcut:windows+R)
    cmake -B "D:/workspace/chai_project/pytorch/pytorch-build" ^
    -S "D:/workspace/chai_project/pytorch/pytorch" ^
    -G "Visual Studio 16 2019" -A x64 ^
    -D USE_TENSORPIPE:BOOL="0" ^
    -D ONNX_ML:BOOL="0" ^
    -D ONNX_GEN_PB_TYPE_STUBS:BOOL="0" ^
    -D USE_MKLDNN:BOOL="0" ^
    -D CMAKE_CUDA_ARCHITECTURES:STRING="75" ^
    -D USE_CUDNN:BOOL="0" ^
    -D USE_EXPERIMENTAL_CUDNN_V8_API:BOOL="0" ^
    -D BUILD_PYTHON:BOOL="0" ^
    -D USE_OPENMP:BOOL="1" ^
    -D CMAKE_INSTALL_PREFIX:PATH="D:/workspace/chai_project/pytorch/pytorch-install" ^
    -D CMAKE_CONFIGURATION_TYPES:STRING="Debug;Release" ^
    -D CUDA_NVCC_FLAGS_RELEASE:STRING=""
    
    ::
    cd /d D:/workspace/chai_project/pytorch/pytorch-build
    
    :: release mode
    cmake --build . --clean-first --config Release &&^
    cmake --install . --prefix D:\workspace\chai_project\pytorch\pytorch-install\release -v
    
    :: debug mode
    cmake --build . --clean-first --config Debug &&^
    cmake --install . --prefix D:\workspace\chai_project\pytorch\pytorch-install\debug -v
    
  3. repeat the above two configurations with a different pytorch version (e.g., master branch and so on)

All in all, all these configurations build without any errors. However, when we try to build a mini cmake project, the program crashes as soon as it starts, exactly the same as libtorch throws c10::error after build on Windows 10 (VS2019) and Libtorch crashes immediately after program starts when build from source on Windows

Until I found this issue and tried ninja, everything was better(more faster)!

I've switched to Ninja now and my build with Ninja works! Also, the Ninja build was much faster (1.5h vs 6-7h).So to me it seems as if only Ninja builds are tested on windows, is this correct? If yes, maybe the documentation should be changed accordingly.

Here is outputs of my mini cmake project

image

lollows
  • 71
  • 1
  • 2
  • 5