Skip to content

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

[GPU] Dual-runtime dispatch: allow two OCL + Level-Zero plugins behind one GPU name (#37178)

Maksim Kutakov891ebb895f6f
diff --git a/cmake/developer_package/plugins/create_plugin_file.cmake b/cmake/developer_package/plugins/create_plugin_file.cmake
index 8472f28a2c9..eb9dc07658d 100644
--- a/cmake/developer_package/plugins/create_plugin_file.cmake
+++ b/cmake/developer_package/plugins/create_plugin_file.cmake
@@ -4,7 +4,19 @@
cmake_policy(SET CMP0007 NEW)
-set(newContent " <plugin name=\"${OV_DEVICE_NAME}\" location=\"${OV_PLUGIN_LIBRARY_NAME}\">")
+# OV_PLUGIN_LIBRARY_NAMES is a list. A single library keeps the legacy `location` attribute
+# (byte-identical to before); several libraries (a dispatch group) become ordered <location>
+# child elements, which ov::Core reconciles per device at runtime.
+list(LENGTH OV_PLUGIN_LIBRARY_NAMES num_libraries)
+if(num_libraries GREATER 1)
+ set(newContent " <plugin name=\"${OV_DEVICE_NAME}\">")
+ foreach(library_name IN LISTS OV_PLUGIN_LIBRARY_NAMES)
+ set(newContent "${newContent}
+ <location>${library_name}</location>")
+ endforeach()
+else()
+ set(newContent " <plugin name=\"${OV_DEVICE_NAME}\" location=\"${OV_PLUGIN_LIBRARY_NAMES}\">")
+endif()
if(OV_PLUGIN_PROPERTIES)
set(newContent "${newContent}
diff --git a/cmake/developer_package/plugins/create_plugins_hpp.cmake b/cmake/developer_package/plugins/create_plugins_hpp.cmake
index 6a88a0598ee..1646744fc72 100644
--- a/cmake/developer_package/plugins/create_plugins_hpp.cmake
+++ b/cmake/developer_package/plugins/create_plugins_hpp.cmake
@@ -14,11 +14,21 @@ set(OV_PLUGINS_DECLARATIONS "")
set(OV_PLUGINS_MAP_DEFINITION
" static const std::map<Key, Value> plugins_hpp = {")
+# Collect the ordered device list and, for shared builds, the list of libraries per device
+# (a device may map to more than one library — a dispatch group). Static builds stay 1:1.
+set(ov_ordered_devices)
foreach(dev_map IN LISTS OV_DEVICE_MAPPING)
string(REPLACE ":" ";" dev_map "${dev_map}")
list(GET dev_map 0 mapped_dev_name)
list(GET dev_map 1 actual_dev_name)
+ list(FIND ov_ordered_devices "${mapped_dev_name}" mapped_dev_idx)
+ if(mapped_dev_idx EQUAL -1)
+ list(APPEND ov_ordered_devices ${mapped_dev_name})
+ endif()
+ list(APPEND ${mapped_dev_name}_ACTUAL_NAMES "${actual_dev_name}")
+endforeach()
+foreach(mapped_dev_name IN LISTS ov_ordered_devices)
# definitions
set(dev_config "{")
if(${mapped_dev_name}_CONFIG)
@@ -34,9 +44,9 @@ foreach(dev_map IN LISTS OV_DEVICE_MAPPING)
endif()
set(dev_config "${dev_config}}")
-
if(NOT BUILD_SHARED_LIBS)
- # common
+ # Static builds are single-RT (COMBINED is prohibited), so exactly one library.
+ list(GET ${mapped_dev_name}_ACTUAL_NAMES 0 actual_dev_name)
set(_OV_CREATE_PLUGIN_FUNC "create_plugin_engine_${actual_dev_name}")
set(_OV_CREATE_EXTENSION_FUNC "create_extensions_${actual_dev_name}")
@@ -53,8 +63,15 @@ foreach(dev_map IN LISTS OV_DEVICE_MAPPING)
set(OV_PLUGINS_MAP_DEFINITION "${OV_PLUGINS_MAP_DEFINITION}
{ \"${mapped_dev_name}\", Value { ${_OV_CREATE_PLUGIN_FUNC}, ${_OV_CREATE_EXTENSION_FUNC}, ${dev_config} } },")
else()
+ # Shared build: one-or-more candidate libraries → a braced initializer list of paths.
+ set(dev_paths "{")
+ foreach(actual_dev_name IN LISTS ${mapped_dev_name}_ACTUAL_NAMES)
+ set(dev_paths "${dev_paths} \"${actual_dev_name}\",")
+ endforeach()
+ set(dev_paths "${dev_paths} }")
+
set(OV_PLUGINS_MAP_DEFINITION "${OV_PLUGINS_MAP_DEFINITION}
- { \"${mapped_dev_name}\", Value { \"${actual_dev_name}\", ${dev_config} } },")
+ { \"${mapped_dev_name}\", Value { ${dev_paths}, ${dev_config} } },")
endif()
endforeach()
diff --git a/cmake/developer_package/plugins/plugins.cmake b/cmake/developer_package/plugins/plugins.cmake
index 50f6a453b5a..d492c0035a3 100644
--- a/cmake/developer_package/plugins/plugins.cmake
+++ b/cmake/developer_package/plugins/plugins.cmake
@@ -39,7 +39,8 @@ endif()
# )
#
function(ov_add_plugin)
- set(options SKIP_INSTALL PSEUDO_DEVICE ADD_CLANG_FORMAT ADD_CLANG_TIDY AS_EXTENSION SKIP_REGISTRATION LINKABLE)
+ set(options SKIP_INSTALL PSEUDO_DEVICE ADD_CLANG_FORMAT ADD_CLANG_TIDY AS_EXTENSION SKIP_REGISTRATION LINKABLE
+ DISPATCH_GROUP)
set(oneValueArgs NAME DEVICE_NAME VERSION_DEFINES_FOR PSEUDO_PLUGIN_FOR)
set(multiValueArgs DEFAULT_CONFIG SOURCES OBJECT_LIBRARIES)
cmake_parse_arguments(OV_PLUGIN "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@@ -83,6 +84,9 @@ function(ov_add_plugin)
# to distinguish functions creating plugin objects
target_compile_definitions(${OV_PLUGIN_NAME} PRIVATE
OV_CREATE_PLUGIN=create_plugin_engine_${OV_PLUGIN_DEVICE_NAME})
+ # likewise for the device-dispatch enumeration probe every plugin defines
+ target_compile_definitions(${OV_PLUGIN_NAME} PRIVATE
+ OV_ENUMERATE_DEVICES=ov_enumerate_dispatch_devices_${OV_PLUGIN_DEVICE_NAME})
if(OV_PLUGIN_AS_EXTENSION)
# to distinguish functions creating extensions objects
target_compile_definitions(${OV_PLUGIN_NAME} PRIVATE
@@ -148,13 +152,21 @@ function(ov_add_plugin)
# Enable for static build to generate correct plugins.hpp
if(NOT OV_PLUGIN_SKIP_REGISTRATION OR NOT BUILD_SHARED_LIBS)
+ # A dispatch group intentionally registers several libraries under one device name;
+ # such a device is exempt from the single-library uniqueness check below.
+ if(OV_PLUGIN_DISPATCH_GROUP)
+ list(APPEND OV_DISPATCH_GROUP_DEVICES ${OV_PLUGIN_DEVICE_NAME})
+ list(REMOVE_DUPLICATES OV_DISPATCH_GROUP_DEVICES)
+ set(OV_DISPATCH_GROUP_DEVICES "${OV_DISPATCH_GROUP_DEVICES}" CACHE INTERNAL "" FORCE)
+ endif()
# check that plugin with such name is not registered
foreach(plugin_entry IN LISTS PLUGIN_FILES)
string(REPLACE ":" ";" plugin_entry "${plugin_entry}")
list(GET plugin_entry -1 library_name)
list(GET plugin_entry 0 plugin_name)
if(plugin_name STREQUAL "${OV_PLUGIN_DEVICE_NAME}" AND
- NOT library_name STREQUAL ${OV_PLUGIN_NAME})
+ NOT library_name STREQUAL ${OV_PLUGIN_NAME} AND
+ NOT plugin_name IN_LIST OV_DISPATCH_GROUP_DEVICES)
message(FATAL_ERROR "${OV_PLUGIN_NAME} and ${library_name} are both registered as ${plugin_name}")
endif()
endforeach()
@@ -207,9 +219,10 @@ macro(ov_register_in_plugins_xml)
VERBATIM)
endforeach()
- # Generate <device_name>.xml files
-
- set(plugin_files_local)
+ # Generate <device_name>.xml files. Group PLUGIN_FILES by device so a device registered
+ # with more than one library (a dispatch group) emits one <plugin> with several <location>
+ # children instead of one file per library.
+ set(registered_devices)
foreach(name IN LISTS PLUGIN_FILES)
string(REPLACE ":" ";" name "${name}")
list(LENGTH name length)
@@ -217,11 +230,22 @@ macro(ov_register_in_plugins_xml)
message(FATAL_ERROR "Unexpected error, please, contact developer of this script")
endif()
list(GET name 0 device_name)
- list(GET name 1 name)
+ list(GET name 1 library_target)
- # create plugin file
+ ov_plugin_get_file_name(${library_target} library_name)
+ # Reset per-device list on first encounter to avoid reusing a stale
+ # ${device_name}_LIBRARY_NAMES from a previous ov_register_plugins() invocation.
+ if(NOT device_name IN_LIST registered_devices)
+ unset(${device_name}_LIBRARY_NAMES)
+ endif()
+ list(APPEND registered_devices ${device_name})
+ list(APPEND ${device_name}_LIBRARY_NAMES "${library_name}")
+ endforeach()
+ list(REMOVE_DUPLICATES registered_devices)
+
+ set(plugin_files_local)
+ foreach(device_name IN LISTS registered_devices)
set(config_file_name "${CMAKE_BINARY_DIR}/plugins/${device_name}.xml")
- ov_plugin_get_file_name(${name} library_name)
add_custom_command(TARGET ${OV_REGISTER_MAIN_TARGET} POST_BUILD
COMMAND
@@ -229,9 +253,9 @@ macro(ov_register_in_plugins_xml)
-D "OV_CONFIG_OUTPUT_FILE=${config_file_name}"
-D "OV_DEVICE_NAME=${device_name}"
-D "OV_PLUGIN_PROPERTIES=${${device_name}_CONFIG}"
- -D "OV_PLUGIN_LIBRARY_NAME=${library_name}"
+ -D "OV_PLUGIN_LIBRARY_NAMES=${${device_name}_LIBRARY_NAMES}"
-P "${OpenVINODeveloperScripts_DIR}/plugins/create_plugin_file.cmake"
- COMMENT "Register ${device_name} device as ${library_name}"
+ COMMENT "Register ${device_name} device as ${${device_name}_LIBRARY_NAMES}"
VERBATIM)
list(APPEND plugin_files_local "${config_file_name}")
diff --git a/cmake/developer_package/plugins/plugins.hpp.in b/cmake/developer_package/plugins/plugins.hpp.in
index 173dc9a604a..f6040facec4 100644
--- a/cmake/developer_package/plugins/plugins.hpp.in
+++ b/cmake/developer_package/plugins/plugins.hpp.in
@@ -7,6 +7,7 @@
#include <map>
#include <string>
#include <filesystem>
+#include <vector>
#ifdef OPENVINO_STATIC_LIBRARY
@@ -34,7 +35,9 @@ struct Value {
#else
struct Value {
- std::filesystem::path m_plugin_path;
+ // One or more candidate libraries for the device. More than one marks a dispatch group
+ // (the shared-build analogue of multiple <location> entries in plugins.xml).
+ std::vector<std::filesystem::path> m_plugin_paths;
std::map<std::string, std::string> m_default_config;
};
diff --git a/cmake/features.cmake b/cmake/features.cmake
index 74761ae8d32..78dd3adfdb5 100644
--- a/cmake/features.cmake
+++ b/cmake/features.cmake
@@ -42,13 +42,19 @@ else()
set(ENABLE_ONEDNN_FOR_GPU_DEFAULT ON)
endif()
-# Set default GPU runtime to OCL
+# Set default GPU runtime to OCL. COMBINED (build ZE and OCL plugins side by side) is
+# opt-in only; the default is never flipped.
set(OV_GPU_DEFAULT_RT "OCL")
if (ENABLE_INTEL_GPU)
- ov_option_enum (GPU_RT_TYPE "Type of GPU runtime. Supported value: OCL, SYCL and ZE (L0 is accepted as ZE alias)" ${OV_GPU_DEFAULT_RT} ALLOWED_VALUES ZE OCL L0 SYCL)
+ ov_option_enum (GPU_RT_TYPE "Type of GPU runtime. Supported values: OCL (default), SYCL, ZE (L0 alias), and COMBINED (ZE+OCL, shared builds only)" ${OV_GPU_DEFAULT_RT} ALLOWED_VALUES ZE OCL L0 SYCL COMBINED)
if(GPU_RT_TYPE STREQUAL "L0")
set(GPU_RT_TYPE "ZE" CACHE STRING "Type of GPU runtime" FORCE)
endif()
+ # COMBINED ships two plugin libraries via plugins.xml, which requires shared libs.
+ if(GPU_RT_TYPE STREQUAL "COMBINED" AND NOT BUILD_SHARED_LIBS)
+ message(FATAL_ERROR "GPU_RT_TYPE=COMBINED requires BUILD_SHARED_LIBS=ON. "
+ "Static/monolithic builds support a single GPU runtime only.")
+ endif()
endif()
ov_dependent_option (ENABLE_ONEDNN_FOR_GPU "Enable oneDNN with GPU support" ${ENABLE_ONEDNN_FOR_GPU_DEFAULT} "ENABLE_INTEL_GPU" OFF)
@@ -232,7 +238,8 @@ else()
set(FORCE_FRONTENDS_USE_PROTOBUF OFF)
endif()
-if(ENABLE_INTEL_NPU OR (ENABLE_INTEL_GPU AND GPU_RT_TYPE STREQUAL "ZE"))
+# COMBINED includes a ZE build, so it needs the Level Zero loader too.
+if(ENABLE_INTEL_NPU OR (ENABLE_INTEL_GPU AND (GPU_RT_TYPE STREQUAL "ZE" OR GPU_RT_TYPE STREQUAL "COMBINED")))
set(ENABLE_OV_ZERO_LOADER ON)
else()
set(ENABLE_OV_ZERO_LOADER OFF)
diff --git a/src/inference/dev_api/openvino/runtime/internal_properties.hpp b/src/inference/dev_api/openvino/runtime/internal_properties.hpp
index a7a92bd869b..ad277ceecc9 100644
--- a/src/inference/dev_api/openvino/runtime/internal_properties.hpp
+++ b/src/inference/dev_api/openvino/runtime/internal_properties.hpp
@@ -55,6 +55,24 @@ static constexpr Property<bool, PropertyMutability::RW> exclusive_async_requests
*/
static constexpr Property<std::string, PropertyMutability::WO> config_device_id{"CONFIG_DEVICE_ID"};
+/**
+ * @brief Renames a plugin's devices to the ids Core exposes for them, as {plugin id -> Core id}.
+ *
+ * Several libraries may be registered under one device name (a "dispatch group"), in which case
+ * Core owns the numbering: it merges what the candidates enumerate and assigns the ".N" ids users
+ * address. A candidate's own enumeration order may differ, so Core pushes this mapping to each
+ * group member before any other property, and the member must address those devices by the given
+ * ids from then on - including in the names it reports back (remote contexts, execution devices).
+ *
+ * The map covers every device the member enumerated, so its id set stays as dense as its own
+ * enumeration; it is not necessarily zero-based. Members must report support for this property in
+ * ov::internal::supported_properties - Core refuses to put a library that does not into a group.
+ * It is never set for a device name served by a single library, whose ids Core does not rename.
+ * @ingroup ov_dev_api_plugin_api
+ */
+static constexpr Property<std::map<std::string, std::string>, PropertyMutability::WO> device_id_map{
+ "DISPATCH_DEVICE_ID_MAP"};
+
/**
* @brief Limit \#threads that are used by IStreamsExecutor to execute `parallel_for` calls
* @ingroup ov_dev_api_plugin_api
diff --git a/src/inference/dev_api/openvino/runtime/iplugin.hpp b/src/inference/dev_api/openvino/runtime/iplugin.hpp
index 88f33a430a8..1e5b4e43d00 100644
--- a/src/inference/dev_api/openvino/runtime/iplugin.hpp
+++ b/src/inference/dev_api/openvino/runtime/iplugin.hpp
@@ -9,8 +9,11 @@
#pragma once
+#include <cstdint>
#include <filesystem>
#include <memory>
+#include <string>
+#include <vector>
#include "openvino/core/any.hpp"
#include "openvino/core/deprecated.hpp"
@@ -291,6 +294,65 @@ using CreatePluginFunc = void(std::shared_ptr<::ov::IPlugin>&);
*/
constexpr static const auto create_plugin_function = OV_PP_TOSTRING(OV_CREATE_PLUGIN);
+/**
+ * @brief A score describing how well a plugin library can serve a physical device
+ * during device-name dispatch. Higher wins; 0 means "cannot serve" and is excluded.
+ * @ingroup ov_dev_api_plugin_api
+ */
+using DeviceCompatibilityScore = int32_t;
+
+/// Vendor/tier mismatch: the library cannot serve this device. Never selected.
+inline constexpr DeviceCompatibilityScore PROBE_SCORE_INCOMPATIBLE = 0;
+/// Can run, but not preferred (fallback tier).
+inline constexpr DeviceCompatibilityScore PROBE_SCORE_SERVABLE = 1;
+/// Can run well and satisfies a hard requirement the peer library may not.
+inline constexpr DeviceCompatibilityScore PROBE_SCORE_CAPABLE = 50;
+/// Ideal runtime for this device.
+inline constexpr DeviceCompatibilityScore PROBE_SCORE_PREFERRED = 100;
+
+/**
+ * @brief One physical device a plugin library reports it can serve, during
+ * device-name dispatch. Produced by the enumeration probe (@ref EnumerateDevicesFunc),
+ * consumed by ov::Core to reconcile candidate libraries for a shared device name.
+ * @ingroup ov_dev_api_plugin_api
+ */
+struct EnumeratedDevice {
+ /// The device id THIS library uses internally (".N"); may differ across libraries.
+ std::string internal_id{};
+ /// Opaque cross-library identity token. Core compares it by equality only, never
+ /// interprets it. Two libraries that build it over the same fields yield equal
+ /// bytes for the same physical device.
+ std::vector<uint8_t> fingerprint{};
+ /// How well this library serves the device (see PROBE_SCORE_* constants).
+ DeviceCompatibilityScore score = PROBE_SCORE_INCOMPATIBLE;
+};
+
+/**
+ * @private
+ * @brief Signature of the enumeration probe. Enumerates every device this library can
+ * serve, cheaply (a driver device query at most) and WITHOUT constructing the plugin
+ * engine. noexcept, idempotent, no observable per-call side effect. It CLEARS the output
+ * vector before filling it - it reports a device list, it does not append to one - so a
+ * library that can serve nothing (no driver) leaves the vector empty.
+ */
+using EnumerateDevicesFunc = void(std::vector<EnumeratedDevice>& /*out*/) noexcept;
+
+/**
+ * @def OV_ENUMERATE_DEVICES
+ * @brief Defines a name of a function running the device-dispatch enumeration probe. A static
+ * build links every plugin into one binary, so the name is made per-device there (as for
+ * OV_CREATE_PLUGIN) to keep the definitions from colliding.
+ * @ingroup ov_dev_api_plugin_api
+ */
+#ifndef OV_ENUMERATE_DEVICES
+# define OV_ENUMERATE_DEVICES ov_enumerate_dispatch_devices
+#endif
+
+/**
+ * @private
+ */
+constexpr static const auto enumerate_devices_function = OV_PP_TOSTRING(OV_ENUMERATE_DEVICES);
+
} // namespace ov
/**
@@ -308,3 +370,38 @@ constexpr static const auto create_plugin_function = OV_PP_TOSTRING(OV_CREATE_PL
OPENVINO_THROW(ex.what()); \
} \
}
+
+/**
+ * @def OV_DEFINE_PLUGIN_ENUMERATE_FUNCTION(enumerate_fn)
+ * @brief Defines the exported `ov_enumerate_dispatch_devices` device-dispatch probe by
+ * forwarding to @p enumerate_fn (a callable with the ov::EnumerateDevicesFunc signature).
+ * Used by plugins that participate in device-name dispatch (e.g. the GPU plugin).
+ * The symbol is resolved and called by ov::Core BEFORE the plugin engine is constructed,
+ * so @p enumerate_fn must not build an engine/context. See ov::EnumerateDevicesFunc.
+ * @ingroup ov_dev_api_plugin_api
+ */
+#define OV_DEFINE_PLUGIN_ENUMERATE_FUNCTION(enumerate_fn) \
+ OPENVINO_PLUGIN_API void OV_ENUMERATE_DEVICES(::std::vector<::ov::EnumeratedDevice>& devices) noexcept; \
+ void OV_ENUMERATE_DEVICES(::std::vector<::ov::EnumeratedDevice>& devices) noexcept { \
+ try { \
+ (enumerate_fn)(devices); \
+ } catch (...) { \
+ /* The probe is noexcept by contract; a throwing callable would terminate the process. */ \
+ /* Report no devices instead - the library is then simply not a candidate. */ \
+ devices.clear(); \
+ } \
+ }
+
+/**
+ * @def OV_DEFINE_PLUGIN_ENUMERATE_STUB()
+ * @brief Defines the exported `ov_enumerate_dispatch_devices` probe as a no-op that reports
+ * no devices. Used by every plugin that does NOT participate in device-name dispatch, so the
+ * symbol is uniformly present across the plugin ABI. ov::Core never calls it for a
+ * single-candidate device name, so a stubbed plugin keeps exactly today's behavior.
+ * @ingroup ov_dev_api_plugin_api
+ */
+#define OV_DEFINE_PLUGIN_ENUMERATE_STUB() \
+ OPENVINO_PLUGIN_API void OV_ENUMERATE_DEVICES(::std::vector<::ov::EnumeratedDevice>& devices) noexcept; \
+ void OV_ENUMERATE_DEVICES(::std::vector<::ov::EnumeratedDevice>& devices) noexcept { \
+ devices.clear(); \
+ }
diff --git a/src/inference/src/cpp/core.cpp b/src/inference/src/cpp/core.cpp
index b3b4957445c..73ca5a5ffc4 100644
--- a/src/inference/src/cpp/core.cpp
+++ b/src/inference/src/cpp/core.cpp
@@ -310,8 +310,7 @@ RemoteContext Core::create_context(const std::string& device_name, const AnyMap&
OPENVINO_ASSERT(device_name.find("BATCH") != 0, "BATCH device does not support remote context");
OV_CORE_CALL_STATEMENT({
- auto parsed = parse_device_name_into_config(device_name, params);
- auto remoteContext = _impl->get_plugin(parsed.m_device_name).create_context(parsed.m_config);
+ auto remoteContext = _impl->create_context(device_name, params);
return {remoteContext._ptr, remoteContext._so};
});
}
@@ -323,8 +322,7 @@ RemoteContext Core::get_default_context(const std::string& device_name) {
OPENVINO_ASSERT(device_name.find("BATCH") != 0, "BATCH device does not support default remote context");
OV_CORE_CALL_STATEMENT({
- auto parsed = parse_device_name_into_config(device_name, AnyMap{});
- auto remoteContext = _impl->get_plugin(parsed.m_device_name).get_default_context(parsed.m_config);
+ auto remoteContext = _impl->get_default_context(device_name);
return {remoteContext._ptr, remoteContext._so};
});
}
diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cpp
index c961028b82f..c64cc6ea43c 100644
--- a/src/inference/src/dev/core_impl.cpp
+++ b/src/inference/src/dev/core_impl.cpp
@@ -4,8 +4,10 @@
#include "core_impl.hpp"
+#include <filesystem>
#include <memory>
#include <optional>
+#include <system_error>
#include <variant>
#include "check_network_batchable.hpp"
@@ -48,6 +50,95 @@ ov::ICore::~ICore() = default;
namespace {
+// Probe each present candidate library and merge the devices they report into one canonical
+// device list, deduped by opaque fingerprint. Probe only (no plugin engine constructed).
+std::vector<ov::DispatchEntry> build_dispatch_entries(const std::vector<std::filesystem::path>& candidate_libs) {
+ std::vector<ov::DispatchEntry> entries;
+ for (size_t idx = 0; idx < candidate_libs.size(); ++idx) {
+ const auto& lib = candidate_libs[idx];
+ // Skip a candidate whose library is absent (missing-plugin fallback).
+ if (lib.empty() || !ov::util::file_exists(lib)) {
+ continue;
+ }
+
+ // Only called for a dispatch group (>1 candidate), so a present candidate MUST export the
+ // probe; a missing symbol is a hard error (an unscoreable library can't share a name).
+ std::vector<ov::EnumeratedDevice> enumerated;
+ auto probe_so = ov::util::load_shared_object(lib); // load failures propagate as-is
+ ov::EnumerateDevicesFunc* probe = nullptr;
+ try {
+ probe = reinterpret_cast<ov::EnumerateDevicesFunc*>(
+ ov::util::get_symbol(probe_so, ov::enumerate_devices_function));
+ } catch (const std::exception& ex) {
+ OPENVINO_THROW("Library ",
+ lib,
+ " is registered as one of several candidates for a device but does not "
+ "export the device-enumeration probe (",
+ ov::enumerate_devices_function,
+ "), so it cannot be scored: ",
+ ex.what());
+ }
+ probe(enumerated);
+ // probe_so is released here; the winner is re-opened lazily on construction.
+
+ // An INCOMPATIBLE view is recorded, not skipped: the candidate still enumerates that
+ // device once constructed, so the id map pushed to it must cover that device too.
+ for (auto& dev : enumerated) {
+ // An empty fingerprint has no identity: it would merge unrelated devices into one
+ // entry (wrong winner / lost devices). Reject it - dispatch members must fingerprint.
+ OPENVINO_ASSERT(!dev.fingerprint.empty(),
+ "Library ",
+ lib,
+ " enumerated a dispatch-group device with an empty fingerprint; a "
+ "scoreable candidate must return a non-empty identity per device.");
+ // Merge by fingerprint equality: a device several candidates see is listed once.
+ auto it = std::find_if(entries.begin(), entries.end(), [&](const ov::DispatchEntry& e) {
+ return e.fingerprint == dev.fingerprint;
+ });
+ if (it == entries.end()) {
+ auto& entry = entries.emplace_back();
+ entry.fingerprint = dev.fingerprint;
+ entry.per_lib.resize(candidate_libs.size());
+ entry.per_lib[idx] = ov::DispatchEntry::CandidateDevice{dev.internal_id, dev.score};
+ } else {
+ // One candidate reporting a fingerprint twice cannot be disambiguated: merging
+ // would drop a device and its id, silently hiding it. Fail loudly instead.
+ OPENVINO_ASSERT(!it->per_lib[idx].has_value(),
+ "Library ",
+ lib,
+ " enumerated devices \"",
+ it->per_lib[idx]->internal_id,
+ "\" and \"",
+ dev.internal_id,
+ "\" with the same fingerprint, so they cannot be told apart. The "
+ "driver may not report the PCI bus info the identity is built from.");
+ it->per_lib[idx] = ov::DispatchEntry::CandidateDevice{dev.internal_id, dev.score};
+ }
+ }
+ }
+
+ // Assign canonical ".N" ids (as in "<device>.N") in stable enumeration order.
+ for (size_t n = 0; n < entries.size(); ++n)
+ entries[n].canonical_id = std::to_string(n);
+ return entries;
+}
+
+// Whether two plugin path spellings denote one and the same library: plugins.xml stores a
+// location resolved next to itself, register_plugin leaves a bare name for the OS loader.
+bool is_same_plugin_library(const std::filesystem::path& lhs, const std::filesystem::path& rhs) {
+ if (lhs == rhs) {
+ return true;
+ }
+ // A bare name has no directory to compare, and under this device it resolves to the
+ // library already registered here.
+ if (!lhs.has_parent_path() || !rhs.has_parent_path()) {
+ return lhs.filename() == rhs.filename();
+ }
+ std::error_code ec;
+ const auto same_file = std::filesystem::equivalent(lhs, rhs, ec);
+ return !ec && same_file;
+}
+
#ifdef PROXY_PLUGIN_ENABLED
std::string get_internal_plugin_name(const std::string& device_name, const ov::AnyMap& properties) {
static constexpr const char* internal_plugin_suffix = "_ov_internal";
@@ -474,7 +565,7 @@ bool ov::CoreImpl::is_proxy_device(const std::string& dev_name) const {
#ifdef PROXY_PLUGIN_ENABLED
std::string real_name = ov::parse_device_name_into_config(dev_name).m_device_name;
return m_plugin_registry.find(real_name) != m_plugin_registry.end() &&
- m_plugin_registry.at(real_name).m_plugin_create_func == ov::proxy::create_plugin;
+ m_plugin_registry.at(real_name).primary().m_plugin_create_func == ov::proxy::create_plugin;
#else
return false;
#endif
@@ -541,7 +632,7 @@ void ov::CoreImpl::register_plugin_in_registry_unsafe(const std::string& device_
std::string dev_name = device_name;
#ifdef PROXY_PLUGIN_ENABLED
- auto&& config = desc.m_default_config;
+ auto&& config = desc.primary().m_default_config;
// Register proxy plugin
if (config.find(ov::proxy::configuration::alias.name()) != config.end()) {
// Create proxy plugin for alias
@@ -554,30 +645,30 @@ void ov::CoreImpl::register_plugin_in_registry_unsafe(const std::string& device_
PluginDescriptor desc = PluginDescriptor(ov::proxy::create_plugin);
// Add internal name for proxy in order to modify fallback order before the initialization
if (alias == device_name)
- desc.m_default_config[ov::proxy::configuration::internal_name.name()] = dev_name;
+ desc.primary().m_default_config[ov::proxy::configuration::internal_name.name()] = dev_name;
- fill_config(desc.m_default_config, config, dev_name);
+ fill_config(desc.primary().m_default_config, config, dev_name);
m_plugin_registry[alias] = std::move(desc);
add_mutex(alias);
} else {
// Update registered plugin
auto& plugin = m_plugin_registry.at(alias);
// Error if we have an alias for HW plugin
- OPENVINO_ASSERT(plugin.m_plugin_create_func == ov::proxy::create_plugin,
+ OPENVINO_ASSERT(plugin.primary().m_plugin_create_func == ov::proxy::create_plugin,
"Cannot register plugin for ",
dev_name,
" plugin with the same name already registered!");
// Add internal name for proxy in order to modify fallback order before the initialization
if (alias == device_name)
- plugin.m_default_config[ov::proxy::configuration::internal_name.name()] = dev_name;
- fill_config(plugin.m_default_config, config, dev_name);
+ plugin.primary().m_default_config[ov::proxy::configuration::internal_name.name()] = dev_name;
+ fill_config(plugin.primary().m_default_config, config, dev_name);
}
} else if (config.find(ov::proxy::configuration::fallback.name()) != config.end()) {
// Fallback without alias means that we need to replace original plugin to proxy
dev_name = get_internal_plugin_name(dev_name, config);
PluginDescriptor desc = PluginDescriptor(ov::proxy::create_plugin);
- desc.m_default_config[ov::proxy::configuration::internal_name.name()] = dev_name;
- fill_config(desc.m_default_config, config, dev_name);
+ desc.primary().m_default_config[ov::proxy::configuration::internal_name.name()] = dev_name;
+ fill_config(desc.primary().m_default_config, config, dev_name);
m_plugin_registry[device_name] = std::move(desc);
add_mutex(device_name);
}
@@ -589,9 +680,9 @@ void ov::CoreImpl::register_plugin_in_registry_unsafe(const std::string& device_
// Register real plugin
for (const auto& proxy_prop : proxy_conf_properties) {
- auto it = desc.m_default_config.find(proxy_prop);
- if (it != desc.m_default_config.end()) {
- desc.m_default_config.erase(it);
+ auto it = desc.primary().m_default_config.find(proxy_prop);
+ if (it != desc.primary().m_default_config.end()) {
+ desc.primary().m_default_config.erase(it);
}
}
#endif
@@ -614,8 +705,8 @@ void ov::CoreImpl::register_compile_time_plugins() {
const decltype(::get_compiled_plugins_registry())& plugins = get_compiled_plugins_registry();
for (const auto& plugin : plugins) {
const auto& device_name = plugin.first;
- if (device_name.find('.') != std::string::npos) {
- OPENVINO_THROW("Device name must not contain dot '.' symbol");
+ if (device_name.find_first_of(".#") != std::string::npos) {
+ OPENVINO_THROW("Device name must not contain dot '.' or hash '#' symbol");
}
#ifdef OPENVINO_STATIC_LIBRARY
if (m_plugin_registry.find(device_name) == m_plugin_registry.end()) {
@@ -625,11 +716,22 @@ void ov::CoreImpl::register_compile_time_plugins() {
register_plugin_in_registry_unsafe(device_name, desc);
}
#else
- const auto& plugin_path = ov::util::get_compiled_plugin_path(plugin.second.m_plugin_path);
- if (m_plugin_registry.find(device_name) == m_plugin_registry.end() && ov::util::file_exists(plugin_path)) {
+ // A device may map to several candidate libraries (a dispatch group); keep the ones
+ // that exist. The first present candidate is primary, the rest are extra candidates.
+ if (m_plugin_registry.find(device_name) == m_plugin_registry.end()) {
ov::AnyMap config = any_copy(plugin.second.m_default_config);
- PluginDescriptor desc{plugin_path, config};
- register_plugin_in_registry_unsafe(device_name, desc);
+ std::vector<std::filesystem::path> present;
+ for (const auto& p : plugin.second.m_plugin_paths) {
+ const auto resolved = ov::util::get_compiled_plugin_path(p);
+ if (ov::util::file_exists(resolved))
+ present.push_back(resolved);
+ }
+ if (!present.empty()) {
+ PluginDescriptor desc{present.front(), config};
+ for (size_t i = 1; i < present.size(); ++i)
+ desc.m_candidates.push_back({present[i], config, nullptr});
+ register_plugin_in_registry_unsafe(device_name, desc);
+ }
}
#endif
}
@@ -651,19 +753,49 @@ void ov::CoreImpl::register_plugins_in_registry(const std::filesystem::path& xml
if (m_plugin_registry.find(device_name) != m_plugin_registry.end()) {
OPENVINO_THROW("Device with \"", device_name, "\" is already registered in the OpenVINO Runtime");
}
- if (device_name.find('.') != std::string::npos) {
- OPENVINO_THROW("Device name must not contain dot '.' symbol");
+ if (device_name.find_first_of(".#") != std::string::npos) {
+ OPENVINO_THROW("Device name must not contain dot '.' or hash '#' symbol");
}
- PluginDescriptor plugin_desc{
- get_plugin_path(make_path(pugixml::get_str_attr(plugin_node, "location")), xml_config_file, by_abs_path)};
+ // Library path(s): either the legacy single "location" attribute, or ordered
+ // <location> children (a dispatch group; first = default). Order is preserved.
+ std::vector<std::filesystem::path> locations;
+ for (const auto& location_node : plugin_node.children("location")) {
+ auto child_location = make_path(location_node.child_value());
+ OPENVINO_ASSERT(!child_location.empty(),
+ "Empty <location> element for device \"",
+ device_name,
+ "\" in the plugins registry");
+ locations.push_back(get_plugin_path(std::move(child_location), xml_config_file, by_abs_path));
+ }
+ if (const auto attr_location = pugixml::get_attribute_view(plugin_node, "location");
+ attr_location && !attr_location->empty()) {
+ OPENVINO_ASSERT(locations.empty(),
+ "Device \"",
+ device_name,
+ "\" declares both a \"location\" attribute and <location> child elements; use one form");
+ locations.push_back(get_plugin_path(make_path(*attr_location), xml_config_file, by_abs_path));
+ }
+ OPENVINO_ASSERT(!locations.empty(),
+ "Device \"",
+ device_name,
+ "\" has no library location in the plugins registry");
+
+ PluginDescriptor plugin_desc{locations.front()};
+ for (size_t i = 1; i < locations.size(); ++i) {
+ plugin_desc.m_candidates.push_back({locations[i], {}, nullptr});
+ }
// check properties
const auto properties_node = plugin_node.child("properties");
if (properties_node) {
FOREACH_CHILD (property_node, properties_node, "property") {
const auto key = pugixml::get_str_attr(property_node, "key");
- plugin_desc.m_default_config[key] = pugixml::get_str_attr(property_node, "value");
+ // Default config from <properties> applies to every candidate library.
+ const auto value = pugixml::get_str_attr(property_node, "value");
+ for (auto& candidate : plugin_desc.m_candidates) {
+ candidate.m_default_config[key] = value;
+ }
}
}
@@ -681,7 +813,105 @@ void ov::CoreImpl::register_plugins_in_registry(const std::filesystem::path& xml
}
}
+std::vector<ov::DispatchEntry>& ov::CoreImpl::get_or_build_dispatch_entries_unsafe(const std::string& device_name,
+ const PluginDescriptor& desc) const {
+ auto map_it = m_dispatch_map.find(device_name);
+ if (map_it == m_dispatch_map.end()) {
+ std::vector<std::filesystem::path> candidate_libs;
+ candidate_libs.reserve(desc.candidate_count());
+ for (size_t idx = 0; idx < desc.candidate_count(); ++idx) {
+ candidate_libs.push_back(desc.candidate_location(idx));
+ }
+ map_it = m_dispatch_map.emplace(device_name, build_dispatch_entries(candidate_libs)).first;
+ }
+ return map_it->second;
+}
+
+std::optional<size_t> ov::CoreImpl::resolve_dispatch_winner_unsafe(const std::string& device_name,
+ const PluginDescriptor& desc,
+ const std::string& device_id) const {
+ auto& entries = get_or_build_dispatch_entries_unsafe(device_name, desc);
+
+ // No id given -> the default device ("0"), mirroring the plugin's m_default_device_id rule.
+ const std::string target_id = device_id.empty() ? std::string("0") : device_id;
+ const auto entry = std::find_if(entries.begin(), entries.end(), [&](const ov::DispatchEntry& e) {
+ return e.canonical_id == target_id;
+ });
+ if (entry == entries.end()) {
+ return std::nullopt;
+ }
+ if (entry->winner_idx) {
+ return entry->winner_idx;
+ }
+
+ // Highest score wins; ties resolve to registry order (the lowest candidate index).
+ // Any runtime override is already baked into the scores by the plugin, so core stays generic.
+ std::optional<size_t> winner;
+ ov::DeviceCompatibilityScore best = ov::PROBE_SCORE_INCOMPATIBLE;
+ for (size_t idx = 0; idx < entry->per_lib.size(); ++idx) {
+ if (const auto& view = entry->per_lib[idx]; view && view->score > best) {
+ best = view->score;
+ winner = idx;
+ }
+ }
+ entry->winner_idx = winner;
+ return winner;
+}
+
+std::map<std::string, std::string> ov::CoreImpl::dispatch_device_id_map_unsafe(const std::string& device_name,
+ size_t candidate_idx) const {
+ std::map<std::string, std::string> id_map;
+ const auto map_it = m_dispatch_map.find(device_name);
+ if (map_it == m_dispatch_map.end()) {
+ return id_map;
+ }
+ // Every device this candidate enumerated, not just the ones it won: it keeps addressing all of
+ // them by the canonical ids, so its id set stays as dense as its own enumeration was.
+ for (const auto& e : map_it->second) {
+ if (candidate_idx < e.per_lib.size()) {
+ if (const auto& view = e.per_lib[candidate_idx]; view) {
+ id_map[view->internal_id] = e.canonical_id;
+ }
+ }
+ }
+ return id_map;
+}
+
+std::optional<std::vector<std::string>> ov::CoreImpl::dispatch_group_device_ids(const std::string& device_name) const {
+ std::lock_guard<std::mutex> g_lock(get_mutex());
+ auto reg_it = m_plugin_registry.find(device_name);
+ if (reg_it == m_plugin_registry.end() || !reg_it->second.is_dispatch_group())
+ return std::nullopt;
+
+ const auto& entries = get_or_build_dispatch_entries_unsafe(device_name, reg_it->second);
+
+ // A device every candidate scored INCOMPATIBLE is not advertised, but its entry keeps its slot
+ // so the canonical ids stay stable and every member's id map stays complete.
+ std::vector<std::string> ids;
+ for (const auto& entry : entries) {
+ const bool servable = std::any_of(entry.per_lib.begin(), entry.per_lib.end(), [](const auto& view) {
+ return view && view->score != ov::PROBE_SCORE_INCOMPATIBLE;
+ });
+ if (servable) {
+ ids.push_back(entry.canonical_id);
+ }
+ }
+ return ids;
+}
+
ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {
+ return get_plugin_impl(plugin_name, /*device_id=*/"");
+}
+
+ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name, const ov::AnyMap& config) const {
+ // The device id (.N) was demoted to config by parse_device_config; route on it.
+ std::string device_id;
+ if (auto it = config.find(ov::device::id.name()); it != config.end())
+ device_id = it->second.as<std::string>();
+ return get_plugin_impl(plugin_name, device_id);
+}
+
+ov::Plugin ov::CoreImpl::get_plugin_impl(const std::string& plugin_name, const std::string& device_id) const {
OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::LoadTime, "CoreImpl::get_plugin");
auto device_name = plugin_name;
@@ -708,28 +938,53 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {
}
std::lock_guard<std::mutex> lock(get_mutex(device_name));
+ // The instance cache key: for a dispatch group it is an internal per-winner key
+ // (e.g. "<device>#1") so ids routed to different winners coexist; the public name otherwise.
+ std::string instance_key = device_name;
+ // Set for a dispatch group: the renaming its winner must adopt before anything addresses ids.
+ std::optional<std::map<std::string, std::string>> dispatch_id_map;
+
PluginDescriptor desc;
{
// Global lock to find plugin.
// Always use global mutex if iterate over plugins or m_plugin_registry
std::lock_guard<std::mutex> g_lock(get_mutex());
- auto it_plugin = m_plugins.find(device_name);
- if (it_plugin != m_plugins.end())
- return it_plugin->second;
desc = it->second;
+
+ // Dispatch group: resolve the winner for the requested (or default) id and make it primary
+ // (design 3.5/3.7). Ids need no translation - the winner adopts the canonical ones below.
+ if (desc.is_dispatch_group()) {
+ const auto winner = resolve_dispatch_winner_unsafe(device_name, desc, device_id);
+ OPENVINO_ASSERT(winner.has_value(),
+ "No registered candidate library can serve device \"",
+ device_name,
+ device_id.empty() ? "" : "." + device_id,
+ "\". Please check the plugins registry and device drivers.");
+ instance_key = device_name + '#' + std::to_string(*winner);
+ dispatch_id_map = dispatch_device_id_map_unsafe(device_name, *winner);
+ if (*winner != 0)
+ std::swap(desc.m_candidates[0], desc.m_candidates[*winner]);
+ }
+
+ auto it_plugin = m_plugins.find(instance_key);
+ if (it_plugin != m_plugins.end())
+ return it_plugin->second;
}
+
+ if (instance_key != device_name)
+ add_mutex(instance_key);
// Plugin is in registry, but not created, let's create
std::shared_ptr<void> so;
try {
ov::Plugin plugin;
- if (desc.m_plugin_create_func) { // static OpenVINO case or proxy plugin
+ if (desc.primary().m_plugin_create_func) { // static OpenVINO case or proxy plugin
std::shared_ptr<ov::IPlugin> plugin_impl;
- desc.m_plugin_create_func(plugin_impl);
+ desc.primary().m_plugin_create_func(plugin_impl);
plugin = Plugin{plugin_impl, {}};
} else {
- so = ov::util::load_shared_object(desc.m_lib_location);
+ so = ov::util::load_shared_object(desc.primary().m_lib_location);
std::shared_ptr<ov::IPlugin> plugin_impl;
reinterpret_cast<ov::CreatePluginFunc*>(ov::util::get_symbol(so, ov::create_plugin_function))(plugin_impl);
const auto& plugin_name = plugin_impl->get_device_name();
@@ -737,7 +992,7 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {
// Check that device plugin name is the same as requested for HW plugins
if (!plugin_name.empty() && !ov::is_virtual_device(plugin_name)) {
OPENVINO_ASSERT(device_name.find(plugin_name) != std::string::npos,
- desc.m_lib_location,
+ desc.primary().m_lib_location,
" is used for ",
device_name,
" , while it contains implementation for ",
@@ -755,29 +1010,45 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {
plugin.set_core(std::move(mutableCore));
}
+ // A group member adopts Core's numbering before anything addresses an id, so every id that
+ // crosses this boundary later - in either direction - is already the canonical one.
+ if (dispatch_id_map) {
+ OPENVINO_ASSERT(device_supports_internal_property(plugin, ov::internal::device_id_map.name()),
+ "Library ",
+ desc.primary().m_lib_location,
+ " is registered as one of several candidates for device \"",
+ device_name,
+ "\" but does not support ",
+ ov::internal::device_id_map.name(),
+ ", so it cannot adopt the device ids Core assigns. Sharing a device "
+ "name requires letting Core name the devices.");
+ plugin.set_property({ov::internal::device_id_map(*dispatch_id_map)});
+ }
+
// configuring
{
#ifdef PROXY_PLUGIN_ENABLED
// Initial setup for proxy plugin.
// It is needed for future initialization to initialize low level plugin
- if (desc.m_plugin_create_func == ov::proxy::create_plugin) {
+ if (desc.primary().m_plugin_create_func == ov::proxy::create_plugin) {
ov::AnyMap initial_config;
- auto it = desc.m_default_config.find(ov::proxy::alias_for.name());
- if (it != desc.m_default_config.end()) {
+ auto it = desc.primary().m_default_config.find(ov::proxy::alias_for.name());
+ if (it != desc.primary().m_default_config.end()) {
initial_config[it->first] = it->second;
}
- it = desc.m_default_config.find(ov::proxy::device_priorities.name());
- if (it != desc.m_default_config.end()) {
+ it = desc.primary().m_default_config.find(ov::proxy::device_priorities.name());
+ if (it != desc.primary().m_default_config.end()) {
initial_config[it->first] = it->second;
}
- it = desc.m_default_config.find(ov::device::priorities.name());
- if (it != desc.m_default_config.end()) {
+ it = desc.primary().m_default_config.find(ov::device::priorities.name());
+ if (it != desc.primary().m_default_config.end()) {
// Fix fallback names in case if proxy plugin got a conflict in the process of plugins registration
auto priorities = it->second.as<std::vector<std::string>>();
- auto internal_name = desc.m_default_config.find(ov::proxy::configuration::internal_name.name());
+ auto internal_name =
+ desc.primary().m_default_config.find(ov::proxy::configuration::internal_name.name());
for (auto&& priority : priorities) {
if (priority == device_name) {
- OPENVINO_ASSERT(internal_name != desc.m_default_config.end(),
+ OPENVINO_ASSERT(internal_name != desc.primary().m_default_config.end(),
"Cannot create proxy device ",
device_name,
". Device has incorrect configuration.");
@@ -814,16 +1085,24 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {
ov::DeviceIDParser parser(pluginDesc.first);
if (pluginDesc.first.find(device_name) != std::string::npos &&
!parser.get_device_id().empty()) {
+ // A group's per-id entry concerns only a member holding that
+ // device; ids are canonical on both sides now, so none is rewritten.
+ const std::string cfg_id = parser.get_device_id();
+ if (dispatch_id_map &&
+ std::none_of(dispatch_id_map->begin(), dispatch_id_map->end(), [&](const auto& kv) {
+ return kv.second == cfg_id;
+ }))
+ continue;
g_lock.unlock();
- pluginDesc.second.m_default_config[deviceKey] = parser.get_device_id();
- plugin.set_property(pluginDesc.second.m_default_config);
+ pluginDesc.second.primary().m_default_config[deviceKey] = cfg_id;
+ plugin.set_property(pluginDesc.second.primary().m_default_config);
}
}
}
}
// set global device-id independent settings to plugin
- plugin.set_property(desc.m_default_config);
+ plugin.set_property(desc.primary().m_default_config);
});
}
@@ -842,10 +1121,10 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {
}
std::move(ext.begin(), ext.end(), std::back_inserter(m_plugin_registry.at(device_name).m_extensions));
- return m_plugins.emplace(device_name, plugin).first->second;
+ return m_plugins.emplace(instance_key, plugin).first->second;
} catch (const ov::Exception& ex) {
OPENVINO_THROW("Failed to create plugin ",
- desc.m_lib_location,
+ desc.primary().m_lib_location,
" for device ",
device_name,
"\n",
@@ -868,7 +1147,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
m_core_config,
config_with_batch,
is_proxy_device(patched_device_name));
- auto plugin = get_plugin(parsed.m_device_name);
+ auto plugin = get_plugin(parsed.m_device_name, parsed.m_config);
const auto& [cache_dir, cache_manager] = parsed.m_core_config.get_cache_config_for_device(plugin);
auto compiled_model = import_compiled_model(plugin, {}, config, model);
// Skip caching for proxy plugin. HW plugin will load network from the cache
@@ -908,7 +1187,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
auto parsed =
parse_device_name_into_config(device_name, m_core_config, config_with_batch, is_proxy_device(device_name));
- auto plugin = get_plugin(parsed.m_device_name);
+ auto plugin = get_plugin(parsed.m_device_name, parsed.m_config);
const auto& [cache_dir, cache_manager] = parsed.m_core_config.get_cache_config_for_device(plugin);
auto compiled_model = import_compiled_model(plugin, context, parsed.m_config, model);
// Skip caching for proxy plugin. HW plugin will load network from the cache
@@ -941,7 +1220,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::filesystem:
OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::LoadTime, "Core::compile_model::Path");
auto parsed = parse_device_config(device_name, m_core_config, config, false);
// in case of compile_model(file_name), we need to clear-up core-level properties
- auto plugin = get_plugin(parsed.m_device_name);
+ auto plugin = get_plugin(parsed.m_device_name, parsed.m_config);
const auto& [cache_dir, cache_manager] = parsed.m_core_config.get_cache_config_for_device(plugin);
auto compiled_model = import_compiled_model(plugin, {}, parsed.m_config, model_path);
@@ -975,7 +1254,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::string& mod
const ov::AnyMap& config) const {
OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::compile_model::from_memory");
auto parsed = parse_device_name_into_config(device_name, m_core_config, config);
- auto plugin = get_plugin(parsed.m_device_name);
+ auto plugin = get_plugin(parsed.m_device_name, parsed.m_config);
const auto& [cache_dir, cache_manager] = parsed.m_core_config.get_cache_config_for_device(plugin);
auto compiled_model = import_compiled_model(plugin, {}, parsed.m_config);
// Skip caching for proxy plugin. HW plugin will load network from the cache
@@ -1006,7 +1285,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::import_model(std::istream& model,
const ov::AnyMap& config) const {
OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::import_model");
auto parsed = parse_device_name_into_config(device_name, config);
- return get_plugin(parsed.m_device_name).import_model(model, parsed.m_config);
+ return get_plugin(parsed.m_device_name, parsed.m_config).import_model(model, parsed.m_config);
}
ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::import_model(std::istream& modelStream,
@@ -1015,7 +1294,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::import_model(std::istream& modelStre
OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::import_model");
OPENVINO_ASSERT(context, "Remote context must not be empty.");
const auto parsed = parse_device_name_into_config(context->get_device_name(), config);
- return get_plugin(parsed.m_device_name).import_model(modelStream, context, parsed.m_config);
+ return get_plugin(parsed.m_device_name, parsed.m_config).import_model(modelStream, context, parsed.m_config);
}
ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::import_model(const ov::Tensor& compiled_blob,
@@ -1023,7 +1302,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::import_model(const ov::Tensor& compi
const ov::AnyMap& config) const {
OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::import_model");
const auto parsed = parse_device_name_into_config(device_name, config);
- return get_plugin(parsed.m_device_name).import_model(compiled_blob, parsed.m_config);
+ return get_plugin(parsed.m_device_name, parsed.m_config).import_model(compiled_blob, parsed.m_config);
}
ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::import_model(const ov::Tensor& compiled_blob,
@@ -1032,7 +1311,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::import_model(const ov::Tensor& compi
OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::import_model");
OPENVINO_ASSERT(context, "Remote context must not be empty.");
const auto parsed = parse_device_name_into_config(context->get_device_name(), config);
- return get_plugin(parsed.m_device_name).import_model(compiled_blob, context, parsed.m_config);
+ return get_plugin(parsed.m_device_name, parsed.m_config).import_model(compiled_blob, context, parsed.m_config);
}
ov::SupportedOpsMap ov::CoreImpl::query_model(const std::shared_ptr<const ov::Model>& model,
@@ -1040,7 +1319,7 @@ ov::SupportedOpsMap ov::CoreImpl::query_model(const std::shared_ptr<const ov::Mo
const ov::AnyMap& config) const {
OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::query_model");
const auto parsed = parse_device_name_into_config(device_name, config);
- return get_plugin(parsed.m_device_name).query_model(model, parsed.m_config);
+ return get_plugin(parsed.m_device_name, parsed.m_config).query_model(model, parsed.m_config);
}
bool ov::CoreImpl::is_hidden_device(const std::string& device_name) const {
@@ -1048,8 +1327,8 @@ bool ov::CoreImpl::is_hidden_device(const std::string& device_name) const {
std::lock_guard<std::mutex> lock(get_mutex());
// Alias hides the device
for (auto&& it : m_plugin_registry) {
- auto it_priority = it.second.m_default_config.find(ov::proxy::alias_for.name());
- if (it.first == device_name || it_priority == it.second.m_default_config.end())
+ auto it_priority = it.second.primary().m_default_config.find(ov::proxy::alias_for.name());
+ if (it.first == device_name || it_priority == it.second.primary().m_default_config.end())
continue;
auto devices = it_priority->second.as<std::vector<std::string>>();
for (const auto& dev : devices) {
@@ -1070,6 +1349,19 @@ std::vector<std::string> ov::CoreImpl::get_available_devices() const {
// Skip hidden devices
if (is_hidden_device(device_name))
continue;
+ // A dispatch group's device list is the merged canonical list core owns (each physical
+ // device once), not a single candidate's - answer it here rather than delegating.
+ if (auto group_ids = dispatch_group_device_ids(device_name)) {
+ // The bare form is only usable when the sole servable id is the default ("0"), which is
+ // what a bare request resolves to; otherwise the qualified id is the only way in.
+ if (group_ids->size() == 1 && group_ids->front() == "0") {
+ devices.push_back(std::move(device_name));
+ } else {
+ for (auto&& id : *group_ids)
+ devices.push_back(device_name + '.' + id);
+ }
+ continue;
+ }
try {
devicesIDs = get_property(device_name, ov::available_devices.name(), {}).as<std::vector<std::string>>();
} catch (const ov::Exception&) {
@@ -1101,7 +1393,7 @@ std::vector<std::string> ov::CoreImpl::get_available_devices() const {
ov::SoPtr<ov::IRemoteContext> ov::CoreImpl::create_context(const std::string& device_name, const AnyMap& params) const {
auto parsed = ov::parse_device_name_into_config(device_name, params);
- return get_plugin(parsed.m_device_name).create_context(parsed.m_config);
+ return get_plugin(parsed.m_device_name, parsed.m_config).create_context(parsed.m_config);
}
ov::AnyMap ov::CoreImpl::get_supported_property(const std::string& full_device_name,
@@ -1131,6 +1423,12 @@ ov::AnyMap ov::CoreImpl::get_supported_property(const std::string& full_device_n
const auto& flattened_config = flattened.m_config;
const auto& device_name = flattened.m_device_name;
+ // The id was demoted out of the name into the flattened config; pass it back as an argument so
+ // a dispatch group answers from the requested device's winner, not the default device's.
+ ov::AnyMap device_id_arg;
+ if (const auto it = flattened_config.find(ov::device::id.name()); it != flattened_config.end())
+ device_id_arg[ov::device::id.name()] = it->second;
+
// virtual plugins should bypass core-level properties to HW plugins
// so, we need to report them as supported
std::vector<std::string> supported_config_keys;
@@ -1142,7 +1440,7 @@ ov::AnyMap ov::CoreImpl::get_supported_property(const std::string& full_device_n
// try to search against OV API 2.0' mutable supported_properties
try {
- for (auto&& property : ICore::get_property(device_name, ov::supported_properties, {})) {
+ for (auto&& property : ICore::get_property(device_name, ov::supported_properties, device_id_arg)) {
if (property.is_mutable()) {
*key_inserter = std::move(property);
}
@@ -1152,7 +1450,7 @@ ov::AnyMap ov::CoreImpl::get_supported_property(const std::string& full_device_n
// try to search against internal supported_properties
try {
- for (auto&& property : ICore::get_property(device_name, ov::internal::supported_properties, {})) {
+ for (auto&& property : ICore::get_property(device_name, ov::internal::supported_properties, device_id_arg)) {
if (property.is_mutable()) {
*key_inserter = std::move(property);
}
@@ -1173,7 +1471,7 @@ ov::AnyMap ov::CoreImpl::get_supported_property(const std::string& full_device_n
ov::SoPtr<ov::IRemoteContext> ov::CoreImpl::get_default_context(const std::string& device_name) const {
auto parsed = ov::parse_device_name_into_config(device_name);
- return get_plugin(parsed.m_device_name).get_default_context(parsed.m_config);
+ return get_plugin(parsed.m_device_name, parsed.m_config).get_default_context(parsed.m_config);
}
std::shared_ptr<const ov::Model> ov::CoreImpl::apply_auto_batching(const std::shared_ptr<const ov::Model>& model,
@@ -1191,8 +1489,10 @@ std::shared_ptr<const ov::Model> ov::CoreImpl::apply_auto_batching(const std::sh
deviceNameWithBatchSize = device_name.substr(pos + 1);
deviceNameWithoutBatch = ov::DeviceIDParser::get_batch_device(deviceNameWithBatchSize);
if (device_name.find("(") == std::string::npos) {
- const auto parsed = ov::parse_device_name_into_config(deviceNameWithoutBatch);
- if (!get_plugin(parsed.m_device_name).is_property_supported(ov::optimal_batch_size.name())) {
+ auto parsed = ov::parse_device_name_into_config(deviceNameWithoutBatch);
+ // Route by id: for a dispatch group ".N" selects that device's winner, not the default.
+ if (!get_plugin(parsed.m_device_name, parsed.m_config)
+ .is_property_supported(ov::optimal_batch_size.name())) {
return model;
}
}
@@ -1227,12 +1527,14 @@ std::shared_ptr<const ov::Model> ov::CoreImpl::apply_auto_batching(const std::sh
if (is_proxy_device(parsed.m_device_name))
return model;
deviceNameWithoutBatch = device_name;
- if (!get_plugin(parsed.m_device_name).is_property_supported(ov::optimal_batch_size.name(), parsed.m_config)) {
+ // Route by id: for a dispatch group ".N" selects that device's winner, not the default.
+ if (!get_plugin(parsed.m_device_name, parsed.m_config)
+ .is_property_supported(ov::optimal_batch_size.name(), parsed.m_config)) {
return model;
}
// if applicable, the Auto-Batching is implicitly enabled via the performance hints
- bool bTputInPlg = get_plugin(parsed.m_device_name)
+ bool bTputInPlg = get_plugin(parsed.m_device_name, parsed.m_config)
.get_property(ov::hint::performance_mode.name(), parsed.m_config)
.as<ov::hint::PerformanceMode>() == ov::hint::PerformanceMode::THROUGHPUT;
const auto& mode = config.find(ov::hint::performance_mode.name());
@@ -1324,15 +1626,42 @@ ov::Any ov::CoreImpl::get_property(const std::string& device_name,
return get_property_for_core(name);
} else if (name == ov::cache_dir.name()) {
return util::path_to_string(
- m_core_config.get_cache_config_for_device(get_plugin(parsed.m_device_name)).m_cache_dir);
+ m_core_config.get_cache_config_for_device(get_plugin(parsed.m_device_name, parsed.m_config)).m_cache_dir);
} else if (name == ov::cache_path.name()) {
- return {m_core_config.get_cache_config_for_device(get_plugin(parsed.m_device_name)).m_cache_dir};
+ return {
+ m_core_config.get_cache_config_for_device(get_plugin(parsed.m_device_name, parsed.m_config)).m_cache_dir};
+ } else if (name == ov::available_devices.name()) {
+ // A group's device list is core's merged canonical list, not a candidate's view; a group
+ // serving nothing answers empty, as an ordinary plugin with no devices does.
+ if (auto group_ids = dispatch_group_device_ids(parsed.m_device_name))
+ return *group_ids;
}
- return get_plugin(parsed.m_device_name).get_property(name, parsed.m_config);
+ // Route by id so a per-device query (e.g. get_property("<device>.1", architecture)) is
+ // answered by that device's winner; a bare-name query resolves to the default-device winner.
+ return get_plugin(parsed.m_device_name, parsed.m_config).get_property(name, parsed.m_config);
}
void ov::CoreImpl::unload_plugin(const std::string& device_name) {
std::lock_guard<std::mutex> lock(get_mutex());
+
+ // A dispatch group caches its resolved instances under internal keys (e.g. "GPU#0",
+ // "GPU#1"), not under the bare name; erase all of them so unload frees every winner.
+ const auto reg_it = m_plugin_registry.find(device_name);
+ if (reg_it != m_plugin_registry.end() && reg_it->second.is_dispatch_group()) {
+ const std::string prefix = device_name + '#';
+ for (auto it = m_plugins.begin(); it != m_plugins.end();) {
+ if (it->first.rfind(prefix, 0) == 0)
+ it = m_plugins.erase(it);
+ else
+ ++it;
+ }
+ // Having nothing to unload is not an error here: a group answers available_devices from the
+ // probe, so enumerating it never constructs a winner. An unknown name still throws below.
+ m_dispatch_map.erase(device_name);
+ reg_it->second.m_extensions.clear();
+ return;
+ }
+
auto it = m_plugins.find(device_name);
if (it == m_plugins.end()) {
OPENVINO_THROW("Device with \"", device_name, "\" name is not registered in the OpenVINO Runtime");
@@ -1344,16 +1673,44 @@ void ov::CoreImpl::unload_plugin(const std::string& device_name) {
void ov::CoreImpl::register_plugin(const std::filesystem::path& plugin,
const std::string& device_name,
const ov::AnyMap& properties) {
+ if (device_name.find_first_of(".#") != std::string::npos) {
+ OPENVINO_THROW("Device name must not contain dot '.' or hash '#' symbol");
+ }
+
+ // Device lock before the global one, in get_plugin_impl's order: appending a candidate must not
+ // race a concurrent first load, which would insert a pre-append instance afterwards.
+ add_mutex(device_name);
+ std::lock_guard<std::mutex> dev_lock(get_mutex(device_name));
std::lock_guard<std::mutex> lock(get_mutex());
+ // A DIFFERENT library under an already-registered name appends a dispatch-group candidate; the
+ // enumeration probe picks the winner per device. (Proxy plugins keep their own handling.)
auto it = m_plugin_registry.find(device_name);
- // Proxy plugins can be configured in the runtime
if (it != m_plugin_registry.end() && !is_proxy_device(device_name)) {
- OPENVINO_THROW("Device with \"", device_name, "\" is already registered in the OpenVINO Runtime");
- }
-
- if (device_name.find('.') != std::string::npos) {
- OPENVINO_THROW("Device name must not contain dot '.' symbol");
+ const auto lib_path = ov::util::get_plugin_path(plugin);
+ // A duplicated candidate enumerates the same devices with the same scores as the one
+ // already registered, so it could only ever shadow itself: reject it.
+ for (size_t i = 0; i < it->second.candidate_count(); ++i) {
+ if (is_same_plugin_library(it->second.candidate_location(i), lib_path))
+ OPENVINO_THROW("Library ",
+ lib_path,
+ " is already registered as device \"",
+ device_name,
+ "\". Sharing a device name requires registering a different library under it.");
+ }
+ it->second.m_candidates.push_back({lib_path, properties, nullptr});
+ // Adding a candidate changes resolution: drop the cached merged device list and any
+ // instance already created for this name (the bare single-candidate instance, or a
+ // stale "<device>#N" winner) so the next request re-probes and re-selects.
+ m_dispatch_map.erase(device_name);
+ const std::string group_prefix = device_name + '#';
+ for (auto p = m_plugins.begin(); p != m_plugins.end();) {
+ if (p->first == device_name || p->first.rfind(group_prefix, 0) == 0)
+ p = m_plugins.erase(p);
+ else
+ ++p;
+ }
+ return;
}
PluginDescriptor desc{ov::util::get_plugin_path(plugin), properties};
@@ -1375,6 +1732,13 @@ std::vector<std::string> ov::CoreImpl::get_registered_devices() const {
return listOfDevices;
}
+size_t ov::CoreImpl::get_registered_candidate_count(const std::string& device_name) const {
+ std::lock_guard<std::mutex> lock(get_mutex());
+
+ const auto it = m_plugin_registry.find(device_name);
+ return it == m_plugin_registry.end() ? 0 : it->second.candidate_count();
+}
+
/**
* @brief Sets property values for a plugin or set of plugins
* @param device_name A device name to set config to
@@ -1392,6 +1756,9 @@ void ov::CoreImpl::set_property_for_device(const ov::AnyMap& config, const std::
std::string clear_device_name = parser.get_device_name();
std::vector<std::pair<std::string, ov::Plugin>> created_plugins;
+ // Dispatch-group routing: the instance key of the id's winner.
+ bool is_group = false, group_select_none = false;
+ std::string group_key;
{
std::lock_guard<std::mutex> lock(get_mutex());
created_plugins.reserve(m_plugins.size());
@@ -1401,7 +1768,7 @@ void ov::CoreImpl::set_property_for_device(const ov::AnyMap& config, const std::
auto base_desc = m_plugin_registry.find(clear_device_name);
if (m_plugin_registry.find(device_name) == m_plugin_registry.end() &&
base_desc != m_plugin_registry.end()) {
- PluginDescriptor desc{base_desc->second.m_lib_location,
+ PluginDescriptor desc{base_desc->second.primary().m_lib_location,
cfg_copy,
base_desc->second.m_list_of_extensions};
m_plugin_registry[device_name] = std::move(desc);
@@ -1412,7 +1779,9 @@ void ov::CoreImpl::set_property_for_device(const ov::AnyMap& config, const std::
for (auto& desc : m_plugin_registry) {
if (device_name.empty() || device_name == desc.first) {
for (auto&& conf : cfg_copy) {
- desc.second.m_default_config[conf.first] = conf.second;
+ for (auto& candidate : desc.second.m_candidates) {
+ candidate.m_default_config[conf.first] = conf.second;
+ }
}
configIsSet = true;
}
@@ -1423,9 +1792,34 @@ void ov::CoreImpl::set_property_for_device(const ov::AnyMap& config, const std::
}
}
+ // A group's live instances are keyed "<device>#<candidate>", which the bare-name match
+ // below never selects; an id-qualified request needs only that id's winner, by its own id.
+ const auto reg_it = m_plugin_registry.find(clear_device_name);
+ is_group = reg_it != m_plugin_registry.end() && reg_it->second.is_dispatch_group();
+ const std::string group_prefix = clear_device_name + '#';
+ // Only a live instance needs routing; resolving otherwise would probe the candidates here.
+ const bool group_live = is_group && std::any_of(m_plugins.begin(), m_plugins.end(), [&](const auto& p) {
+ return p.first.rfind(group_prefix, 0) == 0;
+ });
+ if (group_live && !parser.get_device_id().empty()) {
+ // Resolve this id's winner as get_plugin would: relying on an already-set winner_idx
+ // would leave an unresolved id targeting every group instance with the canonical id.
+ const auto winner =
+ resolve_dispatch_winner_unsafe(clear_device_name, reg_it->second, parser.get_device_id());
+ if (winner) {
+ group_key = group_prefix + std::to_string(*winner);
+ } else {
+ group_select_none = true; // no candidate serves this id: configure nothing
+ }
+ }
+
// set config for already created plugins
for (auto& plugin : m_plugins) {
- if (device_name.empty() || clear_device_name == plugin.first) {
+ bool selected = device_name.empty() || clear_device_name == plugin.first;
+ if (!selected && is_group && !group_select_none) {
+ selected = group_key.empty() ? plugin.first.rfind(group_prefix, 0) == 0 : plugin.first == group_key;
+ }
+ if (selected) {
created_plugins.emplace_back(std::pair<std::string, ov::Plugin>{plugin.first, plugin.second});
}
}
@@ -1480,7 +1874,9 @@ void ov::CoreImpl::add_extension(const std::vector<ov::Extension::Ptr>& extensio
bool ov::CoreImpl::device_supports_model_caching(const std::string& device_name) const {
auto parsed = parse_device_name_into_config(device_name);
- return device_supports_model_caching(get_plugin(parsed.m_device_name));
+ // Route on the id: for a dispatch group the answer belongs to that device's winner, which
+ // need not be the default device's.
+ return device_supports_model_caching(get_plugin(parsed.m_device_name, parsed.m_config));
}
bool ov::CoreImpl::device_supports_model_caching(const ov::Plugin& plugin, const ov::AnyMap& arguments) const {
@@ -1793,7 +2189,7 @@ std::mutex& ov::CoreImpl::get_mutex(const std::string& dev_name) const {
}
}
-void ov::CoreImpl::add_mutex(const std::string& dev_name) {
+void ov::CoreImpl::add_mutex(const std::string& dev_name) const {
std::lock_guard<std::mutex> lock(m_global_mutex);
m_dev_mutexes[dev_name];
}
diff --git a/src/inference/src/dev/core_impl.hpp b/src/inference/src/dev/core_impl.hpp
index 514008ac3fe..40ccf07e6be 100644
--- a/src/inference/src/dev/core_impl.hpp
+++ b/src/inference/src/dev/core_impl.hpp
@@ -4,6 +4,12 @@
#pragma once
+#include <cstdint>
+#include <map>
+#include <optional>
+#include <string>
+#include <vector>
+
#include "cache_guard.hpp"
#include "cache_manager.hpp"
#include "dev/plugin.hpp"
@@ -131,6 +137,22 @@ bool is_config_applicable(const std::string& device_name, const std::string& dev
*/
bool is_virtual_device(const std::string& device_name);
+// One physical device of a dispatch group (a device name with >1 candidate library).
+// Generic: holds only opaque tokens/ids/indices and integer scores, no vendor logic.
+struct DispatchEntry {
+ // How one candidate library sees this device: its own internal id and its score.
+ struct CandidateDevice {
+ std::string internal_id; // the id THIS library uses (may differ across libs)
+ DeviceCompatibilityScore score = PROBE_SCORE_INCOMPATIBLE;
+ };
+ std::string canonical_id; // ".N" shown to the user (core assigns)
+ std::vector<uint8_t> fingerprint; // opaque cross-candidate identity (merge key)
+ // Indexed by candidate index, sized to the candidate count; nullopt where that candidate
+ // did not report this device (its library is absent, or its probe never listed it).
+ std::vector<std::optional<CandidateDevice>> per_lib;
+ std::optional<size_t> winner_idx; // resolved candidate (lazy)
+};
+
class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore> {
private:
mutable std::map<std::string, ov::Plugin> m_plugins;
@@ -141,7 +163,7 @@ private:
mutable std::unordered_map<std::string, std::mutex> m_dev_mutexes;
std::mutex& get_mutex(const std::string& dev_name = "") const;
- void add_mutex(const std::string& dev_name);
+ void add_mutex(const std::string& dev_name) const;
bool is_proxy_device(const ov::Plugin& plugin) const;
bool is_proxy_device(const std::string& dev_name) const;
@@ -170,10 +192,17 @@ private:
mutable ov::CacheGuard m_cache_guard;
struct PluginDescriptor {
- std::filesystem::path m_lib_location{};
- ov::AnyMap m_default_config{};
+ // One candidate plugin library. A descriptor holds >= 1; more than one marks a
+ // dispatch group (see m_dispatch_map). Ordinary device names have exactly one.
+ struct Candidate {
+ std::filesystem::path m_lib_location{};
+ ov::AnyMap m_default_config{};
+ CreatePluginEngineFunc* m_plugin_create_func = nullptr;
+ };
+ std::vector<Candidate> m_candidates{Candidate{}}; // always non-empty
+
+ // Per-descriptor (per device name), shared across candidates.
std::vector<std::filesystem::path> m_list_of_extensions{};
- CreatePluginEngineFunc* m_plugin_create_func = nullptr;
CreateExtensionFunc* m_extension_create_func = nullptr;
mutable std::vector<Extension::Ptr> m_extensions{}; // mutable because of lazy init
@@ -182,20 +211,43 @@ private:
PluginDescriptor(const std::filesystem::path& lib_location,
const ov::AnyMap& default_config = {},
const std::vector<std::filesystem::path>& list_of_extensions = {})
- : m_lib_location(lib_location),
- m_default_config(default_config),
+ : m_candidates{Candidate{lib_location, default_config, nullptr}},
m_list_of_extensions(list_of_extensions) {}
PluginDescriptor(CreatePluginEngineFunc* plugin_create_func,
const ov::AnyMap& default_config = {},
CreateExtensionFunc* extension_create_func = nullptr)
- : m_lib_location(),
- m_default_config(default_config),
- m_list_of_extensions(),
- m_plugin_create_func(plugin_create_func),
+ : m_candidates{Candidate{{}, default_config, plugin_create_func}},
m_extension_create_func(extension_create_func) {}
+
+ // The first candidate; the only one for an ordinary single-plugin device name.
+ Candidate& primary() {
+ return m_candidates.front();
+ }
+ const Candidate& primary() const {
+ return m_candidates.front();
+ }
+ // Number of candidate libraries (>= 1); > 1 marks a dispatch group.
+ size_t candidate_count() const {
+ return m_candidates.size();
+ }
+ bool is_dispatch_group() const {
+ return m_candidates.size() > 1;
+ }
+ const std::filesystem::path& candidate_location(size_t candidate_idx) const {
+ OPENVINO_ASSERT(candidate_idx < m_candidates.size(),
+ "Candidate index ",
+ candidate_idx,
+ " is out of range; the device has ",
+ m_candidates.size(),
+ " candidate librarie(s)");
+ return m_candidates[candidate_idx].m_lib_location;
+ }
};
+ // Canonical dispatch table per dispatch-group device name, lazily built on first use.
+ mutable std::map<std::string, std::vector<DispatchEntry>> m_dispatch_map;
+
std::shared_ptr<ov::threading::ExecutorManager> m_executor_manager;
mutable std::unordered_set<std::string> m_opset_names;
mutable std::vector<Extension::Ptr> m_extensions;
@@ -226,6 +278,33 @@ private:
bool is_hidden_device(const std::string& device_name) const;
void register_plugin_in_registry_unsafe(const std::string& device_name, PluginDescriptor& desc);
+ // Merged device list of a dispatch group, probing the candidates on first use and caching it
+ // in m_dispatch_map. Caller holds the mutex.
+ std::vector<DispatchEntry>& get_or_build_dispatch_entries_unsafe(const std::string& device_name,
+ const PluginDescriptor& desc) const;
+
+ // Candidate index serving device_id (empty = default): argmax(score), ties -> registry order.
+ // Builds m_dispatch_map[device_name] on first use. nullopt if none serves it; caller holds mutex.
+ std::optional<size_t> resolve_dispatch_winner_unsafe(const std::string& device_name,
+ const PluginDescriptor& desc,
+ const std::string& device_id) const;
+
+ // Dispatch-aware get_plugin: resolves the winner for config's device id, or behaves like
+ // get_plugin(plugin_name) for a single-candidate name.
+ ov::Plugin get_plugin(const std::string& plugin_name, const ov::AnyMap& config) const;
+
+ // Shared get_plugin core. device_id (empty = default/bare) selects the dispatch-group winner.
+ ov::Plugin get_plugin_impl(const std::string& plugin_name, const std::string& device_id) const;
+
+ // {candidate's own id -> canonical ".N" id} for every device candidate_idx enumerated, pushed
+ // to a group member so it adopts Core's numbering. Caller holds the mutex.
+ std::map<std::string, std::string> dispatch_device_id_map_unsafe(const std::string& device_name,
+ size_t candidate_idx) const;
+
+ // Canonical merged device ids of a dispatch group (each device once, unserviceable omitted);
+ // nullopt for a non-group name, empty if no candidate serves any. Builds the map on first use.
+ std::optional<std::vector<std::string>> dispatch_group_device_ids(const std::string& device_name) const;
+
void add_extensions_unsafe(const std::vector<ov::Extension::Ptr>& extensions) const;
std::vector<ov::Extension::Ptr> get_extensions_copy() const;
@@ -283,6 +362,14 @@ public:
*/
std::vector<std::string> get_registered_devices() const;
+ /**
+ * @brief Number of candidate libraries registered under a device name. Returns 1 for an
+ * ordinary single-plugin device name, >1 for a dispatch group, and 0 if the device name
+ * is not registered. Read-only; intended for diagnostics and tests.
+ * @param device_name A name of device
+ */
+ size_t get_registered_candidate_count(const std::string& device_name) const;
+
/**
* @brief Sets config values for a plugin or set of plugins
* @param device_name A device name to set config to
diff --git a/src/inference/tests/functional/CMakeLists.txt b/src/inference/tests/functional/CMakeLists.txt
index b28658e8639..873d4fc6891 100644
--- a/src/inference/tests/functional/CMakeLists.txt
+++ b/src/inference/tests/functional/CMakeLists.txt
@@ -10,6 +10,8 @@ endif()
set(DEPENDENCIES
mock_engine
+ mock_dispatch_candidate_a
+ mock_dispatch_candidate_b
openvino_template_extension
)
@@ -50,6 +52,7 @@ ov_add_test_target(
${CMAKE_CURRENT_SOURCE_DIR}/ov_compiled_model_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ov_core_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ov_core_threading.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/ov_dispatch_group_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ov_extension_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ov_extension_test.hpp
${CMAKE_CURRENT_SOURCE_DIR}/ov_infer_request_test.cpp
diff --git a/src/inference/tests/functional/ov_dispatch_group_test.cpp b/src/inference/tests/functional/ov_dispatch_group_test.cpp
new file mode 100644
index 00000000000..22f3681b8b4
--- /dev/null
+++ b/src/inference/tests/functional/ov_dispatch_group_test.cpp
@@ -0,0 +1,515 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+// Functional tests for ov::Core's device-name dispatch: two candidate libraries registered
+// under one device name (a "dispatch group"), each exporting a scriptable enumeration probe.
+// Exercises the real dlopen + probe + merge + resolve path, not just the algorithm.
+
+#include <gtest/gtest.h>
+
+#include <cstdlib>
+#include <filesystem>
+#include <fstream>
+#include <string>
+#include <system_error>
+#include <vector>
+
+#include "common_test_utils/file_utils.hpp"
+#include "common_test_utils/test_assertions.hpp"
+#include "openvino/runtime/core.hpp"
+#include "openvino/util/file_util.hpp"
+
+#ifndef OPENVINO_STATIC_LIBRARY
+
+namespace ov::test {
+namespace {
+
+// PROBE_SCORE_* values (kept literal here so the test states expectations explicitly).
+constexpr int INCOMPATIBLE = 0;
+constexpr int SERVABLE = 1;
+constexpr int CAPABLE = 50;
+constexpr int PREFERRED = 100;
+
+void set_env(const std::string& name, const std::string& value) {
+# ifdef _WIN32
+ _putenv_s(name.c_str(), value.c_str());
+# else
+ ::setenv(name.c_str(), value.c_str(), 1);
+# endif
+}
+void unset_env(const std::string& name) {
+# ifdef _WIN32
+ _putenv_s(name.c_str(), "");
+# else
+ ::unsetenv(name.c_str());
+# endif
+}
+
+std::filesystem::path candidate_lib(const std::string& suffix) {
+ return ov::util::make_plugin_library_name(ov::util::make_path(ov::test::utils::getExecutableDirectory()),
+ "mock_dispatch_candidate_" + suffix + OV_BUILD_POSTFIX);
+}
+
+// Moves the working directory away for a scope, so a bare library name cannot resolve against it.
+class CwdGuard {
+public:
+ explicit CwdGuard(const std::filesystem::path& dir) : m_previous(std::filesystem::current_path()) {
+ std::filesystem::current_path(dir);
+ }
+ CwdGuard(const CwdGuard&) = delete;
+ CwdGuard& operator=(const CwdGuard&) = delete;
+ ~CwdGuard() {
+ std::error_code ec;
+ std::filesystem::current_path(m_previous, ec);
+ }
+
+private:
+ const std::filesystem::path m_previous;
+};
+
+// A dispatch-group test fixture: writes a 2-<location> plugins.xml and scripts both probes.
+class DispatchGroupTest : public ::testing::Test {
+protected:
+ const std::string device = "FAKE";
+ std::filesystem::path xml_path{ov::test::utils::generateTestFilePrefix() + "_test_dispatch_group_plugins.xml"};
+
+ void write_registry(const std::vector<std::filesystem::path>& locations = {candidate_lib("a"),
+ candidate_lib("b")}) {
+ std::ofstream file(xml_path);
+ file << "<ie><plugins><plugin name=\"" << device << "\">";
+ for (const auto& location : locations)
+ file << "<location>" << location.string() << "</location>";
+ file << "</plugin></plugins></ie>";
+ }
+
+ // Script one triple "id,fingerprint,score" per candidate.
+ void script(const std::string& a_enum, const std::string& b_enum) {
+ set_env("MOCK_DISPATCH_A_ENUM", a_enum);
+ set_env("MOCK_DISPATCH_B_ENUM", b_enum);
+ }
+
+ void SetUp() override {
+ write_registry();
+ }
+ void TearDown() override {
+ unset_env("MOCK_DISPATCH_A_ENUM");
+ unset_env("MOCK_DISPATCH_B_ENUM");
+ unset_env("MOCK_DISPATCH_A_NO_ID_MAP");
+ unset_env("MOCK_DISPATCH_B_NO_ID_MAP");
+ unset_env("OV_GPU_RUNTIME");
+ if (ov::util::file_exists(xml_path))
+ std::ignore = std::filesystem::remove(xml_path);
+ }
+
+ // Tag ("A"/"B") of the candidate Core constructed for the bare (default) device.
+ std::string resolved_tag(ov::Core& core) {
+ return core.get_property(device, "MOCK_CANDIDATE_TAG").as<std::string>();
+ }
+ // Tag of the candidate Core constructed for a specific canonical id (e.g. "FAKE.1").
+ std::string resolved_tag(ov::Core& core, const std::string& id) {
+ return core.get_property(device + "." + id, "MOCK_CANDIDATE_TAG").as<std::string>();
+ }
+ // available_devices entries that belong to this dispatch group.
+ std::vector<std::string> group_devices(ov::Core& core) {
+ std::vector<std::string> group;
+ for (const auto& d : core.get_available_devices())
+ if (d == device || d.rfind(device + ".", 0) == 0)
+ group.push_back(d);
+ return group;
+ }
+};
+
+// Same device (equal fingerprint) seen by both: higher score wins, only that one is built.
+TEST_F(DispatchGroupTest, higher_score_wins) {
+ script("0,aa," + std::to_string(PREFERRED), "0,aa," + std::to_string(CAPABLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core), "A");
+}
+
+TEST_F(DispatchGroupTest, higher_score_wins_other_candidate) {
+ script("0,aa," + std::to_string(SERVABLE), "0,aa," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core), "B");
+}
+
+// Tie on score -> first registry candidate (A, listed first) wins.
+TEST_F(DispatchGroupTest, tie_resolves_to_registry_order) {
+ script("0,aa," + std::to_string(SERVABLE), "0,aa," + std::to_string(SERVABLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core), "A");
+}
+
+// INCOMPATIBLE(0) is excluded even if listed first; the other candidate serves the device.
+TEST_F(DispatchGroupTest, incompatible_candidate_excluded) {
+ script("0,aa," + std::to_string(INCOMPATIBLE), "0,aa," + std::to_string(SERVABLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core), "B");
+}
+
+// Only one candidate enumerates the device (divergent lists) -> it serves it.
+TEST_F(DispatchGroupTest, single_candidate_device_served_by_that_candidate) {
+ script("", "0,cc," + std::to_string(SERVABLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core), "B");
+}
+
+// Neither candidate serves any device -> resolution fails cleanly.
+TEST_F(DispatchGroupTest, no_candidate_serves_throws) {
+ script("", "");
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ OV_EXPECT_THROW(std::ignore = resolved_tag(core), ov::Exception, ::testing::_);
+}
+
+// Two devices, opposite per-id winners: GPU.0 -> A, GPU.1 -> B, coexisting.
+TEST_F(DispatchGroupTest, per_id_routing_picks_distinct_winners) {
+ // device aa: A preferred, B capable; device bb: A servable, B preferred.
+ script("0,aa," + std::to_string(PREFERRED) + ";1,bb," + std::to_string(SERVABLE),
+ "0,aa," + std::to_string(CAPABLE) + ";1,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core, "0"), "A");
+ EXPECT_EQ(resolved_tag(core, "1"), "B");
+}
+
+// The merged canonical list has each physical device once, id-qualified.
+TEST_F(DispatchGroupTest, available_devices_merged_canonical_list) {
+ script("0,aa," + std::to_string(PREFERRED) + ";1,bb," + std::to_string(SERVABLE),
+ "0,aa," + std::to_string(CAPABLE) + ";1,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(group_devices(core), (std::vector<std::string>{device + ".0", device + ".1"}));
+}
+
+// Divergent enumeration: a device only one candidate sees still appears once, served by it.
+TEST_F(DispatchGroupTest, divergent_enumeration_non_shared_device) {
+ // Both see aa; only B sees cc (e.g. a non-Intel GPU only the OCL-like candidate lists).
+ script("0,aa," + std::to_string(PREFERRED),
+ "0,aa," + std::to_string(CAPABLE) + ";1,cc," + std::to_string(SERVABLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(group_devices(core), (std::vector<std::string>{device + ".0", device + ".1"}));
+ EXPECT_EQ(resolved_tag(core, "0"), "A"); // shared device -> higher score (A)
+ EXPECT_EQ(resolved_tag(core, "1"), "B"); // B-only device -> B
+}
+
+// cache_dir / cache_path are answered from core config, but for a dispatch group the plugin is
+// still resolved through the requested id's winner. A previous version queried the *default*
+// winner for these two names only, so an unknown id was silently served by the default device
+// instead of failing like every other property. Guard that per-id routing: an invalid id must
+// fail fast for cache_dir/cache_path too.
+TEST_F(DispatchGroupTest, cache_dir_and_cache_path_queries_route_by_id) {
+ // Two distinct physical devices with opposite winners: id 0 -> A, id 1 -> B.
+ script("0,aa," + std::to_string(PREFERRED) + ";1,bb," + std::to_string(SERVABLE),
+ "0,aa," + std::to_string(CAPABLE) + ";1,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+
+ // Valid ids resolve their winner and answer without error.
+ OV_ASSERT_NO_THROW(std::ignore = core.get_property(device + ".0", ov::cache_dir.name()));
+ OV_ASSERT_NO_THROW(std::ignore = core.get_property(device + ".1", ov::cache_dir.name()));
+ OV_ASSERT_NO_THROW(std::ignore = core.get_property(device + ".1", ov::cache_path.name()));
+
+ // An unknown id must fail fast rather than silently fall back to the default winner.
+ OV_EXPECT_THROW(std::ignore = core.get_property(device + ".99", ov::cache_dir.name()), ov::Exception, ::testing::_);
+ OV_EXPECT_THROW(std::ignore = core.get_property(device + ".99", ov::cache_path.name()),
+ ov::Exception,
+ ::testing::_);
+}
+
+// --- unload / lifetime (design 6): resolved group instances tear down cleanly ---
+
+// unload_plugin on a dispatch-group name frees the resolved instances (cached under internal
+// keys), and a subsequent request re-resolves and reloads without error.
+TEST_F(DispatchGroupTest, unload_plugin_frees_group_and_reloads) {
+ script("0,aa," + std::to_string(PREFERRED), "0,aa," + std::to_string(CAPABLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core), "A"); // constructs the winner
+ OV_ASSERT_NO_THROW(core.unload_plugin(device)); // frees it
+ EXPECT_EQ(resolved_tag(core), "A"); // re-resolves and reloads cleanly
+}
+
+// Two per-id winners coexist and both unload together via the group name.
+TEST_F(DispatchGroupTest, unload_plugin_frees_all_group_winners) {
+ script("0,aa," + std::to_string(PREFERRED) + ";1,bb," + std::to_string(SERVABLE),
+ "0,aa," + std::to_string(CAPABLE) + ";1,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core, "0"), "A"); // constructs winner A (GPU#0)
+ EXPECT_EQ(resolved_tag(core, "1"), "B"); // constructs winner B (GPU#1)
+ OV_ASSERT_NO_THROW(core.unload_plugin(device));
+ EXPECT_EQ(resolved_tag(core, "0"), "A"); // both re-resolve after unload
+ EXPECT_EQ(resolved_tag(core, "1"), "B");
+}
+
+// Repeated Core create/destroy with a resolved group must not crash or leak (RAII teardown).
+TEST_F(DispatchGroupTest, repeated_core_lifecycle_is_clean) {
+ script("0,aa," + std::to_string(PREFERRED), "0,aa," + std::to_string(CAPABLE));
+ for (int i = 0; i < 5; ++i) {
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core), "A");
+ // core goes out of scope here: both the winner instance and its .so must release.
+ }
+}
+
+// Global set_property (no device name) iterates every created plugin and locks a per-key mutex.
+// A dispatch winner is cached under an internal key ("FAKE#0"), so that key must have a mutex
+// registered or the lock lookup throws. This exercised the pre-fix crash path.
+TEST_F(DispatchGroupTest, global_set_property_after_group_resolved) {
+ script("0,aa," + std::to_string(PREFERRED), "0,aa," + std::to_string(CAPABLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core), "A"); // constructs the winner under the internal key "FAKE#0"
+ OV_ASSERT_NO_THROW(core.set_property({{"SOME_PROPERTY", "SOME_VALUE"}}));
+}
+
+// get_property(<group>, available_devices) must report core's merged canonical list, not the
+// winner library's own view, which would omit devices only another candidate sees.
+TEST_F(DispatchGroupTest, available_devices_property_reports_merged_list) {
+ script("0,aa," + std::to_string(PREFERRED),
+ "0,aa," + std::to_string(CAPABLE) + ";1,cc," + std::to_string(SERVABLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ // A wins "aa" and does not see "cc" at all; the merged list still has both devices.
+ EXPECT_EQ(core.get_property(device, ov::available_devices), std::vector<std::string>({"0", "1"}));
+}
+
+// set_property(<group>, ...) must reach the already-created winner instance, which is cached
+// under an internal key ("FAKE#N") that a bare-name comparison never matches.
+TEST_F(DispatchGroupTest, set_property_reaches_live_group_instance) {
+ script("0,aa," + std::to_string(PREFERRED), "0,aa," + std::to_string(CAPABLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core), "A"); // instance now live under "FAKE#0"
+ core.set_property(device, {{"MOCK_PROP", "SET_VIA_GROUP"}});
+ EXPECT_EQ(core.get_property(device, "MOCK_PROP").as<std::string>(), "SET_VIA_GROUP");
+}
+
+// --- canonical ids are pushed down, not translated per call (design 3.7) ---
+
+// A group member is renamed to Core's ids for every device it enumerated, so its own numbering
+// stops being observable. Here B enumerates "7" and "9"; Core exposes them as "1" and "2".
+TEST_F(DispatchGroupTest, group_member_adopts_canonical_ids) {
+ script("0,aa," + std::to_string(PREFERRED),
+ "7,bb," + std::to_string(PREFERRED) + ";9,cc," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core, "1"), "B"); // canonical "1" is B's own "7"
+ EXPECT_EQ(core.get_property(device + ".1", "MOCK_ADOPTED_IDS").as<std::vector<std::string>>(),
+ (std::vector<std::string>{"1", "2"}));
+}
+
+// The renaming must land before any property that carries a device id, or the member would apply
+// that config to whichever of its own devices happened to share the number.
+TEST_F(DispatchGroupTest, id_map_is_applied_before_any_other_property) {
+ script("0,aa," + std::to_string(PREFERRED), "7,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ core.set_property(device + ".1", {{"MOCK_PROP", "FOR_B"}});
+ EXPECT_TRUE(core.get_property(device + ".1", "MOCK_ID_MAP_APPLIED_FIRST").as<bool>());
+}
+
+// An id-qualified set_property targets that id's winner, which now answers to the canonical id.
+TEST_F(DispatchGroupTest, set_property_uses_canonical_id_for_group_winner) {
+ script("0,aa," + std::to_string(PREFERRED), "7,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core, "1"), "B"); // canonical "1" is B's own "7"
+ core.set_property(device + ".1", {{"MOCK_PROP", "FOR_B"}});
+ EXPECT_EQ(core.get_property(device + ".1", "MOCK_PROP").as<std::string>(), "FOR_B");
+ // The id handed to the plugin is the canonical one; its internal "7" never crosses the border.
+ EXPECT_EQ(core.get_property(device + ".1", ov::device::id.name()).as<std::string>(), "1");
+}
+
+// An id-qualified set_property issued before that id was ever resolved must still resolve to that
+// id's winner alone: previously it fell back to "every live group instance" carrying the id, so
+// resolving FAKE.0 first and then setting FAKE.1 misconfigured FAKE.0's winner.
+TEST_F(DispatchGroupTest, set_property_for_unresolved_id_targets_only_that_winner) {
+ script("0,aa," + std::to_string(PREFERRED), "7,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ EXPECT_EQ(resolved_tag(core, "0"), "A"); // only canonical "0" resolved so far
+ core.set_property(device + ".1", {{"MOCK_PROP", "FOR_B_ONLY"}});
+ // A (canonical "0") must not have been touched; B gets it under the canonical id.
+ EXPECT_TRUE(core.get_property(device + ".0", "MOCK_PROP").empty());
+ EXPECT_EQ(core.get_property(device + ".1", "MOCK_PROP").as<std::string>(), "FOR_B_ONLY");
+ EXPECT_EQ(core.get_property(device + ".1", ov::device::id.name()).as<std::string>(), "1");
+}
+
+// A candidate that forfeits some devices still enumerates them, so its id map must cover them.
+// Models OV_GPU_RUNTIME=ZE: OCL forfeits its Intel GPUs but still wins the non-Intel one.
+TEST_F(DispatchGroupTest, id_map_covers_devices_the_winner_scored_incompatible) {
+ // A serves cc and forfeits aa/bb; B serves bb. A's served device is enumerated first so its
+ // canonical id is "0" either way - the assertion below is then purely about map completeness.
+ script("0,cc," + std::to_string(SERVABLE) + ";1,aa," + std::to_string(INCOMPATIBLE) + ";2,bb," +
+ std::to_string(INCOMPATIBLE),
+ "0,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+
+ // A wins canonical "0" (device cc) and must be renamed for all three devices it enumerates,
+ // because it still reports all three from its own device query once constructed.
+ EXPECT_EQ(resolved_tag(core, "0"), "A");
+ EXPECT_EQ(core.get_property(device + ".0", "MOCK_ADOPTED_IDS").as<std::vector<std::string>>(),
+ (std::vector<std::string>{"0", "1", "2"}));
+ // B still wins the device it scored, unaffected.
+ EXPECT_EQ(resolved_tag(core, "2"), "B");
+}
+
+// Canonical numbering must not shift just because a candidate forfeited devices: the ids come
+// from what the candidates enumerate, not from what they are willing to serve.
+TEST_F(DispatchGroupTest, forfeited_devices_keep_their_canonical_id_but_are_not_advertised) {
+ // Device aa is forfeited by A and unseen by B, so nothing can serve it.
+ script("0,aa," + std::to_string(INCOMPATIBLE) + ";1,bb," + std::to_string(INCOMPATIBLE) + ";2,cc," +
+ std::to_string(SERVABLE),
+ "0,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+
+ // "0" (aa) keeps its slot so "1"/"2" still mean bb/cc, but it is not offered...
+ EXPECT_EQ(core.get_property(device, ov::available_devices), std::vector<std::string>({"1", "2"}));
+ // ...and asking for it fails with a message naming the id, rather than silently serving another.
+ OV_EXPECT_THROW(std::ignore = resolved_tag(core, "0"), ov::Exception, ::testing::HasSubstr(device + ".0"));
+}
+
+// A reserved slot must not make the sole remaining device unreachable. The bare name resolves to
+// canonical "0", so a group whose only servable id is not "0" must be advertised id-qualified.
+TEST_F(DispatchGroupTest, sole_servable_device_is_advertised_id_qualified_when_not_zero) {
+ // aa (canonical "0") is forfeited by A and unseen by B; only bb is servable, as canonical "1".
+ script("0,aa," + std::to_string(INCOMPATIBLE) + ";1,bb," + std::to_string(SERVABLE), "");
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+
+ // Bare "FAKE" would resolve to canonical "0", which nothing serves - so offer "FAKE.1".
+ EXPECT_EQ(group_devices(core), (std::vector<std::string>{device + ".1"}));
+ // And the advertised name must actually work.
+ EXPECT_EQ(resolved_tag(core, "1"), "A");
+}
+
+// Discovery must not throw for a group that can serve nothing: an empty merged list is the right
+// answer, exactly as for an ordinary plugin that reports no devices.
+TEST_F(DispatchGroupTest, group_serving_nothing_reports_an_empty_device_list) {
+ script("0,aa," + std::to_string(INCOMPATIBLE), "0,aa," + std::to_string(INCOMPATIBLE));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+
+ OV_ASSERT_NO_THROW(std::ignore = core.get_property(device, ov::available_devices));
+ EXPECT_TRUE(core.get_property(device, ov::available_devices).empty());
+ EXPECT_TRUE(group_devices(core).empty());
+ OV_ASSERT_NO_THROW(std::ignore = core.get_available_devices());
+}
+
+// A library that cannot adopt Core's ids cannot share a device name: it would keep naming devices
+// by its own numbering, which leaks back through contexts and execution devices.
+TEST_F(DispatchGroupTest, group_member_without_id_map_support_throws) {
+ script("0,aa," + std::to_string(SERVABLE), "0,aa," + std::to_string(PREFERRED));
+ set_env("MOCK_DISPATCH_B_NO_ID_MAP", "1");
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ OV_EXPECT_THROW(std::ignore = resolved_tag(core), ov::Exception, ::testing::HasSubstr("DISPATCH_DEVICE_ID_MAP"));
+}
+
+// Two devices of one candidate sharing a fingerprint are indistinguishable (e.g. a driver that
+// reports no PCI bus info): merging would silently drop one, so resolution must fail instead.
+TEST_F(DispatchGroupTest, duplicate_fingerprint_from_one_candidate_throws) {
+ script("0,aa," + std::to_string(PREFERRED) + ";1,aa," + std::to_string(PREFERRED),
+ "0,bb," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+ OV_EXPECT_THROW(std::ignore = resolved_tag(core), ov::Exception, ::testing::HasSubstr("same fingerprint"));
+}
+
+// --- register_plugin runtime API forms a dispatch group ---
+
+// A second register_plugin for the same device name now appends a candidate (no opt-in flag),
+// forming a group that resolves per score exactly like the plugins.xml path.
+// Only a DIFFERENT library forms a group. Re-registering the same one still throws, so callers
+// that use that throw to register idempotently keep working and never get a bogus 1-library group.
+TEST_F(DispatchGroupTest, register_plugin_same_library_twice_still_throws) {
+ script("0,aa," + std::to_string(PREFERRED), "");
+ ov::Core core;
+ core.register_plugin(candidate_lib("a").string(), device);
+ OV_EXPECT_THROW(core.register_plugin(candidate_lib("a").string(), device),
+ ov::Exception,
+ ::testing::HasSubstr("is already registered as device \"" + device + "\""));
+ // Still a single-candidate device: it resolves without any probing.
+ EXPECT_EQ(resolved_tag(core), "A");
+}
+
+// The same library re-registered under its device name must be rejected however its path is
+// spelled, or it is appended as a second candidate and the device stops resolving at all.
+TEST_F(DispatchGroupTest, register_plugin_same_library_other_spelling_still_throws) {
+ write_registry({candidate_lib("a")}); // one location, as an ordinary device is registered
+ script("0,aa," + std::to_string(PREFERRED), "");
+ ov::Core core;
+ core.register_plugins(xml_path.string());
+
+ const auto lib = candidate_lib("a");
+ {
+ // A bare name, as register_plugin is given in practice: left to the loader.
+ const CwdGuard cwd{std::filesystem::temp_directory_path()};
+ OV_EXPECT_THROW(core.register_plugin(lib.filename().string(), device),
+ ov::Exception,
+ ::testing::HasSubstr("is already registered as device \"" + device + "\""));
+ }
+ // An absolute but differently spelled path to the same file.
+ OV_EXPECT_THROW(core.register_plugin((lib.parent_path() / "." / lib.filename()).string(), device),
+ ov::Exception,
+ ::testing::HasSubstr("is already registered as device \"" + device + "\""));
+
+ // Still the plain single-candidate device it was registered as.
+ EXPECT_EQ(resolved_tag(core), "A");
+}
+
+TEST_F(DispatchGroupTest, register_plugin_appends_dispatch_group_candidate) {
+ script("0,aa," + std::to_string(SERVABLE), "0,aa," + std::to_string(PREFERRED));
+ ov::Core core;
+ core.register_plugin(candidate_lib("a").string(), device);
+ core.register_plugin(candidate_lib("b").string(), device);
+ // Both candidates present under one device name -> resolves by score (B is PREFERRED).
+ EXPECT_EQ(resolved_tag(core), "B");
+ EXPECT_EQ(group_devices(core), std::vector<std::string>{device}); // single physical device
+}
+
+// A group member that can't be scored (library present but no enumeration probe) is a hard
+// error at resolution. mock_engine exports create_plugin_engine but not the probe, so it fits.
+TEST_F(DispatchGroupTest, register_plugin_group_member_without_probe_throws) {
+ script("0,aa," + std::to_string(PREFERRED), "");
+ ov::Core core;
+ core.register_plugin(candidate_lib("a").string(), device);
+ const auto no_probe_lib =
+ ov::util::make_plugin_library_name(ov::util::make_path(ov::test::utils::getExecutableDirectory()),
+ std::string("mock_engine") + OV_BUILD_POSTFIX);
+ core.register_plugin(no_probe_lib.string(), device);
+ OV_EXPECT_THROW(std::ignore = resolved_tag(core), ov::Exception, ::testing::HasSubstr("enumeration probe"));
+}
+
+// Appending a candidate after the group has already been resolved must invalidate the cached
+// merged device list, so the next resolve re-probes the new candidate set. Here a probe-less
+// library is appended after a successful resolve; the re-probe must now hard-fail on it.
+TEST_F(DispatchGroupTest, register_plugin_append_invalidates_cached_dispatch_map) {
+ script("0,aa," + std::to_string(PREFERRED), "0,aa," + std::to_string(SERVABLE));
+ ov::Core core;
+ core.register_plugin(candidate_lib("a").string(), device);
+ core.register_plugin(candidate_lib("b").string(), device);
+ EXPECT_EQ(resolved_tag(core), "A"); // resolves and caches the {a,b} merge
+
+ const auto no_probe_lib =
+ ov::util::make_plugin_library_name(ov::util::make_path(ov::test::utils::getExecutableDirectory()),
+ std::string("mock_engine") + OV_BUILD_POSTFIX);
+ core.register_plugin(no_probe_lib.string(), device);
+ // Stale cache would still return "A"; a correctly-invalidated map re-probes and fails.
+ OV_EXPECT_THROW(std::ignore = resolved_tag(core), ov::Exception, ::testing::HasSubstr("enumeration probe"));
+}
+
+} // namespace
+} // namespace ov::test
+
+#endif // OPENVINO_STATIC_LIBRARY
diff --git a/src/inference/tests/functional/ov_register_plugin_test.cpp b/src/inference/tests/functional/ov_register_plugin_test.cpp
index dd265ecff2c..28bb539b40c 100644
--- a/src/inference/tests/functional/ov_register_plugin_test.cpp
+++ b/src/inference/tests/functional/ov_register_plugin_test.cpp
@@ -42,6 +42,24 @@ void clearMockPlugin(const std::shared_ptr<void>& m_so) {
ASSERT_TRUE(m_so);
ov::test::utils::make_std_function<void()>(m_so, "ClearTargets")();
}
+
+// InjectPlugin stores a raw pointer to a test-local plugin in a mock_engine global, so it MUST be
+// cleared before the test returns - a fatal assertion that skips it leaves the next test a dangler.
+class InjectedMockPlugin {
+public:
+ InjectedMockPlugin(ov::Core& core, std::shared_ptr<ov::IPlugin>& plugin) {
+ mockPlugin(core, plugin, m_so);
+ }
+ InjectedMockPlugin(const InjectedMockPlugin&) = delete;
+ InjectedMockPlugin& operator=(const InjectedMockPlugin&) = delete;
+ ~InjectedMockPlugin() {
+ if (m_so)
+ ov::test::utils::make_std_function<void()>(m_so, "ClearTargets")();
+ }
+
+private:
+ std::shared_ptr<void> m_so;
+};
} // namespace
TEST(RegisterPluginTests, getVersionforRegisteredPluginThrows) {
@@ -206,23 +224,34 @@ TEST_P(RegisterPluginTestP, registerNewPluginNoThrows) {
core.unload_plugin(mock_plugin_name);
}
+// Re-registering the SAME library under an existing device name still throws: only a different
+// library forms a dispatch group, so idempotent registration keeps working as before.
TEST(RegisterPluginTests, registerExistingPluginThrows) {
ov::Core core;
auto plugin = std::make_shared<ov::test::utils::MockPlugin>();
std::shared_ptr<ov::IPlugin> base_plugin = plugin;
- std::shared_ptr<void> m_so;
- mockPlugin(core, base_plugin, m_so);
+ InjectedMockPlugin injected(core, base_plugin);
+ const auto lib = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
+ std::string("mock_engine") + OV_BUILD_POSTFIX);
std::string mock_plugin_name{"MOCK_HARDWARE"};
- OV_ASSERT_NO_THROW(
- core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
- std::string("mock_engine") + OV_BUILD_POSTFIX),
- mock_plugin_name));
- ASSERT_THROW(core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
- std::string("mock_engine") + OV_BUILD_POSTFIX),
- mock_plugin_name),
- ov::Exception);
- clearMockPlugin(m_so);
+ OV_ASSERT_NO_THROW(core.register_plugin(lib, mock_plugin_name));
+ OV_EXPECT_THROW(core.register_plugin(lib, mock_plugin_name),
+ ov::Exception,
+ ::testing::HasSubstr("is already registered as device \"" + mock_plugin_name + "\""));
+}
+
+// A dispatch group caches its resolved member under "<device>#<candidate>", so a device literally
+// named that way would share the instance slot. Both separators are rejected in a device name.
+TEST(RegisterPluginTests, registerPluginWithReservedSymbolInNameThrows) {
+ ov::Core core;
+ const auto lib = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
+ std::string("mock_engine") + OV_BUILD_POSTFIX);
+ for (const std::string name : {"MOCK_HARDWARE#1", "MOCK_HARDWARE.1"}) {
+ OV_EXPECT_THROW(core.register_plugin(lib, name),
+ ov::Exception,
+ ::testing::HasSubstr("Device name must not contain"));
+ }
}
inline std::string getPluginFile() {
diff --git a/src/inference/tests/unit/core.cpp b/src/inference/tests/unit/core.cpp
index 97468911504..bc510a6b7f7 100644
--- a/src/inference/tests/unit/core.cpp
+++ b/src/inference/tests/unit/core.cpp
@@ -19,12 +19,12 @@
namespace ov::test {
-TEST(CoreTests, Throw_on_register_plugin_twice) {
+TEST(CoreTests, register_plugin_twice_appends_dispatch_group_candidate) {
+ // register_plugin under an already-registered name appends a candidate (forming a group)
+ // rather than throwing. Registration is lazy; group resolution is covered by functional tests.
ov::Core core;
core.register_plugin("test_plugin", "TEST_DEVICE");
- OV_EXPECT_THROW(core.register_plugin("test_plugin", "TEST_DEVICE"),
- ov::Exception,
- ::testing::HasSubstr("Device with \"TEST_DEVICE\" is already registered in the OpenVINO Runtime"));
+ OV_ASSERT_NO_THROW(core.register_plugin("test_plugin_2", "TEST_DEVICE"));
}
TEST(CoreTests, Throw_on_register_plugins_twice) {
@@ -50,6 +50,95 @@ TEST(CoreTests, Throw_on_register_plugins_twice) {
}
}
+namespace {
+// Writes `content` to a uniquely-named plugins.xml and returns its path.
+std::filesystem::path write_plugins_xml(const std::string& file_name, const std::string& content) {
+ std::filesystem::path plugins_xml = ov::test::utils::generateTestFilePrefix() + "_" + file_name;
+ std::ofstream file(plugins_xml);
+ file << content;
+ file.flush();
+ file.close();
+ return plugins_xml;
+}
+} // namespace
+
+// Legacy single "location" attribute -> exactly one candidate (byte-for-byte the old path).
+TEST(CoreTests_dispatch_group, Legacy_location_attribute_is_single_candidate) {
+ ov::CoreImpl core;
+ const auto xml = write_plugins_xml(
+ "test_single_candidate.xml",
+ "<ie><plugins><plugin location=\"libtest_plugin.so\" name=\"TEST_DEVICE\"></plugin></plugins></ie>");
+
+ core.register_plugins_in_registry(xml, false);
+ EXPECT_EQ(core.get_registered_candidate_count("TEST_DEVICE"), 1u);
+
+ if (ov::util::file_exists(xml)) {
+ std::ignore = std::filesystem::remove(xml);
+ }
+}
+
+// Two ordered <location> children -> a 2-candidate dispatch group (order preserved).
+TEST(CoreTests_dispatch_group, Two_location_children_is_dispatch_group) {
+ ov::CoreImpl core;
+ const auto xml = write_plugins_xml("test_dispatch_group.xml",
+ "<ie><plugins>"
+ "<plugin name=\"TEST_DEVICE\">"
+ "<location>libtest_plugin_a.so</location>"
+ "<location>libtest_plugin_b.so</location>"
+ "</plugin>"
+ "</plugins></ie>");
+
+ core.register_plugins_in_registry(xml, false);
+ EXPECT_EQ(core.get_registered_candidate_count("TEST_DEVICE"), 2u);
+
+ if (ov::util::file_exists(xml)) {
+ std::ignore = std::filesystem::remove(xml);
+ }
+}
+
+// A single <location> child is equivalent to the legacy attribute: one candidate.
+TEST(CoreTests_dispatch_group, Single_location_child_is_single_candidate) {
+ ov::CoreImpl core;
+ const auto xml = write_plugins_xml("test_single_location_child.xml",
+ "<ie><plugins>"
+ "<plugin name=\"TEST_DEVICE\">"
+ "<location>libtest_plugin.so</location>"
+ "</plugin>"
+ "</plugins></ie>");
+
+ core.register_plugins_in_registry(xml, false);
+ EXPECT_EQ(core.get_registered_candidate_count("TEST_DEVICE"), 1u);
+
+ if (ov::util::file_exists(xml)) {
+ std::ignore = std::filesystem::remove(xml);
+ }
+}
+
+// Mixing the "location" attribute and <location> children is rejected.
+TEST(CoreTests_dispatch_group, Mixed_location_forms_throw) {
+ ov::CoreImpl core;
+ const auto xml = write_plugins_xml("test_mixed_location.xml",
+ "<ie><plugins>"
+ "<plugin location=\"libtest_plugin.so\" name=\"TEST_DEVICE\">"
+ "<location>libtest_plugin_b.so</location>"
+ "</plugin>"
+ "</plugins></ie>");
+
+ OV_EXPECT_THROW(core.register_plugins_in_registry(xml, false),
+ ov::Exception,
+ ::testing::HasSubstr("both a \"location\" attribute and <location> child elements"));
+
+ if (ov::util::file_exists(xml)) {
+ std::ignore = std::filesystem::remove(xml);
+ }
+}
+
+// An unregistered device name reports zero candidates.
+TEST(CoreTests_dispatch_group, Unregistered_device_has_zero_candidates) {
+ ov::CoreImpl core;
+ EXPECT_EQ(core.get_registered_candidate_count("NOT_REGISTERED"), 0u);
+}
+
TEST(CoreTests_get_plugin_path_from_xml, Use_abs_path_as_is) {
auto xml_path = std::filesystem::path("path_to_plugins.xml");
auto lib_path = std::filesystem::absolute("test_name.ext"); // CWD/test_name.ext
diff --git a/src/plugins/auto/src/plugin.cpp b/src/plugins/auto/src/plugin.cpp
index c2bdfcc6dd7..71ca2c0c569 100644
--- a/src/plugins/auto/src/plugin.cpp
+++ b/src/plugins/auto/src/plugin.cpp
@@ -360,6 +360,9 @@ static const ov::Version version = {CI_BUILD_NUMBER, "openvino_auto_plugin"};
OV_DEFINE_PLUGIN_CREATE_FUNCTION(ov::auto_plugin::Plugin, version)
// ! [plugin:create_plugin_engine]
+// This plugin does not participate in device-name dispatch; export the probe as a stub.
+OV_DEFINE_PLUGIN_ENUMERATE_STUB()
+
Plugin::Plugin() {
set_device_name("AUTO");
}
diff --git a/src/plugins/auto_batch/src/plugin.cpp b/src/plugins/auto_batch/src/plugin.cpp
index c4e1cbac77e..957ed67baeb 100644
--- a/src/plugins/auto_batch/src/plugin.cpp
+++ b/src/plugins/auto_batch/src/plugin.cpp
@@ -115,6 +115,9 @@ void Plugin::set_property(const ov::AnyMap& properties) {
static const ov::Version version = {CI_BUILD_NUMBER, "openvino_auto_batch_plugin"};
OV_DEFINE_PLUGIN_CREATE_FUNCTION(Plugin, version)
+// This plugin does not participate in device-name dispatch; export the probe as a stub.
+OV_DEFINE_PLUGIN_ENUMERATE_STUB()
+
Plugin::Plugin() {
set_device_name("BATCH");
m_plugin_config.insert(ov::auto_batch_timeout(1000)); // default value (ms)
diff --git a/src/plugins/hetero/src/version.cpp b/src/plugins/hetero/src/version.cpp
index c0b07bb1098..74cce597f3b 100644
--- a/src/plugins/hetero/src/version.cpp
+++ b/src/plugins/hetero/src/version.cpp
@@ -5,4 +5,7 @@
#include "plugin.hpp"
static const ov::Version version = {CI_BUILD_NUMBER, "openvino_hetero_plugin"};
-OV_DEFINE_PLUGIN_CREATE_FUNCTION(ov::hetero::Plugin, version)
\ No newline at end of file
+OV_DEFINE_PLUGIN_CREATE_FUNCTION(ov::hetero::Plugin, version)
+
+// This plugin does not participate in device-name dispatch; export the probe as a stub.
+OV_DEFINE_PLUGIN_ENUMERATE_STUB()
\ No newline at end of file
diff --git a/src/plugins/intel_cpu/src/plugin.cpp b/src/plugins/intel_cpu/src/plugin.cpp
index 03d89ef02b2..b6f070e5e9b 100644
--- a/src/plugins/intel_cpu/src/plugin.cpp
+++ b/src/plugins/intel_cpu/src/plugin.cpp
@@ -919,3 +919,6 @@ static const ov::Version version = {CI_BUILD_NUMBER, "openvino_riscv_cpu_plugin"
#endif
OV_DEFINE_PLUGIN_CREATE_FUNCTION(Plugin, version)
+
+// This plugin does not participate in device-name dispatch; export the probe as a stub.
+OV_DEFINE_PLUGIN_ENUMERATE_STUB()
diff --git a/src/plugins/intel_gpu/CMakeLists.txt b/src/plugins/intel_gpu/CMakeLists.txt
index 1c1bb25d359..9096ee965ca 100644
--- a/src/plugins/intel_gpu/CMakeLists.txt
+++ b/src/plugins/intel_gpu/CMakeLists.txt
@@ -135,10 +135,6 @@ if(ENABLE_MLIR_FOR_GPU)
add_compile_definitions(ENABLE_MLIR_FOR_GPU)
endif()
-add_subdirectory(src/runtime)
-add_subdirectory(src/kernel_selector)
-add_subdirectory(src/graph)
-
file(GLOB_RECURSE PLUGIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/include/intel_gpu/plugin/*.hpp)
# MLIR sources are always excluded from the main plugin target. When
@@ -149,74 +145,110 @@ set(OV_GPU_MLIR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/transformations/mlir)
file(GLOB_RECURSE GPU_MLIR_SOURCES ${OV_GPU_MLIR_DIR}/*.cpp)
list(REMOVE_ITEM PLUGIN_SOURCES ${GPU_MLIR_SOURCES})
+# Fetches GraphCompiler, so it must run once rather than once per stack.
if(ENABLE_MLIR_FOR_GPU)
include(thirdparty/cmake/graph-compiler.cmake)
-
- set(mlir_lib openvino_intel_gpu_mlir_obj)
- add_library(${mlir_lib} OBJECT ${GPU_MLIR_SOURCES})
- target_link_libraries(${mlir_lib} PRIVATE openvino::runtime openvino_intel_gpu_graph GraphCompiler)
- target_include_directories(${mlir_lib} PRIVATE
- ${CMAKE_CURRENT_SOURCE_DIR}/include/
- ${OV_GPU_MLIR_DIR})
- # Not created via ov_add_plugin, so clang-tidy has to be applied explicitly.
- ov_apply_clang_tidy(TARGET ${mlir_lib})
-
- set(GPU_PLUGIN_OBJECT_LIBRARIES ${mlir_lib})
- set(GPU_PLUGIN_OPTIONS LINKABLE)
endif()
-ov_add_plugin(NAME ${TARGET_NAME}
- DEVICE_NAME "GPU"
- SOURCES ${PLUGIN_SOURCES}
- OBJECT_LIBRARIES ${GPU_PLUGIN_OBJECT_LIBRARIES}
- ${GPU_PLUGIN_OPTIONS}
- DEFAULT_CONFIG ${PLUGIN_DEFAULT_CONFIG}
- VERSION_DEFINES_FOR src/plugin/plugin.cpp
- # ADD_CLANG_TIDY makes ov_add_plugin apply clang-tidy to this target.
- # Libraries not created via ov_add_plugin call ov_apply_clang_tidy() directly.
- ADD_CLANG_TIDY)
-
-target_compile_options(${TARGET_NAME} PRIVATE
- $<$<CONFIG:Release>:$<IF:$<CXX_COMPILER_ID:MSVC>,/Os,-Os>>)
-
-target_link_libraries(${TARGET_NAME} PRIVATE openvino_intel_gpu_graph openvino::pugixml)
-
-# Unloading a .so with SYCL code is unsafe in two ways:
-# 1. libsycl.so drops the kernel name index on unregister, so kernels provided
-# by another loaded module go missing.
-# 2. libsycl.so's static destructor touches vtables (e.g., SYCLMemObjAllocatorHolder)
-# emitted in the unloaded module at process exit (observed on an NVIDIA backend).
-# Mark the plugin NODELETE so it is never unloaded.
-if(OV_GPU_WITH_SYCL AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
- target_link_options(${TARGET_NAME} PRIVATE "LINKER:-z,nodelete")
-endif()
+# Build one full GPU stack (runtime + kernel_selector + graph + plugin) for runtime RT_TYPE.
+# SUFFIX distinguishes a COMBINED build's two stacks (empty for the ZE/default twin, "_ocl"
+# for the OCL twin) and single-RT builds (empty). MODULE_NAME is the plugin library name.
+# EXTRA_PLUGIN_ARGS are forwarded to ov_add_plugin (e.g. DISPATCH_GROUP for COMBINED).
+function(ov_gpu_build_stack RT_TYPE SUFFIX MODULE_NAME)
+ set(OV_GPU_RT "${RT_TYPE}")
+ set(OV_GPU_SUFFIX "${SUFFIX}")
+
+ # Distinct binary dirs so the same source dirs can be added twice in a COMBINED build.
+ add_subdirectory(src/runtime runtime${SUFFIX})
+ add_subdirectory(src/kernel_selector kernel_selector${SUFFIX})
+ add_subdirectory(src/graph graph${SUFFIX})
+
+ # MLIR runs on OpenCL only: ocl_stream is the sole implementer of the ENABLE_MLIR_FOR_GPU
+ # stream hooks, so a COMBINED build gives the backend to the OCL twin alone.
+ set(stack_with_mlir ${ENABLE_MLIR_FOR_GPU})
+ if(GPU_RT_TYPE STREQUAL "COMBINED" AND NOT RT_TYPE STREQUAL "OCL")
+ set(stack_with_mlir OFF)
+ endif()
-target_include_directories(${TARGET_NAME} PRIVATE
- ${CMAKE_CURRENT_SOURCE_DIR}/include/)
+ # One per stack: the objects link this stack's graph library, so a COMBINED build cannot
+ # share a single target between the twins.
+ if(stack_with_mlir)
+ set(mlir_lib openvino_intel_gpu_mlir_obj${SUFFIX})
+ add_library(${mlir_lib} OBJECT ${GPU_MLIR_SOURCES})
+ target_link_libraries(${mlir_lib} PRIVATE openvino::runtime openvino_intel_gpu_graph${SUFFIX} GraphCompiler)
+ target_include_directories(${mlir_lib} PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/
+ ${OV_GPU_MLIR_DIR})
+ # Not created via ov_add_plugin, so clang-tidy has to be applied explicitly.
+ ov_apply_clang_tidy(TARGET ${mlir_lib})
+
+ set(GPU_PLUGIN_OBJECT_LIBRARIES ${mlir_lib})
+ set(GPU_PLUGIN_OPTIONS LINKABLE)
+ endif()
-if(ENABLE_MLIR_FOR_GPU)
- target_link_libraries(${TARGET_NAME} PRIVATE GraphCompiler)
- # Per target, unlike ENABLE_MLIR_FOR_GPU: must be defined by everyone linking
- # openvino_intel_gpu_mlir_obj, since only it provides mlir::transformMLIR().
- # Workaround to fix tests build: ov_gpu_unit_tests '#includes transformations_pipeline.cpp'
- # (xattention_kv_cache_transform_test.cpp) but links neither the MLIR objects nor the plugin's
- # hidden symbols, so guarding the call with ENABLE_MLIR_FOR_GPU alone breaks that link with an
- # undefined reference to transformMLIR().
- target_compile_definitions(${TARGET_NAME} PRIVATE OV_GPU_MLIR_BACKEND_LINKED)
-endif()
+ ov_add_plugin(NAME ${MODULE_NAME}
+ DEVICE_NAME "GPU"
+ SOURCES ${PLUGIN_SOURCES}
+ OBJECT_LIBRARIES ${GPU_PLUGIN_OBJECT_LIBRARIES}
+ ${GPU_PLUGIN_OPTIONS}
+ DEFAULT_CONFIG ${PLUGIN_DEFAULT_CONFIG}
+ VERSION_DEFINES_FOR src/plugin/plugin.cpp
+ # ADD_CLANG_TIDY makes ov_add_plugin apply clang-tidy to this target.
+ # Libraries not created via ov_add_plugin call ov_apply_clang_tidy() directly.
+ ADD_CLANG_TIDY
+ ${ARGN})
+
+ target_compile_options(${MODULE_NAME} PRIVATE
+ $<$<CONFIG:Release>:$<IF:$<CXX_COMPILER_ID:MSVC>,/Os,-Os>>)
+
+ # Unloading a .so with SYCL code is unsafe in two ways:
+ # 1. libsycl.so drops the kernel name index on unregister, so kernels provided
+ # by another loaded module go missing.
+ # 2. libsycl.so's static destructor touches vtables (e.g., SYCLMemObjAllocatorHolder)
+ # emitted in the unloaded module at process exit (observed on an NVIDIA backend).
+ # Mark the plugin NODELETE so it is never unloaded.
+ if(OV_GPU_WITH_SYCL AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ target_link_options(${MODULE_NAME} PRIVATE "LINKER:-z,nodelete")
+ endif()
-ov_set_threading_interface_for(${TARGET_NAME})
-ov_gpu_set_runtime_interface_for(${TARGET_NAME})
+ target_link_libraries(${MODULE_NAME} PRIVATE openvino_intel_gpu_graph${SUFFIX} openvino::pugixml)
+
+ if(stack_with_mlir)
+ target_link_libraries(${MODULE_NAME} PRIVATE GraphCompiler)
+ # Per target, unlike ENABLE_MLIR_FOR_GPU: must be defined by everyone linking
+ # openvino_intel_gpu_mlir_obj, since only it provides mlir::transformMLIR().
+ # Workaround to fix tests build: ov_gpu_unit_tests '#includes transformations_pipeline.cpp'
+ # (xattention_kv_cache_transform_test.cpp) but links neither the MLIR objects nor the plugin's
+ # hidden symbols, so guarding the call with ENABLE_MLIR_FOR_GPU alone breaks that link with an
+ # undefined reference to transformMLIR().
+ target_compile_definitions(${MODULE_NAME} PRIVATE OV_GPU_MLIR_BACKEND_LINKED)
+ endif()
-set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
+ target_include_directories(${MODULE_NAME} PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/)
-# Workaround to avoid warnings during LTO build
-if(CMAKE_COMPILER_IS_GNUCXX)
- set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_RELEASE "-Wno-error=maybe-uninitialized -Wno-maybe-uninitialized -Wno-stringop-overflow"
- LINK_FLAGS_RELWITHDEBINFO "-Wno-error=maybe-uninitialized -Wno-maybe-uninitialized -Wno-stringop-overflow")
-endif()
+ ov_set_threading_interface_for(${MODULE_NAME})
+ ov_gpu_set_runtime_interface_for(${MODULE_NAME} RUNTIME ${RT_TYPE})
+
+ set_target_properties(${MODULE_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
-ov_build_target_faster(${TARGET_NAME} PCH)
+ # Workaround to avoid warnings during LTO build
+ if(CMAKE_COMPILER_IS_GNUCXX)
+ set_target_properties(${MODULE_NAME} PROPERTIES LINK_FLAGS_RELEASE "-Wno-error=maybe-uninitialized -Wno-maybe-uninitialized -Wno-stringop-overflow"
+ LINK_FLAGS_RELWITHDEBINFO "-Wno-error=maybe-uninitialized -Wno-maybe-uninitialized -Wno-stringop-overflow")
+ endif()
+
+ ov_build_target_faster(${MODULE_NAME} PCH)
+endfunction()
+
+if(GPU_RT_TYPE STREQUAL "COMBINED")
+ # Two libraries under one device name (a dispatch group). OCL is registered first so the merged
+ # device ids follow its enumeration, as today; ZE keeps the default-named targets tests link.
+ ov_gpu_build_stack(OCL "_ocl" ${TARGET_NAME}_ocl DISPATCH_GROUP)
+ ov_gpu_build_stack(ZE "" ${TARGET_NAME} DISPATCH_GROUP)
+else()
+ ov_gpu_build_stack(${GPU_RT_TYPE} "" ${TARGET_NAME})
+endif()
if(ENABLE_TESTS)
add_subdirectory(tests)
diff --git a/src/plugins/intel_gpu/README.md b/src/plugins/intel_gpu/README.md
index 7640fbd2e8a..46917fa21f0 100644
--- a/src/plugins/intel_gpu/README.md
+++ b/src/plugins/intel_gpu/README.md
@@ -29,6 +29,7 @@ GPU Plugin contains the following components:
* [GPU plugin operations enabling flow](./docs/gpu_plugin_ops_enabling.md)
* [GPU plugin unit test](./docs/gpu_plugin_unit_test.md)
* [Run benchmark from device_mem](./docs/use_device_mem.md)
+* [GPU dual-runtime dispatch (COMBINED build)](./docs/gpu_dual_runtime_dispatch.md)
## Documentation on dynamic-shape
This contents explain the internal implementation of dynamic shape support in the GPU Plugin. For general usage of dynamic shape and limitations of the GPU plugin, please refer to this link: [GPU Device — OpenVINO™ documentation - Version(2026)](https://docs.openvino.ai/2026/openvino-workflow/running-inference/inference-devices-and-modes/gpu-device.html#dynamic-shapes).
diff --git a/src/plugins/intel_gpu/cmake/utils.cmake b/src/plugins/intel_gpu/cmake/utils.cmake
index 2d5bdb8037a..7cb61a9e0ed 100644
--- a/src/plugins/intel_gpu/cmake/utils.cmake
+++ b/src/plugins/intel_gpu/cmake/utils.cmake
@@ -2,16 +2,27 @@
# SPDX-License-Identifier: Apache-2.0
#
+# Applies the runtime-specific compile defs / link libs to a target. The runtime defaults to
+# the global GPU_RT_TYPE, but a COMBINED build passes an explicit RUNTIME per twin ("ZE"/"OCL")
+# so both stacks can be configured in one pass. COMBINED itself is never a per-target runtime.
function(ov_gpu_set_runtime_interface_for TARGET_NAME)
- if(GPU_RT_TYPE STREQUAL "ZE")
+ set(oneValueArgs RUNTIME)
+ cmake_parse_arguments(ARG "" "${oneValueArgs}" "" ${ARGN})
+ if(ARG_RUNTIME)
+ set(runtime "${ARG_RUNTIME}")
+ else()
+ set(runtime "${GPU_RT_TYPE}")
+ endif()
+
+ if(runtime STREQUAL "ZE")
target_compile_definitions(${TARGET_NAME} PRIVATE OV_GPU_WITH_ZE_RT=1)
target_link_libraries(${TARGET_NAME} PRIVATE openvino::zero_loader OpenCL::OpenCL)
- elseif(GPU_RT_TYPE STREQUAL "OCL")
+ elseif(runtime STREQUAL "OCL")
target_compile_definitions(${TARGET_NAME} PRIVATE OV_GPU_WITH_OCL_RT=1)
target_link_libraries(${TARGET_NAME} PRIVATE OpenCL::OpenCL)
- elseif(GPU_RT_TYPE STREQUAL "SYCL")
+ elseif(runtime STREQUAL "SYCL")
target_compile_definitions(${TARGET_NAME} PRIVATE OV_GPU_WITH_SYCL_RT=1)
else()
- message(FATAL_ERROR "Invalid GPU runtime type: `${GPU_RT_TYPE}` Only `ZE`, `OCL` and `SYCL` are supported")
+ message(FATAL_ERROR "Invalid GPU runtime type: `${runtime}` Only `ZE`, `OCL` and `SYCL` are supported")
endif()
endfunction()
diff --git a/src/plugins/intel_gpu/docs/gpu_dual_runtime_dispatch.md b/src/plugins/intel_gpu/docs/gpu_dual_runtime_dispatch.md
new file mode 100644
index 00000000000..86eef0e90f8
--- /dev/null
+++ b/src/plugins/intel_gpu/docs/gpu_dual_runtime_dispatch.md
@@ -0,0 +1,77 @@
+# GPU dual-runtime dispatch (COMBINED build)
+
+The GPU plugin can be built for a single compute runtime (OpenCL or Level Zero), selected
+at compile time by `GPU_RT_TYPE`. It can also be built in a **COMBINED** mode that ships
+**both** runtime libraries side by side under the single public device name `GPU` and picks
+the right one **per physical device at runtime**.
+
+This is an opt-in build. **The default build is unchanged**: without `-DGPU_RT_TYPE`, the
+plugin is built single-runtime OpenCL as before, producing one library
+`openvino_intel_gpu_plugin`.
+
+## How to build
+
+```sh
+cmake -DGPU_RT_TYPE=COMBINED -DBUILD_SHARED_LIBS=ON <other options> ..
+cmake --build . --config Release
+```
+
+`COMBINED` requires `BUILD_SHARED_LIBS=ON` (it ships two plugin libraries via `plugins.xml`);
+a static build with `COMBINED` fails fast at configure time. Building it produces two
+libraries:
+
+- `openvino_intel_gpu_plugin_ocl` — the OpenCL (OCL) build (listed first);
+- `openvino_intel_gpu_plugin` — the Level Zero (ZE) build.
+
+Both are shipped in the `gpu` package/component, and `plugins.xml` registers them under one
+device name, in that order:
+
+```xml
+<plugin name="GPU">
+ <location>libopenvino_intel_gpu_plugin_ocl.so</location>
+ <location>libopenvino_intel_gpu_plugin.so</location>
+</plugin>
+```
+
+The order matters for **numbering**: `GPU.0`, `GPU.1`, … are assigned in the order the
+libraries enumerate devices, first library first. OCL is listed first so the numbering matches
+a single-runtime OCL build for every device OpenCL can see, and a `COMBINED` install does not
+renumber the GPUs your scripts already address. Devices only Level Zero enumerates are appended
+after. Order does not affect *which* runtime is chosen — that is decided per device by score.
+If scores tie, Core keeps its registry order and the first-listed library wins; the current
+OCL/ZE score table cannot produce a tie.
+
+Single-runtime builds (`-DGPU_RT_TYPE=OCL` / `ZE` / `SYCL`) are unaffected and keep the
+single-`location` registration.
+
+## How a runtime is chosen per device
+
+`ov::Core` asks each library which devices it can serve and how well, via a lightweight
+enumeration probe (no engine is constructed), then picks the best-scoring library per device:
+
+- **Level Zero** is preferred on **Xe2 and newer** GPUs that support ZE↔OCL interop
+ (`supports_leo`) — the better runtime there, without breaking OpenCL-interop applications.
+- **OpenCL** serves everything else: pre-Xe2 Intel GPUs (better runtime there), Xe2+ GPUs
+ whose driver lacks interop, and all non-Intel GPUs. Level Zero is never selected for a
+ non-Intel GPU.
+
+Different physical GPUs in one system can therefore resolve to different runtimes (e.g.
+`GPU.0` → ZE, `GPU.1` → OCL); both plugin instances coexist in the process.
+
+## Forcing a runtime for debugging
+
+Set `OV_GPU_RUNTIME=OCL` or `OV_GPU_RUNTIME=ZE` to force a runtime for Intel GPUs, bypassing
+the automatic selection. It is an environment variable rather than a config property because the
+enumeration probe reads it before any plugin config exists, and it works in a regular build. An
+unrecognized value is ignored, and it can never attach Level Zero to a non-Intel GPU.
+
+An Intel GPU that the forced runtime cannot serve becomes **unavailable** while the variable is
+set: it is dropped from `available_devices` and addressing it reports that no library can serve
+it. Its `GPU.N` slot is still reserved, so the override never renumbers the other GPUs.
+
+## On-disk cache
+
+The compile-time runtime tag (`OCL`/`ZE`/`SYCL`) is part of the key of every on-disk GPU
+cache (model blob, kernel `.cl_cache`, oneDNN `.onednn.cl_cache`), so OpenCL and Level Zero
+never share a cache file and a binary compiled by one runtime is never loaded by the other.
+Both runtimes' caches persist in `cache_dir` and are independently reusable.
diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/compiled_model.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/compiled_model.hpp
index 17e933f182c..96131dfb23b 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/plugin/compiled_model.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/compiled_model.hpp
@@ -58,7 +58,8 @@ public:
// Version of the runtime requirements descriptor persisted in the blob. Bump this whenever
// build_runtime_requirements() changes (its format or the fields it emits) so the importer
// can detect and reject descriptors produced by a different build.
- static constexpr uint32_t runtime_requirements_version = 1;
+ // v2: added the compile-time runtime tag (rt=) to partition OCL/ZE blobs.
+ static constexpr uint32_t runtime_requirements_version = 2;
// Magic marker that prefixes the compatibility-descriptor block in the exported blob, letting
// the importer reject blobs that lack it (e.g. produced by an OpenVINO build predating this
diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp
index c694accfd2e..58a42a265ac 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/plugin.hpp
@@ -25,6 +25,9 @@ private:
std::map<std::string, std::shared_ptr<RemoteContextImpl>> get_default_contexts() const;
+ // Rename our enumerated devices to the ids Core assigned (ov::internal::device_id_map).
+ void apply_device_id_map(const std::map<std::string, std::string>& id_map);
+
std::shared_ptr<ov::Model> clone_and_transform_model(const std::shared_ptr<const ov::Model>& network,
ExecutionConfig& config,
const std::shared_ptr<RemoteContextImpl>& context) const;
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/device_query.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/device_query.hpp
index 760b7daf317..81cac2e791f 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/device_query.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/device_query.hpp
@@ -10,6 +10,7 @@
#include <map>
#include <string>
#include <algorithm>
+#include <vector>
namespace cldnn {
@@ -41,4 +42,15 @@ public:
private:
std::map<std::string, device::ptr> _available_devices;
};
+
+// One device seen by the lightweight enumeration below.
+struct lightweight_device {
+ std::string map_id; ///< Detector's own id for the device (this library's ".N").
+ device_info info; ///< Device info populated without engine/context construction.
+};
+
+// Cheap device enumeration for pre-construction dispatch: lists the devices this build's
+// runtime can serve with device_info populated, WITHOUT building an engine/context.
+std::vector<lightweight_device> lightweight_enumerate() noexcept;
+
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/dispatch_probe.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/dispatch_probe.hpp
new file mode 100644
index 00000000000..cad4d1b407c
--- /dev/null
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/dispatch_probe.hpp
@@ -0,0 +1,25 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cstdint>
+#include <string_view>
+#include <vector>
+
+#include "device_info.hpp"
+#include "engine_configuration.hpp"
+#include "openvino/runtime/iplugin.hpp"
+
+namespace cldnn {
+
+// Opaque cross-runtime device identity: PCI-BDF + vendor id + sub-device index, the fields both
+// stacks populate identically. UUID is excluded - ZE sets it while legacy OCL zero-fills it.
+std::vector<uint8_t> make_fingerprint(const device_info& info);
+
+// The dispatch-group score runtime 'rt' reports for a device. 'forced_rt' is the raw
+// OV_GPU_RUNTIME value; only "OCL"/"ZE" override, and never for a non-Intel device.
+ov::DeviceCompatibilityScore probe_score(runtime_types rt, const device_info& info, std::string_view forced_rt) noexcept;
+
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/engine_configuration.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/engine_configuration.hpp
index 8854c9f4061..009c2eff386 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/engine_configuration.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/engine_configuration.hpp
@@ -5,6 +5,7 @@
#pragma once
#include <ostream>
+#include <string_view>
namespace cldnn {
@@ -70,4 +71,12 @@ engine_types get_default_engine_type();
/// @brief Get default runtime type
runtime_types get_default_runtime_type();
+// Stable string tag for a runtime type ("OCL"/"ZE"/"SYCL"), used to partition on-disk
+// caches per runtime. This is a COMPATIBILITY CONSTANT: changing a returned value
+// invalidates every existing GPU cache keyed with the old value.
+std::string_view to_cache_tag(runtime_types type);
+
+// to_cache_tag(get_default_runtime_type()) for this build.
+std::string_view get_runtime_cache_tag();
+
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp
index 3198366a46c..ca4e2e85782 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp
@@ -23,6 +23,13 @@ static constexpr Property<std::string, PropertyMutability::RO> driver_version{"G
*/
static constexpr Property<std::string, PropertyMutability::RO> device_id{"GPU_DEVICE_ID"};
+/**
+ * @brief Read-only property carrying the compile-time GPU runtime tag ("OCL"/"ZE"/"SYCL").
+ * Folded into the model cache key so OCL and ZE builds never share a cache blob.
+ * The key string is a cache-compatibility constant - do not rename across releases.
+ */
+static constexpr Property<std::string, PropertyMutability::RO> runtime_type{"GPU_RUNTIME_TYPE"};
+
enum class QueueTypes : int16_t {
in_order,
out_of_order
diff --git a/src/plugins/intel_gpu/src/graph/CMakeLists.txt b/src/plugins/intel_gpu/src/graph/CMakeLists.txt
index 7a19ab6a5e7..11cc216f333 100644
--- a/src/plugins/intel_gpu/src/graph/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/graph/CMakeLists.txt
@@ -2,7 +2,15 @@
# SPDX-License-Identifier: Apache-2.0
#
-set(TARGET_NAME "openvino_intel_gpu_graph")
+set(TARGET_NAME "openvino_intel_gpu_graph${OV_GPU_SUFFIX}")
+if(NOT DEFINED OV_GPU_RT)
+ # Reachable only if this directory is added outside ov_gpu_build_stack(), which always sets a
+ # single runtime; COMBINED names two, so a stack built from it would belong to neither.
+ if(GPU_RT_TYPE STREQUAL "COMBINED")
+ message(FATAL_ERROR "OV_GPU_RT must be set to a single runtime before adding this directory; got COMBINED")
+ endif()
+ set(OV_GPU_RT "${GPU_RT_TYPE}")
+endif()
if(ENABLE_CM_FOR_GPU)
add_compile_definitions(ENABLE_CM_FOR_GPU)
@@ -33,15 +41,15 @@ set(COMMON_INCLUDE_DIRS $<BUILD_INTERFACE:${MAIN_DIR}/src>
)
set(COMMON_LINK_LIBRARIES openvino::shape_inference # for tensor accessor
- openvino_intel_gpu_kernels # for cl_kernel_data_serializer
- openvino_intel_gpu_runtime
+ openvino_intel_gpu_kernels${OV_GPU_SUFFIX} # for cl_kernel_data_serializer
+ openvino_intel_gpu_runtime${OV_GPU_SUFFIX}
openvino::itt
openvino::runtime::dev
openvino::runtime
OpenCL::OpenCL # Onednn needs OCL headers even when running Level Zero
)
-if(GPU_RT_TYPE STREQUAL "ZE")
+if(OV_GPU_RT STREQUAL "ZE")
# Onednn needs ZE headers
list(APPEND COMMON_LINK_LIBRARIES openvino::zero_loader)
endif()
@@ -88,12 +96,12 @@ macro(ov_gpu_add_backend_target)
target_compile_options(${TARGET_NAME} PRIVATE ${COMMON_COMPILE_OPTIONS})
target_compile_definitions(${TARGET_NAME} PRIVATE ${TARGET_DEFINITIONS})
ov_set_threading_interface_for(${TARGET_NAME})
- ov_gpu_set_runtime_interface_for(${TARGET_NAME})
+ ov_gpu_set_runtime_interface_for(${TARGET_NAME} RUNTIME ${OV_GPU_RT})
# We use onednn headers all over the graph module, so we have to append includes to all backends and add a dependency between targets
if (ENABLE_ONEDNN_FOR_GPU)
- target_include_directories(${ARG_NAME} SYSTEM BEFORE PRIVATE $<TARGET_PROPERTY:onednn_gpu_tgt,INTERFACE_INCLUDE_DIRECTORIES>)
- add_dependencies(openvino_intel_gpu_${IMPL_TYPE}_obj onednn_gpu_tgt)
+ target_include_directories(${ARG_NAME} SYSTEM BEFORE PRIVATE $<TARGET_PROPERTY:onednn_gpu_tgt${OV_GPU_SUFFIX},INTERFACE_INCLUDE_DIRECTORIES>)
+ add_dependencies(openvino_intel_gpu_${IMPL_TYPE}_obj${OV_GPU_SUFFIX} onednn_gpu_tgt${OV_GPU_SUFFIX})
endif()
# The graph backend implementations are compiled in these per-backend OBJECT
@@ -107,13 +115,13 @@ set(CODEGEN_TEST_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/common_utils/test_kernels_d
enable_testing()
-add_custom_target(run_codegen_test
+add_custom_target(run_codegen_test${OV_GPU_SUFFIX}
COMMAND ${Python3_EXECUTABLE} -B ${CODEGEN_TEST_SCRIPT}
DEPENDS "${CODEGEN_SCRIPT}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
-add_test(NAME TestOCLCodePreprocessing
+add_test(NAME TestOCLCodePreprocessing${OV_GPU_SUFFIX}
COMMAND ${Python3_EXECUTABLE} -B ${CODEGEN_TEST_SCRIPT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
@@ -121,9 +129,9 @@ foreach(IMPL_TYPE IN LISTS AVAILABLE_IMPL_TYPES)
if(IMPL_TYPE STREQUAL "cm" AND NOT ENABLE_CM_FOR_GPU)
continue()
endif()
- add_subdirectory(impls/${IMPL_TYPE})
- if (TARGET openvino_intel_gpu_${IMPL_TYPE}_obj)
- list(APPEND OBJ_FILES $<TARGET_OBJECTS:openvino_intel_gpu_${IMPL_TYPE}_obj>)
+ add_subdirectory(impls/${IMPL_TYPE} impls/${IMPL_TYPE}${OV_GPU_SUFFIX})
+ if (TARGET openvino_intel_gpu_${IMPL_TYPE}_obj${OV_GPU_SUFFIX})
+ list(APPEND OBJ_FILES $<TARGET_OBJECTS:openvino_intel_gpu_${IMPL_TYPE}_obj${OV_GPU_SUFFIX}>)
endif()
endforeach()
@@ -146,7 +154,7 @@ ov_add_target(
${EXTRA_LINK_LIBRARIES}
openvino::reference # for loop primitive subroutines
DEPENDENCIES
- run_codegen_test
+ run_codegen_test${OV_GPU_SUFFIX}
)
ov_build_target_faster(${TARGET_NAME} PCH)
@@ -154,7 +162,7 @@ ov_build_target_faster(${TARGET_NAME} PCH)
target_compile_options(${TARGET_NAME} PRIVATE ${COMMON_COMPILE_OPTIONS})
ov_set_threading_interface_for(${TARGET_NAME})
-ov_gpu_set_runtime_interface_for(${TARGET_NAME})
+ov_gpu_set_runtime_interface_for(${TARGET_NAME} RUNTIME ${OV_GPU_RT})
set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
diff --git a/src/plugins/intel_gpu/src/graph/impls/cm/CMakeLists.txt b/src/plugins/intel_gpu/src/graph/impls/cm/CMakeLists.txt
index a8bd2f05471..58d5410b3a5 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cm/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/graph/impls/cm/CMakeLists.txt
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
#
-set(TARGET_NAME "openvino_intel_gpu_cm_obj")
+set(TARGET_NAME "openvino_intel_gpu_cm_obj${OV_GPU_SUFFIX}")
# Path which points to root directory where code generated elements are created
# (specific to build configuration).
@@ -70,7 +70,7 @@ add_custom_command(OUTPUT "${CODEGEN_INCDIR}/${KERNEL_SOURCES}"
COMMENT "Updating file if the file changed (${CODEGEN_INCDIR}/${KERNEL_SOURCES}) ..."
)
-add_custom_target(run_cm_codegen ALL DEPENDS "${CODEGEN_INCDIR}/${KERNEL_SOURCES}")
+add_custom_target(run_cm_codegen${OV_GPU_SUFFIX} ALL DEPENDS "${CODEGEN_INCDIR}/${KERNEL_SOURCES}")
ov_gpu_add_backend_target(
NAME ${TARGET_NAME}
@@ -78,6 +78,6 @@ ov_gpu_add_backend_target(
BYPASS
ADDITIONAL_SOURCE_DIRS ${CODEGEN_INCDIR}
EXCLUDED_SOURCE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/include"
- DEPENDENCIES run_cm_codegen
+ DEPENDENCIES run_cm_codegen${OV_GPU_SUFFIX}
ADD_CLANG_FORMAT
)
diff --git a/src/plugins/intel_gpu/src/graph/impls/common/CMakeLists.txt b/src/plugins/intel_gpu/src/graph/impls/common/CMakeLists.txt
index 284155b7442..4d69e33fdcd 100644
--- a/src/plugins/intel_gpu/src/graph/impls/common/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/graph/impls/common/CMakeLists.txt
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
#
-set(TARGET_NAME "openvino_intel_gpu_common_obj")
+set(TARGET_NAME "openvino_intel_gpu_common_obj${OV_GPU_SUFFIX}")
ov_gpu_add_backend_target(
NAME ${TARGET_NAME}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/CMakeLists.txt b/src/plugins/intel_gpu/src/graph/impls/cpu/CMakeLists.txt
index 82d7403ce01..04a74467021 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/CMakeLists.txt
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
#
-set(TARGET_NAME "openvino_intel_gpu_cpu_obj")
+set(TARGET_NAME "openvino_intel_gpu_cpu_obj${OV_GPU_SUFFIX}")
ov_gpu_add_backend_target(
NAME ${TARGET_NAME}
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/CMakeLists.txt b/src/plugins/intel_gpu/src/graph/impls/ocl/CMakeLists.txt
index 15f5cc4a8a3..72fe200be4a 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/CMakeLists.txt
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
#
-set(TARGET_NAME "openvino_intel_gpu_ocl_obj")
+set(TARGET_NAME "openvino_intel_gpu_ocl_obj${OV_GPU_SUFFIX}")
ov_gpu_add_backend_target(
NAME ${TARGET_NAME}
@@ -10,7 +10,7 @@ ov_gpu_add_backend_target(
ov_build_target_faster(${TARGET_NAME} PCH)
-if(GPU_RT_TYPE STREQUAL "SYCL")
+if(OV_GPU_RT STREQUAL "SYCL")
# kernels_cache.cpp includes oneDNN headers that require SYCL backend support.
# Without the SYCL compilation flag, the compiler will fail with "Unsupported compiler" error.
add_sycl_to_target(TARGET ${TARGET_NAME} SOURCES kernels_cache.cpp)
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.cpp
index a8b4d8df499..509f6fe05fa 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/kernels_cache.cpp
@@ -10,6 +10,7 @@
#endif
#include "impls/ocl_v2/utils/kernels_db.hpp"
#include "intel_gpu/runtime/kernel_args.hpp"
+#include "intel_gpu/runtime/engine_configuration.hpp"
#include "openvino/util/pp.hpp"
#include "intel_gpu/graph/serialization/set_serializer.hpp"
#include "intel_gpu/graph/serialization/vector_serializer.hpp"
@@ -235,6 +236,9 @@ void kernels_cache::get_program_source(const kernels_code& kernels_source_code,
std::string full_code = options + " " + _device->get_info().driver_version;
full_code += _device->get_info().dev_name;
+ // Partition the kernel cache per runtime: OCL and ZE store incompatible native
+ // binaries, so their .cl_cache files must never share a hash (wrong-format load).
+ full_code += get_runtime_cache_tag();
for (auto& ss : b.source)
full_code += ss;
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/CMakeLists.txt b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/CMakeLists.txt
index 0ef2a20e900..375d8f4cf11 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/CMakeLists.txt
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
#
-set(TARGET_NAME "openvino_intel_gpu_ocl_v2_obj")
+set(TARGET_NAME "openvino_intel_gpu_ocl_v2_obj${OV_GPU_SUFFIX}")
# Path which points to root directory where code generated elements are created
# (specific to build configuration).
@@ -41,20 +41,20 @@ add_custom_command(OUTPUT "${CODEGEN_INCDIR}/${KERNEL_SOURCES}"
COMMENT "Updating file if the file changed (${CODEGEN_INCDIR}/${KERNEL_SOURCES}) ..."
)
-add_custom_target(run_ocl_codegen ALL DEPENDS "${CODEGEN_INCDIR}/${KERNEL_SOURCES}")
+add_custom_target(run_ocl_codegen${OV_GPU_SUFFIX} ALL DEPENDS "${CODEGEN_INCDIR}/${KERNEL_SOURCES}")
ov_gpu_add_backend_target(
NAME ${TARGET_NAME}
INCLUDES $<BUILD_INTERFACE:${CODEGEN_INCDIR}>
BYPASS
ADDITIONAL_SOURCE_DIRS ${CODEGEN_INCDIR}
- DEPENDENCIES run_ocl_codegen
+ DEPENDENCIES run_ocl_codegen${OV_GPU_SUFFIX}
ADD_CLANG_FORMAT
)
ov_build_target_faster(${TARGET_NAME} PCH)
-if(GPU_RT_TYPE STREQUAL "SYCL")
+if(OV_GPU_RT STREQUAL "SYCL")
# Some sources include oneDNN headers that require SYCL backend support.
# Without the SYCL compilation flag, the compiler will fail with "Unsupported compiler" error.
add_sycl_to_target(TARGET ${TARGET_NAME} SOURCES)
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/CMakeLists.txt b/src/plugins/intel_gpu/src/graph/impls/onednn/CMakeLists.txt
index afcb069a90c..31009bd2ea5 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/CMakeLists.txt
@@ -6,11 +6,11 @@ if (NOT ENABLE_ONEDNN_FOR_GPU)
return()
endif()
-set(TARGET_NAME "openvino_intel_gpu_onednn_obj")
+set(TARGET_NAME "openvino_intel_gpu_onednn_obj${OV_GPU_SUFFIX}")
ov_gpu_add_backend_target(
NAME ${TARGET_NAME}
- LINK_LIBRARIES onednn_gpu_tgt
+ LINK_LIBRARIES onednn_gpu_tgt${OV_GPU_SUFFIX}
)
ov_build_target_faster(${TARGET_NAME} PCH)
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
index 0a79f9a8f0f..6dcd205d2ca 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
@@ -10,6 +10,7 @@
#include "intel_gpu/graph/serialization/binary_buffer.hpp"
#include "intel_gpu/runtime/memory.hpp"
#include "intel_gpu/runtime/file_util.hpp"
+#include "intel_gpu/runtime/engine_configuration.hpp"
#include "to_string_utils.h"
#include "utils.hpp"
@@ -344,6 +345,9 @@ private:
}
std::string key_str(key.begin(), key.end());
+ // Partition the oneDNN cache per runtime so a blob built by one runtime is never
+ // loaded by the other (the driver-string difference alone is not a safe guard).
+ key_str += get_runtime_cache_tag();
size_t hash = std::hash<std::string>()(key_str);
return path + std::to_string(hash) + ".onednn.cl_cache";
}
diff --git a/src/plugins/intel_gpu/src/graph/impls/sycl/CMakeLists.txt b/src/plugins/intel_gpu/src/graph/impls/sycl/CMakeLists.txt
index 4ebb6f169c5..9a536a8a67f 100644
--- a/src/plugins/intel_gpu/src/graph/impls/sycl/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/graph/impls/sycl/CMakeLists.txt
@@ -6,11 +6,11 @@ if(NOT OV_GPU_WITH_SYCL)
return()
endif()
-set(TARGET_NAME "openvino_intel_gpu_sycl_obj")
+set(TARGET_NAME "openvino_intel_gpu_sycl_obj${OV_GPU_SUFFIX}")
set(SOURCES_OCL_RT "${CMAKE_CURRENT_SOURCE_DIR}/impl_example.cpp")
-if(GPU_RT_TYPE STREQUAL "SYCL")
+if(OV_GPU_RT STREQUAL "SYCL")
set(EXCLUDED_SOURCE_PATHS ${SOURCES_OCL_RT})
else()
file(GLOB EXCLUDED_SOURCE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
diff --git a/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt b/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt
index 0108a9002f0..320e9a5d252 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/kernel_selector/CMakeLists.txt
@@ -2,7 +2,15 @@
# SPDX-License-Identifier: Apache-2.0
#
-set(TARGET_NAME "openvino_intel_gpu_kernels")
+set(TARGET_NAME "openvino_intel_gpu_kernels${OV_GPU_SUFFIX}")
+if(NOT DEFINED OV_GPU_RT)
+ # Reachable only if this directory is added outside ov_gpu_build_stack(), which always sets a
+ # single runtime; COMBINED names two, so a stack built from it would belong to neither.
+ if(GPU_RT_TYPE STREQUAL "COMBINED")
+ message(FATAL_ERROR "OV_GPU_RT must be set to a single runtime before adding this directory; got COMBINED")
+ endif()
+ set(OV_GPU_RT "${GPU_RT_TYPE}")
+endif()
find_host_package(Python3 REQUIRED COMPONENTS Interpreter)
@@ -67,11 +75,11 @@ target_compile_options(${TARGET_NAME} PRIVATE
$<$<CONFIG:Release>:$<IF:$<CXX_COMPILER_ID:MSVC>,/Os,-Os>>)
if (ENABLE_ONEDNN_FOR_GPU)
- target_link_libraries(${TARGET_NAME} PRIVATE onednn_gpu_tgt)
+ target_link_libraries(${TARGET_NAME} PRIVATE onednn_gpu_tgt${OV_GPU_SUFFIX})
endif()
target_link_libraries(${TARGET_NAME} PUBLIC openvino::runtime PRIVATE OpenCL::OpenCL openvino::runtime::dev)
-ov_gpu_set_runtime_interface_for(${TARGET_NAME})
+ov_gpu_set_runtime_interface_for(${TARGET_NAME} RUNTIME ${OV_GPU_RT})
target_include_directories(${TARGET_NAME} PRIVATE $<TARGET_PROPERTY:rapidjson,INTERFACE_INCLUDE_DIRECTORIES>)
@@ -91,7 +99,7 @@ endif()
ov_build_target_faster(${TARGET_NAME} PCH)
-if(GPU_RT_TYPE STREQUAL "SYCL")
+if(OV_GPU_RT STREQUAL "SYCL")
# Some sources include oneDNN headers that require SYCL backend support.
# Without the SYCL compilation flag, the compiler will fail with "Unsupported compiler" error.
add_sycl_to_target(TARGET ${TARGET_NAME} SOURCES)
diff --git a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp b/src/plugins/intel_gpu/src/plugin/compiled_model.cpp
index 93b950f9c76..de7f29e2508 100644
--- a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp
+++ b/src/plugins/intel_gpu/src/plugin/compiled_model.cpp
@@ -9,6 +9,7 @@
#include "openvino/core/version.hpp"
#include "intel_gpu/graph/serialization/binary_buffer.hpp"
+#include "intel_gpu/runtime/engine_configuration.hpp"
#include "intel_gpu/runtime/itt.hpp"
#include "intel_gpu/plugin/graph.hpp"
#include "intel_gpu/plugin/compiled_model.hpp"
@@ -281,13 +282,15 @@ std::shared_ptr<const ov::Model> CompiledModel::get_runtime_model() const {
}
std::string CompiledModel::build_runtime_requirements(const cldnn::device_info& info) {
- // v1 GPU compatibility descriptor: meta=<schema>;ov=<major.minor.patch>;desc=[<device props>].
+ // v2 GPU compatibility descriptor: meta=<schema>;ov=<major.minor.patch>;desc=[<device props>].
// The desc fields are the device properties that invalidate a compiled blob if changed:
- // driver (owns the kernel binaries), ip (GFX IP hardware version), eus (execution units).
+ // rt (compile-time runtime - OCL/ZE store incompatible kernel binaries), driver (owns the
+ // kernel binaries), ip (GFX IP hardware version), eus (execution units).
std::ostringstream ss;
ss << "meta=1.0"
<< ";ov=" << OPENVINO_VERSION_MAJOR << "." << OPENVINO_VERSION_MINOR << "." << OPENVINO_VERSION_PATCH
- << ";desc=[driver=" << info.driver_version
+ << ";desc=[rt=" << cldnn::get_runtime_cache_tag()
+ << ";driver=" << info.driver_version
<< ";ip=" << info.gfx_ver.major << "." << static_cast<uint32_t>(info.gfx_ver.minor) << "."
<< static_cast<uint32_t>(info.gfx_ver.revision)
<< ";eus=" << info.execution_units_count << "]";
diff --git a/src/plugins/intel_gpu/src/plugin/plugin.cpp b/src/plugins/intel_gpu/src/plugin/plugin.cpp
index 6cb9a83788b..a3c64553683 100644
--- a/src/plugins/intel_gpu/src/plugin/plugin.cpp
+++ b/src/plugins/intel_gpu/src/plugin/plugin.cpp
@@ -14,6 +14,7 @@
#include <tuple>
#include <vector>
+#include "common_utils/parallel_mem_streambuf.hpp"
#include "intel_gpu/graph/serialization/layout_serializer.hpp"
#include "intel_gpu/graph/serialization/string_serializer.hpp"
#include "intel_gpu/graph/serialization/utils.hpp"
@@ -22,6 +23,7 @@
#include "intel_gpu/plugin/transformations_pipeline.hpp"
#include "intel_gpu/runtime/debug_configuration.hpp"
#include "intel_gpu/runtime/device_query.hpp"
+#include "intel_gpu/runtime/dispatch_probe.hpp"
#include "intel_gpu/runtime/execution_config.hpp"
#include "intel_gpu/runtime/internal_properties.hpp"
#include "intel_gpu/runtime/itt.hpp"
@@ -39,8 +41,8 @@
#include "openvino/runtime/plugin_config.hpp"
#include "openvino/runtime/properties.hpp"
#include "openvino/runtime/shared_buffer.hpp"
-#include "common_utils/parallel_mem_streambuf.hpp"
#include "openvino/runtime/weightless_properties_utils.hpp"
+#include "openvino/util/env_util.hpp"
#include "openvino/util/file_util.hpp"
#include "transformations/common_optimizations/dimension_tracking.hpp"
#include "transformations/init_node_info.hpp"
@@ -331,6 +333,23 @@ ov::SoPtr<ov::IRemoteContext> Plugin::get_default_context(const AnyMap& params)
return get_default_context(device_id);
}
+void Plugin::apply_device_id_map(const std::map<std::string, std::string>& id_map) {
+ // Core owns the numbering when several libraries share a device name; adopt its ids for every
+ // device we enumerated, so nothing downstream (contexts, configs, metrics) sees our own.
+ std::map<std::string, cldnn::device::ptr> renamed_devices;
+ std::map<std::string, ExecutionConfig> renamed_configs;
+ for (const auto& [internal_id, device] : m_device_map) {
+ const auto it = id_map.find(internal_id);
+ OPENVINO_ASSERT(it != id_map.end(), "[GPU] Core did not assign an id for enumerated device \"", internal_id, "\", so it could not be addressed.");
+ renamed_devices[it->second] = device;
+ renamed_configs.emplace(it->second, ExecutionConfig(ov::device::id(it->second)));
+ }
+ m_device_map = std::move(renamed_devices);
+ m_configs_map = std::move(renamed_configs);
+ // The assigned ids need not contain "0": another member may hold the device Core numbered 0.
+ m_default_device_id = m_device_map.empty() ? std::string("0") : m_device_map.begin()->first;
+}
+
void Plugin::set_property(const ov::AnyMap &config) {
auto update_config = [](ExecutionConfig& config, const ov::AnyMap& user_config) {
config.set_user_property(user_config, OptionVisibility::RELEASE);
@@ -342,6 +361,15 @@ void Plugin::set_property(const ov::AnyMap &config) {
}
};
+ auto rest = config;
+ if (auto id_map = rest.extract(ov::internal::device_id_map.name()); !id_map.empty()) {
+ apply_device_id_map(id_map.mapped().as<std::map<std::string, std::string>>());
+ if (!rest.empty()) {
+ set_property(rest);
+ }
+ return;
+ }
+
if (config.find(ov::internal::config_device_id.name()) != config.end()) {
std::string device_id = config.at(ov::internal::config_device_id.name()).as<std::string>();
auto config_for_device = config;
@@ -702,6 +730,9 @@ ov::Any Plugin::get_metric(const std::string& name, const ov::AnyMap& options) c
if (name == ov::max_batch_size) {
return decltype(ov::max_batch_size)::value_type {get_max_batch_size(options)};
}
+ if (name == ov::intel_gpu::runtime_type) {
+ return decltype(ov::intel_gpu::runtime_type)::value_type {std::string(cldnn::get_runtime_cache_tag())};
+ }
if (name == ov::intel_gpu::driver_version) {
return decltype(ov::intel_gpu::driver_version)::value_type {device_info.driver_version};
}
@@ -757,6 +788,7 @@ std::vector<ov::PropertyName> Plugin::get_caching_properties() const {
ov::PropertyName{ov::hint::performance_mode.name(), PropertyMutability::RW},
ov::PropertyName{ov::hint::dynamic_quantization_group_size.name(), PropertyMutability::RW},
ov::PropertyName{ov::hint::activations_scale_factor.name(), PropertyMutability::RW},
+ ov::PropertyName{ov::intel_gpu::runtime_type.name(), PropertyMutability::RO},
};
return caching_properties;
@@ -825,14 +857,15 @@ std::vector<ov::PropertyName> Plugin::get_supported_properties() const {
std::vector<ov::PropertyName> Plugin::get_supported_internal_properties() const {
static const std::vector<ov::PropertyName> supported_internal_properties = {
- ov::PropertyName{ov::internal::caching_properties.name(), ov::PropertyMutability::RO},
- ov::PropertyName{ov::internal::config_device_id.name(), ov::PropertyMutability::WO},
- ov::PropertyName{ov::internal::exclusive_async_requests.name(), ov::PropertyMutability::RW},
- ov::PropertyName{ov::internal::compiled_model_runtime_properties.name(), ov::PropertyMutability::RO},
- ov::PropertyName{ov::internal::compiled_model_runtime_properties_supported.name(), ov::PropertyMutability::RO},
- ov::PropertyName{ov::internal::query_model_ratio.name(), PropertyMutability::RW},
- ov::PropertyName{ov::internal::caching_with_mmap.name(), PropertyMutability::RO},
- ov::PropertyName{ov::internal::cache_header_alignment.name(), PropertyMutability::RO}};
+ ov::PropertyName{ov::internal::caching_properties.name(), ov::PropertyMutability::RO},
+ ov::PropertyName{ov::internal::config_device_id.name(), ov::PropertyMutability::WO},
+ ov::PropertyName{ov::internal::exclusive_async_requests.name(), ov::PropertyMutability::RW},
+ ov::PropertyName{ov::internal::compiled_model_runtime_properties.name(), ov::PropertyMutability::RO},
+ ov::PropertyName{ov::internal::compiled_model_runtime_properties_supported.name(), ov::PropertyMutability::RO},
+ ov::PropertyName{ov::internal::query_model_ratio.name(), PropertyMutability::RW},
+ ov::PropertyName{ov::internal::caching_with_mmap.name(), PropertyMutability::RO},
+ ov::PropertyName{ov::internal::cache_header_alignment.name(), PropertyMutability::RO},
+ ov::PropertyName{ov::internal::device_id_map.name(), ov::PropertyMutability::WO}};
return supported_internal_properties;
}
@@ -1069,5 +1102,31 @@ uint32_t Plugin::get_optimal_batch_size(const ov::AnyMap& options) const {
} // namespace ov::intel_gpu
+namespace {
+
+void enumerate_dispatch_devices(std::vector<ov::EnumeratedDevice>& out) {
+ out.clear(); // The probe reports, it does not append: repeated calls must be idempotent.
+ try {
+ // Read once per process: the debug override cannot change while the library is loaded.
+ static const std::string forced = ov::util::getenv_string("OV_GPU_RUNTIME");
+
+ for (const auto& d : cldnn::lightweight_enumerate()) {
+ ov::EnumeratedDevice e;
+ e.internal_id = d.map_id;
+ e.fingerprint = cldnn::make_fingerprint(d.info);
+ e.score = cldnn::probe_score(cldnn::get_default_runtime_type(), d.info, forced);
+ out.push_back(std::move(e));
+ }
+ } catch (...) {
+ out.clear(); // Any failure -> "I serve nothing"; the probe never throws.
+ }
+}
+
+} // namespace
+
static const ov::Version version = { CI_BUILD_NUMBER, "Intel GPU plugin" };
OV_DEFINE_PLUGIN_CREATE_FUNCTION(ov::intel_gpu::Plugin, version)
+
+// Real implementation of the plugin-ABI enumeration probe (the GPU plugin participates
+// in device-name dispatch); mirrors the stub every other plugin exports.
+OV_DEFINE_PLUGIN_ENUMERATE_FUNCTION(enumerate_dispatch_devices)
diff --git a/src/plugins/intel_gpu/src/runtime/CMakeLists.txt b/src/plugins/intel_gpu/src/runtime/CMakeLists.txt
index 5458d6d5b64..cf868276348 100644
--- a/src/plugins/intel_gpu/src/runtime/CMakeLists.txt
+++ b/src/plugins/intel_gpu/src/runtime/CMakeLists.txt
@@ -2,7 +2,17 @@
# SPDX-License-Identifier: Apache-2.0
#
-set(TARGET_NAME "openvino_intel_gpu_runtime")
+# OV_GPU_SUFFIX (empty for single-RT builds) distinguishes the per-runtime target names of a
+# COMBINED build; OV_GPU_RT is this pass's runtime (defaults to the global GPU_RT_TYPE).
+set(TARGET_NAME "openvino_intel_gpu_runtime${OV_GPU_SUFFIX}")
+if(NOT DEFINED OV_GPU_RT)
+ # Reachable only if this directory is added outside ov_gpu_build_stack(), which always sets a
+ # single runtime; COMBINED names two, so a stack built from it would belong to neither.
+ if(GPU_RT_TYPE STREQUAL "COMBINED")
+ message(FATAL_ERROR "OV_GPU_RT must be set to a single runtime before adding this directory; got COMBINED")
+ endif()
+ set(OV_GPU_RT "${GPU_RT_TYPE}")
+endif()
file(GLOB LIBRARY_SOURCES_MAIN
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
@@ -43,17 +53,17 @@ endif()
set(LIBRARY_SOURCES_ALL ${LIBRARY_SOURCES_MAIN})
-if(GPU_RT_TYPE STREQUAL "OCL")
+if(OV_GPU_RT STREQUAL "OCL")
list(APPEND LIBRARY_SOURCES_ALL ${LIBRARY_SOURCES_OCL})
set(SYCL_SOURCES ${OCL_SYCL_SOURCES})
endif()
-if(GPU_RT_TYPE STREQUAL "ZE")
+if(OV_GPU_RT STREQUAL "ZE")
list(APPEND LIBRARY_SOURCES_ALL ${LIBRARY_SOURCES_OCL})
list(APPEND LIBRARY_SOURCES_ALL ${LIBRARY_SOURCES_ZE})
endif()
-if(GPU_RT_TYPE STREQUAL "SYCL")
+if(OV_GPU_RT STREQUAL "SYCL")
list(APPEND LIBRARY_SOURCES_ALL ${LIBRARY_SOURCES_SYCL})
set(SYCL_SOURCES ${LIBRARY_SOURCES_SYCL})
endif()
@@ -90,11 +100,11 @@ if(GPU_RT_TYPE STREQUAL "SYCL")
endif()
if(ENABLE_ONEDNN_FOR_GPU)
- ov_target_link_libraries_as_system(${TARGET_NAME} PUBLIC onednn_gpu_tgt)
+ ov_target_link_libraries_as_system(${TARGET_NAME} PUBLIC onednn_gpu_tgt${OV_GPU_SUFFIX})
endif()
ov_set_threading_interface_for(${TARGET_NAME})
-ov_gpu_set_runtime_interface_for(${TARGET_NAME})
+ov_gpu_set_runtime_interface_for(${TARGET_NAME} RUNTIME ${OV_GPU_RT})
# Requires OpenCL even for Level Zero builds because of kernel builder and OneDNN
target_link_libraries(${TARGET_NAME} PRIVATE
diff --git a/src/plugins/intel_gpu/src/runtime/device_query.cpp b/src/plugins/intel_gpu/src/runtime/device_query.cpp
index 8f5ee0bc1bb..e74eae547e1 100644
--- a/src/plugins/intel_gpu/src/runtime/device_query.cpp
+++ b/src/plugins/intel_gpu/src/runtime/device_query.cpp
@@ -72,4 +72,19 @@ device_query::device_query(engine_types engine_type,
default: OPENVINO_THROW("[GPU] Unsupported engine/runtime types in device_query");
}
}
+
+std::vector<lightweight_device> lightweight_enumerate() noexcept {
+ std::vector<lightweight_device> result;
+ try {
+ // Reuse the standard detector for this build's runtime, but do NOT initialize
+ // devices (no engine/context) - only the info populated at detection is read.
+ device_query query(nullptr, nullptr, 0, -1, /*initialize_devices=*/false);
+ for (const auto& [map_id, dev] : query.get_available_devices()) {
+ result.push_back({map_id, dev->get_info()});
+ }
+ } catch (...) {
+ result.clear(); // Any failure -> "I serve nothing"; never throw from the probe.
+ }
+ return result;
+}
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/runtime/dispatch_probe.cpp b/src/plugins/intel_gpu/src/runtime/dispatch_probe.cpp
new file mode 100644
index 00000000000..a3139dcd46b
--- /dev/null
+++ b/src/plugins/intel_gpu/src/runtime/dispatch_probe.cpp
@@ -0,0 +1,75 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "intel_gpu/runtime/dispatch_probe.hpp"
+
+#include <type_traits>
+
+#include "intel_gpu/runtime/device.hpp"
+
+namespace cldnn {
+namespace {
+
+// Append the raw bytes of a value to a byte buffer.
+template <typename T>
+void append_bytes(std::vector<uint8_t>& out, const T& value) {
+ static_assert(std::is_trivially_copyable_v<T>, "a fingerprint field must be trivially copyable to be read as bytes");
+ const auto* bytes = reinterpret_cast<const uint8_t*>(&value);
+ out.insert(out.end(), bytes, bytes + sizeof(T));
+}
+
+} // namespace
+
+std::vector<uint8_t> make_fingerprint(const device_info& info) {
+ std::vector<uint8_t> fp;
+ append_bytes(fp, info.pci_info.pci_domain);
+ append_bytes(fp, info.pci_info.pci_bus);
+ append_bytes(fp, info.pci_info.pci_device);
+ append_bytes(fp, info.pci_info.pci_function);
+ append_bytes(fp, info.vendor_id);
+ append_bytes(fp, info.sub_device_idx);
+ return fp;
+}
+
+ov::DeviceCompatibilityScore probe_score(runtime_types rt, const device_info& info, std::string_view forced_rt) noexcept {
+ const bool intel = (info.vendor_id == INTEL_VENDOR_ID);
+ // Perf tier from gfx_ver.major (Xe2+ == 20: BMG/LNL 20.x, PTL 30.x), NOT from gpu_arch,
+ // which is unknown in this no-oneDNN probe build (device_ops_table).
+ const bool xe2_plus = intel && info.gfx_ver.major >= 20;
+
+ ov::DeviceCompatibilityScore score = ov::PROBE_SCORE_SERVABLE;
+ if (rt == runtime_types::ze) {
+ // Level Zero is Intel-only. ZE is PREFERRED only when perf-ideal (Xe2+) AND the real
+ // ZE<->OCL interop capability is present (supports_leo, read without engine init).
+ if (!intel) {
+ score = ov::PROBE_SCORE_INCOMPATIBLE;
+ } else if (xe2_plus && info.supports_leo) {
+ score = ov::PROBE_SCORE_PREFERRED;
+ } else {
+ score = ov::PROBE_SCORE_SERVABLE;
+ }
+ } else if (rt == runtime_types::ocl) {
+ // OCL serves interop natively (no LEO concept). CAPABLE on Xe2+ so it wins when ZE
+ // lacks LEO (ZE=SERVABLE) but loses when ZE has it (ZE=PREFERRED).
+ if (!intel) {
+ score = ov::PROBE_SCORE_SERVABLE;
+ } else if (!xe2_plus) {
+ score = ov::PROBE_SCORE_PREFERRED;
+ } else {
+ score = ov::PROBE_SCORE_CAPABLE;
+ }
+ }
+
+ // The override names what a group ships, so anything else (e.g. SYCL) is ignored: honouring
+ // it would drop every candidate's Intel devices and hide the device entirely.
+ if (forced_rt != "OCL" && forced_rt != "ZE")
+ return score;
+ // It applies only to Intel devices (the runtimes' shared, contended set); a non-Intel GPU
+ // keeps its OCL score so it stays served regardless of the override.
+ if (!intel || score == ov::PROBE_SCORE_INCOMPATIBLE)
+ return score;
+ return forced_rt == to_cache_tag(rt) ? ov::PROBE_SCORE_PREFERRED : ov::PROBE_SCORE_INCOMPATIBLE;
+}
+
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/runtime/engine_configuration.cpp b/src/plugins/intel_gpu/src/runtime/engine_configuration.cpp
index 1c84b66495b..318cd01f911 100644
--- a/src/plugins/intel_gpu/src/runtime/engine_configuration.cpp
+++ b/src/plugins/intel_gpu/src/runtime/engine_configuration.cpp
@@ -29,4 +29,18 @@ runtime_types get_default_runtime_type() {
#error "Expected OpenVINO GPU runtime macros to be defined"
#endif
}
+
+std::string_view to_cache_tag(runtime_types type) {
+ // Stable strings - do not change (see header: cache-compatibility constant).
+ switch (type) {
+ case runtime_types::ocl: return "OCL";
+ case runtime_types::ze: return "ZE";
+ case runtime_types::sycl: return "SYCL";
+ default: return "UNKNOWN";
+ }
+}
+
+std::string_view get_runtime_cache_tag() {
+ return to_cache_tag(get_default_runtime_type());
+}
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/tests/functional/CMakeLists.txt b/src/plugins/intel_gpu/tests/functional/CMakeLists.txt
index 041699ffe97..e9a6adb1a8a 100644
--- a/src/plugins/intel_gpu/tests/functional/CMakeLists.txt
+++ b/src/plugins/intel_gpu/tests/functional/CMakeLists.txt
@@ -45,7 +45,14 @@ ov_add_test_target(
OV GPU
)
-ov_gpu_set_runtime_interface_for(${TARGET_NAME})
+# Functional tests load the plugin dynamically; OV_GPU_WITH_*_RT only selects which remote-tensor
+# interop tests compile. COMBINED ships both runtimes, so compile both sets; single-RT its own.
+if(GPU_RT_TYPE STREQUAL "COMBINED")
+ target_compile_definitions(${TARGET_NAME} PRIVATE OV_GPU_WITH_ZE_RT=1 OV_GPU_WITH_OCL_RT=1)
+ add_dependencies(${TARGET_NAME} openvino_intel_gpu_plugin_ocl)
+else()
+ ov_gpu_set_runtime_interface_for(${TARGET_NAME} RUNTIME ${GPU_RT_TYPE})
+endif()
if(ENABLE_PROXY)
target_compile_definitions(${TARGET_NAME} PUBLIC PROXY_PLUGIN_ENABLED)
diff --git a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/ze_remote_tensor_tests.cpp b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/ze_remote_tensor_tests.cpp
index 1d0920309de..6dd8a33fe7a 100644
--- a/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/ze_remote_tensor_tests.cpp
+++ b/src/plugins/intel_gpu/tests/functional/remote_tensor_tests/ze_remote_tensor_tests.cpp
@@ -4,15 +4,29 @@
#ifdef OV_GPU_WITH_ZE_RT
-#include "openvino/runtime/intel_gpu/remote_properties.hpp"
-#include "openvino/runtime/remote_tensor.hpp"
+# include "intel_gpu/runtime/internal_properties.hpp"
+# include "openvino/runtime/intel_gpu/remote_properties.hpp"
+# include "openvino/runtime/remote_tensor.hpp"
+# include "shared_test_classes/base/ov_behavior_test_utils.hpp"
-#include "shared_test_classes/base/ov_behavior_test_utils.hpp"
-
-TEST(ZeRemoteContext, smoke_CorrectContextType) {
+// When several GPU libraries are registered under one device name, which runtime serves a device
+// is resolved at run time - so assert the context matches the runtime that won, not a fixed one.
+TEST(GpuRemoteContext, smoke_ContextTypeMatchesResolvedRuntime) {
auto core = ov::Core();
- auto remote_context = core.get_default_context(ov::test::utils::DEVICE_GPU);
- ASSERT_EQ(remote_context.get_params().at(ov::intel_gpu::context_type.name()), ov::intel_gpu::ContextType::ZE);
+ const auto runtime = core.get_property(ov::test::utils::DEVICE_GPU, ov::intel_gpu::runtime_type);
+ const auto context_type = core.get_default_context(ov::test::utils::DEVICE_GPU).get_params().at(ov::intel_gpu::context_type.name());
+
+ if (runtime == "OCL") {
+ // An OpenCL build always hands out an OpenCL context.
+ ASSERT_EQ(context_type, ov::intel_gpu::ContextType::OCL);
+ } else if (runtime == "ZE") {
+ // A Level Zero build reports ZE, or OCL once the device offers ZE<->OCL interop (LEO):
+ // that is what keeps OpenCL-interop applications working on a ZE-served device.
+ ASSERT_TRUE(context_type == ov::intel_gpu::ContextType::ZE || context_type == ov::intel_gpu::ContextType::OCL)
+ << "a Level Zero device must report a ZE context, or an OCL one when LEO is enabled";
+ } else {
+ GTEST_SKIP() << "No expected context type mapped for GPU runtime '" << runtime << "'";
+ }
}
#endif // OV_GPU_WITH_ZE_RT
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp
index 09862ef106b..a1471396429 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/behavior/ov_plugin/properties_tests.cpp
@@ -646,15 +646,14 @@ using OVGetMetricPropsTest_CACHING_PROPERTIES = OVClassBaseTestP;
TEST_P(OVGetMetricPropsTest_CACHING_PROPERTIES, smoke_GetMetricAndPrintNoThrow) {
ov::Core ie = ov::test::utils::create_core();
std::vector<ov::PropertyName> caching_properties = {};
- const std::vector<ov::PropertyName> expected_properties = {
- ov::device::architecture.name(),
- ov::intel_gpu::execution_units_count.name(),
- ov::hint::inference_precision.name(),
- ov::hint::execution_mode.name(),
- ov::hint::performance_mode.name(),
- ov::hint::dynamic_quantization_group_size.name(),
- ov::hint::activations_scale_factor.name()
- };
+ const std::vector<ov::PropertyName> expected_properties = {ov::device::architecture.name(),
+ ov::intel_gpu::execution_units_count.name(),
+ ov::hint::inference_precision.name(),
+ ov::hint::execution_mode.name(),
+ ov::hint::performance_mode.name(),
+ ov::hint::dynamic_quantization_group_size.name(),
+ ov::hint::activations_scale_factor.name(),
+ ov::intel_gpu::runtime_type.name()};
OV_ASSERT_NO_THROW(caching_properties = ie.get_property(target_device, ov::internal::caching_properties));
diff --git a/src/plugins/intel_gpu/tests/unit/CMakeLists.txt b/src/plugins/intel_gpu/tests/unit/CMakeLists.txt
index 406095ece6b..e7a82878410 100644
--- a/src/plugins/intel_gpu/tests/unit/CMakeLists.txt
+++ b/src/plugins/intel_gpu/tests/unit/CMakeLists.txt
@@ -18,6 +18,14 @@ endif()
set(TARGET_NAME "ov_gpu_unit_tests")
+# The tests compile and link exactly one runtime's stack. In a COMBINED build that is the ZE
+# twin (it owns the unsuffixed targets linked below); otherwise it is the single RT.
+if(GPU_RT_TYPE STREQUAL "COMBINED")
+ set(OV_GPU_TESTS_RT "ZE")
+else()
+ set(OV_GPU_TESTS_RT "${GPU_RT_TYPE}")
+endif()
+
include(${CMAKE_CURRENT_SOURCE_DIR}/sources.cmake)
# Files excluded from the completeness check when their corresponding runtime/backend condition
@@ -26,13 +34,13 @@ set(GPU_UNIT_TESTS_CHECK_SOURCES_EXCLUDE_FILES)
if(NOT ENABLE_ONEDNN_FOR_GPU)
list(APPEND GPU_UNIT_TESTS_CHECK_SOURCES_EXCLUDE_FILES ${GPU_UNIT_TESTS_ONEDNN_SRCS})
endif()
-if(NOT GPU_RT_TYPE STREQUAL "OCL")
+if(NOT OV_GPU_TESTS_RT STREQUAL "OCL")
list(APPEND GPU_UNIT_TESTS_CHECK_SOURCES_EXCLUDE_FILES ${GPU_UNIT_TESTS_OCL_RT_SRCS})
endif()
-if(NOT GPU_RT_TYPE STREQUAL "ZE")
+if(NOT OV_GPU_TESTS_RT STREQUAL "ZE")
list(APPEND GPU_UNIT_TESTS_CHECK_SOURCES_EXCLUDE_FILES ${GPU_UNIT_TESTS_ZE_RT_SRCS})
endif()
-if(NOT GPU_RT_TYPE STREQUAL "SYCL")
+if(NOT OV_GPU_TESTS_RT STREQUAL "SYCL")
list(APPEND GPU_UNIT_TESTS_CHECK_SOURCES_EXCLUDE_FILES ${GPU_UNIT_TESTS_SYCL_RT_SRCS})
endif()
@@ -72,7 +80,7 @@ ov_add_test_target(
)
ov_set_threading_interface_for(${TARGET_NAME})
-ov_gpu_set_runtime_interface_for(${TARGET_NAME})
+ov_gpu_set_runtime_interface_for(${TARGET_NAME} RUNTIME ${OV_GPU_TESTS_RT})
# Workaround to avoid warnings during LTO build
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/dispatch_probe_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/dispatch_probe_test.cpp
new file mode 100644
index 00000000000..f5703db5a54
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/unit/module_tests/dispatch_probe_test.cpp
@@ -0,0 +1,134 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+// Unit tests for the GPU dispatch-probe policy: the score each runtime reports for a device,
+// and the cross-runtime device identity Core merges candidates by. Both are pure functions of
+// device_info, so a single binary covers the OCL and ZE rows regardless of the runtime it links.
+
+#include "intel_gpu/runtime/dispatch_probe.hpp"
+
+#include <gtest/gtest.h>
+
+#include "intel_gpu/runtime/device.hpp" // INTEL_VENDOR_ID
+
+using namespace cldnn;
+
+namespace {
+
+constexpr uint32_t OTHER_VENDOR_ID = 0x10de;
+
+device_info make_info(uint32_t vendor_id, uint16_t gfx_major, bool supports_leo) {
+ device_info info{};
+ info.vendor_id = vendor_id;
+ info.gfx_ver.major = gfx_major;
+ info.supports_leo = supports_leo;
+ return info;
+}
+
+device_info intel_pre_xe2() {
+ return make_info(INTEL_VENDOR_ID, 12, false);
+}
+device_info intel_xe2_with_leo() {
+ return make_info(INTEL_VENDOR_ID, 20, true);
+}
+device_info intel_xe2_no_leo() {
+ return make_info(INTEL_VENDOR_ID, 20, false);
+}
+device_info non_intel() {
+ return make_info(OTHER_VENDOR_ID, 20, true);
+}
+
+// The winner Core would pick for a device: highest score, ties to the first candidate.
+runtime_types winner(const device_info& info, std::string_view forced = "") {
+ const auto ze = probe_score(runtime_types::ze, info, forced);
+ const auto ocl = probe_score(runtime_types::ocl, info, forced);
+ return ze > ocl ? runtime_types::ze : runtime_types::ocl;
+}
+
+} // namespace
+
+TEST(dispatch_probe, ze_serves_only_intel_devices) {
+ EXPECT_EQ(probe_score(runtime_types::ze, non_intel(), ""), ov::PROBE_SCORE_INCOMPATIBLE);
+ EXPECT_NE(probe_score(runtime_types::ze, intel_pre_xe2(), ""), ov::PROBE_SCORE_INCOMPATIBLE);
+}
+
+TEST(dispatch_probe, ze_prefers_xe2_only_with_leo) {
+ EXPECT_EQ(probe_score(runtime_types::ze, intel_xe2_with_leo(), ""), ov::PROBE_SCORE_PREFERRED);
+ // Without the interop capability ZE yields, even on a perf-ideal device.
+ EXPECT_EQ(probe_score(runtime_types::ze, intel_xe2_no_leo(), ""), ov::PROBE_SCORE_SERVABLE);
+ // LEO alone does not lift a pre-Xe2 device.
+ EXPECT_EQ(probe_score(runtime_types::ze, make_info(INTEL_VENDOR_ID, 12, true), ""), ov::PROBE_SCORE_SERVABLE);
+}
+
+TEST(dispatch_probe, ocl_prefers_pre_xe2_and_stays_capable_on_xe2) {
+ EXPECT_EQ(probe_score(runtime_types::ocl, intel_pre_xe2(), ""), ov::PROBE_SCORE_PREFERRED);
+ EXPECT_EQ(probe_score(runtime_types::ocl, intel_xe2_with_leo(), ""), ov::PROBE_SCORE_CAPABLE);
+ EXPECT_EQ(probe_score(runtime_types::ocl, intel_xe2_no_leo(), ""), ov::PROBE_SCORE_CAPABLE);
+}
+
+TEST(dispatch_probe, ocl_serves_non_intel_devices) {
+ EXPECT_EQ(probe_score(runtime_types::ocl, non_intel(), ""), ov::PROBE_SCORE_SERVABLE);
+}
+
+// The product behaviour: which backend actually gets the device.
+TEST(dispatch_probe, winner_per_device_class) {
+ EXPECT_EQ(winner(intel_xe2_with_leo()), runtime_types::ze);
+ EXPECT_EQ(winner(intel_xe2_no_leo()), runtime_types::ocl);
+ EXPECT_EQ(winner(intel_pre_xe2()), runtime_types::ocl);
+ EXPECT_EQ(winner(non_intel()), runtime_types::ocl);
+}
+
+TEST(dispatch_probe, override_forces_the_named_runtime_for_intel_devices) {
+ // ZE would lose this device on score, but the override hands it over.
+ EXPECT_EQ(probe_score(runtime_types::ze, intel_pre_xe2(), "ZE"), ov::PROBE_SCORE_PREFERRED);
+ EXPECT_EQ(probe_score(runtime_types::ocl, intel_pre_xe2(), "ZE"), ov::PROBE_SCORE_INCOMPATIBLE);
+ EXPECT_EQ(winner(intel_pre_xe2(), "ZE"), runtime_types::ze);
+
+ // And the other way round for a device ZE would otherwise win.
+ EXPECT_EQ(probe_score(runtime_types::ocl, intel_xe2_with_leo(), "OCL"), ov::PROBE_SCORE_PREFERRED);
+ EXPECT_EQ(probe_score(runtime_types::ze, intel_xe2_with_leo(), "OCL"), ov::PROBE_SCORE_INCOMPATIBLE);
+ EXPECT_EQ(winner(intel_xe2_with_leo(), "OCL"), runtime_types::ocl);
+}
+
+TEST(dispatch_probe, override_never_promotes_a_device_ze_cannot_serve) {
+ // ZE is INCOMPATIBLE with non-Intel devices; the override must not override that.
+ EXPECT_EQ(probe_score(runtime_types::ze, non_intel(), "ZE"), ov::PROBE_SCORE_INCOMPATIBLE);
+ // And OCL keeps serving it, so the device stays visible under any override.
+ EXPECT_EQ(probe_score(runtime_types::ocl, non_intel(), "ZE"), ov::PROBE_SCORE_SERVABLE);
+ EXPECT_EQ(winner(non_intel(), "ZE"), runtime_types::ocl);
+}
+
+TEST(dispatch_probe, unshipped_or_malformed_override_is_ignored) {
+ // A runtime no group ships (or garbage) must not drop every candidate's Intel devices.
+ for (const auto& forced : {"SYCL", "ocl", "", "GARBAGE"}) {
+ EXPECT_EQ(probe_score(runtime_types::ze, intel_xe2_with_leo(), forced), ov::PROBE_SCORE_PREFERRED) << forced;
+ EXPECT_EQ(probe_score(runtime_types::ocl, intel_xe2_with_leo(), forced), ov::PROBE_SCORE_CAPABLE) << forced;
+ }
+}
+
+TEST(dispatch_probe, fingerprint_ignores_uuid_but_separates_pci_addresses) {
+ auto a = intel_xe2_with_leo();
+ auto b = a;
+ // ZE populates the UUID and legacy OCL zero-fills it, so the same device must still match.
+ b.uuid.uuid[0] = 0x42;
+ EXPECT_EQ(make_fingerprint(a), make_fingerprint(b));
+
+ b = a;
+ b.pci_info.pci_device += 1;
+ EXPECT_NE(make_fingerprint(a), make_fingerprint(b));
+
+ b = a;
+ b.sub_device_idx = 3;
+ EXPECT_NE(make_fingerprint(a), make_fingerprint(b));
+
+ b = a;
+ b.vendor_id = OTHER_VENDOR_ID;
+ EXPECT_NE(make_fingerprint(a), make_fingerprint(b));
+}
+
+TEST(dispatch_probe, fingerprint_is_fixed_width_and_never_empty) {
+ // Core rejects an empty fingerprint, and compares by == only, so the layout must be stable.
+ const auto fp = make_fingerprint(device_info{});
+ EXPECT_FALSE(fp.empty());
+ EXPECT_EQ(fp.size(), make_fingerprint(intel_xe2_with_leo()).size());
+}
diff --git a/src/plugins/intel_gpu/tests/unit/sources.cmake b/src/plugins/intel_gpu/tests/unit/sources.cmake
index a189923e23b..49022f8b7c7 100644
--- a/src/plugins/intel_gpu/tests/unit/sources.cmake
+++ b/src/plugins/intel_gpu/tests/unit/sources.cmake
@@ -56,6 +56,7 @@ set(GPU_UNIT_TESTS_SRCS
${CMAKE_CURRENT_LIST_DIR}/module_tests/canonicalize_fused_shapes_test.cpp
${CMAKE_CURRENT_LIST_DIR}/module_tests/convert_and_copy_test.cpp
${CMAKE_CURRENT_LIST_DIR}/module_tests/dispatch_data_func_test.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/module_tests/dispatch_probe_test.cpp
${CMAKE_CURRENT_LIST_DIR}/module_tests/execution_config_test.cpp
${CMAKE_CURRENT_LIST_DIR}/module_tests/force_implementations_test.cpp
${CMAKE_CURRENT_LIST_DIR}/module_tests/format_test.cpp
@@ -497,7 +498,7 @@ set(GPU_UNIT_TESTS_OCL_RT_SRCS
${CMAKE_CURRENT_LIST_DIR}/test_cases/cl_mem_input_test.cpp
${CMAKE_CURRENT_LIST_DIR}/test_cases/mem_perf_test.cpp
)
-if(GPU_RT_TYPE STREQUAL "OCL")
+if(OV_GPU_TESTS_RT STREQUAL "OCL")
list(APPEND GPU_UNIT_TESTS_SRCS ${GPU_UNIT_TESTS_OCL_RT_SRCS})
endif()
@@ -510,7 +511,7 @@ set(GPU_UNIT_TESTS_ZE_RT_SRCS
${CMAKE_CURRENT_LIST_DIR}/module_tests/ze/ze_resource_test.cpp
${CMAKE_CURRENT_LIST_DIR}/module_tests/ze/ze_usm_memory_test.cpp
)
-if(GPU_RT_TYPE STREQUAL "ZE")
+if(OV_GPU_TESTS_RT STREQUAL "ZE")
list(APPEND GPU_UNIT_TESTS_SRCS ${GPU_UNIT_TESTS_ZE_RT_SRCS})
endif()
@@ -522,6 +523,6 @@ set(GPU_UNIT_TESTS_SYCL_RT_SRCS
${CMAKE_CURRENT_LIST_DIR}/module_tests/sycl/sycl_kernel_builder_test.cpp
${CMAKE_CURRENT_LIST_DIR}/module_tests/sycl/sycl_usm_memory_test.cpp
)
-if(GPU_RT_TYPE STREQUAL "SYCL")
+if(OV_GPU_TESTS_RT STREQUAL "SYCL")
list(APPEND GPU_UNIT_TESTS_SRCS ${GPU_UNIT_TESTS_SYCL_RT_SRCS})
endif()
diff --git a/src/plugins/intel_gpu/thirdparty/CMakeLists.txt b/src/plugins/intel_gpu/thirdparty/CMakeLists.txt
index 37d233304ec..b7e4d294d55 100644
--- a/src/plugins/intel_gpu/thirdparty/CMakeLists.txt
+++ b/src/plugins/intel_gpu/thirdparty/CMakeLists.txt
@@ -9,14 +9,23 @@ set(XETLA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/xetla/include/" CACHE PATH "P
#
if(ENABLE_ONEDNN_FOR_GPU)
- function(build_onednn_gpu GPU_RUNTIME)
+ # Cached because the installed OpenVINOConfig.cmake resolves this name; the per-twin names
+ # below derive from it, so it must stay outside the function to reach that scope.
+ set(DNNL_GPU_LIBRARY_NAME "openvino_onednn_gpu" CACHE STRING "Name of oneDNN library for Intel GPU Plugin")
+
+ # SUFFIX (empty for single-RT) makes all names per-runtime so COMBINED can build oneDNN
+ # twice (ZE and OCL differ, e.g. LTO is disabled for ZE) without colliding.
+ function(build_onednn_gpu GPU_RUNTIME SUFFIX)
include(ExternalProject)
- set(ONEDNN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_build")
- set(ONEDNN_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_install" CACHE PATH "Installation path for oneDNN GPU library")
- set(ONEDNN_PREFIX_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_root")
+ # Plain (non-CACHE) locals: a COMBINED build calls this function twice, and CACHE would
+ # freeze the first runtime's values, so the second would reuse them and collide. Anything
+ # the install/export needs is published to the cache explicitly instead (see below).
+ set(ONEDNN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_build${SUFFIX}")
+ set(ONEDNN_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_install${SUFFIX}")
+ set(ONEDNN_PREFIX_DIR "${CMAKE_CURRENT_BINARY_DIR}/onednn_gpu_root${SUFFIX}")
set(ONEDNN_ENABLED_PRIMITIVES "CONCAT;CONVOLUTION;DECONVOLUTION;GATED_MLP;MATMUL;REORDER;POOLING;REDUCTION;RNN")
set(ONEDNN_ENABLED_ISA "XELP;XEHP;XEHPG;XE2;XE3;XE3P")
- set(DNNL_GPU_LIBRARY_NAME "openvino_onednn_gpu" CACHE STRING "Name of oneDNN library for Intel GPU Plugin")
+ set(onednn_lib_name "${DNNL_GPU_LIBRARY_NAME}${SUFFIX}")
if(X86_64)
set(ONEDNN_TARGET_ARCH "X64" CACHE STRING "" FORCE)
@@ -126,9 +135,17 @@ if(ENABLE_ONEDNN_FOR_GPU)
endif()
endif()
- set(onednn_gpu_lib "${CMAKE_STATIC_LIBRARY_PREFIX}${DNNL_GPU_LIBRARY_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
- set(ONEDNN_GPU_LIB_PATH ${ONEDNN_INSTALL_DIR}/lib/${onednn_gpu_lib} CACHE FILEPATH "Path to oneDNN GPU library")
- set(ONEDNN_GPU_DIR ${CMAKE_CURRENT_SOURCE_DIR}/onednn_gpu CACHE FILEPATH "Path to oneDNN GPU repository")
+ set(onednn_gpu_lib "${CMAKE_STATIC_LIBRARY_PREFIX}${onednn_lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ # This twin's own library: everything below builds, links and installs THIS path, so it
+ # must stay local - sharing it across twins would link one runtime against the other's.
+ set(onednn_lib_path "${ONEDNN_INSTALL_DIR}/lib/${onednn_gpu_lib}")
+ # ONEDNN_GPU_LIB_PATH escapes to src/cmake/openvino.cmake (OpenVINOConfig PATH_VARS) so it
+ # must be cached, and it names one library: publish the default twin's, the one whose name
+ # DNNL_GPU_LIBRARY_NAME carries, rather than whichever call ran last.
+ if(NOT SUFFIX)
+ set(ONEDNN_GPU_LIB_PATH "${onednn_lib_path}" CACHE FILEPATH "Path to oneDNN GPU library" FORCE)
+ endif()
+ set(ONEDNN_GPU_DIR ${CMAKE_CURRENT_SOURCE_DIR}/onednn_gpu)
if(GPU_RUNTIME STREQUAL "ZE")
set(ONEDNN_GPU_RT "ZE")
# OneDNN is using different version of L0 headers
@@ -143,7 +160,7 @@ if(ENABLE_ONEDNN_FOR_GPU)
set(ONEDNN_ENABLE_LTO ${ENABLE_LTO})
endif()
- ExternalProject_Add(onednn_gpu_build
+ ExternalProject_Add(onednn_gpu_build${SUFFIX}
# Directory Options:
PREFIX "${ONEDNN_PREFIX_DIR}"
SOURCE_DIR "${ONEDNN_GPU_DIR}"
@@ -157,7 +174,7 @@ if(ENABLE_ONEDNN_FOR_GPU)
"-DDNNL_TARGET_ARCH=${ONEDNN_TARGET_ARCH}"
"-DDNNL_CPU_RUNTIME=NONE"
"-DDNNL_GPU_RUNTIME=${ONEDNN_GPU_RT}"
- "-DDNNL_LIBRARY_NAME=${DNNL_GPU_LIBRARY_NAME}"
+ "-DDNNL_LIBRARY_NAME=${onednn_lib_name}"
"-DCMAKE_INSTALL_PREFIX=${ONEDNN_INSTALL_DIR}"
"-DDNNL_ENABLE_CONCURRENT_EXEC=ON"
"-DDNNL_ENABLE_PRIMITIVE_CACHE=ON"
@@ -180,13 +197,13 @@ if(ENABLE_ONEDNN_FOR_GPU)
# Thus we pass it via CMAKE_CACHE_ARGS
${onednn_gpu_cache_args}
# Build Step Options:
- BUILD_BYPRODUCTS ${ONEDNN_GPU_LIB_PATH}
+ BUILD_BYPRODUCTS ${onednn_lib_path}
# Target Options:
EXCLUDE_FROM_ALL ON
)
if(WIN32 AND NOT BUILD_SHARED_LIBS)
- ExternalProject_Add_Step(onednn_gpu_build post-build
+ ExternalProject_Add_Step(onednn_gpu_build${SUFFIX} post-build
COMMAND ${CMAKE_COMMAND}
-D "BUILD_DIR=${ONEDNN_BUILD_DIR}/src"
-D "OUTPUT_DIR=${OPENVINO_STATIC_PDB_OUTPUT_DIRECTORY}"
@@ -213,24 +230,30 @@ if(ENABLE_ONEDNN_FOR_GPU)
list(APPEND LIB_DEFINITIONS NGEN_LINK_OPENCL)
endif()
- add_library(onednn_gpu_tgt INTERFACE)
- set_target_properties(onednn_gpu_tgt PROPERTIES
- INTERFACE_LINK_LIBRARIES $<BUILD_INTERFACE:${ONEDNN_GPU_LIB_PATH}>
+ add_library(onednn_gpu_tgt${SUFFIX} INTERFACE)
+ set_target_properties(onednn_gpu_tgt${SUFFIX} PROPERTIES
+ INTERFACE_LINK_LIBRARIES $<BUILD_INTERFACE:${onednn_lib_path}>
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${LIB_INCLUDE_DIRS}>"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${LIB_INCLUDE_DIRS}>"
INTERFACE_COMPILE_DEFINITIONS "${LIB_DEFINITIONS}"
)
- add_dependencies(onednn_gpu_tgt onednn_gpu_build)
+ add_dependencies(onednn_gpu_tgt${SUFFIX} onednn_gpu_build${SUFFIX})
if(NOT BUILD_SHARED_LIBS)
- ov_install_static_lib(onednn_gpu_tgt ${OV_CPACK_COMP_CORE})
+ ov_install_static_lib(onednn_gpu_tgt${SUFFIX} ${OV_CPACK_COMP_CORE})
# we need to install library explicitly and set_target_properties in OpenVINOConfig.cmake for 'onednn_gpu_tgt'
# to point to installation location of this file
- install(FILES "${ONEDNN_GPU_LIB_PATH}"
+ install(FILES "${onednn_lib_path}"
DESTINATION ${OV_CPACK_ARCHIVEDIR}
COMPONENT ${OV_CPACK_COMP_CORE})
endif()
endfunction()
- build_onednn_gpu(${GPU_RT_TYPE})
+ if(GPU_RT_TYPE STREQUAL "COMBINED")
+ # ZE twin keeps the default (empty-suffix) names; OCL twin is suffixed.
+ build_onednn_gpu(ZE "")
+ build_onednn_gpu(OCL "_ocl")
+ else()
+ build_onednn_gpu(${GPU_RT_TYPE} "")
+ endif()
endif()
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index 214954575ac..de64c01bc10 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -749,4 +749,7 @@ std::atomic<int> Plugin::_compiledModelLoadCounter{1};
static const ov::Version version = {CI_BUILD_NUMBER, NPU_PLUGIN_LIB_NAME.data()};
OV_DEFINE_PLUGIN_CREATE_FUNCTION(Plugin, version)
+// This plugin does not participate in device-name dispatch; export the probe as a stub.
+OV_DEFINE_PLUGIN_ENUMERATE_STUB()
+
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/tests/functional/behavior/npuw/llm_smoke_accuracy_tests.cpp b/src/plugins/intel_npu/tests/functional/behavior/npuw/llm_smoke_accuracy_tests.cpp
index 99749d81e99..122ffc1e21b 100644
--- a/src/plugins/intel_npu/tests/functional/behavior/npuw/llm_smoke_accuracy_tests.cpp
+++ b/src/plugins/intel_npu/tests/functional/behavior/npuw/llm_smoke_accuracy_tests.cpp
@@ -78,8 +78,7 @@ public:
try {
core->register_plugin(std::string(cpu_plugin_file_name) + OV_BUILD_POSTFIX, "CPU");
} catch (ov::Exception& ex) {
- if (std::string{ex.what()}.find("Device with \"CPU\" is already registered in the OpenVINO Runtime")
- == std::string::npos) {
+ if (std::string{ex.what()}.find("is already registered as device \"CPU\"") == std::string::npos) {
throw ex;
}
}
diff --git a/src/plugins/template/src/plugin.cpp b/src/plugins/template/src/plugin.cpp
index b2e12fa2bc0..23a4da95201 100644
--- a/src/plugins/template/src/plugin.cpp
+++ b/src/plugins/template/src/plugin.cpp
@@ -468,6 +468,11 @@ static const ov::Version version = {CI_BUILD_NUMBER, "openvino_template_plugin"}
OV_DEFINE_PLUGIN_CREATE_FUNCTION(ov::template_plugin::Plugin, version)
// ! [plugin:create_plugin_engine]
+// ! [plugin:enumerate_dispatch_devices]
+// This plugin does not participate in device-name dispatch; export the probe as a stub.
+OV_DEFINE_PLUGIN_ENUMERATE_STUB()
+// ! [plugin:enumerate_dispatch_devices]
+
// ! [plugin:get_runtime_requirements]
std::string_view ov::template_plugin::Plugin::get_runtime_requirements() const {
return "TEMPLATE_PLUGIN_CAPABILITIES_v1";
diff --git a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/hetero_synthetic.cpp b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/hetero_synthetic.cpp
index 8efbeb93cea..a6720c8f2bb 100644
--- a/src/tests/functional/base_func_tests/src/behavior/ov_plugin/hetero_synthetic.cpp
+++ b/src/tests/functional/base_func_tests/src/behavior/ov_plugin/hetero_synthetic.cpp
@@ -60,9 +60,10 @@ void OVHeteroSyntheticTest::SetUp() {
core->register_plugin(pluginParameter._location + OV_BUILD_POSTFIX, pluginParameter._name);
}
} catch (ov::Exception& ex) {
- if (std::string{ex.what()}.find("Device with \"" + pluginParameter._name
- + "\" is already registered in the OpenVINO Runtime")
- == std::string::npos) {
+ // A previous test case in this suite already registered this library under this name;
+ // the shared Core keeps it, so skip it here and leave it registered on TearDown.
+ if (std::string{ex.what()}.find("is already registered as device \"" + pluginParameter._name + "\"") ==
+ std::string::npos) {
throw ex;
} else {
registred = false;
diff --git a/src/tests/test_utils/unit_test_utils/CMakeLists.txt b/src/tests/test_utils/unit_test_utils/CMakeLists.txt
index 6142aec96c9..cd6dded8dd2 100644
--- a/src/tests/test_utils/unit_test_utils/CMakeLists.txt
+++ b/src/tests/test_utils/unit_test_utils/CMakeLists.txt
@@ -9,6 +9,7 @@ endif()
set(TARGET_NAME unit_test_utils)
add_subdirectory(mocks/mock_engine)
+add_subdirectory(mocks/mock_dispatch_candidate)
ov_add_target(
NAME ${TARGET_NAME}
diff --git a/src/tests/test_utils/unit_test_utils/mocks/mock_dispatch_candidate/CMakeLists.txt b/src/tests/test_utils/unit_test_utils/mocks/mock_dispatch_candidate/CMakeLists.txt
new file mode 100644
index 00000000000..86cecf20d1b
--- /dev/null
+++ b/src/tests/test_utils/unit_test_utils/mocks/mock_dispatch_candidate/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Copyright (C) 2018-2026 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+#
+
+# Two independent candidate module libraries built from one source, tagged "A"/"B".
+# Distinct .so files give each its own globals so the dispatch tests can script them
+# separately (registering the same .so twice would share a single dlopen handle).
+foreach(SUFFIX a b)
+ string(TOUPPER ${SUFFIX} TAG)
+ set(TARGET_NAME "mock_dispatch_candidate_${SUFFIX}")
+
+ add_library(${TARGET_NAME} MODULE ${CMAKE_CURRENT_SOURCE_DIR}/mock_dispatch_candidate.cpp)
+
+ target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+ target_link_libraries(${TARGET_NAME} PRIVATE openvino::runtime::dev)
+ target_compile_definitions(${TARGET_NAME} PRIVATE
+ IMPLEMENT_OPENVINO_RUNTIME_PLUGIN
+ MOCK_CANDIDATE_TAG="${TAG}")
+
+ install(TARGETS ${TARGET_NAME}
+ LIBRARY DESTINATION tests COMPONENT tests EXCLUDE_FROM_ALL)
+endforeach()
diff --git a/src/tests/test_utils/unit_test_utils/mocks/mock_dispatch_candidate/mock_dispatch_candidate.cpp b/src/tests/test_utils/unit_test_utils/mocks/mock_dispatch_candidate/mock_dispatch_candidate.cpp
new file mode 100644
index 00000000000..e28497dc821
--- /dev/null
+++ b/src/tests/test_utils/unit_test_utils/mocks/mock_dispatch_candidate/mock_dispatch_candidate.cpp
@@ -0,0 +1,167 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+// A minimal dispatch-group candidate plugin for testing ov::Core's device dispatch.
+// Built into two independent module libraries (tags "A"/"B" via MOCK_CANDIDATE_TAG) so
+// each has its own globals and can be scripted separately. Both register under one fake
+// device name. The enumeration probe returns a scriptable device list read from the env
+// var MOCK_DISPATCH_<TAG>_ENUM, formatted as ';'-separated "id,fingerprint_hex,score"
+// triples - e.g. "0,aa,100;1,bb,1". Empty/unset means "serves nothing".
+// Setting MOCK_DISPATCH_<TAG>_NO_ID_MAP=1 makes it stop reporting support for the device-id
+// renaming, so a test can drive Core's refusal to group a library that cannot be renamed.
+
+#include <cstdlib>
+#include <map>
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "openvino/core/except.hpp"
+#include "openvino/runtime/internal_properties.hpp"
+#include "openvino/runtime/iplugin.hpp"
+#include "openvino/runtime/properties.hpp"
+
+#ifndef MOCK_CANDIDATE_TAG
+# define MOCK_CANDIDATE_TAG "A"
+#endif
+
+namespace {
+
+class MockCandidatePlugin : public ov::IPlugin {
+public:
+ MockCandidatePlugin() {
+ set_device_name("FAKE");
+ }
+
+ std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>&,
+ const ov::AnyMap&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+ std::shared_ptr<ov::ICompiledModel> compile_model(const std::filesystem::path&, const ov::AnyMap&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+ std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>&,
+ const ov::AnyMap&,
+ const ov::SoPtr<ov::IRemoteContext>&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+ void set_property(const ov::AnyMap& properties) override {
+ for (const auto& p : properties) {
+ // Adopt Core's numbering, as a real group member would: record the ids it hands us and
+ // the order they arrived in, so a test can assert both the renaming and its timing.
+ if (p.first == ov::internal::device_id_map.name()) {
+ m_id_map = p.second.as<std::map<std::string, std::string>>();
+ m_saw_id_map_first = m_properties.empty();
+ continue;
+ }
+ m_properties[p.first] = p.second;
+ }
+ }
+ ov::Any get_property(const std::string& name, const ov::AnyMap&) const override {
+ if (name == ov::supported_properties.name())
+ return std::vector<ov::PropertyName>{};
+ if (name == ov::internal::supported_properties.name()) {
+ if (!supports_id_map())
+ return std::vector<ov::PropertyName>{};
+ return std::vector<ov::PropertyName>{
+ ov::PropertyName{ov::internal::device_id_map.name(), ov::PropertyMutability::WO}};
+ }
+ if (name == ov::available_devices.name())
+ return std::vector<std::string>{};
+ // The ids this instance now answers to, i.e. what Core renamed its own devices to.
+ if (name == "MOCK_ADOPTED_IDS") {
+ std::vector<std::string> ids;
+ for (const auto& [internal, canonical] : m_id_map)
+ ids.push_back(canonical);
+ return ids;
+ }
+ if (name == "MOCK_ID_MAP_APPLIED_FIRST")
+ return m_saw_id_map_first;
+ // Echo back whatever was set, so a test can assert set_property reached this instance.
+ if (const auto it = m_properties.find(name); it != m_properties.end())
+ return it->second;
+ // Report which candidate answered, so a test can assert who was constructed.
+ if (name == "MOCK_CANDIDATE_TAG")
+ return std::string(MOCK_CANDIDATE_TAG);
+ return {};
+ }
+ ov::SoPtr<ov::IRemoteContext> create_context(const ov::AnyMap&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+ ov::SoPtr<ov::IRemoteContext> get_default_context(const ov::AnyMap&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+ std::shared_ptr<ov::ICompiledModel> import_model(std::istream&, const ov::AnyMap&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+ std::shared_ptr<ov::ICompiledModel> import_model(std::istream&,
+ const ov::SoPtr<ov::IRemoteContext>&,
+ const ov::AnyMap&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+ std::shared_ptr<ov::ICompiledModel> import_model(const ov::Tensor&, const ov::AnyMap&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+ std::shared_ptr<ov::ICompiledModel> import_model(const ov::Tensor&,
+ const ov::SoPtr<ov::IRemoteContext>&,
+ const ov::AnyMap&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+ ov::SupportedOpsMap query_model(const std::shared_ptr<const ov::Model>&, const ov::AnyMap&) const override {
+ OPENVINO_NOT_IMPLEMENTED;
+ }
+
+private:
+ // Scripted opt-out, so a test can drive Core's refusal of a candidate that cannot be renamed.
+ static bool supports_id_map() {
+ const char* opt_out = std::getenv("MOCK_DISPATCH_" MOCK_CANDIDATE_TAG "_NO_ID_MAP");
+ return !opt_out || std::string(opt_out) != "1";
+ }
+
+ ov::AnyMap m_properties;
+ std::map<std::string, std::string> m_id_map;
+ bool m_saw_id_map_first = false;
+};
+
+// Parse the scripted enumeration for this candidate from its env var.
+void mock_enumerate(std::vector<ov::EnumeratedDevice>& out) noexcept {
+ out.clear();
+ const char* script = std::getenv("MOCK_DISPATCH_" MOCK_CANDIDATE_TAG "_ENUM");
+ if (!script)
+ return;
+ try {
+ std::stringstream devices(script);
+ std::string triple;
+ while (std::getline(devices, triple, ';')) {
+ if (triple.empty())
+ continue;
+ std::stringstream fields(triple);
+ std::string id, fingerprint_hex, score;
+ std::getline(fields, id, ',');
+ std::getline(fields, fingerprint_hex, ',');
+ std::getline(fields, score, ',');
+
+ // Odd-length hex would silently drop the last nibble and yield a different
+ // fingerprint; treat it as malformed so a bad script fails deterministically.
+ if (fingerprint_hex.size() % 2 != 0) {
+ out.clear();
+ return;
+ }
+
+ ov::EnumeratedDevice e;
+ e.internal_id = id;
+ for (size_t i = 0; i + 1 < fingerprint_hex.size(); i += 2)
+ e.fingerprint.push_back(static_cast<uint8_t>(std::stoi(fingerprint_hex.substr(i, 2), nullptr, 16)));
+ e.score = static_cast<ov::DeviceCompatibilityScore>(std::stoi(score));
+ out.push_back(std::move(e));
+ }
+ } catch (...) {
+ out.clear(); // malformed script: serve nothing rather than terminate the process
+ }
+}
+
+} // namespace
+
+static const ov::Version version = {"0.0.0", "openvino_mock_dispatch_candidate"};
+OV_DEFINE_PLUGIN_CREATE_FUNCTION(MockCandidatePlugin, version)
+OV_DEFINE_PLUGIN_ENUMERATE_FUNCTION(mock_enumerate)