Skip to content

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

[AUTO] perf_curve_table property for device selection by interpolated performance curve (#37196)

Wang, Yang56512368f77d
diff --git a/src/bindings/python/src/pyopenvino/core/properties/properties.cpp b/src/bindings/python/src/pyopenvino/core/properties/properties.cpp
index 17def3e17b1..80863009c0f 100644
--- a/src/bindings/python/src/pyopenvino/core/properties/properties.cpp
+++ b/src/bindings/python/src/pyopenvino/core/properties/properties.cpp
@@ -4,6 +4,8 @@
#include "pyopenvino/core/properties/properties.hpp"
+#include <pybind11/stl.h>
+
#include "openvino/runtime/auto/properties.hpp"
#include "openvino/runtime/intel_cpu/properties.hpp"
#include "openvino/runtime/intel_gpu/properties.hpp"
@@ -340,6 +342,25 @@ void regmodule_properties(py::module m) {
wrap_property_RW(m_intel_auto, ov::intel_auto::enable_runtime_fallback, "enable_runtime_fallback");
wrap_property_RW(m_intel_auto, ov::intel_auto::schedule_policy, "schedule_policy");
wrap_property_RW(m_intel_auto, ov::intel_auto::devices_utilization_threshold, "devices_utilization_threshold");
+ // perf_curve_table: name/string/map overloads (map form uses pybind11's default STL caster).
+ m_intel_auto.def("perf_curve_table", []() {
+ return ov::intel_auto::perf_curve_table.name();
+ });
+ // String form, e.g. "{CPU:{0:0,100:100}}".
+ m_intel_auto.def("perf_curve_table", [](const std::string& value) {
+ try {
+ return ov::intel_auto::perf_curve_table(
+ ov::Any(value).as<std::map<std::string, std::map<unsigned, float>>>());
+ } catch (const ov::Exception& e) {
+ OPENVINO_THROW("PERF_CURVE_TABLE: failed to parse string '",
+ value,
+ "'. Expected format: {DeviceName:{util:score,...},...}. ",
+ e.what());
+ }
+ });
+ m_intel_auto.def("perf_curve_table", [](const std::map<std::string, std::map<unsigned, float>>& value) {
+ return ov::intel_auto::perf_curve_table(value);
+ });
wrap_property_RW(m_intel_auto, ov::intel_auto::low_power_device, "low_power_device");
// Submodule npu
diff --git a/src/bindings/python/src/pyopenvino/utils/utils.cpp b/src/bindings/python/src/pyopenvino/utils/utils.cpp
index ffc107d0345..3e01248ac1c 100644
--- a/src/bindings/python/src/pyopenvino/utils/utils.cpp
+++ b/src/bindings/python/src/pyopenvino/utils/utils.cpp
@@ -7,6 +7,7 @@
#include <pybind11/stl.h>
#include <pybind11/stl/filesystem.h>
+#include <cmath>
#include <map>
#include <set>
#include <string>
@@ -196,6 +197,10 @@ py::object from_ov_any(const ov::Any& any) {
else if (any.is<std::map<std::string, uint64_t>>()) {
return py::cast(any.as<std::map<std::string, uint64_t>>());
}
+ // Check for ov::intel_auto::PerfCurveTable (std::map<std::string, std::map<unsigned, float>>)
+ else if (any.is<ov::intel_auto::PerfCurveTable>()) {
+ return py::cast(any.as<ov::intel_auto::PerfCurveTable>());
+ }
// Check for std::map<element::Type, float>
else if (any.is<std::map<ov::element::Type, float>>()) {
return py::cast(any.as<std::map<ov::element::Type, float>>());
@@ -362,6 +367,9 @@ std::map<std::string, ov::Any> properties_to_any_map(const std::map<std::string,
thresholds[key] = static_cast<unsigned>(value);
}
properties_to_cpp[property.first] = thresholds;
+ } else if (property.first == ov::intel_auto::perf_curve_table.name() &&
+ py::isinstance<py::dict>(property.second)) {
+ properties_to_cpp[property.first] = property.second.cast<ov::intel_auto::PerfCurveTable>();
} else {
properties_to_cpp[property.first] = Common::utils::py_object_to_any(property.second);
}
diff --git a/src/bindings/python/tests/test_runtime/test_properties.py b/src/bindings/python/tests/test_runtime/test_properties.py
index 330b678884c..35e7d07f103 100644
--- a/src/bindings/python/tests/test_runtime/test_properties.py
+++ b/src/bindings/python/tests/test_runtime/test_properties.py
@@ -615,6 +615,67 @@ def test_properties_devices_utilization_threshold():
assert "incompatible function arguments" in str(e.value)
+def test_properties_perf_curve_table():
+ # Assert the property name is correctly registered
+ assert intel_auto.perf_curve_table == "PERF_CURVE_TABLE"
+
+ def check(value1, value2):
+ ret = intel_auto.perf_curve_table(value1)
+ assert ret[0] == "PERF_CURVE_TABLE"
+ assert ret[1].value == value2
+
+ # Nested dict form: device -> {utilization: score}
+ check({"CPU": {0: 0.0, 100: 100.0}}, {"CPU": {0: 0.0, 100: 100.0}})
+ check({"CPU": {50: 25.5}, "NPU": {50: 40.0}},
+ {"CPU": {50: 25.5}, "NPU": {50: 40.0}})
+
+ # String form is accepted and parsed to the same nested map.
+ check("{CPU:{0:0,100:100}}", {"CPU": {0: 0.0, 100: 100.0}})
+
+ # bool is accepted as int/float (bool is an int subclass in Python).
+ check({"CPU": {True: 1.0}}, {"CPU": {1: 1.0}})
+ check({"CPU": {10: True}}, {"CPU": {10: 1.0}})
+
+ # Type mismatches are rejected by pybind11's overload dispatch with TypeError.
+ with pytest.raises(TypeError) as e:
+ intel_auto.perf_curve_table({23: {0: 1.0}})
+ assert "incompatible function arguments" in str(e.value)
+
+ with pytest.raises(TypeError) as e:
+ intel_auto.perf_curve_table({"CPU": {0: "high"}})
+ assert "incompatible function arguments" in str(e.value)
+
+
+def test_properties_perf_curve_table_set_property_roundtrip():
+ core = Core()
+ # AUTO is a bundled virtual plugin; skip if it cannot be loaded in this environment.
+ try:
+ core.get_property("AUTO", props.supported_properties)
+ except RuntimeError:
+ pytest.skip("AUTO plugin is not available in this environment")
+
+ # Dict form: the helper builds a typed PerfCurveTable, so set/get round-trips to a dict.
+ expected = {"CPU": {0: 0.0, 100: 100.0}, "NPU": {50: 40.0}}
+ core.set_property("AUTO", intel_auto.perf_curve_table(expected))
+ assert core.get_property("AUTO", intel_auto.perf_curve_table) == expected
+
+ # Helper string form is parsed to the same typed map before it is set.
+ core.set_property("AUTO", intel_auto.perf_curve_table("{CPU:{0:0,100:100}}"))
+ assert core.get_property("AUTO", intel_auto.perf_curve_table) == {"CPU": {0: 0.0, 100: 100.0}}
+
+ # Raw string in a property dict exercises py_object_to_any -> validator parsing.
+ core.set_property("AUTO", {"PERF_CURVE_TABLE": "{NPU:{0:0,100:50}}"})
+ assert core.get_property("AUTO", intel_auto.perf_curve_table) == {"NPU": {0: 0.0, 100: 50.0}}
+
+ # Semantic rules are enforced by PerfCurveTableValidator at set_property time.
+ with pytest.raises(RuntimeError):
+ core.set_property("AUTO", intel_auto.perf_curve_table({"CPU": {}})) # empty curve
+ with pytest.raises(RuntimeError):
+ core.set_property("AUTO", intel_auto.perf_curve_table({"XXX": {0: 1.0}})) # non-whitelisted device
+ with pytest.raises(RuntimeError):
+ core.set_property("AUTO", {"PERF_CURVE_TABLE": "not-a-valid-table"}) # unparsable string
+
+
def test_properties_low_power_device():
assert intel_auto.low_power_device == "LOW_POWER_DEVICE"
diff --git a/src/inference/include/openvino/runtime/auto/properties.hpp b/src/inference/include/openvino/runtime/auto/properties.hpp
index 60727a661f8..6861e1fc582 100644
--- a/src/inference/include/openvino/runtime/auto/properties.hpp
+++ b/src/inference/include/openvino/runtime/auto/properties.hpp
@@ -4,6 +4,7 @@
#pragma once
+#include <map>
#include <openvino/runtime/properties.hpp>
#include <string>
@@ -82,6 +83,22 @@ static constexpr Property<SchedulePolicy> schedule_policy{"SCHEDULE_POLICY"};
static constexpr Property<std::map<std::string, unsigned>> devices_utilization_threshold{
"DEVICES_UTILIZATION_THRESHOLD"};
+/**
+ * @brief Type of the ov::intel_auto::perf_curve_table property: maps a device key
+ * ("CPU", "iGPU", "dGPU", "NPU") to a utilization-percent -> performance-score curve.
+ * @ingroup ov_runtime_cpp_prop_api
+ */
+using PerfCurveTable = std::map<std::string, std::map<unsigned, float>>;
+
+/**
+ * @brief Per-device performance curve table mapping utilization percent to a relative performance score, used by
+ * AUTO for device selection when set. A lower interpolated score indicates a more preferred device: AUTO ranks
+ * candidates in ascending order of score and selects the one with the lowest score for the current utilization.
+ * Device key must be one of "CPU", "iGPU", "dGPU", "NPU".
+ * @ingroup ov_runtime_cpp_prop_api
+ */
+static constexpr Property<PerfCurveTable> perf_curve_table{"PERF_CURVE_TABLE"};
+
/**
* @brief Name of the device AUTO should prefer while the platform is in low power mode
* (as reported by IPF/DTT). Takes precedence over
diff --git a/src/plugins/auto/src/auto_schedule.cpp b/src/plugins/auto/src/auto_schedule.cpp
index f619b6121f3..f4d466a808e 100644
--- a/src/plugins/auto/src/auto_schedule.cpp
+++ b/src/plugins/auto/src/auto_schedule.cpp
@@ -54,7 +54,7 @@ bool AutoSchedule::select_other_device(const std::string& cur_dev_name) {
m_plugin->select_device(m_context->m_device_priorities,
m_compile_context[FALLBACKDEVICE].m_model_precision,
m_context->m_model_priority,
- m_context->m_utilization_thresholds,
+ m_context->m_selection_policy,
m_context->m_low_power_device);
try {
m_compile_context[FALLBACKDEVICE].m_task();
@@ -99,7 +99,7 @@ void AutoSchedule::init() {
m_plugin->select_device(m_context->m_device_priorities,
m_compile_context[ACTUALDEVICE].m_model_precision,
m_context->m_model_priority,
- m_context->m_utilization_thresholds,
+ m_context->m_selection_policy,
m_context->m_low_power_device);
auto load_device_task = [&](AutoCompileContext* context_ptr, const std::shared_ptr<ov::Model>& model) {
@@ -371,7 +371,7 @@ void AutoSchedule::try_to_compile_model(AutoCompileContext& context, const std::
context.m_device_info = m_plugin->select_device(device_list,
context.m_model_precision,
m_context->m_model_priority,
- m_context->m_utilization_thresholds,
+ m_context->m_selection_policy,
m_context->m_low_power_device);
} catch (const ov::Exception&) {
return;
diff --git a/src/plugins/auto/src/common.hpp b/src/plugins/auto/src/common.hpp
index aac03b0c602..9e114c48a22 100644
--- a/src/plugins/auto/src/common.hpp
+++ b/src/plugins/auto/src/common.hpp
@@ -197,6 +197,14 @@ struct IdleGuard<NotBusyPriorityWorkerRequests> {
};
class Plugin;
+
+// Selection-policy inputs consumed by Plugin::select_device: a hard filter (utilization thresholds)
+// applied first, then a ranking (performance curves) applied to the survivors.
+struct DeviceSelectionPolicy {
+ std::unordered_map<std::string, unsigned> utilization_thresholds;
+ ov::intel_auto::PerfCurveTable perf_curve_table;
+};
+
class ScheduleContext : public std::enable_shared_from_this<ScheduleContext> {
public:
using Ptr = std::shared_ptr<ScheduleContext>;
@@ -222,7 +230,7 @@ public:
std::mutex m_fallback_mutex;
SoCompiledModel m_hw_compiled_model;
std::string m_model_precision;
- std::unordered_map<std::string, unsigned> m_utilization_thresholds;
+ DeviceSelectionPolicy m_selection_policy;
std::string m_low_power_device;
// hold the resource of static variable to avoid the unexpected destruction.
std::shared_ptr<std::mutex> m_mtx;
diff --git a/src/plugins/auto/src/plugin.cpp b/src/plugins/auto/src/plugin.cpp
index 804d690cff0..6fee97ca25c 100644
--- a/src/plugins/auto/src/plugin.cpp
+++ b/src/plugins/auto/src/plugin.cpp
@@ -6,8 +6,10 @@
#include "plugin.hpp"
#include <algorithm>
+#include <cmath>
#include <map>
#include <memory>
+#include <numeric>
#include <string>
#include <transformations/utils/utils.hpp>
#include <unordered_map>
@@ -483,8 +485,13 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model_impl(const std::filesy
}
auto device_utilization_thresholds = load_config.get_property(ov::intel_auto::devices_utilization_threshold);
if (!device_utilization_thresholds.empty()) {
- auto_s_context->m_utilization_thresholds.insert(device_utilization_thresholds.begin(),
- device_utilization_thresholds.end());
+ auto_s_context->m_selection_policy.utilization_thresholds.insert(device_utilization_thresholds.begin(),
+ device_utilization_thresholds.end());
+ }
+ // 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;
}
auto low_power_device = load_config.get_property(ov::intel_auto::low_power_device);
if (!low_power_device.empty()) {
@@ -641,17 +648,10 @@ std::list<DeviceInformation> Plugin::get_valid_device(const std::vector<DeviceIn
if (device_info.device_name.find("CPU") == 0) {
CPU.push_back(device_info);
} else if (device_info.device_name.find("GPU") == 0) {
- std::string device_type;
- try {
- // can optimize to typed function when gpu swith to 2.0 api
- device_type =
- get_core()->get_property(device_info.device_name, ov::device::type.name(), {}).as<std::string>();
- } catch (const ov::Exception&) {
- LOG_DEBUG_TAG("get property :%s for %s failed ", "DEVICE_TYPE", device_info.device_name.c_str());
- }
- if (device_type == "integrated") {
+ const auto device_key = resolve_device_key(device_info.device_name);
+ if (device_key.logical_key == "iGPU") {
iGPU.push_back(device_info);
- } else if (device_type == "discrete") {
+ } else if (device_key.logical_key == "dGPU") {
dGPU.push_back(device_info);
} else {
LOG_DEBUG_TAG("Unknown device type for %s", device_info.device_name.c_str());
@@ -693,15 +693,54 @@ std::list<DeviceInformation> Plugin::get_valid_device(const std::vector<DeviceIn
return valid_filtered_devices;
}
+Plugin::DeviceKey Plugin::resolve_device_key(const std::string& device_name) const {
+ DeviceKey key;
+ key.base_name = ov::DeviceIDParser(device_name).get_device_name();
+ key.logical_key = key.base_name;
+ if (key.base_name != "GPU") {
+ return key;
+ }
+ // A GPU maps to "iGPU"/"dGPU" via ov::device::type; leave logical_key empty when it is unavailable.
+ // Read as std::string for consistency with get_valid_device() (the typed GPU 2.0 API is future work).
+ try {
+ key.device_type = get_core()->get_property(device_name, ov::device::type.name(), {}).as<std::string>();
+ } catch (const ov::Exception&) {
+ key.device_type.clear();
+ }
+ if (key.device_type == "integrated") {
+ key.logical_key = "iGPU";
+ } else if (key.device_type == "discrete") {
+ key.logical_key = "dGPU";
+ } else {
+ key.logical_key.clear();
+ }
+ return key;
+}
+
DeviceInformation Plugin::select_device(const std::vector<DeviceInformation>& meta_devices,
const std::string& model_precision,
unsigned int priority,
- const std::unordered_map<std::string, unsigned>& utilization_thresholds,
+ const DeviceSelectionPolicy& selection_policy,
const std::string& low_power_device) {
OV_ITT_SCOPED_TASK(itt::domains::AutoPlugin, "Plugin::SelectDevice");
+ const auto& utilization_thresholds = selection_policy.utilization_thresholds;
+ 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 %zu device curves", perf_curve_table.size());
+ for (const auto& [device_key, curve] : perf_curve_table) {
+ LOG_DEBUG_TAG("PERF_CURVE_TABLE[%s] contains %zu points", device_key.c_str(), curve.size());
+ for (const auto& [utilization, score] : curve) {
+ LOG_DEBUG_TAG("PERF_CURVE_TABLE[%s]: utilization=%u, score=%f",
+ 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
@@ -731,6 +770,25 @@ DeviceInformation Plugin::select_device(const std::vector<DeviceInformation>& me
}
DeviceInformation* ptr_select_device = nullptr;
+ std::list<DeviceInformation> perf_curve_sorted_devices;
+ // Resolve a device's effective utilization threshold: prefer an exact device-name match
+ // (e.g. "GPU.0"), then fall back to the base device name (e.g. "GPU").
+ auto find_utilization_threshold =
+ [&utilization_thresholds](const std::string& device_name,
+ const std::string& base_name) -> std::optional<unsigned> {
+ if (utilization_thresholds.empty()) {
+ return std::nullopt;
+ }
+ const auto exact_it = utilization_thresholds.find(device_name);
+ if (exact_it != utilization_thresholds.end()) {
+ return exact_it->second;
+ }
+ const auto base_it = utilization_thresholds.find(base_name);
+ if (base_it != utilization_thresholds.end()) {
+ return base_it->second;
+ }
+ 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.
auto find_low_power_device = [&]() -> DeviceInformation* {
@@ -752,72 +810,64 @@ 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 {
- // select the higher priority device in case all of device utilization is exceeded the threshold.
- last_device = valid_devices.front();
- 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());
- while (!ptr_select_device) {
- // select the first device in the rest of available devices.
- if (valid_devices.empty()) {
- // after remove higher priority device,but the available devices is null,
- // so select the last device of all available Devices.
- ptr_select_device = &last_device;
- } else {
- auto device = &valid_devices.front();
+ // When both properties are configured, apply utilization thresholds first.
+ 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;
- // check utilization here.
- ov::DeviceIDParser parsed{device->device_name};
- unsigned device_utilization_threshold = 0;
- bool has_device_utilization_threshold = false;
- if (!utilization_thresholds.empty()) {
- const auto exact_it = utilization_thresholds.find(device->device_name);
- if (exact_it != utilization_thresholds.end()) {
- device_utilization_threshold = exact_it->second;
- has_device_utilization_threshold = true;
- } else {
- const auto base_it = utilization_thresholds.find(parsed.get_device_name());
- if (base_it != utilization_thresholds.end()) {
- device_utilization_threshold = base_it->second;
- has_device_utilization_threshold = true;
- }
- }
- }
-
- if (has_device_utilization_threshold) {
+ 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 (parsed.get_device_name() == "GPU") {
- try {
- device_type = get_core()
- ->get_property(device->device_name, ov::device::type.name(), {})
- .as<std::string>();
- } catch (const ov::Exception&) {
- 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);
+ const auto device_utilization = get_device_utilization(device.device_name, device_type);
if (!device_utilization.has_value()) {
- LOG_DEBUG_TAG("Cannot get utilization for %s. Will keep it in the list",
- device->device_name.c_str());
+ 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(),
+ device.device_name.c_str(),
std::to_string(device_utilization.value()).c_str());
- if (device_utilization.value() >= device_utilization_threshold) {
+ if (device_utilization.value() >= device_threshold.value()) {
is_excluded = true;
LOG_DEBUG_TAG("[%s] Current utilization [%s] exceeds the threshold[%s]",
- device->device_name.c_str(),
+ device.device_name.c_str(),
std::to_string(device_utilization.value()).c_str(),
- std::to_string(device_utilization_threshold).c_str());
+ std::to_string(device_threshold.value()).c_str());
}
}
}
- if (is_excluded) {
- // Remove the excluded candidate at the front in O(1).
- valid_devices.erase(valid_devices.begin());
- } else {
- ptr_select_device = device;
+ if (!is_excluded) {
+ threshold_filtered_devices.push_back(device);
}
}
+
+ if (threshold_filtered_devices.empty()) {
+ // All candidates were filtered by threshold: keep previous fallback behavior.
+ ptr_select_device = &last_device;
+ } else {
+ valid_devices = std::move(threshold_filtered_devices);
+ }
+ }
+
+ 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.
+ size_t scored_count = 0;
+ perf_curve_sorted_devices = sort_device_by_perf_curve(valid_devices, perf_curve_table, &scored_count);
+ if (scored_count > 0) {
+ ptr_select_device = &perf_curve_sorted_devices.front();
+ }
+ }
+
+ if (!ptr_select_device) {
+ // No scored device from perf_curve_table: choose the highest-priority remaining candidate.
+ ptr_select_device = &valid_devices.front();
}
}
//recode the device priority
@@ -825,6 +875,107 @@ DeviceInformation Plugin::select_device(const std::vector<DeviceInformation>& me
return *ptr_select_device;
}
+float Plugin::interpolate_perf_score(const std::map<unsigned, float>& curve, float utilization) {
+ if (curve.empty()) {
+ OPENVINO_THROW("perf_curve_table contains an empty curve; cannot compute performance score");
+ }
+ if (!std::isfinite(utilization)) {
+ OPENVINO_THROW("Device utilization is not a finite value; cannot compute performance score");
+ }
+ const float min_key = static_cast<float>(curve.begin()->first);
+ const float max_key = static_cast<float>(curve.rbegin()->first);
+ if (utilization < min_key || utilization > max_key) {
+ OPENVINO_THROW("Device utilization ",
+ utilization,
+ " is out of the perf_curve_table range [",
+ min_key,
+ ", ",
+ max_key,
+ "]");
+ }
+ // upper_bound(floor(util)) is the upper bracket; when util equals a key, the lower bracket
+ // yields ratio == 0 so exact matches need no special case.
+ auto hi_it = curve.upper_bound(static_cast<unsigned>(utilization));
+ if (hi_it == curve.end()) {
+ // utilization == max_key: no upper bracket, return the last entry.
+ return curve.rbegin()->second;
+ }
+ auto lo_it = std::prev(hi_it);
+ const float lo_key = static_cast<float>(lo_it->first);
+ const float hi_key = static_cast<float>(hi_it->first);
+ const float ratio = (utilization - lo_key) / (hi_key - lo_key);
+ return lo_it->second + ratio * (hi_it->second - lo_it->second);
+}
+
+std::list<DeviceInformation> Plugin::sort_device_by_perf_curve(
+ const std::list<DeviceInformation>& valid_devices,
+ const ov::intel_auto::PerfCurveTable& perf_curve_table,
+ size_t* out_scored_count) {
+ // Use (index, score) pairs to avoid copying DeviceInformation during sorting.
+ const std::vector<const DeviceInformation*> device_ptrs = [&] {
+ std::vector<const DeviceInformation*> v;
+ v.reserve(valid_devices.size());
+ for (const auto& d : valid_devices) {
+ v.push_back(&d);
+ }
+ return v;
+ }();
+ const size_t n = device_ptrs.size();
+ std::vector<std::optional<float>> scores(n);
+ for (size_t i = 0; i < n; ++i) {
+ const auto& device = *device_ptrs[i];
+ const auto device_key = resolve_device_key(device.device_name);
+ if (device_key.logical_key.empty()) {
+ // GPU whose integrated/discrete type is unavailable: leave unscored.
+ LOG_DEBUG_TAG("[%s] No logical device key resolved for perf_curve_table lookup; treat as no-score",
+ device.device_name.c_str());
+ continue;
+ }
+ const auto curve_it = perf_curve_table.find(device_key.logical_key);
+ if (curve_it == perf_curve_table.end()) {
+ LOG_DEBUG_TAG("[%s] No perf_curve_table entry for key %s; treat as no-score",
+ device.device_name.c_str(),
+ 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()) {
+ 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());
+ LOG_DEBUG_TAG("[%s] perf_curve_table: key=%s, utilization=%f, performance_score=%f",
+ device.device_name.c_str(),
+ device_key.logical_key.c_str(),
+ utilization.value(),
+ scores[i].value());
+ } catch (const ov::Exception& ex) {
+ LOG_DEBUG_TAG("[%s] perf_curve_table score computation failed: %s. Treat as no-score",
+ device.device_name.c_str(),
+ ex.what());
+ }
+ }
+ // Sort indices: scored devices ascending, unscored devices trailing in original order.
+ std::vector<size_t> order(n);
+ std::iota(order.begin(), order.end(), 0);
+ const auto boundary_it = std::stable_partition(order.begin(), order.end(), [&scores](size_t i) {
+ return scores[i].has_value();
+ });
+ if (out_scored_count) {
+ *out_scored_count = static_cast<size_t>(std::distance(order.begin(), boundary_it));
+ }
+ std::stable_sort(order.begin(), boundary_it, [&scores](size_t a, size_t b) {
+ return scores[a].value() < scores[b].value();
+ });
+ std::list<DeviceInformation> result;
+ for (size_t idx : order) {
+ result.push_back(*device_ptrs[idx]);
+ }
+ return result;
+}
+
+
void Plugin::unregister_priority(const unsigned int& priority, const std::string& device_name) {
if (m_mtx && m_priority_map) {
std::lock_guard<std::mutex> lck(*m_mtx);
diff --git a/src/plugins/auto/src/plugin.hpp b/src/plugins/auto/src/plugin.hpp
index 57167e7bb6e..3b25e1f1c67 100644
--- a/src/plugins/auto/src/plugin.hpp
+++ b/src/plugins/auto/src/plugin.hpp
@@ -61,8 +61,12 @@ public:
select_device(const std::vector<DeviceInformation>& meta_devices,
const std::string& model_precision = "FP32",
unsigned int priority = 0,
- const std::unordered_map<std::string, unsigned>& utilization_thresholds = {},
+ const DeviceSelectionPolicy& selection_policy = {},
const std::string& low_power_device = {});
+ MOCKTESTMACRO std::list<DeviceInformation> sort_device_by_perf_curve(
+ const std::list<DeviceInformation>& valid_devices,
+ const ov::intel_auto::PerfCurveTable& perf_curve_table,
+ size_t* out_scored_count = nullptr);
void unregister_priority(const unsigned int& priority, const std::string& device_name);
void register_priority(const unsigned int& priority, const std::string& device_name);
@@ -101,6 +105,15 @@ private:
const std::shared_ptr<const ov::Model>& model,
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.
+ struct DeviceKey {
+ std::string base_name;
+ std::string logical_key;
+ std::string device_type;
+ };
+ DeviceKey resolve_device_key(const std::string& device_name) const;
+ static float interpolate_perf_score(const std::map<unsigned, float>& curve, float utilization);
static std::shared_ptr<std::mutex> m_mtx;
static std::shared_ptr<std::map<unsigned int, std::list<std::string>>> m_priority_map;
PluginConfig m_plugin_config;
diff --git a/src/plugins/auto/src/plugin_config.cpp b/src/plugins/auto/src/plugin_config.cpp
index b63283a3fab..7a3b81f799e 100644
--- a/src/plugins/auto/src/plugin_config.cpp
+++ b/src/plugins/auto/src/plugin_config.cpp
@@ -28,6 +28,7 @@ void PluginConfig::set_default() {
std::make_tuple(ov::intel_auto::enable_startup_fallback, true),
std::make_tuple(ov::intel_auto::enable_runtime_fallback, true),
std::make_tuple(ov::intel_auto::devices_utilization_threshold, std::map<std::string, unsigned>{}, DeviceUtilizationThresholdValidator()),
+ std::make_tuple(ov::intel_auto::perf_curve_table, ov::intel_auto::PerfCurveTable{}, PerfCurveTableValidator()),
std::make_tuple(ov::intel_auto::low_power_device, std::string{}),
// RO for register only
std::make_tuple(ov::device::full_name),
@@ -52,9 +53,11 @@ void PluginConfig::set_property(const ov::AnyMap& properties) {
if (is_supported(kv.first)) {
OPENVINO_ASSERT(property_validators.at(name)->is_valid(val),
"Invalid value for property ", name, ": ", val.as<std::string>());
- internal_properties[name] = val;
+ // Store the validator-normalized value so get_property() returns a consistent type.
+ auto normalized_val = property_validators.at(name)->convert(val);
+ internal_properties[name] = normalized_val;
// when user call set_property to set some config to plugin, we also respect this and pass through the config in this case
- user_properties[name] = val;
+ user_properties[name] = normalized_val;
if (kv.first == ov::log::level.name()) {
if (!set_log_level(kv.second)) {
OPENVINO_THROW("Unsupported log level: ", kv.second.as<std::string>());
@@ -98,8 +101,9 @@ void PluginConfig::set_user_property(const ov::AnyMap& config) {
if (is_supported(name)) {
OPENVINO_ASSERT(property_validators.at(name)->is_valid(val),
"Invalid value for property ", name, ": ", val.as<std::string>());
- internal_properties[kv.first] = kv.second;
- user_properties[kv.first] = kv.second;
+ auto normalized_val = property_validators.at(name)->convert(val);
+ internal_properties[kv.first] = normalized_val;
+ user_properties[kv.first] = normalized_val;
} else {
user_properties[kv.first] = kv.second;
}
diff --git a/src/plugins/auto/src/plugin_config.hpp b/src/plugins/auto/src/plugin_config.hpp
index f9e883ab766..98ed7cd07d0 100644
--- a/src/plugins/auto/src/plugin_config.hpp
+++ b/src/plugins/auto/src/plugin_config.hpp
@@ -11,6 +11,7 @@
#include "utils/log_util.hpp"
#include "openvino/runtime/device_id_parser.hpp"
#include <algorithm>
+#include <cmath>
#include <string>
#include <map>
#include <set>
@@ -24,6 +25,8 @@ public:
using Ptr = std::shared_ptr<BaseValidator>;
virtual ~BaseValidator() = default;
virtual bool is_valid(const ov::Any& v) const = 0;
+ // Normalizes a validated value to its canonical typed Any (e.g. parses a string into a map).
+ virtual ov::Any convert(const ov::Any& v) const { return v; }
};
template<typename T>
@@ -75,6 +78,40 @@ public:
return false;
}
}
+
+ ov::Any convert(const ov::Any& v) const override {
+ return ov::Any(v.as<std::map<std::string, unsigned>>());
+ }
+};
+
+class PerfCurveTableValidator : public BaseValidator {
+public:
+ bool is_valid(const ov::Any& v) const override {
+ try {
+ const auto& table = v.as<std::map<std::string, std::map<unsigned, float>>>();
+ static const std::set<std::string> allowed_devices = {"CPU", "iGPU", "dGPU", "NPU"};
+ for (const auto& [device, curve] : table) {
+ if (allowed_devices.find(device) == allowed_devices.end()) {
+ return false;
+ }
+ if (curve.empty()) {
+ return false;
+ }
+ for (const auto& [utilization, score] : curve) {
+ if (utilization > 100 || score < 0.f || !std::isfinite(score)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ } catch (const ov::Exception&) {
+ return false;
+ }
+ }
+
+ ov::Any convert(const ov::Any& v) const override {
+ return ov::Any(v.as<std::map<std::string, std::map<unsigned, float>>>());
+ }
};
class PluginConfig {
@@ -178,6 +215,9 @@ public:
multi_supported_configKeys.erase(std::remove(
multi_supported_configKeys.begin(), multi_supported_configKeys.end(), ov::intel_auto::devices_utilization_threshold.name()),
multi_supported_configKeys.end());
+ multi_supported_configKeys.erase(std::remove(
+ multi_supported_configKeys.begin(), multi_supported_configKeys.end(), ov::intel_auto::perf_curve_table.name()),
+ multi_supported_configKeys.end());
multi_supported_configKeys.erase(std::remove(
multi_supported_configKeys.begin(), multi_supported_configKeys.end(), ov::intel_auto::low_power_device.name()),
multi_supported_configKeys.end());
@@ -200,6 +240,10 @@ public:
multi_supported_properties.end(),
ov::intel_auto::devices_utilization_threshold),
multi_supported_properties.end());
+ multi_supported_properties.erase(std::remove(multi_supported_properties.begin(),
+ multi_supported_properties.end(),
+ ov::intel_auto::perf_curve_table),
+ multi_supported_properties.end());
multi_supported_properties.erase(std::remove(multi_supported_properties.begin(),
multi_supported_properties.end(),
ov::intel_auto::low_power_device),
diff --git a/src/plugins/auto/tests/unit/auto_unit_test.cpp b/src/plugins/auto/tests/unit/auto_unit_test.cpp
index 0197d10e450..09b2b3c7db6 100644
--- a/src/plugins/auto/tests/unit/auto_unit_test.cpp
+++ b/src/plugins/auto/tests/unit/auto_unit_test.cpp
@@ -121,9 +121,16 @@ ov::mock_auto_plugin::tests::BaseTest::BaseTest(const MODELTYPE modelType) {
.WillByDefault([this](const std::vector<DeviceInformation>& metaDevices,
const std::string& netPrecision,
unsigned int priority,
- const std::unordered_map<std::string, unsigned>& utilization_thresholds,
+ const ov::auto_plugin::DeviceSelectionPolicy& selection_policy,
const std::string& low_power_device) {
- return plugin->Plugin::select_device(metaDevices, netPrecision, priority, utilization_thresholds, low_power_device);
+ return plugin->Plugin::select_device(metaDevices, netPrecision, priority, selection_policy, low_power_device);
+ });
+
+ ON_CALL(*plugin, sort_device_by_perf_curve)
+ .WillByDefault([this](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);
});
ON_CALL(*plugin, get_valid_device)
diff --git a/src/plugins/auto/tests/unit/include/gmock_plugin.hpp b/src/plugins/auto/tests/unit/include/gmock_plugin.hpp
index d9a6ce40be5..1bd043e38b9 100644
--- a/src/plugins/auto/tests/unit/include/gmock_plugin.hpp
+++ b/src/plugins/auto/tests/unit/include/gmock_plugin.hpp
@@ -37,9 +37,15 @@ public:
((const std::vector<DeviceInformation>&),
const std::string&,
unsigned int,
- (const std::unordered_map<std::string, unsigned>&),
+ (const DeviceSelectionPolicy&),
const std::string&),
(override));
+ MOCK_METHOD((std::list<DeviceInformation>),
+ sort_device_by_perf_curve,
+ ((const std::list<DeviceInformation>&),
+ (const ov::intel_auto::PerfCurveTable&),
+ size_t*),
+ (override));
MOCK_METHOD((std::vector<DeviceInformation>),
parse_meta_devices,
(const std::string&, const ov::AnyMap&),
diff --git a/src/plugins/auto/tests/unit/perf_curve_table_validator_test.cpp b/src/plugins/auto/tests/unit/perf_curve_table_validator_test.cpp
new file mode 100644
index 00000000000..bfa6943084d
--- /dev/null
+++ b/src/plugins/auto/tests/unit/perf_curve_table_validator_test.cpp
@@ -0,0 +1,57 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <gtest/gtest.h>
+
+#include <limits>
+#include <string>
+#include <tuple>
+
+#include "plugin_config.hpp"
+
+using ov::auto_plugin::PerfCurveTableValidator;
+using ov::intel_auto::PerfCurveTable;
+
+// (value, expected is_valid) — PerfCurveTableValidator is the single source of truth for the
+// semantic rules (device whitelist, non-empty curve, utilization range, finite non-negative score).
+using PerfCurveValidatorParams = std::tuple<ov::Any, bool>;
+
+class PerfCurveTableValidatorTest : public ::testing::TestWithParam<PerfCurveValidatorParams> {};
+
+TEST_P(PerfCurveTableValidatorTest, is_valid) {
+ const auto& [value, expected] = GetParam();
+ PerfCurveTableValidator validator;
+ EXPECT_EQ(validator.is_valid(value), expected);
+}
+
+const std::vector<PerfCurveValidatorParams> perfCurveValidatorConfigs = {
+ // Empty table disables the feature and is valid (matches the registered default).
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{}), true},
+ // Whitelisted devices, in-range utilization, finite non-negative scores.
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{{"CPU", {{0, 0.f}, {100, 100.f}}}}), true},
+ PerfCurveValidatorParams{
+ ov::Any(PerfCurveTable{{"iGPU", {{50, 25.5f}}}, {"dGPU", {{0, 0.f}}}, {"NPU", {{100, 40.f}}}}),
+ true},
+ // Whitelist violation: unknown device and the base "GPU" (must be iGPU/dGPU).
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{{"XXX", {{0, 0.f}}}}), false},
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{{"GPU", {{0, 0.f}}}}), false},
+ // Empty curve for a device.
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{{"CPU", {}}}), false},
+ // Utilization key out of [0, 100].
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{{"CPU", {{101, 10.f}}}}), false},
+ // Negative score.
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{{"CPU", {{0, -1.f}}}}), false},
+ // Non-finite scores.
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{{"CPU", {{0, std::numeric_limits<float>::quiet_NaN()}}}}), false},
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{{"CPU", {{0, std::numeric_limits<float>::infinity()}}}}), false},
+ // Wrong Any type that cannot be parsed into a PerfCurveTable.
+ PerfCurveValidatorParams{ov::Any(std::string("not-a-table")), false},
+ PerfCurveValidatorParams{ov::Any(42), false},
+ // Validate the minimum and maximum utilization values with corresponding scores.
+ PerfCurveValidatorParams{ov::Any(PerfCurveTable{{"CPU", {{0, 0.f}, {100, 100.f}}}}), true},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_Auto_PerfCurveTableValidator,
+ PerfCurveTableValidatorTest,
+ ::testing::ValuesIn(perfCurveValidatorConfigs));
diff --git a/src/plugins/auto/tests/unit/select_device_test.cpp b/src/plugins/auto/tests/unit/select_device_test.cpp
index 60399335960..5ed71807440 100644
--- a/src/plugins/auto/tests/unit/select_device_test.cpp
+++ b/src/plugins/auto/tests/unit/select_device_test.cpp
@@ -200,9 +200,9 @@ public:
.WillByDefault([this](const std::vector<DeviceInformation>& metaDevices,
const std::string& netPrecision,
unsigned int priority,
- const std::unordered_map<std::string, unsigned>& utilization_thresholds,
+ const ov::auto_plugin::DeviceSelectionPolicy& selection_policy,
const std::string& low_power_device) {
- return plugin->Plugin::select_device(metaDevices, netPrecision, priority, utilization_thresholds, low_power_device);
+ return plugin->Plugin::select_device(metaDevices, netPrecision, priority, selection_policy, low_power_device);
});
ON_CALL(*plugin, get_valid_device)
.WillByDefault([this](const std::vector<DeviceInformation>& metaDevices, const std::string& netPrecision) {
@@ -326,7 +326,7 @@ protected:
TEST_P(SelectDeviceWithUtilizationTest, selectDeviceWithUtilization) {
// get Parameter
std::string netPrecision = "FP32";
- auto result = plugin->select_device(devices, netPrecision, 0, threshold, {});
+ auto result = plugin->select_device(devices, netPrecision, 0, {threshold, {}}, {});
compare(result, selectedDeviceInfo);
}
@@ -459,6 +459,313 @@ INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests,
::testing::ValuesIn(testValidConfigs),
SelectDeviceWithUtilizationTest::getTestCaseName);
+
+// ------------------------------------------------------------------------------------------
+// select_device() end-to-end tests driven by perf_curve_table
+// ------------------------------------------------------------------------------------------
+using ConfigPerfCurveParams = std::tuple<ov::intel_auto::PerfCurveTable, // perf_curve_table
+ std::vector<DeviceInformation>, // device candidate list
+ std::map<std::string, float>, // device utilization (device_name -> value)
+ DeviceInformation // expected selected device
+ >;
+
+class SelectDeviceWithPerfCurveTableTest : public tests::AutoTest,
+ public ::testing::TestWithParam<ConfigPerfCurveParams> {
+public:
+ static std::string getTestCaseName(testing::TestParamInfo<ConfigPerfCurveParams> obj) {
+ ov::intel_auto::PerfCurveTable perfCurveTable;
+ std::vector<ov::auto_plugin::DeviceInformation> devices;
+ ov::auto_plugin::DeviceInformation selectedDeviceInfo;
+ std::map<std::string, float> deviceUtilization;
+ std::tie(perfCurveTable, devices, deviceUtilization, selectedDeviceInfo) = obj.param;
+ std::ostringstream result;
+ result << "candidateDeviceList_";
+ for (const auto& dev : devices)
+ result << dev.device_name << "_priority_" << dev.device_priority << "_";
+ result << "utilization_";
+ for (const auto& item : deviceUtilization) {
+ result << item.first << "_" << item.second << "_";
+ }
+ result << "curveDevices_";
+ for (const auto& item : perfCurveTable) {
+ result << item.first << "_";
+ }
+ result << "expectedSelectedDevice_" << selectedDeviceInfo.unique_name;
+
+ auto sanitize_for_gtest = [](std::string name) {
+ for (char& ch : name) {
+ const unsigned char c = static_cast<unsigned char>(ch);
+ if (!std::isalnum(c) && ch != '_') {
+ ch = '_';
+ }
+ }
+ return name;
+ };
+
+ return sanitize_for_gtest(result.str());
+ }
+
+ void compare(const DeviceInformation& a, const DeviceInformation& b) {
+ EXPECT_EQ(a.device_name, b.device_name);
+ EXPECT_EQ(a.unique_name, b.unique_name);
+ EXPECT_EQ(a.default_device_id, b.default_device_id);
+ }
+
+ void SetUp() override {
+ std::tie(perfCurveTable, devices, deviceUtilization, selectedDeviceInfo) = GetParam();
+ 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;
+ }
+ return it->second;
+ });
+ ON_CALL(*plugin, get_valid_device)
+ .WillByDefault([this](const std::vector<DeviceInformation>& metaDevices, const std::string& netPrecision) {
+ return plugin->Plugin::get_valid_device(metaDevices, netPrecision);
+ });
+ }
+
+protected:
+ ov::intel_auto::PerfCurveTable perfCurveTable;
+ std::vector<ov::auto_plugin::DeviceInformation> devices;
+ ov::auto_plugin::DeviceInformation selectedDeviceInfo;
+ std::map<std::string, float> deviceUtilization;
+};
+
+TEST_P(SelectDeviceWithPerfCurveTableTest, selectDeviceWithPerfCurveTable) {
+ std::string netPrecision = "FP32";
+ auto result = plugin->select_device(devices, netPrecision, 0, {{}, perfCurveTable}, {});
+ compare(result, selectedDeviceInfo);
+ // m_priority_map is process-wide static state; clean up to avoid leaking into other suites.
+ plugin->unregister_priority(0, result.unique_name);
+}
+
+const std::vector<ConfigPerfCurveParams> testPerfCurveConfigs = {
+ // 1. Single device, pure interpolation.
+ ConfigPerfCurveParams{{{"CPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}},
+ {{"CPU", 25.f}},
+ {"CPU", {}, -1, "01", "CPU_01", 0}},
+ // 2. Two devices; lower interpolated score wins.
+ ConfigPerfCurveParams{{{"CPU", {{0, 0.f}, {100, 100.f}}}, {"NPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}},
+ {{"CPU", 70.f}, {"NPU", 30.f}},
+ {"NPU", {}, -1, "01", "NPU_01", 0}},
+ // 3. iGPU/dGPU resolved via ov::device::type.
+ ConfigPerfCurveParams{{{"iGPU", {{0, 0.f}, {100, 100.f}}}, {"dGPU", {{0, 100.f}, {100, 0.f}}}},
+ {{"GPU.0", {}, -1, "01", "iGPU_01", 0}, {"GPU.1", {}, -1, "01", "dGPU_01", 0}},
+ {{"GPU.0", 80.f}, {"GPU.1", 80.f}},
+ {"GPU.1", {}, -1, "01", "dGPU_01", 0}},
+ // 4. No curve entry for a candidate excludes it from ranking.
+ ConfigPerfCurveParams{{{"CPU", {{0, 0.f}, {100, 100.f}}}, {"NPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0},
+ {"NPU", {}, -1, "01", "NPU_01", 0},
+ {"GPU.0", {}, -1, "01", "iGPU_01", 0}},
+ {{"CPU", 60.f}, {"NPU", 20.f}, {"GPU.0", 5.f}},
+ {"NPU", {}, -1, "01", "NPU_01", 0}},
+ // 5. No utilization data for a candidate treats it as unscored.
+ ConfigPerfCurveParams{{{"CPU", {{0, 0.f}, {100, 100.f}}}, {"NPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}},
+ {{"CPU", 45.f}},
+ {"CPU", {}, -1, "01", "CPU_01", 0}},
+ // 6. Out-of-range utilization throws internally; treated as unscored.
+ ConfigPerfCurveParams{{{"CPU", {{50, 0.f}, {100, 50.f}}}, {"NPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}},
+ {{"CPU", 10.f}, {"NPU", 70.f}},
+ {"NPU", {}, -1, "01", "NPU_01", 0}},
+ // 7. No curve entry matches any device; falls back to priority order.
+ ConfigPerfCurveParams{{{"iGPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 1}, {"NPU", {}, -1, "01", "NPU_01", 2}},
+ {{"CPU", 50.f}, {"NPU", 10.f}},
+ {"CPU", {}, -1, "01", "CPU_01", 1}},
+ // 8. Fine-grained (10-unit step) curves; interpolation picks the correct bracketing pair.
+ ConfigPerfCurveParams{
+ {{"CPU",
+ {{0, 0.f}, {10, 5.f}, {20, 15.f}, {30, 30.f}, {40, 50.f}, {50, 52.f}, {60, 55.f},
+ {70, 60.f}, {80, 70.f}, {90, 85.f}, {100, 100.f}}},
+ {"NPU",
+ {{0, 100.f}, {10, 90.f}, {20, 80.f}, {30, 70.f}, {40, 60.f}, {50, 50.f}, {60, 40.f},
+ {70, 30.f}, {80, 20.f}, {90, 10.f}, {100, 0.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}},
+ {{"CPU", 45.f}, {"NPU", 75.f}},
+ {"NPU", {}, -1, "01", "NPU_01", 0}},
+ // 9. CPU + iGPU + NPU, all fine-grained (10-unit step); lowest score among all three wins.
+ ConfigPerfCurveParams{
+ {{"CPU",
+ {{0, 100.f}, {10, 90.f}, {20, 80.f}, {30, 70.f}, {40, 60.f}, {50, 50.f}, {60, 40.f},
+ {70, 30.f}, {80, 20.f}, {90, 10.f}, {100, 0.f}}},
+ {"iGPU",
+ {{0, 80.f}, {10, 60.f}, {20, 40.f}, {30, 20.f}, {40, 10.f}, {50, 5.f}, {60, 10.f},
+ {70, 20.f}, {80, 40.f}, {90, 60.f}, {100, 80.f}}},
+ {"NPU",
+ {{0, 0.f}, {10, 10.f}, {20, 20.f}, {30, 30.f}, {40, 40.f}, {50, 50.f}, {60, 60.f},
+ {70, 70.f}, {80, 80.f}, {90, 90.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0},
+ {"GPU.0", {}, -1, "01", "iGPU_01", 0},
+ {"NPU", {}, -1, "01", "NPU_01", 0}},
+ {{"CPU", 65.f}, {"GPU.0", 52.f}, {"NPU", 20.f}},
+ {"GPU.0", {}, -1, "01", "iGPU_01", 0}},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests,
+ SelectDeviceWithPerfCurveTableTest,
+ ::testing::ValuesIn(testPerfCurveConfigs),
+ SelectDeviceWithPerfCurveTableTest::getTestCaseName);
+
+// devices_utilization_threshold is applied before perf_curve_table when both are set.
+class SelectDeviceThresholdBeforePerfCurveTableTest : public tests::AutoTest, public ::testing::Test {
+public:
+ void SetUp() override {
+ 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;
+ }
+ return it->second;
+ });
+ ON_CALL(*plugin, get_valid_device)
+ .WillByDefault([this](const std::vector<DeviceInformation>& metaDevices, const std::string& netPrecision) {
+ return plugin->Plugin::get_valid_device(metaDevices, netPrecision);
+ });
+ }
+
+protected:
+ std::map<std::string, float> deviceUtilization = {{"CPU", 90.f}, {"NPU", 10.f}};
+};
+
+TEST_F(SelectDeviceThresholdBeforePerfCurveTableTest, thresholdFiltersCandidatesBeforePerfCurveRanking) {
+ std::string netPrecision = "FP32";
+ std::vector<DeviceInformation> devices = {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}};
+ // CPU exceeds this threshold and must be excluded before perf_curve_table ranking.
+ std::unordered_map<std::string, unsigned> thresholds = {{"CPU", 50}};
+ ov::intel_auto::PerfCurveTable perfCurveTable = {{"CPU", {{0, 0.f}, {100, 0.f}}},
+ {"NPU", {{0, 100.f}, {100, 100.f}}}};
+
+ auto result = plugin->select_device(devices, netPrecision, 0, {thresholds, perfCurveTable}, {});
+ EXPECT_EQ(result.unique_name, "NPU_01");
+ // m_priority_map is process-wide static state; clean up to avoid leaking into other suites.
+ plugin->unregister_priority(0, result.unique_name);
+}
+
+TEST_F(SelectDeviceThresholdBeforePerfCurveTableTest, thresholdResultIsKeptWhenPerfCurveDoesNotScore) {
+ std::string netPrecision = "FP32";
+ std::vector<DeviceInformation> devices = {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}};
+ // CPU (utilization 90) exceeds its threshold and is excluded by threshold filtering.
+ std::unordered_map<std::string, unsigned> thresholds = {{"CPU", 50}};
+ // perf_curve_table covers only iGPU, so remaining candidates are selected by priority.
+ ov::intel_auto::PerfCurveTable perfCurveTable = {{"iGPU", {{0, 0.f}, {100, 100.f}}}};
+
+ auto result = plugin->select_device(devices, netPrecision, 0, {thresholds, perfCurveTable}, {});
+ EXPECT_EQ(result.unique_name, "NPU_01");
+ plugin->unregister_priority(0, result.unique_name);
+}
+
+// ------------------------------------------------------------------------------------------
+// sort_device_by_perf_curve() unit tests: verify score computation (exact match, interpolation),
+// stable ordering (scored-ascending first, unscored trailing in original relative order), and
+// graceful handling of out-of-range utilization.
+// ------------------------------------------------------------------------------------------
+using ConfigSortByPerfCurveParams = std::tuple<ov::intel_auto::PerfCurveTable, // perf_curve_table
+ std::list<DeviceInformation>, // input device list (order matters)
+ std::map<std::string, float>, // device utilization
+ std::vector<std::string> // expected unique_name order
+ >;
+
+class SortDeviceByPerfCurveTest : public tests::AutoTest, public ::testing::TestWithParam<ConfigSortByPerfCurveParams> {
+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:
+ ov::intel_auto::PerfCurveTable perfCurveTable;
+ std::list<DeviceInformation> inputDevices;
+ std::map<std::string, float> deviceUtilization;
+ std::vector<std::string> expectedOrder;
+};
+
+TEST_P(SortDeviceByPerfCurveTest, sortDeviceByPerfCurve) {
+ auto result = plugin->sort_device_by_perf_curve(inputDevices, perfCurveTable, nullptr);
+ std::vector<std::string> actualOrder;
+ for (const auto& device : result) {
+ actualOrder.push_back(device.unique_name);
+ }
+ EXPECT_EQ(actualOrder, expectedOrder);
+}
+
+const std::vector<ConfigSortByPerfCurveParams> testSortByPerfCurveConfigs = {
+ // 1. Exact key match: utilization equals a curve key, no interpolation needed.
+ ConfigSortByPerfCurveParams{{{"CPU", {{0, 0.f}, {50, 50.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}},
+ {{"CPU", 50.f}},
+ {"CPU_01"}},
+ // 2. Linear interpolation ratio determines relative ordering.
+ ConfigSortByPerfCurveParams{{{"CPU", {{0, 0.f}, {100, 40.f}}}, {"NPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}},
+ {{"CPU", 25.f}, {"NPU", 5.f}},
+ {"NPU_01", "CPU_01"}},
+ // 3. Three scored devices sorted ascending by interpolated score.
+ ConfigSortByPerfCurveParams{{{"CPU", {{0, 0.f}, {100, 100.f}}},
+ {"NPU", {{0, 0.f}, {100, 100.f}}},
+ {"iGPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0},
+ {"NPU", {}, -1, "01", "NPU_01", 0},
+ {"GPU.0", {}, -1, "01", "iGPU_01", 0}},
+ {{"CPU", 30.f}, {"NPU", 10.f}, {"GPU.0", 20.f}},
+ {"NPU_01", "iGPU_01", "CPU_01"}},
+ // 4. Unscored devices trail scored ones, keeping their original relative order.
+ ConfigSortByPerfCurveParams{{{"CPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0},
+ {"NPU", {}, -1, "01", "NPU_01", 0},
+ {"GPU.0", {}, -1, "01", "iGPU_01", 0}},
+ {{"CPU", 40.f}},
+ {"CPU_01", "NPU_01", "iGPU_01"}},
+ // 5. Out-of-range utilization throws internally; treated as unscored (trailing).
+ ConfigSortByPerfCurveParams{{{"CPU", {{50, 0.f}, {100, 50.f}}}, {"NPU", {{0, 0.f}, {100, 100.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}},
+ {{"CPU", 10.f}, {"NPU", 60.f}},
+ {"NPU_01", "CPU_01"}},
+ // 6. iGPU/dGPU curve resolution affects final ordering.
+ ConfigSortByPerfCurveParams{{{"iGPU", {{0, 0.f}, {100, 100.f}}}, {"dGPU", {{0, 100.f}, {100, 0.f}}}},
+ {{"GPU.0", {}, -1, "01", "iGPU_01", 0}, {"GPU.1", {}, -1, "01", "dGPU_01", 0}},
+ {{"GPU.0", 80.f}, {"GPU.1", 80.f}},
+ {"dGPU_01", "iGPU_01"}},
+ // 7. Boundary: utilization equals max_key for both devices -> score is the last curve value
+ // (upper_bound == end() path). Ordering reflects those last values (30 < 90).
+ ConfigSortByPerfCurveParams{{{"CPU", {{0, 0.f}, {100, 90.f}}}, {"NPU", {{0, 0.f}, {100, 30.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}},
+ {{"CPU", 100.f}, {"NPU", 100.f}},
+ {"NPU_01", "CPU_01"}},
+ // 8. Mid-range interpolation between two non-zero keys combined with a max_key hit.
+ // CPU: ratio (50-20)/(80-20)=0.5 -> 10 + 0.5*(70-10) = 40; NPU at max_key -> 50. 40 < 50.
+ ConfigSortByPerfCurveParams{{{"CPU", {{20, 10.f}, {80, 70.f}}}, {"NPU", {{0, 0.f}, {100, 50.f}}}},
+ {{"CPU", {}, -1, "01", "CPU_01", 0}, {"NPU", {}, -1, "01", "NPU_01", 0}},
+ {{"CPU", 50.f}, {"NPU", 100.f}},
+ {"CPU_01", "NPU_01"}},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests,
+ SortDeviceByPerfCurveTest,
+ ::testing::ValuesIn(testSortByPerfCurveConfigs),
+ ::testing::PrintToStringParamName());
+
// -----------------------------------------------------------------------------------
// ov::intel_auto::low_power_device must take precedence over
// devices_utilization_threshold whenever the platform is reported as being in low power mode.
@@ -503,14 +810,14 @@ protected:
TEST_F(SelectDeviceWithLowPowerDevicePrecedenceTest, lowPowerDeviceOverridesThreshold) {
EXPECT_CALL(*plugin, get_low_power_mode()).WillOnce(Return(true));
- auto result = plugin->select_device(devices, netPrecision, 0, thresholds, "NPU");
+ auto result = plugin->select_device(devices, netPrecision, 0, {thresholds, {}}, "NPU");
selectedUniqueName = result.unique_name;
EXPECT_EQ(result.unique_name, "NPU_01");
}
TEST_F(SelectDeviceWithLowPowerDevicePrecedenceTest, fallsBackToThresholdWhenNotInLowPowerMode) {
EXPECT_CALL(*plugin, get_low_power_mode()).WillOnce(Return(false));
- auto result = plugin->select_device(devices, netPrecision, 0, thresholds, "NPU");
+ auto result = plugin->select_device(devices, netPrecision, 0, {thresholds, {}}, "NPU");
selectedUniqueName = result.unique_name;
// threshold logic excludes the over-utilized NPU once low_power_device is not applicable.
EXPECT_EQ(result.unique_name, "CPU_01");
@@ -518,7 +825,7 @@ TEST_F(SelectDeviceWithLowPowerDevicePrecedenceTest, fallsBackToThresholdWhenNot
TEST_F(SelectDeviceWithLowPowerDevicePrecedenceTest, unknownLowPowerModeTreatedAsNotLowPower) {
EXPECT_CALL(*plugin, get_low_power_mode()).WillOnce(Return(std::nullopt));
- auto result = plugin->select_device(devices, netPrecision, 0, thresholds, "NPU");
+ auto result = plugin->select_device(devices, netPrecision, 0, {thresholds, {}}, "NPU");
selectedUniqueName = result.unique_name;
EXPECT_EQ(result.unique_name, "CPU_01");
}
@@ -526,7 +833,7 @@ TEST_F(SelectDeviceWithLowPowerDevicePrecedenceTest, unknownLowPowerModeTreatedA
TEST_F(SelectDeviceWithLowPowerDevicePrecedenceTest, lowPowerDeviceNotInCandidateListFallsThrough) {
// get_low_power_mode() is not called when the preferred device is not a candidate.
EXPECT_CALL(*plugin, get_low_power_mode()).Times(0);
- auto result = plugin->select_device(devices, netPrecision, 0, thresholds, "GPU.0");
+ auto result = plugin->select_device(devices, netPrecision, 0, {thresholds, {}}, "GPU.0");
selectedUniqueName = result.unique_name;
EXPECT_EQ(result.unique_name, "CPU_01");
}
@@ -534,7 +841,7 @@ TEST_F(SelectDeviceWithLowPowerDevicePrecedenceTest, lowPowerDeviceNotInCandidat
TEST_F(SelectDeviceWithLowPowerDevicePrecedenceTest, getLowPowerModeNotQueriedWhenLowPowerDeviceUnset) {
// Guarantees zero behavior/perf impact on all pre-existing callers that leave low_power_device empty.
EXPECT_CALL(*plugin, get_low_power_mode()).Times(0);
- auto result = plugin->select_device(devices, netPrecision, 0, thresholds, {});
+ auto result = plugin->select_device(devices, netPrecision, 0, {thresholds, {}}, {});
selectedUniqueName = result.unique_name;
EXPECT_EQ(result.unique_name, "CPU_01");
}