executorch-sys
For a general description of the project, see the the executorch crate.
Build
To build the library, you need to build the C++ library first.
The C++ library allow for great flexibility with many flags, customizing which modules, kernels, and extensions are built.
Multiple static libraries are built, and the Rust library links to them.
In the following example we build the C++ library with the necessary flags to run example hello_world_add:
# Clone the C++ library
# Install requirements
# Build C++ library
&&
# Static libraries are in cmake-out/
# core:
# cmake-out/libexecutorch.a
# cmake-out/libexecutorch_no_prim_ops.a
# kernels implementations:
# cmake-out/kernels/portable/libportable_ops_lib.a
# cmake-out/kernels/portable/libportable_kernels.a
# extension data loader, enabled with EXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON:
# cmake-out/extension/data_loader/libextension_data_loader.a
# extension module, enabled with EXECUTORCH_BUILD_EXTENSION_MODULE=ON:
# cmake-out/extension/module/libextension_module_static.a
# Run example
# We set EXECUTORCH_RS_EXECUTORCH_LIB_DIR to the path of the C++ build output
EXECUTORCH_RS_EXECUTORCH_LIB_DIR=/executorch/cmake-out
The executorch crate will always look for the following static libraries:
libexecutorch.alibexecutorch_no_prim_ops.a
Additional libs are required if feature flags are enabled (see next section):
libextension_data_loader.alibextension_module_static.a
The static libraries of the kernels implementations are required only if your model uses them, and they should be linked manually by the binary that uses the executorch crate.
For example, the hello_world_add example uses a model with a single addition operation, so it compile the C++ library with DEXECUTORCH_SELECT_OPS_LIST=aten::add.out and contain the following lines in its build.rs:
println!;
println!;
let libs_dir = var.unwrap;
println!;
Note that the ops and kernels libs are linked with +whole-archive to ensure that all symbols are included in the binary.
Cargo Features
-
data-loaderIncludes the
FileDataLoaderandMmapDataLoaderstructs. Without this feature the only available data loader isBufferDataLoader. Thelibextension_data_loader.astatic library is required, compile C++executorchwithEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON. -
moduleIncludes the
Modulestruct. Thelibextension_module_static.astatic library is required, compile C++executorchwithEXECUTORCH_BUILD_EXTENSION_MODULE=ON. Also includes thestdfeature. -
stdEnable the standard library. This feature is enabled by default, but can be disabled to build
executorchin ano_stdenvironment. NOTE: no_std is still WIP, see https://github.com/pytorch/executorch/issues/4561
By default the std feature is enabled.