diff --git a/src/inference/dev_api/openvino/runtime/iplugin.hpp b/src/inference/dev_api/openvino/runtime/iplugin.hpp index 7e6f9a917a1d1e..e88c3e4a539d15 100644 --- a/src/inference/dev_api/openvino/runtime/iplugin.hpp +++ b/src/inference/dev_api/openvino/runtime/iplugin.hpp @@ -193,7 +193,8 @@ class OPENVINO_RUNTIME_API IPlugin : public std::enable_shared_from_this import_model(std::shared_ptr model_buffer, + virtual std::shared_ptr import_model(std::istream& model, + std::shared_ptr model_buffer, const ov::AnyMap& properties) const; /** @@ -206,7 +207,8 @@ class OPENVINO_RUNTIME_API IPlugin : public std::enable_shared_from_this import_model(std::shared_ptr model_buffer, + virtual std::shared_ptr import_model(std::istream& model, + std::shared_ptr model_buffer, const ov::SoPtr& context, const ov::AnyMap& properties) const; diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cpp index fff63bed147325..d30581c0c98beb 100644 --- a/src/inference/src/dev/core_impl.cpp +++ b/src/inference/src/dev/core_impl.cpp @@ -1460,8 +1460,8 @@ ov::SoPtr ov::CoreImpl::load_model_from_cache( } } if (model_buffer) { - compiled_model = context ? plugin.import_model(model_buffer, context, update_config) - : plugin.import_model(model_buffer, update_config); + compiled_model = context ? plugin.import_model(networkStream, model_buffer, context, update_config) + : plugin.import_model(networkStream, model_buffer, update_config); } else { compiled_model = context ? plugin.import_model(networkStream, context, update_config) : plugin.import_model(networkStream, update_config); diff --git a/src/inference/src/dev/iplugin.cpp b/src/inference/src/dev/iplugin.cpp index 403beb3ccd0451..42d735baa0449a 100644 --- a/src/inference/src/dev/iplugin.cpp +++ b/src/inference/src/dev/iplugin.cpp @@ -57,12 +57,14 @@ const std::string& ov::IPlugin::get_device_name() const { return m_plugin_name; } -std::shared_ptr ov::IPlugin::import_model(std::shared_ptr model_buffer, +std::shared_ptr ov::IPlugin::import_model(std::istream& model, + std::shared_ptr model_buffer, const ov::AnyMap& properties) const{ OPENVINO_THROW_NOT_IMPLEMENTED("This method is not implemented"); } -std::shared_ptr ov::IPlugin::import_model(std::shared_ptr model_buffer, +std::shared_ptr ov::IPlugin::import_model(std::istream& model, + std::shared_ptr model_buffer, const ov::SoPtr& context, const ov::AnyMap& properties) const{ OPENVINO_THROW_NOT_IMPLEMENTED("This method is not implemented"); diff --git a/src/inference/src/dev/plugin.cpp b/src/inference/src/dev/plugin.cpp index a6f211743d5c7f..23e0e04bb6d0e0 100644 --- a/src/inference/src/dev/plugin.cpp +++ b/src/inference/src/dev/plugin.cpp @@ -79,14 +79,15 @@ ov::SoPtr ov::Plugin::import_model(std::istream& model, OV_PLUGIN_CALL_STATEMENT(return {m_ptr->import_model(model, context, config), m_so}); } -ov::SoPtr ov::Plugin::import_model(std::shared_ptr model_buffer, const ov::AnyMap& properties) const { - OV_PLUGIN_CALL_STATEMENT(return {m_ptr->import_model(model_buffer, properties), m_so}); +ov::SoPtr ov::Plugin::import_model(std::istream& model, std::shared_ptr model_buffer, const ov::AnyMap& properties) const { + OV_PLUGIN_CALL_STATEMENT(return {m_ptr->import_model(model, model_buffer, properties), m_so}); } -ov::SoPtr ov::Plugin::import_model(std::shared_ptr model_buffer, +ov::SoPtr ov::Plugin::import_model(std::istream& model, + std::shared_ptr model_buffer, const ov::SoPtr& context, const ov::AnyMap& config) const { - OV_PLUGIN_CALL_STATEMENT(return {m_ptr->import_model(model_buffer, context, config), m_so}); + OV_PLUGIN_CALL_STATEMENT(return {m_ptr->import_model(model, model_buffer, context, config), m_so}); } ov::SoPtr ov::Plugin::create_context(const AnyMap& params) const { diff --git a/src/inference/src/dev/plugin.hpp b/src/inference/src/dev/plugin.hpp index 792900c4698f2d..004fcc04446c0a 100644 --- a/src/inference/src/dev/plugin.hpp +++ b/src/inference/src/dev/plugin.hpp @@ -59,9 +59,10 @@ class Plugin { const ov::SoPtr& context, const ov::AnyMap& config) const; - SoPtr import_model(std::shared_ptr model_buffer, const ov::AnyMap& properties) const; + SoPtr import_model(std::istream& model, std::shared_ptr model_buffer, const ov::AnyMap& properties) const; - SoPtr import_model(std::shared_ptr model_buffer, + SoPtr import_model(std::istream& model, + std::shared_ptr model_buffer, const ov::SoPtr& context, const ov::AnyMap& config) const; diff --git a/src/plugins/intel_cpu/src/plugin.cpp b/src/plugins/intel_cpu/src/plugin.cpp index 5f98002d5436cc..4dcceb1f4ee628 100644 --- a/src/plugins/intel_cpu/src/plugin.cpp +++ b/src/plugins/intel_cpu/src/plugin.cpp @@ -555,48 +555,12 @@ ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr& std::shared_ptr Plugin::import_model(std::istream& model_stream, const ov::AnyMap& config) const { - OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::intel_cpu_LT, "import_model"); - - CacheDecrypt decrypt{ codec_xor }; - bool decript_from_string = false; - if (config.count(ov::cache_encryption_callbacks.name())) { - auto encryption_callbacks = config.at(ov::cache_encryption_callbacks.name()).as(); - decrypt.m_decrypt_str = encryption_callbacks.decrypt; - decript_from_string = true; - } - - ModelDeserializer deserializer( - model_stream, - nullptr, - [this](const std::shared_ptr& model, const std::shared_ptr& weights) { - return get_core()->read_model(model, weights); - }, - decrypt, decript_from_string); - - std::shared_ptr model; - deserializer >> model; - - Config conf = engConfig; - Config::ModelType modelType = getModelType(model); - - // check ov::loaded_from_cache property and erase it to avoid exception in readProperties. - auto _config = config; - const auto& it = _config.find(ov::loaded_from_cache.name()); - bool loaded_from_cache = false; - if (it != _config.end()) { - loaded_from_cache = it->second.as(); - _config.erase(it); - } - conf.readProperties(_config, modelType); - - // import config props from caching model - calculate_streams(conf, model, true); - auto compiled_model = std::make_shared(model, shared_from_this(), conf, loaded_from_cache); - return compiled_model; + return import_model(model_stream, nullptr, config); } -std::shared_ptr Plugin::import_model(std::shared_ptr model_buffer, +std::shared_ptr Plugin::import_model(std::istream& model_stream, + std::shared_ptr model_buffer, const ov::AnyMap& config) const { OV_ITT_SCOPE(FIRST_INFERENCE, itt::domains::intel_cpu_LT, "import_model"); @@ -608,10 +572,8 @@ std::shared_ptr Plugin::import_model(std::shared_ptr& model, const std::shared_ptr& weights) { return get_core()->read_model(model, weights); diff --git a/src/plugins/intel_cpu/src/plugin.h b/src/plugins/intel_cpu/src/plugin.h index 3d8e9afcfa11bb..fad3f388a2385f 100644 --- a/src/plugins/intel_cpu/src/plugin.h +++ b/src/plugins/intel_cpu/src/plugin.h @@ -34,9 +34,11 @@ class Plugin : public ov::IPlugin { "import_model with RemoteContext is not supported by CPU plugin!"); }; - std::shared_ptr import_model(std::shared_ptr model_buffer, + std::shared_ptr import_model(std::istream& model, + std::shared_ptr model_buffer, const ov::AnyMap& properties) const override; - std::shared_ptr import_model(std::shared_ptr model_buffer, + std::shared_ptr import_model(std::istream& model, + std::shared_ptr model_buffer, const ov::SoPtr& context, const ov::AnyMap& properties) const override { OPENVINO_THROW_NOT_IMPLEMENTED( diff --git a/src/plugins/intel_cpu/src/utils/serialize.cpp b/src/plugins/intel_cpu/src/utils/serialize.cpp index afe8efb3019a0e..33d8140fbe4a84 100644 --- a/src/plugins/intel_cpu/src/utils/serialize.cpp +++ b/src/plugins/intel_cpu/src/utils/serialize.cpp @@ -47,13 +47,14 @@ ModelDeserializer::ModelDeserializer(std::istream& model_stream, void ModelDeserializer::operator>>(std::shared_ptr& model) { if (m_model_buffer) { - process_mmap(m_model_buffer); + process_mmap(model, m_model_buffer); } else { process_stream(model); } } -void ModelDeserializer::process_mmap(const std::shared_ptr& mmemory) { +void ModelDeserializer::process_mmap(std::shared_ptr& model, + const std::shared_ptr& mmemory) { // Note: Don't use seekg with mmaped stream. This may affect the performance of some models. // Get file size before seek content. // Blob from cache may have other header, so need to skip this. @@ -106,7 +107,7 @@ void ModelDeserializer::process_mmap(const std::shared_ptr& m hdr.model_size, xml_buff); - auto model = m_model_builder(model_buf, weights_buf); + model = m_model_builder(model_buf, weights_buf); // Set Info pugi::xml_node root = xml_in_out_doc.child("cnndata"); diff --git a/src/plugins/intel_cpu/src/utils/serialize.hpp b/src/plugins/intel_cpu/src/utils/serialize.hpp index f018b3ca415952..4dfdd6b22afbd4 100644 --- a/src/plugins/intel_cpu/src/utils/serialize.hpp +++ b/src/plugins/intel_cpu/src/utils/serialize.hpp @@ -31,7 +31,7 @@ class ModelDeserializer { public: typedef std::function(const std::shared_ptr&, const std::shared_ptr&)> ModelBuilder; - ModelDeserializer(std::istream& model_stream, + ModelDeserializer(std::istream& model, std::shared_ptr model_buffer, ModelBuilder fn, const CacheDecrypt& encrypt_fn, @@ -44,7 +44,7 @@ class ModelDeserializer { protected: static void set_info(pugi::xml_node& root, std::shared_ptr& model); - void process_mmap(const std::shared_ptr& memory); + void process_mmap(std::shared_ptr& model, const std::shared_ptr& memory); void process_stream(std::shared_ptr& model);