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
[core] Add is_supported_property to plugin interface (#34113)
Pawel Raasz083b0f1a9f61
diff --git a/src/inference/dev_api/openvino/runtime/iplugin.hpp b/src/inference/dev_api/openvino/runtime/iplugin.hppindex 1c680bb1a93..0c72b0bfa9e 100644--- a/src/inference/dev_api/openvino/runtime/iplugin.hpp+++ b/src/inference/dev_api/openvino/runtime/iplugin.hpp@@ -234,8 +234,18 @@ public:*/const std::shared_ptr<ov::threading::ExecutorManager>& get_executor_manager() const;+virtual ~IPlugin() = default;+ /**+ * @brief Checks if a property is supported by the plugin.+ *+ * @param name Name of the property.+ * @param arguments Optional map of arguments for the property.+ * @return true if the property is supported, otherwise false.+ */+ virtual bool is_property_supported(const std::string& name, const ov::AnyMap& arguments = {}) const;+protected:IPlugin();diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cppindex 29292b77c26..96f0a406840 100644--- a/src/inference/src/dev/core_impl.cpp+++ b/src/inference/src/dev/core_impl.cpp@@ -252,14 +252,12 @@ ov::SoPtr<ov::ICompiledModel> import_compiled_model(const ov::Plugin& plugin,auto cfg = config;const auto apply_model_hint = ov::util::VariantVisitor{[&cfg, &plugin](const std::shared_ptr<const ov::Model>& model_ptr) {- if (model_ptr != nullptr &&- ov::util::contains(plugin.get_property(ov::supported_properties), ov::hint::model)) {+ if (model_ptr != nullptr && plugin.is_property_supported(ov::hint::model.name())) {cfg[ov::hint::model.name()] = model_ptr;}},[&cfg, &plugin](const std::filesystem::path& model_path) {- if (cfg.count(ov::weights_path.name()) == 0 &&- ov::util::contains(plugin.get_property(ov::supported_properties), ov::weights_path)) {+ if (cfg.count(ov::weights_path.name()) == 0 && plugin.is_property_supported(ov::weights_path.name())) {std::filesystem::path weights_path{model_path};weights_path.replace_extension(".bin");if (ov::util::file_exists(weights_path)) {@@ -400,7 +398,7 @@ ov::Parsed parse_device_config(const std::string& device_name,void emplace_cache_dir_if_supported(ov::AnyMap& config,const ov::Plugin& plugin,const std::filesystem::path& cache_dir) {- if (ov::util::contains(plugin.get_property(ov::supported_properties), ov::cache_dir)) {+ if (plugin.is_property_supported(ov::cache_dir.name())) {config.emplace(ov::cache_dir(ov::util::path_to_string(cache_dir)));}}@@ -1149,10 +1147,10 @@ std::shared_ptr<const ov::Model> ov::CoreImpl::apply_auto_batching(const std::shdeviceNameWithBatchSize = device_name.substr(pos + 1);deviceNameWithoutBatch = ov::DeviceIDParser::get_batch_device(deviceNameWithBatchSize);if (device_name.find("(") == std::string::npos) {- auto supported_properties = ICore::get_property(deviceNameWithoutBatch, ov::supported_properties, {});- if (std::find(supported_properties.begin(), supported_properties.end(), ov::optimal_batch_size) ==- supported_properties.end())+ 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())) {return model;+ }}// when user sets the BATCH device explicitly, we may check the dims less strictly// as the result is being checked by the user@@ -1185,12 +1183,9 @@ std::shared_ptr<const ov::Model> ov::CoreImpl::apply_auto_batching(const std::shif (is_proxy_device(parsed.m_device_name))return model;deviceNameWithoutBatch = device_name;- auto metrics = get_plugin(parsed.m_device_name)- .get_property(ov::supported_properties.name(), parsed.m_config)- .as<std::vector<ov::PropertyName>>();- auto it = std::find(metrics.begin(), metrics.end(), ov::optimal_batch_size.name());- if (metrics.end() == it)+ if (!get_plugin(parsed.m_device_name).is_property_supported(ov::optimal_batch_size.name(), parsed.m_config)) {return model;+ }// if applicable, the Auto-Batching is implicitly enabled via the performance hintsbool bTputInPlg = get_plugin(parsed.m_device_name)@@ -1440,20 +1435,16 @@ bool ov::CoreImpl::device_supports_model_caching(const std::string& device_name)return device_supports_model_caching(get_plugin(parsed.m_device_name));}-bool ov::CoreImpl::device_supports_property(const ov::Plugin& plugin, const ov::PropertyName& key) const {- return util::contains(plugin.get_property(ov::supported_properties), key);-}--bool ov::CoreImpl::device_supports_internal_property(const ov::Plugin& plugin, const ov::PropertyName& key) const {- return util::contains(plugin.get_property(ov::internal::supported_properties), key);-}-bool ov::CoreImpl::device_supports_model_caching(const ov::Plugin& plugin, const ov::AnyMap& arguments) const {ov::AnyMap properties_to_virtual_dev = arguments.empty() ? ov::AnyMap{ov::device::priorities("")} : arguments;return ov::is_virtual_device(plugin.get_name()) ? plugin.supports_model_caching(properties_to_virtual_dev): plugin.supports_model_caching();}+bool ov::CoreImpl::device_supports_internal_property(const ov::Plugin& plugin, const ov::PropertyName& key) const {+ return util::contains(plugin.get_property(ov::internal::supported_properties), key);+}+ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model_and_cache(ov::Plugin& plugin,const std::shared_ptr<const ov::Model>& model,const ov::AnyMap& parsedConfig,@@ -1506,8 +1497,8 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(try {cacheContent.m_cache_manager->read_cache_entry(cacheContent.m_blob_id,- cacheContent.m_mmap_enabled && ov::util::contains(plugin.get_property(ov::internal::supported_properties),- ov::internal::caching_with_mmap),+ cacheContent.m_mmap_enabled &&+ device_supports_internal_property(plugin, ov::internal::caching_with_mmap.name()),[&](ICacheManager::CompiledBlobVariant& compiled_blob) {OV_ITT_SCOPE(FIRST_INFERENCE,ov::itt::domains::LoadTime,@@ -1530,8 +1521,9 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(// Original file is changed, don't use cacheOPENVINO_THROW("Original model file is changed");}- if (util::contains(plugin.get_property(ov::internal::supported_properties),- ov::internal::compiled_model_runtime_properties_supported.name())) {+ if (device_supports_internal_property(+ plugin,+ ov::internal::compiled_model_runtime_properties_supported.name())) {ov::AnyMap compiled_model_runtime_properties = {{ov::internal::compiled_model_runtime_properties.name(),std::string(header.get_runtime_info())}};@@ -1556,12 +1548,11 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(ov::AnyMap update_config = config;update_config[ov::loaded_from_cache.name()] = true;- if (cacheContent.model &&- util::contains(plugin.get_property(ov::supported_properties), ov::hint::model)) {+ if (cacheContent.model && plugin.is_property_supported(ov::hint::model.name())) {update_config[ov::hint::model.name()] = cacheContent.model;}- if (util::contains(plugin.get_property(ov::supported_properties), ov::weights_path)) {+ if (plugin.is_property_supported(ov::weights_path.name())) {std::filesystem::path weights_path;if (auto&& path_hint = update_config.find(ov::weights_path.name());@@ -1611,7 +1602,6 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(ov::AnyMap ov::CoreImpl::create_compile_config(const ov::Plugin& plugin, const ov::AnyMap& user_config) const {ov::AnyMap property_config;-// 0. Move ov::device::priorities key to property_configauto device_priorities_it = user_config.find(ov::device::priorities.name());if (device_priorities_it != user_config.end()) {@@ -1619,7 +1609,7 @@ ov::AnyMap ov::CoreImpl::create_compile_config(const ov::Plugin& plugin, const o}// 1. Move DEVICE_ID key to property_config- const bool supports_device_id = device_supports_property(plugin, ov::device::id);+ const bool supports_device_id = plugin.is_property_supported(ov::device::id.name());auto deviceIt = user_config.find(ov::device::id.name());if (deviceIt != user_config.end()) {property_config[deviceIt->first] = deviceIt->second.as<std::string>();diff --git a/src/inference/src/dev/core_impl.hpp b/src/inference/src/dev/core_impl.hppindex 7302874d7cb..b28801f18ef 100644--- a/src/inference/src/dev/core_impl.hpp+++ b/src/inference/src/dev/core_impl.hpp@@ -213,7 +213,6 @@ private:bool device_supports_model_caching(const ov::Plugin& plugin, const ov::AnyMap& orig_config = {}) const;- bool device_supports_property(const ov::Plugin& plugin, const ov::PropertyName& key) const;bool device_supports_internal_property(const ov::Plugin& plugin, const ov::PropertyName& key) const;ov::AnyMap create_compile_config(const ov::Plugin& plugin, const ov::AnyMap& orig_config) const;diff --git a/src/inference/src/dev/iplugin.cpp b/src/inference/src/dev/iplugin.cppindex 4e6d63e839d..588af7b2c75 100644--- a/src/inference/src/dev/iplugin.cpp+++ b/src/inference/src/dev/iplugin.cpp@@ -9,6 +9,8 @@#include "openvino/op/util/op_types.hpp"#include "openvino/op/util/shape_of_base.hpp"#include "openvino/pass/manager.hpp"+#include "openvino/runtime/properties.hpp"+#include "openvino/util/common_util.hpp"#include "transformations/common_optimizations/fused_names_cleanup.hpp"#include "transformations/rt_info/fused_names_attribute.hpp"@@ -88,6 +90,11 @@ std::shared_ptr<ov::ICompiledModel> ov::IPlugin::compile_model(const std::stringreturn compile_model(model, local_properties);}+bool ov::IPlugin::is_property_supported(const std::string& name, const ov::AnyMap& arguments) const {+ const auto properties = get_property(ov::supported_properties.name(), arguments);+ return util::contains(properties.as<std::vector<ov::PropertyName>>(), name);+}+std::unordered_set<std::string> ov::get_supported_nodes(const std::shared_ptr<const ov::Model>& model,std::function<void(std::shared_ptr<ov::Model>&)> transform,diff --git a/src/inference/src/dev/plugin.cpp b/src/inference/src/dev/plugin.cppindex 48d8f4284fb..aef53804097 100644--- a/src/inference/src/dev/plugin.cpp+++ b/src/inference/src/dev/plugin.cpp@@ -113,10 +113,11 @@ ov::Any ov::Plugin::get_property(const std::string& name, const AnyMap& argument}bool ov::Plugin::supports_model_caching(const ov::AnyMap& arguments) const {- bool supported(false);- supported =- util::contains(get_property(ov::supported_properties), ov::device::capabilities) &&- util::contains(get_property(ov::device::capabilities, arguments), ov::device::capability::EXPORT_IMPORT) &&- util::contains(get_property(ov::internal::supported_properties), ov::internal::caching_properties);- return supported;+ return util::contains(get_property(ov::internal::supported_properties), ov::internal::caching_properties) &&+ is_property_supported(ov::device::capabilities.name(), arguments) &&+ util::contains(get_property(ov::device::capabilities, arguments), ov::device::capability::EXPORT_IMPORT);+}++bool ov::Plugin::is_property_supported(const std::string& name, const ov::AnyMap& arguments) const {+ OV_PLUGIN_CALL_STATEMENT(return m_ptr->is_property_supported(name, arguments));}diff --git a/src/inference/src/dev/plugin.hpp b/src/inference/src/dev/plugin.hppindex 2f2cdbb2867..1a6c5894973 100644--- a/src/inference/src/dev/plugin.hpp+++ b/src/inference/src/dev/plugin.hpp@@ -82,6 +82,8 @@ public:return get_property(property.name(), arguments).template as<T>();}bool supports_model_caching(const AnyMap& arguments = {}) const;++ bool is_property_supported(const std::string& name, const ov::AnyMap& arguments = {}) const;};} // namespace ov