Skip to content

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

[core] Refactor Header view methods to make interface more flexible (#38691)

Pawel Raasz58fa87964e53
diff --git a/src/inference/dev_api/openvino/runtime/hsm_format.hpp b/src/inference/dev_api/openvino/runtime/hsm_format.hpp
index 98295f1adc3..6d2ce82a13a 100644
--- a/src/inference/dev_api/openvino/runtime/hsm_format.hpp
+++ b/src/inference/dev_api/openvino/runtime/hsm_format.hpp
@@ -115,9 +115,19 @@ struct Header {
* in place, no copy.
* @warning No bounds checking: caller must ensure `data` points to at least `sizeof(Header)` readable bytes.
*/
- static const Header& view(const uint8_t* data) noexcept {
+ static const Header& view(const void* data) noexcept {
return *reinterpret_cast<const Header*>(data);
}
+
+ /**
+ * @brief Non-owning view of the header at the start of an HSM container buffer - reinterprets the bytes
+ * in place, no copy.
+ * @note Debug-asserts if @p data is too small for a Header; still the caller's responsibility in Release.
+ */
+ static const Header& view(ov::util::MemoryView data) noexcept {
+ OPENVINO_DEBUG_ASSERT(data.size() >= sizeof(Header));
+ return view(data.data());
+ }
};
#pragma pack(pop)
static_assert(sizeof(Header) == 32,
diff --git a/src/inference/src/dev/hsm_format.cpp b/src/inference/src/dev/hsm_format.cpp
index 871a7ffa039..06fda51c5a5 100644
--- a/src/inference/src/dev/hsm_format.cpp
+++ b/src/inference/src/dev/hsm_format.cpp
@@ -28,7 +28,7 @@ bool MultiBlobView::NextContainer::is_blob() const noexcept {
}
const Header& ContainerView::header() const noexcept {
- return Header::view(reinterpret_cast<const uint8_t*>(begin()));
+ return Header::view(m_view);
}
const ManifestEntry& ContainerView::manifest() const noexcept {
@@ -88,7 +88,7 @@ ContainerView MultiBlobView::blob_at(size_t index) const noexcept {
std::optional<MultiBlobView::NextContainer> MultiBlobView::advance_container(
const ov::util::MemoryView& view) noexcept {
- const auto& hdr = Header::view(reinterpret_cast<const uint8_t*>(view.data()));
+ const auto& hdr = Header::view(view);
if (!is_recognized_header(hdr) || hdr.container_size > view.size()) {
return std::nullopt;
} else {