Closed ehsanmok closed 5 years ago
tch-rs/gen/gen.ml
generates:
libtch/torch_api_generated.{cpp.h,.h}
. src/tensor/c_wrapper_generated.rs
.
It uses the Declarations.yaml
file generated when compiling libtorch from source.The generated files are also stored in git so there is no need to run this code generation in the normal build process. It's only useful to execute it when updating to a new major libtorch version but this is rather infrequent (there was no need to rerun it between 1.0.0 and 1.0.1).
The code generation is in ocaml as it's adapted from the ocaml-torch bindings. To run it you will need a working ocaml install including the dune, base, stdio, and yaml packages, the Declarations.yaml
file and you could run dune exec gen/gen.exe
.
Binding to the library directly would be a bit tricky: it's in C++ so bindgen does not work very well, writing manual wrappers is a bit of a pain as there are more than a thousand functions to expose.
Very interesting! thanks for the clarifications. Absolutely makes sense to reuse what you've made before.
Would it be able to support more than one major libtorch versions at the same time (in the future)?
With the current release cycle of PyTorch, I hope for that not to be necessary. However if this becomes a concern, we could certainly consider generating the code in the build process at some point.
Hi
Do you mind explaining how
tch-rs/gen
work? and when does it kick in?Why not binding against c-api in
$LIBTORCH/include/torch/csrc/api/include/torch/
directly?Thanks