Skip to content

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

[CORE] Weights reading with parallel stream buffer support (#38019)

barnasm11585e4eb503f
diff --git a/src/core/xml_util/src/weights_provider.cpp b/src/core/xml_util/src/weights_provider.cpp
index cf78be34a98..230cf1af9f6 100644
--- a/src/core/xml_util/src/weights_provider.cpp
+++ b/src/core/xml_util/src/weights_provider.cpp
@@ -11,6 +11,7 @@
#include "openvino/util/common_util.hpp"
#include "openvino/util/file_util.hpp"
#include "openvino/util/mmap_object.hpp"
+#include "openvino/util/native_stream.hpp"
#include "openvino/util/parallel_io.hpp"
namespace ov::util {
@@ -79,7 +80,11 @@ std::shared_ptr<ov::AlignedBuffer> FileWeightsProvider::make_region(size_t offse
} else {
auto file_region = std::make_shared<ov::AlignedBuffer>(size);
if (size > 0) {
- OPENVINO_ASSERT(ov::util::positional_read(m_weights_handle, file_region->get_ptr<char>(), size, offset),
+ ov::util::NativeIfstream weights_stream(m_weights_handle,
+ static_cast<std::streamoff>(offset),
+ static_cast<std::streamoff>(size));
+ weights_stream.read(file_region->get_ptr<char>(), static_cast<std::streamsize>(size));
+ OPENVINO_ASSERT(weights_stream && static_cast<size_t>(weights_stream.gcount()) == size,
"Failed to read weights from ",
m_weights_path);
}