-
Notifications
You must be signed in to change notification settings - Fork 2.4k
StaticLibraries
- Introduction
- Configure OpenVINO runtime in CMake stage
- Build static OpenVINO libraries
- Link static OpenVINO runtime
- Static OpenVINO libraries + Conditional compilation for particular models
- Limitations
Building static OpenVINO Runtime libraries allows to additionally reduce a binary size when it's used together with conditional compilation. This happens because all interface symbols of OpenVINO runtime libraries are not exported to end users during static build, which allows linker to remove them. See Static OpenVINO libraries + Conditional compilation for particular models
Default architecture of OpenVINO runtime assumes that the following components can be dynamically loaded in runtime:
- Inference backends (CPU, GPU, MULTI, HETERO, etc)
- Frontends (IR, ONNX, PDPD, etc)
- Preprocessing library (to perform preprocessing like resize, color space conversions)
- IR v7 reader (used in legacy tests only, if you are to going to run OpenVINO tests, set
-DENABLE_TESTS=OFF
which disables IR v7 reader)
In the static OpenVINO runtime, all these plugins should be linked into a final user application, so to minimize the total binary size, turn OFF
unnecessary components. Use CMake Options for Custom Compilation as a reference for OpenVINO CMake configuration.
For example, to enable only IR v11 reading and CPU inference capabilities, use:
cmake -DENABLE_VPU=OFF \
-DENABLE_IR_V7_READER=OFF \
-DENABLE_CLDNN=OFF \
-DENABLE_GNA=OFF \
-DENABLE_VPU=OFF \
-DENABLE_HETERO=OFF \
-DENABLE_MULTI=OFF \
-DNGRAPH_ONNX_FRONTEND_ENABLE=OFF \
-DNGRAPH_PDPD_FRONTEND_ENABLE=OFF \
-DNGRAPH_TF_FRONTEND_ENABLE=OFF
Note: Inference backends located in external repositories can also be used in static build. Use -DIE_EXTRA_MODULES=<path to external plugin root>
to enable them.
To build OpenVINO runtime in a static mode, you need to specify the additional CMake option:
cmake -DBUILD_SHARED_LIBS=OFF <all other CMake options> <openvino_sources root>
After as usual CMake build command:
cmake --build . --target inference_engine --config Release -j12
Then installation step:
cmake -DCMAKE_INSTALL_PREFIX=<install_root> -P cmake_install.cmake
The OpenVINO runtime is located in <install_root>/runtime/lib
Once you build static OpenVINO Runtime libraries and installed them, you can use one of the ways to add them to your project
Just use CMake's find_package
as usual and link openvino::runtime
:
find_package(OpenVINO REQUIRED)
target_link_libraries(<application> PRIVATE openvino::runtime)
openvino::runtime
transitively adds all other static OpenVINO libraries to linker command.
If you want to configure your project directly, you need to pass all libraries from <install_root>/runtime/lib
to linker command.
Note: this way is not recommended since a proper order of static libraries should be used, while CMake interface supports this out of box. Please, contact developers to have explanations for a proper command.
OpenVINO Runtime can be compiled for particular models using Conditional compilation for particular models guide. Conditional compilation feature can be paired with static OpenVINO libraries to build even smaller end user applications in terms of binary size. The following procedure can be used (based on detailed Conditional compilation for particular models guide):
- Build OpenVINO Runtime as usual with CMake option
-DSELECTIVE_BUILD=COLLECT
- Run targets applications on targets models to collect traces
- Build final OpenVINO static Runtime with
-DSELECTIVE_BUILD=ON -DSELECTIVE_BUILD_STAT=/path/*.csv -DBUILD_SHARED_LIBS=OFF
-
Supported OSes:
- Windows x64
- Linux x64
- All other OSes may work, but not explicitly tested
-
Enabled and tests capabilities on OpenVINO runtime in static build:
- OpenVINO common runtime - work with
ov::Function
, perform model loading on particular device - CPU, MULTI, HETERO, AUTO inference plugins
-
Not enabled: GNA, GPU, MYRIAD
Still compiled as shared libraries: IR, ONNX, PDPD, TF frontends to read
ov::Function
- OpenVINO common runtime - work with
-
Static build support building of static libraries only for OpenVINO Runtime libraries. All other thirdparty dependencies remain in the same format:
-
libGNA
is still a shared library -
TBB
is still a shared library; to provide your own TBB build from oneTBB source code useexport TBBROOT=<tbb_root>
before OpenVINO CMake scripts are run
Note: TBB team does not recommend to use oneTBB as a static library, see Why onetbb not like static library?
-
-
TBBBind_2_5
is not available on Windows x64 during static OpenVINO build (see description forENABLE_TBBBIND_2_5
CMake option here). So, capabilities enabled byTBBBind_2_5
are not available. To enable these capabilities, build oneTBB from source code and provide path to built oneTBB artifacts viaTBBROOT
environment variable before OpenVINO CMake scripts are run. -
ov::Op::type_info
static member is deprecated and not available in static build. Don't usetype_info
during implementation of your own custom operations, useov::Op::get_type_info_static()
instead
© Copyright 2018-2024, OpenVINO team
- Home
- General resources
- How to build
-
Developer documentation
- Inference Engine architecture
- CPU plugin
- GPU plugin
- HETERO plugin architecture
- Snippets
- Sample for IE C++/C/Python API
- Proxy plugin (Concept)
- Tests