Closed walkacross closed 5 years ago
For the first, this is a bit tricky. I can give you the command, which I mostly got by using cmake and then make VERBOSE=1
. For CPU:
$ LIBTORCH=/path/to/unzipped/libtorch
$ c++ -I"$LIBTORCH/include" -I"$LIBTORCH/include/torch/csrc/api/include" -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 example-app.cpp -o example-app -Wl,-rpath "$LIBTORCH/lib" "$LIBTORCH/lib/libtorch.so" "$LIBTORCH/lib/libcaffe2.so" "$LIBTORCH/lib/libc10.so"
Where example-app.cpp
is the example from https://pytorch.org/cppdocs/installing.html. The reason I say it's tricky is that for us cmake is effectively an abstraction over the exact build steps required. I can tell you with certainty that the names of the libraries to link against will change in the future, for example, or maybe we'll require a new include directory, or the flags will change etc. With cmake, we can do those changes in the background and your cmake will just continue to work in the future with no effort on your side. For this reason, you're free to use the above command, but I'd rather not put this in the documentation website itself.
For the second point of mixing C++ with Python, it depends on what you want to do:
Let me know if this answers your questions.
Yep, the answer is clear, I got it. Thanks for your time and kind response.
Sure. I will write a tutorial for binding the C++ frontend into Python once that is more mature. Feel free to open more issues with suggestions or questions in the meantime.
I am having a package with its own cmake. I am trying to like the libraries of libtorch with it . But after successful cmake following error is coming out error: macro "Error" passed 4 arguments, but takes just 1 AT_ASSERT(impl == nullptr || impl->type() == device.type()); ^
@goldsborough your answer totally save my life while trying to compile against libtorch directly on visual studio 2019. Tip use #pragma warning (disable : 4146)
to ignore stupid 4146 warning assumed as error by vstudio.
hey, thanks for this great framework and the c++ API design philosophy is really user-friendly for old pytorch user using python.
could you please provide some more concrete examples about (1) how to install and use libtorch not only with cmake ( add g++ example?); (2) what is the best practice to use pybind to invoke c++ tensor functions or models in python. considering some pythoners do have the desire to use libtorch and conduct mix programming but with knowing a little about the c++.
@goldsborough @soumith @apaszke
have a nice day.