Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/openvino-finder/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
openvino-finder
===============

A utility for locating OpenVINO™ libraries on a host system.
A utility for locating OpenVINO™ libraries on a host system. It will attempt to find the OpenVINO
shared libraries in:
- the `OPENVINO_INSTALL_DIR` environment variable (pointed at the top-level OpenVINO installation,
e.g. `/opt/intel/openvino`)
- the `INTEL_OPENVINO_DIR` environment variable (same as above; this is set by OpenVINO setup
scripts)
- the environment's library path (e.g., `LD_LIBRARY_PATH` in Linux; this is also set by the OpenVINO
setup scripts)
- OpenVINO's default installation paths for the OS (a best effort attempt)

> #### WARNING
> This crate is currently experimental--its API surface is subject to change.
Expand Down
3 changes: 3 additions & 0 deletions crates/openvino/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ thiserror = "1.0.20"

[dev-dependencies]
float-cmp = "0.8"

[features]
runtime-linking = ["openvino-sys/runtime-linking"]
16 changes: 10 additions & 6 deletions crates/openvino/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
//! [API](https://docs.openvinotoolkit.org/latest/ie_c_api/modules.html).

use crate::blob::Blob;
use crate::network::{CNNNetwork, ExecutableNetwork};
use crate::tensor_desc::TensorDesc;
use crate::{cstr, drop_using_function, try_unsafe, util::Result};
use crate::{
error::{LoadingError, SetupError},
network::{CNNNetwork, ExecutableNetwork},
};
use crate::{Layout, Precision};
use openvino_sys::{
self, ie_config_t, ie_core_create, ie_core_free, ie_core_load_network, ie_core_read_network,
Expand All @@ -19,17 +22,18 @@ drop_using_function!(Core, ie_core_free);

impl Core {
/// Construct a new OpenVINO [Core]--this is the primary entrypoint for constructing and using
/// inference networks.
pub fn new(xml_config_file: Option<&str>) -> Result<Core> {
openvino_sys::library::load().expect("unable to load shared library");
/// inference networks. Because this function may load OpenVINO's shared libraries at runtime,
/// there are more ways than usual that this function can fail (e.g., [LoadingError]s).
pub fn new(xml_config_file: Option<&str>) -> std::result::Result<Core, SetupError> {
openvino_sys::library::load().or_else(|e| Err(LoadingError::SystemFailure(e)))?;

let file = match xml_config_file {
None => format!(
"{}/plugins.xml",
openvino_sys::library::find()
.expect("unable to find path to OpenVINO libraries")
.ok_or(LoadingError::CannotFindPath)?
.parent()
.expect("unable to get the parent of the linked OpenVINO library")
.ok_or(LoadingError::NoParentDirectory)?
.display()
),
Some(f) => f.to_string(),
Expand Down
30 changes: 24 additions & 6 deletions crates/openvino/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use thiserror::Error;

/// See
/// Enumerate errors returned by the OpenVINO implementation. See
/// [IEStatusCode](https://docs.openvinotoolkit.org/latest/ie_c_api/ie__c__api_8h.html#a391683b1e8e26df8b58d7033edd9ee83).
///
/// TODO Replace this in bindgen with
/// [newtype_enum](https://docs.rs/bindgen/0.54.1/bindgen/struct.Builder.html#method.newtype_enum)
/// or
/// [rustified_enum](https://docs.rs/bindgen/0.54.1/bindgen/struct.Builder.html#method.rustified_enum).
/// TODO This could be auto-generated (https://github.com/intel/openvino-rs/issues/20).
#[derive(Debug, Error)]
pub enum InferenceError {
#[error("general error")]
Expand Down Expand Up @@ -58,3 +54,25 @@ impl InferenceError {
}
}
}

/// Enumberate setup failures: in some cases, this library calls library loading code that may fail
/// in a different way (i.e., [LoadingError]) than the calls in to the OpenVINO libraries (i.e.,
/// [InferenceError]).
#[derive(Debug, Error)]
pub enum SetupError {
#[error("inference error")]
Inference(#[from] InferenceError),
#[error("library loading error")]
Loading(#[from] LoadingError),
}

/// Enumerate the ways that library loading can fail.
#[derive(Debug, Error)]
pub enum LoadingError {
#[error("system failed to load shared libraries (see https://github.com/intel/openvino-rs/blob/main/crates/openvino-finder): {0}")]
SystemFailure(String),
#[error("cannot find path to shared libraries (see https://github.com/intel/openvino-rs/blob/main/crates/openvino-finder)")]
CannotFindPath,
#[error("no parent directory found for shared library path")]
NoParentDirectory,
}
2 changes: 1 addition & 1 deletion crates/openvino/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod util;

pub use crate::core::Core;
pub use blob::Blob;
pub use error::InferenceError;
pub use error::{InferenceError, LoadingError, SetupError};
pub use network::{CNNNetwork, ExecutableNetwork};
// Re-publish some OpenVINO enums with a conventional Rust naming (see
// `crates/openvino-sys/build.rs`).
Expand Down