Skip to content

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

[core] Make LazyBuffer::hint_evict() a no-op (#37651)

Tomasz Jankowskiead308accf98
diff --git a/src/core/dev_api/openvino/runtime/lazy_buffer.hpp b/src/core/dev_api/openvino/runtime/lazy_buffer.hpp
index 12e0b233998..9060bc80b5d 100644
--- a/src/core/dev_api/openvino/runtime/lazy_buffer.hpp
+++ b/src/core/dev_api/openvino/runtime/lazy_buffer.hpp
@@ -9,17 +9,19 @@
#include <memory>
#include <mutex>
+#include "openvino/core/deprecated.hpp"
#include "openvino/runtime/aligned_buffer.hpp"
namespace ov {
/** \brief LazyBuffer is lazy loaded AlignedBuffer which provides a view on a file w/o memory mapping. */
-class OPENVINO_API LazyBuffer : public AlignedBuffer {
+class OPENVINO_API OPENVINO_DEPRECATED("LazyBuffer is deprecated and will be removed in 2026.5 release") LazyBuffer
+ : public AlignedBuffer {
public:
/**
* @brief Constructs a LazyBuffer which provides a view on a file. The file content is loaded to memory when
- * get_ptr() is called for the first time after object creation or after hint_evict() is called. The file content is
- * loaded at aligned addresses, so the actual allocated memory may be larger than the requested byte size.
+ * get_ptr() is called for the first time after object creation. The file content is loaded at aligned addresses,
+ * so the actual allocated memory may be larger than the requested byte size.
* @param file_path Path to the file to load
* @param offset Offset in the file to start the view
* @param byte_size Size of the view in bytes
@@ -42,8 +44,7 @@ public:
}
/**
- * @brief Evicts the buffer from memory. After this call, next call to hint_prefetch() will load the file content
- * again.
+ * @brief No-op by design: once loaded, LazyBuffer keeps file content resident until destroyed.
*/
void hint_evict() noexcept override;
diff --git a/src/core/src/runtime/lazy_buffer.cpp b/src/core/src/runtime/lazy_buffer.cpp
index 97ea52e74c6..5025bc9f59d 100644
--- a/src/core/src/runtime/lazy_buffer.cpp
+++ b/src/core/src/runtime/lazy_buffer.cpp
@@ -8,6 +8,7 @@
#include <mutex>
#include <utility>
+#include "openvino/core/deprecated.hpp"
#include "openvino/core/except.hpp"
#include "openvino/core/memory_util.hpp"
#include "openvino/util/file_util.hpp"
@@ -15,6 +16,7 @@
#include "openvino/util/parallel_read_streambuf.hpp"
namespace ov {
+OPENVINO_SUPPRESS_DEPRECATED_START
LazyBuffer::LazyBuffer(std::filesystem::path file_path, size_t offset, size_t byte_size)
: AlignedBuffer(),
m_file_path{std::move(file_path)},
@@ -91,20 +93,8 @@ void LazyBuffer::hint_prefetch() const {
}
}
-void LazyBuffer::hint_evict() noexcept {
- hint_evict(0, m_byte_size);
-}
+void LazyBuffer::hint_evict() noexcept {}
-void LazyBuffer::hint_evict(size_t offset, size_t size) noexcept {
- if (m_loaded.load(std::memory_order_acquire)) {
- try {
- std::lock_guard lock{m_loading};
- if (m_loaded.load(std::memory_order_relaxed)) {
- util::vm_decommit(m_aligned_buffer, m_byte_size);
- m_loaded.store(false, std::memory_order_release);
- }
- } catch (...) {
- }
- }
-}
+void LazyBuffer::hint_evict(size_t offset, size_t size) noexcept {}
+OPENVINO_SUPPRESS_DEPRECATED_END
} // namespace ov
diff --git a/src/core/tests/lazy_buffer.cpp b/src/core/tests/lazy_buffer.cpp
index 93b9791ea6b..6df1296d203 100644
--- a/src/core/tests/lazy_buffer.cpp
+++ b/src/core/tests/lazy_buffer.cpp
@@ -11,10 +11,12 @@
#include "common_test_utils/common_utils.hpp"
#include "common_test_utils/test_assertions.hpp"
+#include "openvino/core/deprecated.hpp"
using namespace testing;
namespace ov::test {
+OPENVINO_SUPPRESS_DEPRECATED_START
class LazyBufferTest : public Test {
protected:
std::filesystem::path m_file_path;
@@ -109,7 +111,7 @@ TEST_F(LazyBufferTest, load_on_first_get_ptr) {
EXPECT_THAT(first_rewrite, ElementsAreArray(second_ptr, size));
}
-TEST_F(LazyBufferTest, evict_and_reload) {
+TEST_F(LazyBufferTest, hint_evict_is_noop) {
write_test_data(128);
constexpr size_t offset = 31;
@@ -125,18 +127,13 @@ TEST_F(LazyBufferTest, evict_and_reload) {
ASSERT_NE(first_ptr, nullptr);
ASSERT_THAT(first_rewrite, ElementsAreArray(first_ptr, size));
- // After evict(), get_ptr() should load the same file content again
- buffer->hint_evict();
- ASSERT_NO_THROW((first_ptr = buffer->get_ptr<char>()));
- ASSERT_NE(first_ptr, nullptr);
- ASSERT_THAT(first_rewrite, ElementsAreArray(first_ptr, size));
-
- // After evict(), get_ptr() should load the file content again and reflect the second overwrite.
+ // hint_evict() is a no-op: cached content and pointer must stay the same even after a later file overwrite.
buffer->hint_evict();
overwrite_test_data(offset, second_rewrite);
char* second_ptr = nullptr;
ASSERT_NO_THROW((second_ptr = buffer->get_ptr<char>()));
ASSERT_EQ(second_ptr, first_ptr);
- EXPECT_THAT(second_rewrite, ElementsAreArray(second_ptr, size));
+ EXPECT_THAT(first_rewrite, ElementsAreArray(second_ptr, size));
}
+OPENVINO_SUPPRESS_DEPRECATED_END
} // namespace ov::test
diff --git a/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp b/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp
index 2146fe68ebb..a422134f11d 100644
--- a/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp
+++ b/src/frontends/onnx/frontend/src/utils/tensor_external_data.cpp
@@ -8,6 +8,7 @@
#include <sstream>
#include "exceptions.hpp"
+#include "openvino/core/deprecated.hpp"
#include "openvino/runtime/lazy_buffer.hpp"
#include "openvino/util/file_util.hpp"
#include "openvino/util/log.hpp"
@@ -102,11 +103,13 @@ Buffer<ov::AlignedBuffer> TensorExternalData::load_external_data(const std::file
read_data);
};
const auto get_lazy_buffer = [&]() {
+ OPENVINO_SUPPRESS_DEPRECATED_START
const auto lazy = std::make_shared<LazyBuffer>(full_path, m_offset, read_data_length);
return std::make_shared<SharedBuffer<std::shared_ptr<AlignedBuffer>>>(
static_cast<char*>(lazy->get_reserved_ptr()),
lazy->size(),
lazy);
+ OPENVINO_SUPPRESS_DEPRECATED_END
};
constexpr size_t lazy_loading_threshold = 0x100000; // 1MB