Skip to content

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

[core] Weight sharing manage context lifetime (#34845)

Pawel Raaszad50d01a6f53
diff --git a/src/common/util/include/openvino/util/common_util.hpp b/src/common/util/include/openvino/util/common_util.hpp
index 9c8265678e4..8d0b2844b85 100644
--- a/src/common/util/include/openvino/util/common_util.hpp
+++ b/src/common/util/include/openvino/util/common_util.hpp
@@ -9,6 +9,7 @@
#include <cctype>
#include <cstdint>
#include <cstring>
+#include <filesystem>
#include <numeric>
#include <sstream>
#include <string>
@@ -94,8 +95,8 @@ constexpr uint64_t u64_hash_combine(uint64_t h, uint64_t k) {
return h + 0xe6546b64;
}
-constexpr uint64_t u64_hash_combine(std::initializer_list<uint64_t>&& values) {
- uint64_t h = 0;
+constexpr uint64_t u64_hash_combine(uint64_t seed, std::initializer_list<uint64_t>&& values) {
+ uint64_t h = seed;
for (uint64_t k : values) {
h = u64_hash_combine(h, k);
}
diff --git a/src/common/util/include/openvino/util/ov_version.hpp b/src/common/util/include/openvino/util/ov_version.hpp
index 496314bb96f..f27f9759a9d 100644
--- a/src/common/util/include/openvino/util/ov_version.hpp
+++ b/src/common/util/include/openvino/util/ov_version.hpp
@@ -29,6 +29,8 @@ struct Version {
size_t tweak = 0;
size_t build = 0;
+ constexpr Version() = default;
+
explicit Version(const char* version_str) {
// Pattern: MAJOR.MINOR.PATCH[.TWEAK]-BUILD-...
std::regex full_pattern(R"(^([0-9]+)\.([0-9]+)\.([0-9]+)(?:\.([0-9]+))?\-([0-9]+)\-.*)");
@@ -65,29 +67,29 @@ struct Version {
build{build} {}
// Comparison operators
- bool operator==(const Version& other) const {
+ constexpr bool operator==(const Version& other) const {
return std::tie(major, minor, patch, tweak, build) ==
std::tie(other.major, other.minor, other.patch, other.tweak, other.build);
}
- bool operator!=(const Version& other) const {
+ constexpr bool operator!=(const Version& other) const {
return !(*this == other);
}
- bool operator<(const Version& other) const {
+ constexpr bool operator<(const Version& other) const {
return std::tie(major, minor, patch, tweak, build) <
std::tie(other.major, other.minor, other.patch, other.tweak, other.build);
}
- bool operator>(const Version& other) const {
+ constexpr bool operator>(const Version& other) const {
return other < *this;
}
- bool operator<=(const Version& other) const {
+ constexpr bool operator<=(const Version& other) const {
return !(other < *this);
}
- bool operator>=(const Version& other) const {
+ constexpr bool operator>=(const Version& other) const {
return !(*this < other);
}
};
diff --git a/src/common/util/src/os/lin/lin_mmap_object.cpp b/src/common/util/src/os/lin/lin_mmap_object.cpp
index 96ef6cf5bb4..fd151082d20 100644
--- a/src/common/util/src/os/lin/lin_mmap_object.cpp
+++ b/src/common/util/src/os/lin/lin_mmap_object.cpp
@@ -81,7 +81,7 @@ public:
" for mapping. Ensure that file exists and has appropriate permissions.");
}
set_from_fd(fd, offset, size);
- m_id = util::u64_hash_combine({std::hash<std::filesystem::path::string_type>{}(path.native()), offset, size});
+ m_id = util::u64_hash_combine(std::filesystem::hash_value(path), {offset, size});
}
void set_from_fd(const int fd, const size_t offset, const size_t size) {
@@ -109,7 +109,7 @@ public:
m_data = static_cast<char*>(m_mapped_view) + (offset - aligned_offset);
}
m_id =
- util::u64_hash_combine({static_cast<uint64_t>(sb.st_ino), static_cast<uint64_t>(sb.st_dev), offset, size});
+ util::u64_hash_combine(static_cast<uint64_t>(sb.st_ino), {static_cast<uint64_t>(sb.st_dev), offset, size});
}
uint64_t get_id() const noexcept override {
diff --git a/src/common/util/src/os/win/win_mmap_object.cpp b/src/common/util/src/os/win/win_mmap_object.cpp
index f9c941c0193..d9f9f9b3b30 100644
--- a/src/common/util/src/os/win/win_mmap_object.cpp
+++ b/src/common/util/src/os/win/win_mmap_object.cpp
@@ -78,7 +78,7 @@ public:
const auto h =
::CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
map(path, h, offset, size);
- m_id = util::u64_hash_combine({std::hash<std::filesystem::path::string_type>{}(path.native()), offset, size});
+ m_id = util::u64_hash_combine(std::filesystem::hash_value(path), {offset, size});
}
void set_from_handle(HANDLE h, size_t offset, size_t size) {
@@ -104,7 +104,7 @@ private:
uint64_t fid_l, fid_r;
std::memcpy(&fid_l, &info.FileId, sizeof(fid_l));
std::memcpy(&fid_r, reinterpret_cast<const char*>(&info.FileId) + sizeof(fid_l), sizeof(fid_r));
- m_id = util::u64_hash_combine({offset, size, info.VolumeSerialNumber, fid_l, fid_r});
+ m_id = util::u64_hash_combine(offset, {size, info.VolumeSerialNumber, fid_l, fid_r});
} else {
throw std::runtime_error{"Cannot obtain file id info for handle " +
std::to_string(reinterpret_cast<uint64_t>(h))};
diff --git a/src/inference/dev_api/openvino/runtime/icache_manager.hpp b/src/inference/dev_api/openvino/runtime/icache_manager.hpp
index 374ceb21ae0..245ee574ef5 100644
--- a/src/inference/dev_api/openvino/runtime/icache_manager.hpp
+++ b/src/inference/dev_api/openvino/runtime/icache_manager.hpp
@@ -77,6 +77,8 @@ public:
*/
class IContextStore {
public:
+ virtual ~IContextStore() = default;
+
/**
* @brief Writes context to the storage
* @param context The context to be stored
@@ -88,6 +90,13 @@ public:
* @return The stored context
*/
virtual std::shared_ptr<ov::wsh::Context> get_context() const = 0;
+
+ /**
+ * @brief Initializes the context store with the provided weight sharing context
+ * .
+ * @param weight_sharing_context The weight sharing context to initialize the store with.
+ */
+ virtual void initialize(std::shared_ptr<ov::wsh::Context> weight_sharing_context) = 0;
};
/**
diff --git a/src/inference/dev_api/openvino/runtime/icompiled_model.hpp b/src/inference/dev_api/openvino/runtime/icompiled_model.hpp
index 3e3c2b7ec86..69ef786fc71 100644
--- a/src/inference/dev_api/openvino/runtime/icompiled_model.hpp
+++ b/src/inference/dev_api/openvino/runtime/icompiled_model.hpp
@@ -147,6 +147,7 @@ private:
std::vector<ov::Output<const ov::Node>> m_inputs;
std::vector<ov::Output<const ov::Node>> m_outputs;
ov::SoPtr<IRemoteContext> m_context;
+ std::shared_ptr<const void> m_weight_context;
std::shared_ptr<ov::threading::ITaskExecutor> m_task_executor = nullptr; //!< Holds a task executor
std::shared_ptr<ov::threading::ITaskExecutor> m_callback_executor = nullptr; //!< Holds a callback executor
diff --git a/src/inference/dev_api/openvino/runtime/single_file_storage.hpp b/src/inference/dev_api/openvino/runtime/single_file_storage.hpp
index 3b917390282..d7be109b2dd 100644
--- a/src/inference/dev_api/openvino/runtime/single_file_storage.hpp
+++ b/src/inference/dev_api/openvino/runtime/single_file_storage.hpp
@@ -59,6 +59,8 @@ public:
*/
std::shared_ptr<wsh::Context> get_context() const override;
+ void initialize(std::shared_ptr<ov::wsh::Context> weight_sharing_context = {}) override;
+
using BlobIdType = uint64_t;
using DataIdType = uint64_t;
using PadSizeType = uint64_t;
diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cpp
index 80a261a6efa..5c3af4886f4 100644
--- a/src/inference/src/dev/core_impl.cpp
+++ b/src/inference/src/dev/core_impl.cpp
@@ -38,6 +38,7 @@
#include "openvino/util/variant_visitor.hpp"
#include "openvino/util/xml_parse_utils.hpp"
#include "ov_plugins.hpp"
+#include "shared_context_manager.hpp"
#ifdef PROXY_PLUGIN_ENABLED
# include "openvino/proxy/plugin.hpp"
# include "openvino/proxy/properties.hpp"
@@ -293,6 +294,11 @@ std::string get_blob_id_or_compute(const ov::AnyMap& user_config, std::function<
return calculate_blob_id();
}
}
+
+ov::SharedContextManager& get_cache_wsh_ctx_manager() {
+ static ov::SharedContextManager s_cache_wsh_ctx_manager;
+ return s_cache_wsh_ctx_manager;
+}
} // namespace
bool ov::is_config_applicable(const std::string& user_device_name, const std::string& subprop_device_name) {
@@ -871,6 +877,9 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
} else if (cache_manager && device_supports_model_caching(plugin, parsed.m_config) && !is_proxy_device(plugin)) {
emplace_cache_dir_if_supported(parsed.m_config, plugin, cache_dir);
CacheContent cache_content{cache_manager, parsed.m_core_config.get_enable_mmap(), get_cache_model_path(config)};
+ get_cache_wsh_ctx_manager().init_and_sync_context(std::filesystem::hash_value(cache_dir),
+ cache_content.m_shared_ctx);
+
const auto compiled_config = create_compile_config(plugin, parsed.m_config);
cache_content.m_blob_id = get_blob_id_or_compute(config, [&] {
return ModelCache::compute_hash(model, cache_content.m_model_path, compiled_config);
@@ -908,6 +917,8 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
} else if (cache_manager && device_supports_model_caching(plugin, parsed.m_config) && !is_proxy_device(plugin)) {
emplace_cache_dir_if_supported(parsed.m_config, plugin, cache_dir);
CacheContent cache_content{cache_manager, parsed.m_core_config.get_enable_mmap(), get_cache_model_path(config)};
+ get_cache_wsh_ctx_manager().init_and_sync_context(std::filesystem::hash_value(cache_dir),
+ cache_content.m_shared_ctx);
const auto compiled_config = create_compile_config(plugin, parsed.m_config);
cache_content.m_blob_id = get_blob_id_or_compute(config, [&] {
return ModelCache::compute_hash(model, cache_content.m_model_path, compiled_config);
@@ -941,6 +952,8 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::filesystem:
CoreConfig::remove_core(parsed.m_config);
emplace_cache_dir_if_supported(parsed.m_config, plugin, cache_dir);
CacheContent cache_content{cache_manager, parsed.m_core_config.get_enable_mmap(), model_path};
+ get_cache_wsh_ctx_manager().init_and_sync_context(std::filesystem::hash_value(cache_dir),
+ cache_content.m_shared_ctx);
cache_content.m_blob_id = get_blob_id_or_compute(config, [&] {
return ModelCache::compute_hash(cache_content.m_model_path, create_compile_config(plugin, parsed.m_config));
});
@@ -971,6 +984,8 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::string& mod
} else if (cache_manager && device_supports_model_caching(plugin, parsed.m_config) && !is_proxy_device(plugin)) {
emplace_cache_dir_if_supported(parsed.m_config, plugin, cache_dir);
CacheContent cache_content{cache_manager, parsed.m_core_config.get_enable_mmap()};
+ get_cache_wsh_ctx_manager().init_and_sync_context(std::filesystem::hash_value(cache_dir),
+ cache_content.m_shared_ctx);
cache_content.m_blob_id = get_blob_id_or_compute(config, [&] {
return ModelCache::compute_hash(model_str, weights, create_compile_config(plugin, parsed.m_config));
});
@@ -1507,6 +1522,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model_and_cache(ov::Plugin&
}
try {
if (cache_content.m_shared_ctx) {
+ compiled_model->m_weight_context = cache_content.m_shared_ctx->get_context();
auto ctx = compiled_model->get_property(ov::internal::model_sharing_context.name())
.as<ov::internal::WeightSharingCtxPtr>();
if (ctx) {
@@ -1655,6 +1671,9 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(
OPENVINO_WARN("Could not load model from cache.");
compiled_model = compile_model_lambda();
}
+ if (compiled_model && cache_content.m_shared_ctx) {
+ compiled_model->m_weight_context = cache_content.m_shared_ctx->get_context();
+ }
return compiled_model;
}
diff --git a/src/inference/src/dev/core_impl.hpp b/src/inference/src/dev/core_impl.hpp
index 49c8bed1f78..da5e9dde8ca 100644
--- a/src/inference/src/dev/core_impl.hpp
+++ b/src/inference/src/dev/core_impl.hpp
@@ -233,7 +233,6 @@ private:
public:
CoreImpl();
-
~CoreImpl() override = default;
/**
diff --git a/src/inference/src/shared_context_manager.cpp b/src/inference/src/shared_context_manager.cpp
new file mode 100644
index 00000000000..eb56a19ac6a
--- /dev/null
+++ b/src/inference/src/shared_context_manager.cpp
@@ -0,0 +1,45 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "shared_context_manager.hpp"
+
+#include "openvino/runtime/icache_manager.hpp"
+
+namespace ov {
+
+void SharedContextManager::clean() {
+ std::lock_guard lock(m_mutex);
+ erase_expired();
+}
+
+void SharedContextManager::init_and_sync_context(uint64_t cache_id, ov::IContextStore* context_store) {
+ std::lock_guard lock(m_mutex);
+ erase_expired();
+ if (context_store) {
+ context_store->initialize(get_context(cache_id).lock());
+ set_context(cache_id, context_store->get_context());
+ }
+}
+
+std::weak_ptr<ov::wsh::Context> SharedContextManager::get_context(uint64_t id) const {
+ const auto ctx_it = m_weight_contexts.find(id);
+ return ctx_it != m_weight_contexts.end() ? ctx_it->second : std::weak_ptr<ov::wsh::Context>{};
+}
+
+void SharedContextManager::set_context(uint64_t id, std::weak_ptr<ov::wsh::Context> context) {
+ if (!context.expired()) {
+ m_weight_contexts[id] = std::move(context);
+ }
+}
+
+void SharedContextManager::erase_expired() {
+ for (auto it = m_weight_contexts.begin(); it != m_weight_contexts.end();) {
+ if (it->second.expired()) {
+ it = m_weight_contexts.erase(it);
+ } else {
+ ++it;
+ }
+ }
+}
+} // namespace ov
diff --git a/src/inference/src/shared_context_manager.hpp b/src/inference/src/shared_context_manager.hpp
new file mode 100644
index 00000000000..fde1f78c532
--- /dev/null
+++ b/src/inference/src/shared_context_manager.hpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+#include <mutex>
+#include <unordered_map>
+
+#include "openvino/core/weight_sharing_util.hpp"
+
+namespace ov {
+
+class IContextStore;
+
+class SharedContextManager {
+public:
+ /**
+ * @brief Initialize shared context in context store object and synchronize it with shared context manager.
+ *
+ * @param cache_id Cache identifier.
+ * @param context_store Pointer to shared context store object.
+ */
+ void init_and_sync_context(uint64_t cache_id, ov::IContextStore* context_store);
+
+ /** @brief Clean up Shared Context Manager by removing expired contexts. */
+ void clean();
+
+private:
+ std::weak_ptr<ov::wsh::Context> get_context(uint64_t id) const;
+ void set_context(uint64_t id, std::weak_ptr<ov::wsh::Context> context);
+ void erase_expired();
+
+ mutable std::mutex m_mutex{};
+ std::unordered_map<uint64_t, std::weak_ptr<ov::wsh::Context>> m_weight_contexts{};
+};
+} // namespace ov
diff --git a/src/inference/src/single_file_storage.cpp b/src/inference/src/single_file_storage.cpp
index c97291c7cd5..648c6e646e6 100644
--- a/src/inference/src/single_file_storage.cpp
+++ b/src/inference/src/single_file_storage.cpp
@@ -85,12 +85,6 @@ SingleFileStorage::SingleFileStorage(const std::filesystem::path& path)
util::Version file_version{0, 0, 0};
read_version(stream, file_version);
validate_version(file_version);
-
- if (!build_content_index(stream)) {
- m_blob_index.clear();
- m_shared_context->m_cache_sources.clear();
- m_shared_context->m_weight_registry.clear();
- }
}
}
@@ -332,5 +326,23 @@ void SingleFileStorage::write_context(const weight_sharing::Context& context) {
};
write_tlv_record(stream, static_cast<TLVTraits::TagType>(Tag::WeightSource), weight_source_writer);
}
+
+ for (const auto& [source_id, buffer] : context.m_runtime_sources) {
+ m_shared_context->m_runtime_sources.emplace(source_id, buffer);
+ }
}
+
+void SingleFileStorage::initialize(std::shared_ptr<ov::wsh::Context> weight_sharing_context) {
+ if (weight_sharing_context) {
+ m_shared_context = std::move(weight_sharing_context);
+ }
+
+ if (std::ifstream stream(m_file_path, std::ios::binary); stream.good()) {
+ util::Version file_version;
+ read_version(stream, file_version);
+ OPENVINO_ASSERT(util::is_version_compatible(m_version, file_version), "Incompatible cache format");
+ OPENVINO_ASSERT(build_content_index(stream), "The cache file may be corrupted or in an unsupported format");
+ }
+}
+
}; // namespace ov::runtime
diff --git a/src/inference/tests/functional/caching_test.cpp b/src/inference/tests/functional/caching_test.cpp
index 5848945b8ca..47747245ff9 100644
--- a/src/inference/tests/functional/caching_test.cpp
+++ b/src/inference/tests/functional/caching_test.cpp
@@ -44,6 +44,56 @@ namespace ov::weight_sharing {
inline bool operator==(const ov::wsh::WeightMetaData& lhs, const ov::wsh::WeightMetaData& rhs) {
return std::tie(lhs.m_offset, lhs.m_size) == std::tie(rhs.m_offset, rhs.m_size);
}
+
+inline bool operator==(const ov::wsh::WeightSource& lhs, const ov::wsh::WeightSource& rhs) {
+ const auto lhs_buff = lhs.m_weights.lock();
+ const auto rhs_buff = rhs.m_weights.lock();
+ return lhs.m_device == rhs.m_device && lhs_buff == rhs_buff;
+}
+
+inline bool are_weight_registries_equal(const WeightRegistry& lhs, const WeightRegistry& rhs) {
+ if (lhs.size() != rhs.size()) {
+ return false;
+ }
+ for (const auto& [data_id, weight_meta_map] : lhs) {
+ const auto rhs_it = rhs.find(data_id);
+ if (rhs_it == rhs.end()) {
+ return false;
+ }
+ const auto& rhs_weight_meta_map = rhs_it->second;
+ if (weight_meta_map.size() != rhs_weight_meta_map.size()) {
+ return false;
+ }
+ for (const auto& [weight_id, weight_meta_data] : weight_meta_map) {
+ const auto rhs_weight_it = rhs_weight_meta_map.find(weight_id);
+ if (rhs_weight_it == rhs_weight_meta_map.end()) {
+ return false;
+ }
+ if (!(weight_meta_data == rhs_weight_it->second)) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+inline bool are_weight_source_registries_equal(const WeightSourceRegistry& lhs, const WeightSourceRegistry& rhs) {
+ if (lhs.size() != rhs.size()) {
+ return false;
+ }
+ for (const auto& [key, value] : lhs) {
+ auto it = rhs.find(key);
+ if (it == rhs.end()) {
+ return false;
+ }
+ // Ensure WeightSource objects compare equal
+ if (!(value == it->second)) {
+ return false;
+ }
+ }
+ return true;
+}
+
} // namespace ov::weight_sharing
using namespace ::testing;
@@ -3163,15 +3213,20 @@ TEST_P(CachingTest, import_from_cache_model_by_custom_model_rt_info) {
}
MATCHER_P(IsAnyShCtx, other, "") {
+ bool result = false;
if (arg.first == ov::internal::model_sharing_context.name()) {
const auto& map = arg.second.template as<ov::internal::WeightSharingCtxPtr>();
if (map) {
- return map->m_weight_registry == other.m_weight_registry;
+ result = are_weight_registries_equal(map->m_weight_registry, other.m_weight_registry);
+ if (result) {
+ result = are_weight_source_registries_equal(map->m_runtime_sources, other.m_runtime_sources);
+ }
+
} else if (!map && other.m_weight_registry.empty()) {
- return true;
+ result = true;
}
}
- return false;
+ return result;
}
TEST_P(CachingTest, test_share_weight_create_ctx_single_core) {
@@ -3183,10 +3238,14 @@ TEST_P(CachingTest, test_share_weight_create_ctx_single_core) {
std::string("mock_engine") + OV_BUILD_POSTFIX),
deviceName);
const auto empty_ctx = ov::wsh::Context();
- const auto ctx1 = [] {
- auto constants_meta = ov::wsh::WeightMetaMap{{0, ov::wsh::WeightMetaData{0, 100, ov::element::u8}}};
- auto tmp = ov::wsh::WeightRegistry{{1, std::move(constants_meta)}};
- return ov::wsh::Context{tmp, {}};
+ auto wt_1 = std::make_shared<ov::AlignedBuffer>(200);
+
+ const auto ctx1 = [&] {
+ auto constants_meta = ov::wsh::WeightMetaMap{{0, ov::wsh::WeightMetaData{0, 200, ov::element::u8}}};
+ auto runtime_sources = ov::wsh::WeightSourceRegistry{{0, ov::wsh::WeightSource{"", wt_1}}};
+ return ov::wsh::Context{ov::wsh::WeightRegistry{{1, std::move(constants_meta)}},
+ {},
+ std::move(runtime_sources)};
}();
EXPECT_CALL(*mockPlugin, get_property(ov::supported_properties.name(), _)).Times(AnyNumber());
@@ -3241,14 +3300,15 @@ TEST_P(CachingTest, test_share_weight_create_ctx_single_core) {
TEST_P(CachingTest, test_share_weight_create_ctx) {
m_cacheDir += ".bin";
+ auto wt_1 = std::make_shared<ov::AlignedBuffer>(200);
const auto empty_ctx = ov::wsh::Context();
- const auto ctx1 = [] {
+ const auto ctx1 = [&] {
auto constants_meta = ov::wsh::WeightMetaMap{{0, ov::wsh::WeightMetaData{0, 200, ov::element::u8}}};
- // auto c = std::make_shared<ov::wsh::Context>();
- // c->m_constants_meta_data = {{1, std::move(constants_meta)}};
- // return c;
- return ov::wsh::Context{ov::wsh::WeightRegistry{{1, std::move(constants_meta)}}, {}};
+ auto runtime_sources = ov::wsh::WeightSourceRegistry{{0, ov::wsh::WeightSource{"", wt_1}}};
+ return ov::wsh::Context{ov::wsh::WeightRegistry{{1, std::move(constants_meta)}},
+ {},
+ std::move(runtime_sources)};
}();
EXPECT_CALL(*mockPlugin, get_property(ov::supported_properties.name(), _)).Times(AnyNumber());
@@ -3308,21 +3368,26 @@ TEST_P(CachingTest, test_share_weight_create_ctx) {
TEST_P(CachingTest, test_share_weight_create_ctx_multiple_compilation) {
// use ov::weight path as cache property to force different blob id for same model
m_cacheDir += ".bin";
+
+ auto wt_1 = std::make_shared<ov::AlignedBuffer>(200);
+
const auto empty_ctx = ov::wsh::Context();
auto cm1 = ov::wsh::WeightMetaMap{{1, ov::wsh::WeightMetaData{0, 200, ov::element::u8}},
{2, ov::wsh::WeightMetaData{200, 200, ov::element::u8}}};
auto wt_c1 = ov::wsh::WeightRegistry{{10, cm1}};
- auto ctx1 = ov::wsh::Context();
- ctx1.m_weight_registry = wt_c1;
+ auto ctx1 = ov::wsh::Context{wt_c1, {}, {}};
+ ctx1.m_cache_sources = {{10, ov::wsh::WeightSource{"", wt_1}}};
+ ctx1.m_runtime_sources = {{1, ov::wsh::WeightSource{"", wt_1}}};
auto cm2 = ov::wsh::WeightMetaMap{{1, ov::wsh::WeightMetaData{0, 300, ov::element::u8}},
{2, ov::wsh::WeightMetaData{300, 300, ov::element::u8}}};
auto wt_c2 = ov::wsh::WeightRegistry{{20, cm2}};
- auto ctx2 = ov::wsh::Context();
- ctx2.m_weight_registry = wt_c2;
+ auto ctx2 = ov::wsh::Context{wt_c2, {}, {}};
+ ctx2.m_runtime_sources = {{1, ov::wsh::WeightSource{"", wt_1}}};
+
+ auto final_ctx =
+ ov::wsh::Context{ov::wsh::WeightRegistry{{10, cm1}, {20, cm2}}, ctx1.m_cache_sources, ctx1.m_runtime_sources};
- auto final_ctx = ov::wsh::Context();
- final_ctx.m_weight_registry = {{10, cm1}, {20, cm2}};
EXPECT_CALL(*mockPlugin, get_property(ov::supported_properties.name(), _))
.Times(AnyNumber())
.WillRepeatedly(Return(std::vector<ov::PropertyName>{ov::supported_properties.name(),
@@ -3418,7 +3483,7 @@ TEST_P(CachingTest, test_share_weight_create_ctx_multiple_compilation) {
EXPECT_CALL(*mockPlugin, import_model(A<const ov::Tensor&>(), _)).Times(0);
EXPECT_CALL(*mockPlugin, get_property(ov::weights_path.name(), _)).WillOnce(Return(""));
testLoad([&](ov::Core& core) {
- core.set_property(ov::cache_dir(m_cacheDir));
+ core.set_property(ov::cache_path(m_cacheDir));
m_testFunction(core);
});
EXPECT_EQ(comp_models.size(), 2);
diff --git a/src/inference/tests/unit/single_file_storage.cpp b/src/inference/tests/unit/single_file_storage.cpp
index c839c2ea0d3..2b9457516e5 100644
--- a/src/inference/tests/unit/single_file_storage.cpp
+++ b/src/inference/tests/unit/single_file_storage.cpp
@@ -30,6 +30,7 @@ protected:
void SetUp() override {
m_file_path = ov::test::utils::generateTestFilePrefix() + ".bin";
m_storage = std::make_unique<SingleFileStorage>(m_file_path);
+ m_storage->initialize();
ASSERT_TRUE(std::filesystem::exists(m_file_path));
}
@@ -101,6 +102,7 @@ TEST_F(SingleFileStorageTest, WriteReadCacheEntry) {
blob_read_test(*m_storage);
m_storage.reset();
SingleFileStorage reopened_storage(m_file_path);
+ reopened_storage.initialize();
blob_read_test(reopened_storage);
}
@@ -168,6 +170,7 @@ TEST_F(SingleFileStorageTest, AppendOnlyCacheEntry) {
m_storage.reset();
SingleFileStorage reopened_storage(m_file_path);
+ reopened_storage.initialize();
OV_EXPECT_THROW_HAS_SUBSTRING(reopened_storage.write_cache_entry(blob_id, [&](std::ostream&) {}),
ov::AssertFailure,
blob_id + " already exists in cache");
@@ -215,6 +218,7 @@ TEST_F(SingleFileStorageTest, ContextMetaWriteRead) {
m_storage.reset();
SingleFileStorage reopened_storage(m_file_path);
+ reopened_storage.initialize();
meta_read_test(reopened_storage);
}
@@ -234,7 +238,9 @@ TEST_F(SingleFileStorageTest, ContextMetaAppendDelta) {
m_storage.reset();
const auto file_size_after_first_write = test::utils::fileSize(m_file_path.string());
- SingleFileStorage{m_file_path}.write_context(test_context);
+ SingleFileStorage storage{m_file_path};
+ storage.initialize();
+ storage.write_context(test_context);
const auto file_size_after_second_write = test::utils::fileSize(m_file_path.string());
EXPECT_EQ(file_size_after_second_write, file_size_after_first_write)
<< "Rewriting the same context should not increase file size";
@@ -298,7 +304,9 @@ TEST_F(SingleFileStorageTest, ContextWeightSourceAppendDelta) {
m_storage.reset();
const auto file_size_after_first_write = test::utils::fileSize(m_file_path.string());
- SingleFileStorage{m_file_path}.write_context(test_context);
+ SingleFileStorage file_storage{m_file_path};
+ file_storage.initialize();
+ file_storage.write_context(test_context);
const auto file_size_after_second_write = test::utils::fileSize(m_file_path.string());
EXPECT_EQ(file_size_after_second_write, file_size_after_first_write)
<< "Rewriting the same context should not increase file size";