Skip to content

Commit fda88dc

Browse files
authored
docs: describe how OpenVINO paths are found (#62)
`openvino-finder` encodes some rather complex logic to find OpenVINO files over several versions. This change describes that logic (and the rationale for it) in more detail and moves this text to the Rust documentation, closer to the code.
1 parent ad226e9 commit fda88dc

File tree

4 files changed

+96
-48
lines changed

4 files changed

+96
-48
lines changed

README.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,41 @@ crate (high-level, ergonomic bindings) for accessing OpenVINO™ functionality i
1717

1818
### Prerequisites
1919

20-
The [openvino-sys] crate creates bindings to the OpenVINO™ C API using `bindgen`; this requires a
21-
local installation of `libclang`. Also, be sure to retrieve all Git submodules.
22-
23-
This repo currently uses [git-lfs](https://git-lfs.github.com/) for large file storage. If you
24-
[install it](https://github.com/git-lfs/git-lfs/wiki/Installation) before cloning this repository,
25-
it should have downloaded all large files. To check this, verify that `find crates/openvino -name
26-
*.bin | xargs ls -lhr` returns `.bin` files of tens of megabytes. If not, download the large files
27-
with:
28-
29-
```shell
30-
git lfs fetch
31-
git lfs checkout
32-
```
20+
1. The [openvino-sys] crate creates bindings to the OpenVINO™ C API using `bindgen`; this requires a
21+
local installation of `libclang`. Also, be sure to retrieve all Git submodules.
22+
23+
2. This repo currently uses [git-lfs](https://git-lfs.github.com/) for large file storage. If you
24+
[install it](https://github.com/git-lfs/git-lfs/wiki/Installation) before cloning this
25+
repository, it should have downloaded all large files. To check this, verify that `find
26+
crates/openvino -name *.bin | xargs ls -lhr` returns `.bin` files of tens of megabytes. If not,
27+
download the large files with:
28+
29+
```shell
30+
git lfs fetch
31+
git lfs checkout
32+
```
33+
34+
3. This library binds to OpenVINO™'s shared libraries; how those native libraries are configured and
35+
installed on your system determines how these Rust bindings work. The [openvino-finder] crate
36+
attempts to locate the necessary libraries and configuration; if you run into problems, you may
37+
need to understand additional details documented in the [`openvino-finder`
38+
docs][openvino-finder-docs].
3339

40+
[openvino-finder-docs]: https://docs.rs/openvino-finder
3441

3542
### Build from an OpenVINO™ installation
3643

3744
```shell script
3845
cargo build
39-
source /opt/intel/openvino/setupvars.sh
4046
cargo test
4147
```
4248

4349
The quickest method to build the [openvino] and [openvino-sys] crates is with a local installation
44-
of OpenVINO™ (see, e.g., [installing from an apt repository][install-apt]). The build script will
50+
of OpenVINO™ (see, e.g., [installing from an APT repository][install-apt]). The build script will
4551
attempt to locate an existing installation (see [openvino-finder]) and link against its shared
4652
libraries. Provide the `OPENVINO_INSTALL_DIR` environment variable to point at a specific
4753
installation. Ensure that the correct libraries are available on the system's load path; OpenVINO™'s
48-
`setupvars.sh` script will do this automatically.
54+
`setupvars.sh` script will do this automatically (e.g., `source /opt/intel/openvino/setupvars.sh`).
4955

5056
[install-apt]: https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_apt.html
5157

@@ -54,17 +60,17 @@ installation. Ensure that the correct libraries are available on the system's lo
5460
### Build for runtime linking
5561

5662
```shell script
57-
cargo build --features openvino-sys/runtime-linking
58-
source /opt/intel/openvino/setupvars.sh
59-
cargo test --features openvino-sys/runtime-linking
63+
cargo build --features runtime-linking
64+
cargo test --features runtime-linking
6065
```
6166

6267
The `openvino-rs` crates also support linking from a shared library at runtime (i.e.
6368
`dlopen`-style). This allow building the crates with no OpenVINO™ installation or source code
64-
present and only later--at runtime--providing the OpenVINO™ shared libraries. All underlying system
65-
calls are wrapped so that a call to `openvino_sys::library::load` will link them to their shared
66-
library implementation (using the logic in [openvino-finder] to locate the shared libraries). For
67-
high-level users, call `openvino::Core::new` first to automatically load and link the libraries.
69+
present and only later — at runtime — providing the OpenVINO™ shared libraries. All
70+
underlying system calls are wrapped so that a call to `openvino_sys::library::load` will link them
71+
to their shared library implementation (using the logic in [openvino-finder] to locate the shared
72+
libraries). For high-level users, call `openvino::Core::new` first to automatically load and link
73+
the libraries.
6874

6975

7076

crates/openvino-finder/README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
openvino-finder
22
===============
33

4-
A utility for locating OpenVINO™ libraries on a host system. It will attempt to find the OpenVINO
5-
shared libraries in:
6-
- the `OPENVINO_BUILD_DIR` environment variable (pointed at a locally-built OpenVINO repository)
7-
- the `OPENVINO_INSTALL_DIR` environment variable (pointed at the top-level OpenVINO installation,
8-
e.g., `/opt/intel/openvino`)
9-
- the `INTEL_OPENVINO_DIR` environment variable (same as above; this is set by OpenVINO setup
10-
scripts)
11-
- the environment's library path (e.g., `LD_LIBRARY_PATH` in Linux; this is also set by the OpenVINO
12-
setup scripts)
13-
- OpenVINO's default installation paths for the OS (a best effort attempt)
4+
A utility for locating OpenVINO™ files on a host system. Consult the [docs] for an in-depth
5+
description of how to use this crate (and troubleshoot issues).
146

15-
### Use
16-
17-
```Rust
18-
let path = openvino_finder::find("inference_engine_c_api").unwrap();
19-
```
7+
[docs]: https://docs.rs/openvino-finder

crates/openvino-finder/src/lib.rs

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1-
//! Provides a mechanism for locating the OpenVINO shared libraries installed on a system.
1+
//! This crate provides a mechanism for locating the OpenVINO files installed on a system.
2+
//!
3+
//! OpenVINO can be installed several ways: [from an archive][install-archive], [from an APT
4+
//! repository][install-apt], [via Python `pip`][install-pip]. The Rust bindings need to be able to:
5+
//! 1. locate the shared libraries (e.g., `libopenvino_c.so` on Linux) — see [`find`]
6+
//! 2. locate the plugin configuration file (i.e., `plugins.xml`) — see [`find_plugins_xml`].
7+
//! These files are located in different locations based on the installation method, so this crate
8+
//! encodes "how to find" OpenVINO files. This crate's goal is to locate __only the latest version__
9+
//! of OpenVINO; older versions may continue to be supported on a best-effort basis.
10+
//!
11+
//! [install-archive]: https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_from_archive_linux.html
12+
//! [install-apt]: https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_apt.html
13+
//! [install-pip]: https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_pip.html
14+
//!
15+
//! Problems with the OpenVINO bindings are most likely to be due to "finding" the right files. Both
16+
//! [`find`] and [`find_plugins_xml`] provide various ways of configuring the search paths, first by
17+
//! examining _special environment variables_ and then by looking in _known installation locations_.
18+
//! When [installing from an archive][install-archive], OpenVINO provides a setup script (e.g.,
19+
//! `source /opt/intel/openvino/setupvars.sh`) that sets these special environment variables. Note
20+
//! that you may need to have the OpenVINO environment ready both when building (`cargo build`) and
21+
//! running (e.g., `cargo test`) when the libraries are linked at compile-time (the default). By
22+
//! using the `runtime-linking` feature, the libraries are only searched for at run-time.
23+
//!
24+
//! If you do run into problems, the following chart summarizes some of the known installation
25+
//! locations of the OpenVINO files as of version `2022.3.0`:
26+
//!
27+
//! | Installation Method | Path | Available on | Notes |
28+
//! | ------------------- | -------------------------------------------------- | --------------------- | -------------------------------- |
29+
//! | Archive (`.tar.gz`) | `<extracted folder>/runtime/lib/<arch>` | Linux, MacOS | `<arch>`: `intel64,armv7l,arm64` |
30+
//! | Archive (`.zip`) | `<unzipped folder>/runtime/bin/<arch>/Release` | Windows | `<arch>`: `intel64,armv7l,arm64` |
31+
//! | PyPI | `<pip install folder>/site-packages/openvino/libs` | Linux, MacOS, Windows | Find install folder with `pip show openvino` |
32+
//! | DEB | `/usr/lib/x86_64-linux-gnu/openvino-<version>/` | Linux (APT-based) | This path is for plugins; the libraries are one directory above |
33+
//! | RPM | `/usr/lib64/` | Linux (YUM-based) | |
234
335
#![deny(missing_docs)]
436
#![deny(clippy::all)]
@@ -22,11 +54,33 @@ macro_rules! check_and_return {
2254
};
2355
}
2456

25-
/// Find the path to an OpenVINO library. This will try:
26-
/// - the `OPENVINO_INSTALL_DIR` environment variable with several subdirectories appended
27-
/// - the `INTEL_OPENVINO_DIR` environment variable with several subdirectories appended
28-
/// - the environment's library path (e.g. `LD_LIBRARY_PATH` in Linux)
29-
/// - OpenVINO's default installation paths for the OS
57+
/// Find the path to an OpenVINO library.
58+
///
59+
/// Because OpenVINO can be installed in quite a few ways (see module documentation), this function
60+
/// attempts the difficult and thankless task of locating the installation's shared libraries for
61+
/// use in the Rust bindings (i.e., [openvino] and [openvino-sys]). It uses observations from
62+
/// various OpenVINO releases across several operating systems and conversations with the OpenVINO
63+
/// development team, but it may not perfectly locate the libraries in every environment &mdash;
64+
/// hence the `Option<PathBuf>` return type.
65+
///
66+
/// [openvino]: https://docs.rs/openvino
67+
/// [openvino-sys]: https://docs.rs/openvino-sys
68+
///
69+
/// This function will probe:
70+
/// - the `OPENVINO_BUILD_DIR` environment variable with known build subdirectories appended &mdash;
71+
/// this is useful for finding libraries built from source
72+
/// - the `OPENVINO_INSTALL_DIR`, `INTEL_OPENVINO_DIR`, and `LD_LIBRARY_PATH` (or OS-equivalent)
73+
/// environment variables with known install subdirectories appended &mdash; one of these is set
74+
/// by a version of OpenVINO's environment script (e.g., `source
75+
/// /opt/intel/openvino/setupvars.sh`)
76+
/// - OpenVINO's package installation paths for the OS (e.g., `/usr/lib64`) &mdash; this is useful
77+
/// for DEB or RPM installations
78+
/// - OpenVINO's documented extract paths &mdash; this is useful for users who extract the TAR or
79+
/// ZIP archive to the default locations or use the Docker images
80+
///
81+
/// The locations above may change over time. As OpenVINO has released new versions, the documented
82+
/// locations of the shared libraries has changed. New versions of this function will reflect this,
83+
/// removing older, unused locations over time.
3084
pub fn find(library_name: &str) -> Option<PathBuf> {
3185
let file = format!(
3286
"{}{}{}",
@@ -177,11 +231,11 @@ const KNOWN_BUILD_SUBDIRECTORIES: &[&str] = &[
177231
/// DEB/RPM installations, it is found in a version-suffixed directory beside the OpenVINO libraries
178232
/// (e.g., `openvino-2022.3.0/plugins.xml`).
179233
///
180-
/// This function will check:
181-
/// - the `OPENVINO_PLUGINS_XML` environment variable--this is specific to this library
234+
/// This function will probe:
235+
/// - the `OPENVINO_PLUGINS_XML` environment variable &mdash; this is specific to this library
182236
/// - the same directory as the `openvino_c` shared library, as discovered by [find]
183237
/// - the latest version directory beside the `openvino_c` shared library (i.e.,
184-
/// `openvino-<version>/`)
238+
/// `openvino-<latest version>/`)
185239
pub fn find_plugins_xml() -> Option<PathBuf> {
186240
const FILE_NAME: &str = "plugins.xml";
187241

crates/xtask/src/bump.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct BumpCommand {
1616
/// 'Release v[bumped version]'`.
1717
#[structopt(long)]
1818
git: bool,
19-
/// What part of the semver version to change: major | minor | patch | <version string>
19+
/// What part of the semver version to change: major | minor | patch | [version string]
2020
#[structopt(name = "KIND")]
2121
bump: Bump,
2222
}

0 commit comments

Comments
 (0)