diff --git a/src/inference/dev_api/openvino/runtime/icompiled_model.hpp b/src/inference/dev_api/openvino/runtime/icompiled_model.hpp index 9cbe08b7d54..2620b894d1b 100644 --- a/src/inference/dev_api/openvino/runtime/icompiled_model.hpp +++ b/src/inference/dev_api/openvino/runtime/icompiled_model.hpp @@ -140,6 +140,13 @@ public: virtual ~ICompiledModel() = default; + /** + * @brief Detects that compiled model supports caching and import/export + * + * @return true if caching is supported, else in other case + */ + bool supports_caching() const; + private: std::shared_ptr m_plugin; std::vector> m_inputs; diff --git a/src/inference/src/dev/icompiled_model.cpp b/src/inference/src/dev/icompiled_model.cpp index 6e81c091719..af848150d21 100644 --- a/src/inference/src/dev/icompiled_model.cpp +++ b/src/inference/src/dev/icompiled_model.cpp @@ -6,8 +6,13 @@ #include "dev/converter_utils.hpp" #include "icompiled_model_wrapper.hpp" +#include "ie_common.h" +#include "ie_plugin_config.hpp" +#include "openvino/core/except.hpp" #include "openvino/core/model.hpp" +#include "openvino/runtime/internal_properties.hpp" #include "openvino/runtime/properties.hpp" +#include "openvino/util/common_util.hpp" #include "transformations/utils/utils.hpp" ov::ICompiledModel::ICompiledModel(const std::shared_ptr& model, @@ -144,3 +149,26 @@ ov::SoPtr ov::ICompiledModel::get_context() const { return m_context; return m_plugin->get_default_context({}); } + +bool ov::ICompiledModel::supports_caching() const { + bool supported(false); + try { + auto supportedMetricKeys = get_property(METRIC_KEY(SUPPORTED_METRICS)).as>(); + supported = util::contains(supportedMetricKeys, METRIC_KEY(IMPORT_EXPORT_SUPPORT)) && + get_property(METRIC_KEY(IMPORT_EXPORT_SUPPORT)).as(); + } catch (const InferenceEngine::Exception& ex) { + } catch (const ov::Exception& ex) { + } + if (!supported) { + supported = util::contains(get_property(ov::supported_properties.name()).as>(), + ov::device::capabilities) && + util::contains(get_property(ov::device::capabilities.name()).as>(), + ov::device::capability::EXPORT_IMPORT); + } + if (supported) { + supported = + util::contains(get_property(ov::internal::supported_properties.name()).as>(), + ov::internal::caching_properties); + } + return supported; +} diff --git a/src/plugins/hetero/src/compiled_model.cpp b/src/plugins/hetero/src/compiled_model.cpp index 519218e18b1..1c8e81aae32 100644 --- a/src/plugins/hetero/src/compiled_model.cpp +++ b/src/plugins/hetero/src/compiled_model.cpp @@ -687,33 +687,30 @@ void ov::hetero::CompiledModel::export_model(std::ostream& model_stream) const { model_stream << std::endl; for (const auto& comp_model_desc : m_compiled_submodels) { - if (get_plugin()->get_core()->device_supports_model_caching(comp_model_desc.device)) { - try { - // Batch plugin reports property of low level plugin - // If we use Batch plugin inside hetero, we won't be able to call export - // Auto batch plugin will throw NOT_IMPLEMENTED - comp_model_desc.compiled_model->export_model(model_stream); - continue; - } catch (ov::NotImplemented&) { - } + if (comp_model_desc.compiled_model->supports_caching()) { + // Batch plugin reports property of low level plugin + // If we use Batch plugin inside hetero, we won't be able to call export + // Auto batch plugin will throw NOT_IMPLEMENTED + comp_model_desc.compiled_model->export_model(model_stream); + } else { + auto model = comp_model_desc.model; + if (!model) + OPENVINO_THROW("OpenVINO Model is empty"); + + std::stringstream xmlFile, binFile; + ov::pass::Serialize serializer(xmlFile, binFile); + serializer.run_on_model(model); + + auto constants = binFile.str(); + auto model_str = xmlFile.str(); + + auto dataSize = static_cast(model_str.size()); + model_stream.write(reinterpret_cast(&dataSize), sizeof(dataSize)); + model_stream.write(model_str.c_str(), dataSize); + + dataSize = static_cast(constants.size()); + model_stream.write(reinterpret_cast(&dataSize), sizeof(dataSize)); + model_stream.write(reinterpret_cast(&constants[0]), dataSize); } - auto model = comp_model_desc.model; - if (!model) - OPENVINO_THROW("OpenVINO Model is empty"); - - std::stringstream xmlFile, binFile; - ov::pass::Serialize serializer(xmlFile, binFile); - serializer.run_on_model(model); - - auto constants = binFile.str(); - auto model_str = xmlFile.str(); - - auto dataSize = static_cast(model_str.size()); - model_stream.write(reinterpret_cast(&dataSize), sizeof(dataSize)); - model_stream.write(model_str.c_str(), dataSize); - - dataSize = static_cast(constants.size()); - model_stream.write(reinterpret_cast(&dataSize), sizeof(dataSize)); - model_stream.write(reinterpret_cast(&constants[0]), dataSize); } } diff --git a/src/plugins/proxy/tests/proxy_tests.cpp b/src/plugins/proxy/tests/proxy_tests.cpp index d2bac8ac722..d608751c9a0 100644 --- a/src/plugins/proxy/tests/proxy_tests.cpp +++ b/src/plugins/proxy/tests/proxy_tests.cpp @@ -197,7 +197,17 @@ public: } ov::Any get_property(const std::string& name) const override { - OPENVINO_NOT_IMPLEMENTED; + if (name == ov::internal::supported_properties) { + return decltype(ov::internal::supported_properties)::value_type( + {ov::PropertyName{ov::internal::caching_properties.name(), ov::PropertyMutability::RO}}); + } else if (name == ov::supported_properties) { + std::vector supportedProperties; + return decltype(ov::supported_properties)::value_type( + {ov::PropertyName{ov::device::capability::EXPORT_IMPORT, ov::PropertyMutability::RO}}); + } else if (ov::device::capability::EXPORT_IMPORT == name) { + return true; + } + OPENVINO_THROW("Property ", name, " wasn't found!"); } std::shared_ptr create_sync_infer_request() const override; @@ -547,7 +557,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_support_reshape(ov::Core& cor RO_property(ov::available_devices.name()), RO_property(ov::loaded_from_cache.name()), RO_property(ov::device::uuid.name()), - RO_property(METRIC_KEY(IMPORT_EXPORT_SUPPORT)), + RO_property(ov::device::capability::EXPORT_IMPORT), RO_property(ov::optimal_batch_size.name()), RW_property(ov::hint::performance_mode.name()), RW_property(ov::hint::num_requests.name()), @@ -602,7 +612,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_support_reshape(ov::Core& cor configs.emplace_back(property); } return configs; - } else if (METRIC_KEY(IMPORT_EXPORT_SUPPORT) == name) { + } else if (ov::device::capability::EXPORT_IMPORT == name) { return true; } else if (ov::internal::caching_properties == name) { std::vector caching_properties = {ov::device::uuid}; @@ -680,7 +690,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_support_subtract(ov::Core& co RO_property(ov::available_devices.name()), RO_property(ov::loaded_from_cache.name()), RO_property(ov::device::uuid.name()), - RO_property(METRIC_KEY(IMPORT_EXPORT_SUPPORT)), + RO_property(ov::device::capability::EXPORT_IMPORT), }; // the whole config is RW before network is loaded. const static std::vector rwProperties{ @@ -728,7 +738,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_support_subtract(ov::Core& co configs.emplace_back(property); } return configs; - } else if (METRIC_KEY(IMPORT_EXPORT_SUPPORT) == name) { + } else if (ov::device::capability::EXPORT_IMPORT == name) { return true; } else if (ov::internal::caching_properties == name) { std::vector caching_properties = {ov::device::uuid}; @@ -787,7 +797,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_without_devices(ov::Core& cor RO_property(ov::supported_properties.name()), RO_property(ov::available_devices.name()), RO_property(ov::loaded_from_cache.name()), - RO_property(METRIC_KEY(IMPORT_EXPORT_SUPPORT)), + RO_property(ov::device::capability::EXPORT_IMPORT), }; // the whole config is RW before network is loaded. const static std::vector rwProperties{ @@ -823,7 +833,7 @@ void ov::proxy::tests::ProxyTests::register_plugin_without_devices(ov::Core& cor configs.emplace_back(property); } return configs; - } else if (METRIC_KEY(IMPORT_EXPORT_SUPPORT) == name) { + } else if (ov::device::capability::EXPORT_IMPORT == name) { return true; } else if (name == "SUPPORTED_METRICS") { // TODO: Remove this key std::vector configs;