Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[AUTO] Optimize device utilization queries and logging in Plugin (#38179)

Wang, Yang46e7e8403329
diff --git a/src/plugins/auto/src/plugin.cpp b/src/plugins/auto/src/plugin.cpp
index 71ca2c0c569..fefdadef387 100644
--- a/src/plugins/auto/src/plugin.cpp
+++ b/src/plugins/auto/src/plugin.cpp
@@ -490,11 +490,23 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model_impl(const std::filesy
if (!device_utilization_thresholds.empty()) {
auto_s_context->m_selection_policy.utilization_thresholds.insert(device_utilization_thresholds.begin(),
device_utilization_thresholds.end());
+ for (const auto& item : device_utilization_thresholds) {
+ LOG_DEBUG_TAG("Device: %s. Utilization threshold: %s",
+ item.first.c_str(),
+ std::to_string(item.second).c_str());
+ }
}
// Values are already validated by PerfCurveTableValidator when the property is set, so no re-check here.
auto perf_curve_table = load_config.get_property(ov::intel_auto::perf_curve_table);
if (!perf_curve_table.empty()) {
auto_s_context->m_selection_policy.perf_curve_table = perf_curve_table;
+ LOG_DEBUG_TAG("PERF_CURVE_TABLE contains %s device curves", std::to_string(perf_curve_table.size()).c_str());
+ for (const auto& [device_key, curve] : perf_curve_table) {
+ LOG_DEBUG_TAG("PERF_CURVE_TABLE[%s] contains %s points", device_key.c_str(), std::to_string(curve.size()).c_str());
+ for (const auto& [utilization, score] : curve) {
+ LOG_DEBUG_TAG("PERF_CURVE_TABLE[%s]: utilization=%u, score=%lf", device_key.c_str(), utilization, score);
+ }
+ }
}
auto low_power_device = load_config.get_property(ov::intel_auto::low_power_device);
if (!low_power_device.empty()) {
@@ -593,18 +605,23 @@ ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>&
return res;
}
-std::optional<float> Plugin::get_device_utilization(const std::string& device_name,
- const std::string& device_type) {
+std::unordered_map<std::string, float> Plugin::get_device_utilizations(const std::list<DeviceInformation>& devices) {
std::call_once(m_telemetry_client_init_once, [this]() {
m_telemetry_client = std::make_unique<device_monitor::TelemetryClient>();
});
- auto result = m_telemetry_client->utilization(device_name, device_type);
- if (result.has_value()) {
- LOG_DEBUG_TAG("[IPF] Device %s utilization: %s",
- device_name.c_str(),
- std::to_string(result.value()).c_str());
- } else {
- LOG_DEBUG_TAG("[IPF] Device %s utilization query failed/unavailable", device_name.c_str());
+ std::vector<std::pair<std::string, std::string>> device_name_and_type;
+ device_name_and_type.reserve(devices.size());
+ for (const auto& device : devices) {
+ device_name_and_type.emplace_back(device.device_name, resolve_device_key(device.device_name).device_type);
+ }
+ const auto result = m_telemetry_client->utilizations(device_name_and_type);
+ for (const auto& device : devices) {
+ const auto it = result.find(device.device_name);
+ if (it != result.end()) {
+ LOG_DEBUG_TAG("[IPF] Device %s utilization: %s", device.device_name.c_str(), std::to_string(it->second).c_str());
+ } else {
+ LOG_DEBUG_TAG("[IPF] Device %s utilization query failed/unavailable", device.device_name.c_str());
+ }
}
return result;
}
@@ -732,22 +749,6 @@ DeviceInformation Plugin::select_device(const std::vector<DeviceInformation>& me
const auto& perf_curve_table = selection_policy.perf_curve_table;
std::list<DeviceInformation> valid_devices = get_valid_device(meta_devices, model_precision);
- if (!perf_curve_table.empty()) {
- LOG_DEBUG_TAG("PERF_CURVE_TABLE contains %s device curves",
- std::to_string(perf_curve_table.size()).c_str());
- for (const auto& [device_key, curve] : perf_curve_table) {
- LOG_DEBUG_TAG("PERF_CURVE_TABLE[%s] contains %s points",
- device_key.c_str(),
- std::to_string(curve.size()).c_str());
- for (const auto& [utilization, score] : curve) {
- LOG_DEBUG_TAG("PERF_CURVE_TABLE[%s]: utilization=%u, score=%lf",
- device_key.c_str(),
- utilization,
- score);
- }
- }
- }
-
// all available Devices are in valid_devices now
// need to remove higher priority devices
// save the last device first
@@ -796,10 +797,7 @@ DeviceInformation Plugin::select_device(const std::vector<DeviceInformation>& me
}
return std::nullopt;
};
- // low_power_device (driven by IPF/DTT OnEpoGearChanged) takes precedence over
- // devices_utilization_threshold whenever the platform is in low power mode.
- // Match by exact device name (e.g. "NPU.5010") first, then fall back to the
- // base device name (e.g. "NPU"), mirroring find_utilization_threshold.
+ // Finds the configured low-power device by exact or base device name.
auto find_low_power_device = [&]() -> DeviceInformation* {
if (low_power_device.empty()) {
return nullptr;
@@ -822,34 +820,32 @@ DeviceInformation Plugin::select_device(const std::vector<DeviceInformation>& me
} else if (auto* low_power_selected = find_low_power_device()) {
ptr_select_device = low_power_selected;
} else {
- // When both properties are configured, apply utilization thresholds first.
+ std::unordered_map<std::string, float> device_utilizations;
+ if (!utilization_thresholds.empty() || !perf_curve_table.empty()) {
+ device_utilizations = get_device_utilizations(valid_devices);
+ }
+ // Apply utilization thresholds before performance-curve ranking.
if (!utilization_thresholds.empty()) {
last_device = valid_devices.front();
std::list<DeviceInformation> threshold_filtered_devices;
- for (const auto& item : utilization_thresholds)
- LOG_DEBUG_TAG("Device: %s. Utilization threshold: %s", item.first.c_str(), std::to_string(item.second).c_str());
for (const auto& device : valid_devices) {
bool is_excluded = false;
const auto base_name = ov::DeviceIDParser(device.device_name).get_device_name();
const auto device_threshold = find_utilization_threshold(device.device_name, base_name);
if (device_threshold.has_value()) {
- std::string device_type;
- if (base_name == "GPU") {
- device_type = resolve_device_key(device.device_name).device_type;
- }
- const auto device_utilization = get_device_utilization(device.device_name, device_type);
- if (!device_utilization.has_value()) {
+ const auto utilization_it = device_utilizations.find(device.device_name);
+ if (utilization_it == device_utilizations.end()) {
LOG_DEBUG_TAG("Cannot get utilization for %s. Will keep it in the list", device.device_name.c_str());
} else {
LOG_DEBUG_TAG("Device: %s\tutilization: %s",
device.device_name.c_str(),
- std::to_string(device_utilization.value()).c_str());
- if (device_utilization.value() >= device_threshold.value()) {
+ std::to_string(utilization_it->second).c_str());
+ if (utilization_it->second >= device_threshold.value()) {
is_excluded = true;
LOG_DEBUG_TAG("[%s] Current utilization [%s] exceeds the threshold[%s]",
device.device_name.c_str(),
- std::to_string(device_utilization.value()).c_str(),
+ std::to_string(utilization_it->second).c_str(),
std::to_string(device_threshold.value()).c_str());
}
}
@@ -860,7 +856,7 @@ DeviceInformation Plugin::select_device(const std::vector<DeviceInformation>& me
}
if (threshold_filtered_devices.empty()) {
- // All candidates were filtered by threshold: keep previous fallback behavior.
+ // Fall back when all candidates exceed their thresholds.
ptr_select_device = &last_device;
} else {
valid_devices = std::move(threshold_filtered_devices);
@@ -868,10 +864,10 @@ DeviceInformation Plugin::select_device(const std::vector<DeviceInformation>& me
}
if (!ptr_select_device && !perf_curve_table.empty()) {
- // perf_curve_table ranks only candidates that already passed threshold filtering;
- // scored_count > 0 confirms at least one candidate resolved to a curve entry.
+ // Rank candidates with performance curves.
size_t scored_count = 0;
- perf_curve_sorted_devices = sort_device_by_perf_curve(valid_devices, perf_curve_table, &scored_count);
+ perf_curve_sorted_devices =
+ sort_device_by_perf_curve(device_utilizations, valid_devices, perf_curve_table, &scored_count);
if (scored_count > 0) {
ptr_select_device = &perf_curve_sorted_devices.front();
}
@@ -920,6 +916,7 @@ float Plugin::interpolate_perf_score(const std::map<unsigned, float>& curve, flo
}
std::list<DeviceInformation> Plugin::sort_device_by_perf_curve(
+ const std::unordered_map<std::string, float>& device_utilizations,
const std::list<DeviceInformation>& valid_devices,
const ov::intel_auto::PerfCurveTable& perf_curve_table,
size_t* out_scored_count) {
@@ -950,17 +947,17 @@ std::list<DeviceInformation> Plugin::sort_device_by_perf_curve(
device_key.logical_key.c_str());
continue; // no curve entry for this device -> unscored
}
- const auto utilization = get_device_utilization(device.device_name, device_key.device_type);
- if (!utilization.has_value()) {
+ const auto utilization_it = device_utilizations.find(device.device_name);
+ if (utilization_it == device_utilizations.end()) {
LOG_DEBUG_TAG("Cannot get utilization for %s via perf_curve_table lookup", device.device_name.c_str());
continue;
}
try {
- scores[i] = interpolate_perf_score(curve_it->second, utilization.value());
+ scores[i] = interpolate_perf_score(curve_it->second, utilization_it->second);
LOG_DEBUG_TAG("[%s] perf_curve_table: key=%s, utilization=%lf, performance_score=%lf",
device.device_name.c_str(),
device_key.logical_key.c_str(),
- utilization.value(),
+ utilization_it->second,
scores[i].value());
} catch (const ov::Exception& ex) {
LOG_DEBUG_TAG("[%s] perf_curve_table score computation failed: %s. Treat as no-score",
diff --git a/src/plugins/auto/src/plugin.hpp b/src/plugins/auto/src/plugin.hpp
index 3b25e1f1c67..5848bb71922 100644
--- a/src/plugins/auto/src/plugin.hpp
+++ b/src/plugins/auto/src/plugin.hpp
@@ -64,6 +64,7 @@ public:
const DeviceSelectionPolicy& selection_policy = {},
const std::string& low_power_device = {});
MOCKTESTMACRO std::list<DeviceInformation> sort_device_by_perf_curve(
+ const std::unordered_map<std::string, float>& device_utilizations,
const std::list<DeviceInformation>& valid_devices,
const ov::intel_auto::PerfCurveTable& perf_curve_table,
size_t* out_scored_count = nullptr);
@@ -81,8 +82,9 @@ public:
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model,
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& properties) const override;
- MOCKTESTMACRO std::optional<float> get_device_utilization(const std::string& device_name,
- const std::string& device_type = "");
+ // Returns utilization values for the specified devices.
+ MOCKTESTMACRO std::unordered_map<std::string, float> get_device_utilizations(
+ const std::list<DeviceInformation>& devices);
// Whether the platform is currently in low power mode; see device_monitor::TelemetryClient.
MOCKTESTMACRO std::optional<bool> get_low_power_mode();
@@ -106,7 +108,8 @@ private:
PluginConfig& load_config) const;
std::string get_log_tag() const noexcept;
// Base family name, perf_curve_table lookup key ("iGPU"/"dGPU" for GPUs via ov::device::type,
- // empty when it cannot be determined), and the ov::device::type string used by get_device_utilization.
+ // empty when it cannot be determined), and the ov::device::type string used to resolve a
+ // device's IPF utilization metric key.
struct DeviceKey {
std::string base_name;
std::string logical_key;
diff --git a/src/plugins/auto/src/utils/device_telemetry.cpp b/src/plugins/auto/src/utils/device_telemetry.cpp
index e0a3c10a51e..ff8046b41e5 100644
--- a/src/plugins/auto/src/utils/device_telemetry.cpp
+++ b/src/plugins/auto/src/utils/device_telemetry.cpp
@@ -6,6 +6,7 @@
#ifdef OV_AUTO_ENABLE_IPF
+# include <algorithm>
# include <atomic>
# include <cmath>
# include <memory>
@@ -39,10 +40,9 @@ void gear_changed_callback(const char* path, const char* event, void* context);
namespace {
-std::optional<float> parse_utilization_from_aiselector_json_impl(const std::string& json_str,
- const std::string& metric_key,
- std::string_view metric_key_view,
- const std::string& device_name) {
+// Parses the raw IPF response once; returns the "Performance" section, or nullopt if
+// malformed/missing so callers can look up multiple devices' metrics without reparsing.
+std::optional<nlohmann::json> parse_performance_section(const std::string& json_str) {
try {
LOG_DEBUG_TAG("TelemetryClient: raw IPF response: %s", json_str.c_str());
const auto parsed = nlohmann::json::parse(json_str);
@@ -50,47 +50,53 @@ std::optional<float> parse_utilization_from_aiselector_json_impl(const std::stri
LOG_WARNING_TAG("TelemetryClient: JSON missing 'Performance' section");
return std::nullopt;
}
- const auto& performance = parsed["Performance"];
- auto metric_it = performance.find(metric_key);
- // IGPU may be reported under either IGPUUtilization or GPUUtilization; fall back to the latter.
- const bool igpu_fallback_attempted = metric_it == performance.end() && metric_key_view == k_igpu_utilization_metric;
- if (igpu_fallback_attempted) {
- static const std::string igpu_fallback_key{k_igpu_utilization_fallback_metric};
- metric_it = performance.find(igpu_fallback_key);
- }
- if (metric_it == performance.end()) {
- if (igpu_fallback_attempted) {
- LOG_WARNING_TAG("TelemetryClient: Performance section missing keys: %s and fallback %.*s",
- metric_key.c_str(),
- static_cast<int>(k_igpu_utilization_fallback_metric.size()),
- k_igpu_utilization_fallback_metric.data());
- } else {
- LOG_WARNING_TAG("TelemetryClient: Performance section missing key: %s", metric_key.c_str());
- }
- return std::nullopt;
- }
- if (!metric_it->is_number()) {
- const auto& resolved_metric_key = metric_it.key();
- LOG_WARNING_TAG("TelemetryClient: Performance value for key %s is not a number", resolved_metric_key.c_str());
- return std::nullopt;
- }
- float value = metric_it->get<float>();
- const std::string value_as_string = std::to_string(value);
- LOG_DEBUG_TAG("TelemetryClient: parsed utilization=%s for device=%s", value_as_string.c_str(), device_name.c_str());
- if (!std::isfinite(value) || value < 0.0f || value > 100.0f) {
- LOG_WARNING_TAG("TelemetryClient: utilization value out of supported range [0,100], value=%s for device=%s",
- value_as_string.c_str(),
- device_name.c_str());
- return std::nullopt;
- }
-
- return value;
+ return parsed["Performance"];
} catch (const nlohmann::json::exception& e) {
LOG_DEBUG_TAG("TelemetryClient: JSON parsing exception: %s", e.what());
return std::nullopt;
}
}
+std::optional<float> extract_utilization(const nlohmann::json& performance,
+ const std::string& metric_key,
+ std::string_view metric_key_view,
+ const std::string& device_name) {
+ auto metric_it = performance.find(metric_key);
+ // IGPU may be reported under either IGPUUtilization or GPUUtilization; fall back to the latter.
+ const bool igpu_fallback_attempted = metric_it == performance.end() && metric_key_view == k_igpu_utilization_metric;
+ if (igpu_fallback_attempted) {
+ static const std::string igpu_fallback_key{k_igpu_utilization_fallback_metric};
+ metric_it = performance.find(igpu_fallback_key);
+ }
+ if (metric_it == performance.end()) {
+ if (igpu_fallback_attempted) {
+ LOG_WARNING_TAG("TelemetryClient: Performance section missing keys: %s and fallback %.*s",
+ metric_key.c_str(),
+ static_cast<int>(k_igpu_utilization_fallback_metric.size()),
+ k_igpu_utilization_fallback_metric.data());
+ } else {
+ LOG_WARNING_TAG("TelemetryClient: Performance section missing key: %s", metric_key.c_str());
+ }
+ return std::nullopt;
+ }
+ if (!metric_it->is_number()) {
+ const auto& resolved_metric_key = metric_it.key();
+ LOG_WARNING_TAG("TelemetryClient: Performance value for key %s is not a number", resolved_metric_key.c_str());
+ return std::nullopt;
+ }
+ float value = metric_it->get<float>();
+ const std::string value_as_string = std::to_string(value);
+ LOG_DEBUG_TAG("TelemetryClient: parsed utilization=%s for device=%s", value_as_string.c_str(), device_name.c_str());
+ if (!std::isfinite(value) || value < 0.0f || value > 100.0f) {
+ LOG_WARNING_TAG("TelemetryClient: utilization value out of supported range [0,100], value=%s for device=%s",
+ value_as_string.c_str(),
+ device_name.c_str());
+ return std::nullopt;
+ }
+
+ return value;
+}
+
} // namespace
// Calls into the statically linked IPF ClientApi through the plain-C ABI (ClientApiC.h).
@@ -169,23 +175,31 @@ public:
}
}
- std::optional<float> utilization(const std::string& device_name, const std::string& device_type) {
+ // Single IPF round trip; the returned JSON snapshot covers every device's utilization at
+ // once, so callers should fetch it once per decision and reuse it for all candidates.
+ std::string fetch_utilization_snapshot() {
if (m_handle == nullptr) {
- LOG_DEBUG_TAG("TelemetryClient::utilization(%s): client not initialized", device_name.c_str());
- return std::nullopt;
+ LOG_DEBUG_TAG("TelemetryClient::fetch_utilization_snapshot: client not initialized");
+ return {};
}
- const auto metric_key_view = device_to_metric_key(device_name, device_type);
- if (metric_key_view.empty()) {
- LOG_WARNING_TAG("TelemetryClient::utilization(%s): unknown device type, metric_key empty", device_name.c_str());
- return std::nullopt;
+ LOG_DEBUG_TAG("TelemetryClient::fetch_utilization_snapshot: querying IPF for AISelector snapshot");
+ return get_node("Platform.Features.AISelector");
+ }
+
+ // Fetches one snapshot and resolves utilization for every requested device from it.
+ std::unordered_map<std::string, float> utilizations(
+ const std::vector<std::pair<std::string, std::string>>& devices) {
+ const bool any_supported = std::any_of(devices.begin(), devices.end(), [](const auto& device) {
+ return !device_to_metric_key(device.first, device.second).empty();
+ });
+ if (!any_supported) {
+ return {};
}
- const std::string metric_key{metric_key_view};
- LOG_DEBUG_TAG("TelemetryClient::utilization(%s): querying IPF for metric_key=%s", device_name.c_str(), metric_key.c_str());
- const std::string json_str = get_node("Platform.Features.AISelector");
- if (json_str.empty()) {
- return std::nullopt;
+ const std::string snapshot = fetch_utilization_snapshot();
+ if (snapshot.empty()) {
+ return {};
}
- return parse_utilization_from_aiselector_json_impl(json_str, metric_key, metric_key_view, device_name);
+ return utilization_from_snapshot(snapshot, devices);
}
std::optional<bool> is_low_power_mode() {
@@ -404,26 +418,53 @@ TelemetryClient::TelemetryClient() : m_impl(std::make_unique<Impl>()) {}
TelemetryClient::~TelemetryClient() = default;
-std::optional<float> TelemetryClient::utilization(const std::string& device_name, const std::string& device_type) {
- return m_impl->utilization(device_name, device_type);
+std::unordered_map<std::string, float> TelemetryClient::utilizations(
+ const std::vector<std::pair<std::string, std::string>>& devices) {
+ return m_impl->utilizations(devices);
}
std::optional<bool> TelemetryClient::is_low_power_mode() {
return m_impl->is_low_power_mode();
}
+std::unordered_map<std::string, float> utilization_from_snapshot(
+ const std::string& snapshot,
+ const std::vector<std::pair<std::string, std::string>>& devices) {
+ std::unordered_map<std::string, float> result;
+ if (snapshot.empty() || devices.empty()) {
+ return result;
+ }
+ const auto performance = parse_performance_section(snapshot);
+ if (!performance.has_value()) {
+ return result;
+ }
+ for (const auto& [device_name, device_type] : devices) {
+ const auto metric_key_view = device_to_metric_key(device_name, device_type);
+ if (metric_key_view.empty()) {
+ continue;
+ }
+ const auto utilization =
+ extract_utilization(*performance, std::string{metric_key_view}, metric_key_view, device_name);
+ if (utilization.has_value()) {
+ result.emplace(device_name, *utilization);
+ }
+ }
+ return result;
+}
+
+std::optional<float> utilization_from_snapshot(const std::string& snapshot,
+ const std::string& device_name,
+ const std::string& device_type) {
+ const auto result = utilization_from_snapshot(snapshot, std::vector<std::pair<std::string, std::string>>{{device_name, device_type}});
+ const auto it = result.find(device_name);
+ return it != result.end() ? std::optional<float>(it->second) : std::nullopt;
+}
+
#ifdef MULTIUNITTEST
std::optional<float> parse_utilization_from_aiselector_json_for_test(const std::string& json_str,
const std::string& device_name,
const std::string& device_type) {
- const auto metric_key_view = device_to_metric_key(device_name, device_type);
- if (metric_key_view.empty()) {
- return std::nullopt;
- }
- return parse_utilization_from_aiselector_json_impl(json_str,
- std::string{metric_key_view},
- metric_key_view,
- device_name);
+ return utilization_from_snapshot(json_str, device_name, device_type);
}
#endif
@@ -443,14 +484,24 @@ TelemetryClient::TelemetryClient() : m_impl(nullptr) {}
TelemetryClient::~TelemetryClient() = default;
-std::optional<float> TelemetryClient::utilization(const std::string&, const std::string&) {
- return std::nullopt;
+std::unordered_map<std::string, float> TelemetryClient::utilizations(const std::vector<std::pair<std::string, std::string>>&) {
+ return {};
}
std::optional<bool> TelemetryClient::is_low_power_mode() {
return std::nullopt;
}
+std::unordered_map<std::string, float> utilization_from_snapshot(
+ const std::string&,
+ const std::vector<std::pair<std::string, std::string>>&) {
+ return {};
+}
+
+std::optional<float> utilization_from_snapshot(const std::string&, const std::string&, const std::string&) {
+ return std::nullopt;
+}
+
} // namespace device_monitor
} // namespace auto_plugin
} // namespace ov
diff --git a/src/plugins/auto/src/utils/device_telemetry.hpp b/src/plugins/auto/src/utils/device_telemetry.hpp
index 26e88accead..2c87fc87b40 100644
--- a/src/plugins/auto/src/utils/device_telemetry.hpp
+++ b/src/plugins/auto/src/utils/device_telemetry.hpp
@@ -8,6 +8,9 @@
#include <optional>
#include <string>
#include <string_view>
+#include <unordered_map>
+#include <utility>
+#include <vector>
#include "../common.hpp"
@@ -31,7 +34,9 @@ public:
TelemetryClient();
~TelemetryClient();
- std::optional<float> utilization(const std::string& device_name, const std::string& device_type = "");
+ // Resolves utilization for multiple (device_name, device_type) devices, keyed by device_name.
+ // Fetches and parses the underlying IPF snapshot only once regardless of device count.
+ std::unordered_map<std::string, float> utilizations(const std::vector<std::pair<std::string, std::string>>& devices);
// Whether the platform is currently in low power mode, based on startup CurrentGear state and
// any later IPF/DTT OnEpoGearChanged notifications. std::nullopt means the mode is unknown.
@@ -46,6 +51,17 @@ private:
std::unique_ptr<Impl> m_impl;
};
+// Parses utilization for multiple (device_name, device_type) devices from one snapshot,
+// keyed by device_name. Parses the snapshot only once regardless of device count.
+std::unordered_map<std::string, float> utilization_from_snapshot(
+ const std::string& snapshot,
+ const std::vector<std::pair<std::string, std::string>>& devices);
+
+// Parses one device's utilization from a snapshot.
+std::optional<float> utilization_from_snapshot(const std::string& snapshot,
+ const std::string& device_name,
+ const std::string& device_type = "");
+
inline constexpr std::string_view k_cpu_utilization_metric = "CPUUtilization";
inline constexpr std::string_view k_igpu_utilization_metric = "IGPUUtilization";
// Fallback key: some platforms report integrated GPU utilization as "GPUUtilization".
diff --git a/src/plugins/auto/tests/unit/auto_unit_test.cpp b/src/plugins/auto/tests/unit/auto_unit_test.cpp
index 09b2b3c7db6..0eb0d6569c7 100644
--- a/src/plugins/auto/tests/unit/auto_unit_test.cpp
+++ b/src/plugins/auto/tests/unit/auto_unit_test.cpp
@@ -127,10 +127,14 @@ ov::mock_auto_plugin::tests::BaseTest::BaseTest(const MODELTYPE modelType) {
});
ON_CALL(*plugin, sort_device_by_perf_curve)
- .WillByDefault([this](const std::list<DeviceInformation>& validDevices,
+ .WillByDefault([this](const std::unordered_map<std::string, float>& deviceUtilizations,
+ const std::list<DeviceInformation>& validDevices,
const ov::intel_auto::PerfCurveTable& perfCurveTable,
size_t* out_scored_count) {
- return plugin->Plugin::sort_device_by_perf_curve(validDevices, perfCurveTable, out_scored_count);
+ return plugin->Plugin::sort_device_by_perf_curve(deviceUtilizations,
+ validDevices,
+ perfCurveTable,
+ out_scored_count);
});
ON_CALL(*plugin, get_valid_device)
@@ -143,10 +147,8 @@ ov::mock_auto_plugin::tests::BaseTest::BaseTest(const MODELTYPE modelType) {
return plugin->Plugin::get_property(name, arguments);
});
- ON_CALL(*plugin, get_device_utilization)
- .WillByDefault([](const std::string& device_name, const std::string& device_type) -> std::optional<float> {
- return std::nullopt;
- });
+ ON_CALL(*plugin, get_device_utilizations)
+ .WillByDefault(Return(std::unordered_map<std::string, float>{}));
}
ov::mock_auto_plugin::tests::BaseTest::~BaseTest() {
diff --git a/src/plugins/auto/tests/unit/device_telemetry_test.cpp b/src/plugins/auto/tests/unit/device_telemetry_test.cpp
index eb08ea23539..2db49d4ea7a 100644
--- a/src/plugins/auto/tests/unit/device_telemetry_test.cpp
+++ b/src/plugins/auto/tests/unit/device_telemetry_test.cpp
@@ -10,6 +10,7 @@
#include <sstream>
#include <string>
#include <tuple>
+#include <unordered_map>
#include <vector>
#include "utils/device_telemetry.hpp"
@@ -90,26 +91,47 @@ TEST(DeviceMonitorTest, telemetry_client_low_power_mode_is_safe) {
#endif
}
-// TelemetryClient::utilization must never throw and must return a value within
-// [0.0, 100.0] when available, or std::nullopt otherwise. On builds without the
-// telemetry backend it consistently returns std::nullopt.
-TEST(DeviceMonitorTest, telemetry_client_utilization_is_safe) {
+// TelemetryClient::utilizations must never throw and must return values within
+// [0.0, 100.0] when available. On builds without the telemetry backend it consistently
+// returns an empty map.
+TEST(DeviceMonitorTest, telemetry_client_utilizations_is_safe) {
device_monitor::TelemetryClient client;
- std::optional<float> utilization;
- ASSERT_NO_THROW(utilization = client.utilization("CPU"));
- if (utilization.has_value()) {
- EXPECT_GE(utilization.value(), 0.0f);
- EXPECT_LE(utilization.value(), 100.0f);
+ std::unordered_map<std::string, float> utilizations;
+ ASSERT_NO_THROW(utilizations = client.utilizations({{"CPU", ""}}));
+ for (const auto& [device_name, utilization] : utilizations) {
+ EXPECT_GE(utilization, 0.0f);
+ EXPECT_LE(utilization, 100.0f);
}
}
-TEST(DeviceMonitorTest, telemetry_client_unknown_device_returns_nullopt) {
+TEST(DeviceMonitorTest, telemetry_client_unknown_device_is_excluded) {
device_monitor::TelemetryClient client;
- std::optional<float> utilization;
- ASSERT_NO_THROW(utilization = client.utilization("UNKNOWN_DEVICE"));
- EXPECT_FALSE(utilization.has_value());
+ std::unordered_map<std::string, float> utilizations;
+ ASSERT_NO_THROW(utilizations = client.utilizations({{"UNKNOWN_DEVICE", ""}}));
+ EXPECT_EQ(utilizations.count("UNKNOWN_DEVICE"), 0u);
}
+#ifdef OV_AUTO_ENABLE_IPF
+TEST(DeviceMonitorTest, utilization_values_are_parsed_from_one_snapshot) {
+ const std::string snapshot = R"({
+ "Performance": {
+ "CPUUtilization": 12.5,
+ "NPUUtilization": 37.5
+ },
+ "Status": "Online"
+ })";
+
+ const auto utilizations = device_monitor::utilization_from_snapshot(
+ snapshot,
+ std::vector<std::pair<std::string, std::string>>{{"CPU", ""}, {"NPU", ""}});
+
+ ASSERT_EQ(utilizations.count("CPU"), 1u);
+ ASSERT_EQ(utilizations.count("NPU"), 1u);
+ EXPECT_FLOAT_EQ(utilizations.at("CPU"), 12.5f);
+ EXPECT_FLOAT_EQ(utilizations.at("NPU"), 37.5f);
+}
+#endif
+
#ifdef OV_AUTO_ENABLE_IPF
TEST(DeviceMonitorTest, parse_utilization_uses_gpu_fallback_for_igpu) {
const std::string aiselector_json = R"({
diff --git a/src/plugins/auto/tests/unit/include/gmock_plugin.hpp b/src/plugins/auto/tests/unit/include/gmock_plugin.hpp
index 1bd043e38b9..a2fdb3c4357 100644
--- a/src/plugins/auto/tests/unit/include/gmock_plugin.hpp
+++ b/src/plugins/auto/tests/unit/include/gmock_plugin.hpp
@@ -18,9 +18,9 @@ namespace mock_auto_plugin {
class MockAutoPlugin : public Plugin {
public:
MOCK_METHOD((ov::Any), get_property, ((const std::string&), (const ov::AnyMap&)), (const, override));
- MOCK_METHOD((std::optional<float>),
- get_device_utilization,
- ((const std::string&), (const std::string&)),
+ MOCK_METHOD((std::unordered_map<std::string, float>),
+ get_device_utilizations,
+ (const std::list<DeviceInformation>&),
(override));
MOCK_METHOD((std::optional<bool>), get_low_power_mode, (), (override));
MOCK_METHOD((std::string),
@@ -42,7 +42,8 @@ public:
(override));
MOCK_METHOD((std::list<DeviceInformation>),
sort_device_by_perf_curve,
- ((const std::list<DeviceInformation>&),
+ ((const std::unordered_map<std::string, float>&),
+ (const std::list<DeviceInformation>&),
(const ov::intel_auto::PerfCurveTable&),
size_t*),
(override));
diff --git a/src/plugins/auto/tests/unit/select_device_test.cpp b/src/plugins/auto/tests/unit/select_device_test.cpp
index 25c39f9c04c..2c73048844b 100644
--- a/src/plugins/auto/tests/unit/select_device_test.cpp
+++ b/src/plugins/auto/tests/unit/select_device_test.cpp
@@ -302,13 +302,16 @@ public:
StrEq(ov::intel_auto::devices_utilization_threshold.name()),
_))
.WillByDefault(Return(ov::Any(properties_thresholds)));
- ON_CALL(*plugin, get_device_utilization)
- .WillByDefault([this](const std::string& device_name, const std::string& device_type) -> std::optional<float> {
- const auto it = deviceUtilization.find(device_name);
- if (it == deviceUtilization.end()) {
- return std::nullopt;
+ ON_CALL(*plugin, get_device_utilizations)
+ .WillByDefault([this](const std::list<DeviceInformation>& devices) -> std::unordered_map<std::string, float> {
+ std::unordered_map<std::string, float> result;
+ for (const auto& device : devices) {
+ auto it = deviceUtilization.find(device.device_name);
+ if (it != deviceUtilization.end()) {
+ result.emplace(it->first, it->second);
+ }
}
- return it->second;
+ return result;
});
ON_CALL(*plugin, get_valid_device)
.WillByDefault([this](const std::vector<DeviceInformation>& metaDevices, const std::string& netPrecision) {
@@ -516,13 +519,16 @@ public:
std::vector<std::string> npuCapability = {"FP32", "FP16", "INT8", "BIN"};
ON_CALL(*core, get_property(StrEq(ov::test::utils::DEVICE_NPU), StrEq(ov::device::capabilities.name()), _))
.WillByDefault(RETURN_MOCK_VALUE(npuCapability));
- ON_CALL(*plugin, get_device_utilization)
- .WillByDefault([this](const std::string& device_name, const std::string& device_type) -> std::optional<float> {
- const auto it = deviceUtilization.find(device_name);
- if (it == deviceUtilization.end()) {
- return std::nullopt;
+ ON_CALL(*plugin, get_device_utilizations)
+ .WillByDefault([this](const std::list<DeviceInformation>& devices) -> std::unordered_map<std::string, float> {
+ std::unordered_map<std::string, float> result;
+ for (const auto& device : devices) {
+ auto it = deviceUtilization.find(device.device_name);
+ if (it != deviceUtilization.end()) {
+ result.emplace(it->first, it->second);
+ }
}
- return it->second;
+ return result;
});
ON_CALL(*plugin, get_valid_device)
.WillByDefault([this](const std::vector<DeviceInformation>& metaDevices, const std::string& netPrecision) {
@@ -624,13 +630,16 @@ public:
std::vector<std::string> npuCapability = {"FP32", "FP16", "INT8", "BIN"};
ON_CALL(*core, get_property(StrEq(ov::test::utils::DEVICE_NPU), StrEq(ov::device::capabilities.name()), _))
.WillByDefault(RETURN_MOCK_VALUE(npuCapability));
- ON_CALL(*plugin, get_device_utilization)
- .WillByDefault([this](const std::string& device_name, const std::string& device_type) -> std::optional<float> {
- const auto it = deviceUtilization.find(device_name);
- if (it == deviceUtilization.end()) {
- return std::nullopt;
+ ON_CALL(*plugin, get_device_utilizations)
+ .WillByDefault([this](const std::list<DeviceInformation>& devices) -> std::unordered_map<std::string, float> {
+ std::unordered_map<std::string, float> result;
+ for (const auto& device : devices) {
+ auto it = deviceUtilization.find(device.device_name);
+ if (it != deviceUtilization.end()) {
+ result.emplace(it->first, it->second);
+ }
}
- return it->second;
+ return result;
});
ON_CALL(*plugin, get_valid_device)
.WillByDefault([this](const std::vector<DeviceInformation>& metaDevices, const std::string& netPrecision) {
@@ -684,14 +693,6 @@ class SortDeviceByPerfCurveTest : public tests::AutoTest, public ::testing::Test
public:
void SetUp() override {
std::tie(perfCurveTable, inputDevices, deviceUtilization, expectedOrder) = GetParam();
- ON_CALL(*plugin, get_device_utilization)
- .WillByDefault([this](const std::string& device_name, const std::string& device_type) -> std::optional<float> {
- const auto it = deviceUtilization.find(device_name);
- if (it == deviceUtilization.end()) {
- return std::nullopt;
- }
- return it->second;
- });
}
protected:
@@ -702,7 +703,11 @@ protected:
};
TEST_P(SortDeviceByPerfCurveTest, sortDeviceByPerfCurve) {
- auto result = plugin->sort_device_by_perf_curve(inputDevices, perfCurveTable, nullptr);
+ auto result = plugin->sort_device_by_perf_curve(
+ std::unordered_map<std::string, float>(deviceUtilization.begin(), deviceUtilization.end()),
+ inputDevices,
+ perfCurveTable,
+ nullptr);
std::vector<std::string> actualOrder;
for (const auto& device : result) {
actualOrder.push_back(device.unique_name);
@@ -778,13 +783,16 @@ public:
std::vector<std::string> npuCapability = {"FP32", "FP16", "INT8", "BIN"};
ON_CALL(*core, get_property(StrEq(ov::test::utils::DEVICE_NPU), StrEq(ov::device::capabilities.name()), _))
.WillByDefault(RETURN_MOCK_VALUE(npuCapability));
- ON_CALL(*plugin, get_device_utilization)
- .WillByDefault([this](const std::string& device_name, const std::string& device_type) -> std::optional<float> {
- const auto it = deviceUtilization.find(device_name);
- if (it == deviceUtilization.end()) {
- return std::nullopt;
+ ON_CALL(*plugin, get_device_utilizations)
+ .WillByDefault([this](const std::list<DeviceInformation>& devices) -> std::unordered_map<std::string, float> {
+ std::unordered_map<std::string, float> result;
+ for (const auto& device : devices) {
+ auto it = deviceUtilization.find(device.device_name);
+ if (it != deviceUtilization.end()) {
+ result.emplace(it->first, it->second);
+ }
}
- return it->second;
+ return result;
});
ON_CALL(*plugin, get_valid_device)
.WillByDefault([this](const std::vector<DeviceInformation>& metaDevices, const std::string& netPrecision) {