Query Device Properties - Configuration — OpenVINO™ documentation (original) (raw)

This article provides an overview of how to query different device properties and configuration values at runtime.

OpenVINO runtime has two types of properties:

An OpenVINO property is represented as a named constexpr variable with a given string name and a type. The following example represents a read-only property with the C++ name of ov::available_devices, the string name of AVAILABLE_DEVICES and the type ofstd::vector<std::string>:

static constexpr Property<std::vectorstd::string, PropertyMutability::RO> available_devices{"AVAILABLE_DEVICES"};

Refer to the Hello Query Device C++ Samplesources for an example of using the setting and getting properties in user applications.

Get a Set of Available Devices#

Based on the ov::available_devices read-only property, OpenVINO Core collects information about currently available devices enabled by OpenVINO plugins and returns information, using the ov::Core::get_available_devices method:

Python

core = ov.Core()
available_devices = core.available_devices

C++

ov::Core core; std::vectorstd::string available_devices = core.get_available_devices();

The function returns a list of available devices, for example:

If there are multiple instances of a specific device, the devices are enumerated with a suffix comprising a full stop and a unique string identifier, such as .suffix. Each device name can then be passed to:

Working with Properties in Your Code#

The ov::Core class provides the following method to query device information, set or get different device configuration properties:

The ov::CompiledModel class is also extended to support the properties:

For documentation about OpenVINO common device-independent properties, refer toproperties.hpp (GitHub). Device-specific configuration keys can be found in a corresponding device folders, for example, openvino/runtime/intel_gpu/properties.hpp.

Working with Properties via Core#

Getting Device Properties#

The code below demonstrates how to query HETERO device priority of devices which will be used to infer the model:

Python

device_priorites = core.get_property("HETERO", device.priorities)

C++

auto device_priorites = core.get_property("HETERO", ov::device::priorities);

Note

All properties have a type, which is specified during property declaration. Based on this, actual type under auto is automatically deduced by C++ compiler.

To extract device properties such as available devices (ov::available_devices), device name (ov::device::full_name), supported properties (ov::supported_properties), and others, use the ov::Core::get_property method:

Python

cpu_device_name = core.get_property("CPU", device.full_name)

C++

auto cpu_device_name = core.get_property("CPU", ov::device::full_name);

A returned value appears as follows: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz.

Note

In order to understand a list of supported properties on ov::Core or ov::CompiledModel levels, use ov::supported_propertieswhich contains a vector of supported property names. Properties which can be changed, has ov::PropertyName::is_mutablereturning the true value. Most of the properties which are changeable on ov::Core level, cannot be changed once the model is compiled, so it becomes immutable read-only property.

Configure a Work with a Model#

The ov::Core methods like:

accept a selection of properties as last arguments. Each of the properties should be used as a function call to pass a property value with a specified property type.

Python

config = {hints.performance_mode: hints.PerformanceMode.THROUGHPUT,
        hints.inference_precision: ov.Type.f32}
compiled_model = core.compile_model(model, "CPU", config)

C++

auto compiled_model = core.compile_model(model, "CPU", ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT), ov::hint::inference_precision(ov::element::f32));

The example below specifies hints that a model should be compiled to be inferred with multiple inference requests in parallel to achieve best throughput, while inference should be performed without accuracy loss with FP32 precision.

Setting Properties Globally#

ov::Core::set_property with a given device name should be used to set global configuration properties, which are the same across multiple ov::Core::compile_model, ov::Core::query_model, and other calls. However, setting properties on a specific ov::Core::compile_model call applies properties only for the current call:

Python

# latency hint is a default for CPU
core.set_property("CPU", {hints.performance_mode: hints.PerformanceMode.LATENCY})
# compiled with latency configuration hint
compiled_model_latency = core.compile_model(model, "CPU")
# compiled with overridden performance hint value
config = {hints.performance_mode: hints.PerformanceMode.THROUGHPUT}
compiled_model_thrp = core.compile_model(model, "CPU", config)

C++

// set letency hint is a default for CPU core.set_property("CPU", ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY)); // compiled with latency configuration hint auto compiled_model_latency = core.compile_model(model, "CPU"); // compiled with overridden ov::hint::performance_mode value auto compiled_model_thrp = core.compile_model(model, "CPU", ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT));

Properties on CompiledModel Level#

Getting Property#

The ov::CompiledModel::get_property method is used to get property values the compiled model has been created with or a compiled model level property such as ov::optimal_number_of_infer_requests:

Python

compiled_model = core.compile_model(model, "CPU")
nireq = compiled_model.get_property(props.optimal_number_of_infer_requests)

C++

auto compiled_model = core.compile_model(model, "CPU"); auto nireq = compiled_model.get_property(ov::optimal_number_of_infer_requests);

Or the number of threads that would be used for inference on CPU device:

Python

compiled_model = core.compile_model(model, "CPU")
nthreads = compiled_model.get_property(props.inference_num_threads)

C++

auto compiled_model = core.compile_model(model, "CPU"); auto nthreads = compiled_model.get_property(ov::inference_num_threads);