OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU] Add runtime requirements compatibility string (#36540)
Omkar Vivek Sabnis82733ddc28e0
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.hppindex 94af3ebe2da..a38389c76ac 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@@ -46,6 +46,22 @@ public:ov::Any get_property(const std::string& name) const override;+ // Builds the simplified v1 GPU compatibility descriptor.+ // Format: meta=<ver>;ov=<ov>;desc=[<driver/hw features>]+ static std::string build_runtime_requirements(const cldnn::device_info& info);++ // 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;++ // 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+ // feature) instead of misreading their input count. Chosen far larger than any realistic input+ // count so such a blob's first post-cache_mode word can never collide with it ("OVEP_RRQ" in ASCII).+ // [DO NOT CHANGE THIS CONSTANT] changing it breaks import of every previously exported blob.+ static constexpr uint64_t runtime_requirements_magic = 0x4F5645505F525251ULL;+void set_property(const ov::AnyMap& properties) override {OPENVINO_THROW_NOT_IMPLEMENTED("It's not possible to set property of an already compiled model. Set property ""to Core::compile_model during compilation");@@ -84,6 +100,7 @@ private:std::vector<ov::Output<const ov::Node>> m_outputs;std::vector<std::shared_ptr<Graph>> m_graphs;bool m_loaded_from_cache;+ std::string m_runtime_requirements;std::shared_ptr<ov::Tensor> _backing_tensor;};diff --git a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp b/src/plugins/intel_gpu/src/plugin/compiled_model.cppindex fce3963fd3f..7488f472de5 100644--- a/src/plugins/intel_gpu/src/plugin/compiled_model.cpp+++ b/src/plugins/intel_gpu/src/plugin/compiled_model.cpp@@ -6,6 +6,7 @@#include "openvino/runtime/intel_gpu/properties.hpp"#include "openvino/runtime/internal_properties.hpp"#include "openvino/runtime/plugin_config.hpp"+#include "openvino/core/version.hpp"#include "intel_gpu/graph/serialization/binary_buffer.hpp"#include "intel_gpu/runtime/itt.hpp"@@ -13,6 +14,7 @@#include "intel_gpu/plugin/compiled_model.hpp"#include "intel_gpu/plugin/async_infer_request.hpp"+#include <sstream>#include <sys/types.h>namespace ov::intel_gpu {@@ -61,6 +63,7 @@ CompiledModel::CompiledModel(std::shared_ptr<ov::Model> model,m_inputs(ov::ICompiledModel::inputs()),m_outputs(ov::ICompiledModel::outputs()),m_loaded_from_cache(false) {+ m_runtime_requirements = build_runtime_requirements(m_context->get_engine().get_device_info());auto graph_base = std::make_shared<Graph>(model, m_context, m_config, 0);for (uint16_t n = 0; n < m_config.get_num_streams(); n++) {auto graph = n == 0 ? graph_base : std::make_shared<Graph>(graph_base, n);@@ -83,8 +86,27 @@ CompiledModel::CompiledModel(cldnn::BinaryInputBuffer& ib,, m_wait_executor(std::make_shared<ov::threading::CPUStreamsExecutor>(ov::threading::IStreamsExecutor::Config{"Intel GPU plugin wait executor"})), m_model_name(""), m_loaded_from_cache(loaded_from_cache) {+ // After ov::CacheMode the blob must start with the magic-guarded compatibility-descriptor+ // block written by export_model. A blob lacking the magic was produced by an OpenVINO build+ // predating this feature; cross-version blob import is not supported, so fail fast.+ uint64_t requirements_magic = 0;+ ib >> requirements_magic;+ OPENVINO_ASSERT(requirements_magic == runtime_requirements_magic,+ "[GPU] Cannot import compiled blob: missing compatibility descriptor "+ "(blob produced by an incompatible OpenVINO version).");++ uint32_t requirements_version = 0;+ ib >> requirements_version;+ // An unrecognized version means the descriptor block follows an on-disk contract we don't+ // understand, so the remainder of the blob cannot be parsed safely. Fail the import; the+ // caching layer then falls back to recompiling the model.+ OPENVINO_ASSERT(requirements_version == runtime_requirements_version,+ "[GPU] Unsupported compatibility descriptor version ", requirements_version,+ " in compiled blob (expected ", runtime_requirements_version, ").");+ ib >> m_runtime_requirements;+{- size_t num_params;+ size_t num_params = 0;ib >> num_params;for (size_t idx = 0; idx < num_params; ++idx) {@@ -173,9 +195,12 @@ std::shared_ptr<ov::IAsyncInferRequest> CompiledModel::create_infer_request() coreturn async_infer_request;}-// Cache blob format:-// [ is_dynamic flag ]-// [ ov::Node::Input/ ov::Node::Output ]+// Cache blob format (ov::CacheMode is written here but consumed by Plugin::import_model):+// [ ov::CacheMode ]+// [ compatibility-descriptor block:+// [ uint64 magic ][ uint32 descriptor layout version ][ descriptor string ] ]+// [ inputs: count + per-input records ]+// [ outputs: count + per-output records ]// [ ov::intel_gpu::Graph ]void CompiledModel::export_model(std::ostream& model) const {OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "CompiledModel::export_model");@@ -192,6 +217,13 @@ void CompiledModel::export_model(std::ostream& model) const {ob << cldnn::make_data(&cache_mode, sizeof(ov::CacheMode));+ // Compatibility-descriptor block (see blob format above).+ const uint64_t requirements_magic = runtime_requirements_magic;+ ob << requirements_magic;+ const uint32_t requirements_version = runtime_requirements_version;+ ob << requirements_version;+ ob << m_runtime_requirements;+// Inputs{const auto& params = inputs();@@ -238,6 +270,20 @@ void CompiledModel::export_model(std::ostream& model) const {std::shared_ptr<const ov::Model> CompiledModel::get_runtime_model() const {return get_graph(0)->get_runtime_model();}++std::string CompiledModel::build_runtime_requirements(const cldnn::device_info& info) {+ // v1 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).+ std::ostringstream ss;+ ss << "meta=1.0"+ << ";ov=" << OPENVINO_VERSION_MAJOR << "." << OPENVINO_VERSION_MINOR << "." << OPENVINO_VERSION_PATCH+ << ";desc=[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 << "]";+ return ss.str();+}const std::vector<std::shared_ptr<Graph>>& CompiledModel::get_graphs() const {return m_graphs;}@@ -278,6 +324,7 @@ ov::Any CompiledModel::get_property(const std::string& name) const {ov::PropertyName{ov::hint::kv_cache_precision.name(), PropertyMutability::RO},ov::PropertyName{ov::device::id.name(), PropertyMutability::RO},ov::PropertyName{ov::execution_devices.name(), PropertyMutability::RO},+ ov::PropertyName{ov::runtime_requirements.name(), PropertyMutability::RO},};} else if (name == ov::model_name) {return decltype(ov::model_name)::value_type {m_model_name};@@ -290,6 +337,8 @@ ov::Any CompiledModel::get_property(const std::string& name) const {return decltype(ov::optimal_number_of_infer_requests)::value_type {nr};} else if (name == ov::execution_devices) {return decltype(ov::execution_devices)::value_type{m_context->get_device_name()};+ } else if (name == ov::runtime_requirements) {+ return decltype(ov::runtime_requirements)::value_type{m_runtime_requirements};}return m_config.get_property(name, OptionVisibility::RELEASE);diff --git a/src/plugins/intel_gpu/src/plugin/plugin.cpp b/src/plugins/intel_gpu/src/plugin/plugin.cppindex 0b6732b84b4..ca2786bf4cb 100644--- a/src/plugins/intel_gpu/src/plugin/plugin.cpp+++ b/src/plugins/intel_gpu/src/plugin/plugin.cpp@@ -701,6 +701,17 @@ ov::Any Plugin::get_metric(const std::string& name, const ov::AnyMap& options) creturn decltype(ov::device::pci_info)::value_type {info};} else if (name == ov::internal::cache_header_alignment) {return decltype(ov::internal::cache_header_alignment)::value_type{4096};+ } else if (name == ov::compatibility_check) {+ if (auto it = options.find(ov::runtime_requirements.name()); it != options.end()) {+ const auto& requirements = it->second.as<std::string>();+ if (!requirements.empty()) {+ // v1: full-string equality against the current device descriptor.+ const auto current = CompiledModel::build_runtime_requirements(device_info);+ return requirements == current ? ov::CompatibilityCheck::SUPPORTED+ : ov::CompatibilityCheck::UNSUPPORTED;+ }+ }+ return ov::CompatibilityCheck::NOT_APPLICABLE;} else {OPENVINO_THROW("Unsupported metric key ", name);}@@ -743,6 +754,7 @@ std::vector<ov::PropertyName> Plugin::get_supported_properties() const {ov::PropertyName{ov::intel_gpu::uarch_version.name(), PropertyMutability::RO},ov::PropertyName{ov::intel_gpu::execution_units_count.name(), PropertyMutability::RO},ov::PropertyName{ov::intel_gpu::memory_statistics.name(), PropertyMutability::RO},+ ov::PropertyName{ov::compatibility_check.name(), PropertyMutability::RO},// Configsov::PropertyName{ov::enable_profiling.name(), PropertyMutability::RW},diff --git a/src/plugins/intel_gpu/tests/functional/behavior/compatibility_string.cpp b/src/plugins/intel_gpu/tests/functional/behavior/compatibility_string.cppnew file mode 100644index 00000000000..dee766ad040--- /dev/null+++ b/src/plugins/intel_gpu/tests/functional/behavior/compatibility_string.cpp@@ -0,0 +1,259 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <algorithm>+#include <cstring>+#include <iostream>+#include <sstream>++#include "common_test_utils/subgraph_builders/conv_pool_relu.hpp"+#include "openvino/runtime/core.hpp"+#include "openvino/runtime/intel_gpu/properties.hpp"+#include "openvino/runtime/properties.hpp"+#include "shared_test_classes/base/ov_behavior_test_utils.hpp"++namespace {++class CompatibilityStringGPU : public ::testing::Test {+public:+ std::shared_ptr<ov::Model> model;++ void SetUp() override {+ model = ov::test::utils::make_conv_pool_relu();+ }+};++// The compiled model exposes a non-empty runtime requirements descriptor.+TEST_F(CompatibilityStringGPU, RuntimeRequirementsIsSupportedAndNonEmpty) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ ov::Core core;+ ov::CompiledModel compiled_model;+ OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, ov::test::utils::DEVICE_GPU));++ auto supported = compiled_model.get_property(ov::supported_properties);+ ASSERT_NE(std::find(supported.begin(), supported.end(), ov::runtime_requirements.name()), supported.end());++ std::string requirements;+ OV_ASSERT_NO_THROW(requirements = compiled_model.get_property(ov::runtime_requirements));+ ASSERT_FALSE(requirements.empty());+ std::cout << "[ INFO ] GPU ov::runtime_requirements = " << requirements << std::endl;+}++// The plugin advertises compatibility_check among its supported properties.+TEST_F(CompatibilityStringGPU, CompatibilityCheckListedInSupportedProperties) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ ov::Core core;+ auto supported = core.get_property(ov::test::utils::DEVICE_GPU, ov::supported_properties);+ ASSERT_NE(std::find(supported.begin(), supported.end(), ov::compatibility_check.name()), supported.end());+}++// A descriptor generated on this device is reported as SUPPORTED.+TEST_F(CompatibilityStringGPU, GenerateAndCheckSupported) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ ov::Core core;+ ov::CompiledModel compiled_model;+ OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, ov::test::utils::DEVICE_GPU));++ const auto requirements = compiled_model.get_property(ov::runtime_requirements);++ ov::CompatibilityCheck result = ov::CompatibilityCheck::NOT_APPLICABLE;+ OV_ASSERT_NO_THROW(result = core.get_property(ov::test::utils::DEVICE_GPU,+ ov::compatibility_check,+ {{ov::runtime_requirements.name(), requirements}}));+ ASSERT_EQ(result, ov::CompatibilityCheck::SUPPORTED);+}++// A tampered descriptor is reported as UNSUPPORTED.+TEST_F(CompatibilityStringGPU, TamperedRequirementsUnsupported) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ ov::Core core;+ ov::CompiledModel compiled_model;+ OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, ov::test::utils::DEVICE_GPU));++ auto requirements = compiled_model.get_property(ov::runtime_requirements);+ requirements += ";tampered=1";++ ov::CompatibilityCheck result = ov::CompatibilityCheck::NOT_APPLICABLE;+ OV_ASSERT_NO_THROW(result = core.get_property(ov::test::utils::DEVICE_GPU,+ ov::compatibility_check,+ {{ov::runtime_requirements.name(), requirements}}));+ ASSERT_EQ(result, ov::CompatibilityCheck::UNSUPPORTED);+}++// An empty or missing requirements argument yields NOT_APPLICABLE.+TEST_F(CompatibilityStringGPU, EmptyAndNoArgumentNotApplicable) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ ov::Core core;++ ov::CompatibilityCheck empty_result = ov::CompatibilityCheck::SUPPORTED;+ OV_ASSERT_NO_THROW(empty_result = core.get_property(ov::test::utils::DEVICE_GPU,+ ov::compatibility_check,+ {{ov::runtime_requirements.name(), std::string{}}}));+ ASSERT_EQ(empty_result, ov::CompatibilityCheck::NOT_APPLICABLE);++ ov::CompatibilityCheck missing_result = ov::CompatibilityCheck::SUPPORTED;+ OV_ASSERT_NO_THROW(missing_result = core.get_property(ov::test::utils::DEVICE_GPU, ov::compatibility_check));+ ASSERT_EQ(missing_result, ov::CompatibilityCheck::NOT_APPLICABLE);+}++// The descriptor survives an export/import round-trip of the compiled blob.+TEST_F(CompatibilityStringGPU, ExportImportPreservesRequirements) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ ov::Core core;+ ov::CompiledModel compiled_model;+ OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, ov::test::utils::DEVICE_GPU));+ const auto requirements = compiled_model.get_property(ov::runtime_requirements);++ std::stringstream blob;+ OV_ASSERT_NO_THROW(compiled_model.export_model(blob));++ ov::CompiledModel imported;+ OV_ASSERT_NO_THROW(imported = core.import_model(blob, ov::test::utils::DEVICE_GPU));++ std::string imported_requirements;+ OV_ASSERT_NO_THROW(imported_requirements = imported.get_property(ov::runtime_requirements));+ ASSERT_EQ(requirements, imported_requirements);+}++// Locks the on-disk contract: the compiled blob must begin (after ov::CacheMode) with the+// magic-guarded descriptor block. The magic is far larger than any realistic input count, so a+// non-conforming blob is rejected cleanly instead of being misread as a descriptor length.+TEST_F(CompatibilityStringGPU, DescriptorBlockIsMagicGuardedInBlob) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ ov::Core core;+ ov::CompiledModel compiled_model;+ OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, ov::test::utils::DEVICE_GPU));++ std::stringstream blob;+ OV_ASSERT_NO_THROW(compiled_model.export_model(blob));+ const std::string data = blob.str();++ // Must match CompiledModel::runtime_requirements_magic ("OVEP_RRQ").+ constexpr uint64_t expected_magic = 0x4F5645505F525251ULL;+ ASSERT_GE(data.size(), sizeof(ov::CacheMode) + sizeof(expected_magic));++ uint64_t magic = 0;+ std::memcpy(&magic, data.data() + sizeof(ov::CacheMode), sizeof(magic));+ ASSERT_EQ(magic, expected_magic);+ // The guard only works if the magic can never collide with a real input count.+ ASSERT_GT(magic, static_cast<uint64_t>(1) << 32) << "magic must dwarf any realistic input count";+}++// A blob whose descriptor header is corrupted must be rejected by import rather than mis-parsed.+// The corruption is byte-for-byte in place, so the blob size (and the graph's page alignment) is+// unchanged and the failure comes purely from the magic/version guard. Covers both guard paths:+// - magic absent -> "missing compatibility descriptor"+// - unrecognized version -> "unsupported compatibility descriptor version"+TEST_F(CompatibilityStringGPU, ImportRejectsCorruptedDescriptorHeader) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ ov::Core core;+ ov::CompiledModel compiled_model;+ OV_ASSERT_NO_THROW(compiled_model = core.compile_model(model, ov::test::utils::DEVICE_GPU));++ std::stringstream good_blob;+ OV_ASSERT_NO_THROW(compiled_model.export_model(good_blob));+ const std::string original = good_blob.str();++ constexpr size_t magic_offset = sizeof(ov::CacheMode);+ constexpr size_t version_offset = magic_offset + sizeof(uint64_t);+ ASSERT_GE(original.size(), version_offset + sizeof(uint32_t));++ // Sanity: the untouched blob imports cleanly (guards the offsets used below).+ {+ std::stringstream blob(original);+ ov::CompiledModel imported;+ OV_ASSERT_NO_THROW(imported = core.import_model(blob, ov::test::utils::DEVICE_GPU));+ }++ // Corrupt the magic: the importer can no longer recognize the descriptor block and must fail.+ {+ std::string corrupted = original;+ corrupted[magic_offset] ^= 0xFF;+ std::stringstream blob(corrupted);+ EXPECT_THROW((void)core.import_model(blob, ov::test::utils::DEVICE_GPU), ov::Exception);+ }++ // Keep the magic but set an unrecognized descriptor version: import must fail.+ {+ std::string corrupted = original;+ const uint32_t bad_version = 0xFFFFFFFFu;+ std::memcpy(&corrupted[version_offset], &bad_version, sizeof(bad_version));+ std::stringstream blob(corrupted);+ EXPECT_THROW((void)core.import_model(blob, ov::test::utils::DEVICE_GPU), ov::Exception);+ }+}++// Mirror of the ONNX Runtime OrtCompiledModelCompatibility states that the GPU plugin+// can actually produce. OpenVINO's ov::CompatibilityCheck has 3 states and the GPU+// plugin never reports a "runs but suboptimal" outcome, so the ORT+// EP_SUPPORTED_PREFER_RECOMPILATION state is intentionally not mirrored here.+enum class OrtCompatibility {+ EP_NOT_APPLICABLE = 0,+ EP_SUPPORTED_OPTIMAL,+ EP_UNSUPPORTED,+};++// The mapping an OpenVINO EP would apply when answering ORT's+// ValidateCompiledModelCompatibilityInfo / GetModelCompatibilityForEpDevices.+OrtCompatibility to_ort_compatibility(ov::CompatibilityCheck check) {+ switch (check) {+ case ov::CompatibilityCheck::SUPPORTED:+ return OrtCompatibility::EP_SUPPORTED_OPTIMAL;+ case ov::CompatibilityCheck::UNSUPPORTED:+ return OrtCompatibility::EP_UNSUPPORTED;+ case ov::CompatibilityCheck::NOT_APPLICABLE:+ default:+ return OrtCompatibility::EP_NOT_APPLICABLE;+ }+}++// End-to-end simulation of the ONNX Runtime EP-compatibility handshake:+// 1. Producer side (OrtEp::GetCompiledModelCompatibilityInfo): compile a model and+// read ov::runtime_requirements to obtain the opaque descriptor string.+// 2. The descriptor crosses an opaque serialization boundary (stand-in for the+// EPContext node attribute). It must survive byte-for-byte.+// 3. Validator side (OrtEpFactory::ValidateCompiledModelCompatibilityInfo): on a+// fresh Core, WITHOUT importing or compiling anything, query+// ov::compatibility_check and map the result to ORT's 4-state enum.+TEST_F(CompatibilityStringGPU, OrtFactoryValidationFlow) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ std::string descriptor;+ {+ // Producer side: a separate Core, as if running in the compiling process.+ ov::Core producer_core;+ ov::CompiledModel compiled_model;+ OV_ASSERT_NO_THROW(compiled_model = producer_core.compile_model(model, ov::test::utils::DEVICE_GPU));+ OV_ASSERT_NO_THROW(descriptor = compiled_model.get_property(ov::runtime_requirements));+ ASSERT_FALSE(descriptor.empty());+ }++ // Opaque transfer of the descriptor (e.g. embedded in an EPContext node).+ std::stringstream channel;+ channel << descriptor;+ const std::string received = channel.str();+ ASSERT_EQ(descriptor, received) << "descriptor must round-trip byte-for-byte";++ // Validator side: a fresh Core with no session/import, mimicking the EP factory.+ ov::Core validator_core;++ ov::CompatibilityCheck matched = ov::CompatibilityCheck::NOT_APPLICABLE;+ OV_ASSERT_NO_THROW(matched = validator_core.get_property(ov::test::utils::DEVICE_GPU,+ ov::compatibility_check,+ {{ov::runtime_requirements.name(), received}}));+ EXPECT_EQ(to_ort_compatibility(matched), OrtCompatibility::EP_SUPPORTED_OPTIMAL);++ ov::CompatibilityCheck tampered = ov::CompatibilityCheck::NOT_APPLICABLE;+ OV_ASSERT_NO_THROW(tampered = validator_core.get_property(ov::test::utils::DEVICE_GPU,+ ov::compatibility_check,+ {{ov::runtime_requirements.name(), received + ";tampered=1"}}));+ EXPECT_EQ(to_ort_compatibility(tampered), OrtCompatibility::EP_UNSUPPORTED);++ ov::CompatibilityCheck empty = ov::CompatibilityCheck::SUPPORTED;+ OV_ASSERT_NO_THROW(empty = validator_core.get_property(ov::test::utils::DEVICE_GPU,+ ov::compatibility_check,+ {{ov::runtime_requirements.name(), std::string{}}}));+ EXPECT_EQ(to_ort_compatibility(empty), OrtCompatibility::EP_NOT_APPLICABLE);+}++} // namespace