Skip to content

Commit

Permalink
Fix OV cache header not being removed from blob for memory mapped cac…
Browse files Browse the repository at this point in the history
…he file
  • Loading branch information
MirceaDan99 committed Nov 20, 2024
1 parent 4ba15f6 commit 11714e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/dev_api/openvino/runtime/aligned_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ class OPENVINO_API AlignedBuffer {
size_t size() const {
return m_byte_size;
}
void updateOffset(size_t offset) {
m_offset = offset;
}
void* get_ptr(size_t offset) const {
return m_aligned_buffer + offset;
}
void* get_ptr() {
return m_aligned_buffer;
return m_aligned_buffer + m_offset;
}
const void* get_ptr() const {
return m_aligned_buffer;
return m_aligned_buffer + m_offset;
}
template <typename T>
T* get_ptr() {
Expand All @@ -61,6 +64,7 @@ class OPENVINO_API AlignedBuffer {
char* m_allocated_buffer;
char* m_aligned_buffer;
size_t m_byte_size;
size_t m_offset = 0;
};

template <>
Expand Down
21 changes: 21 additions & 0 deletions src/core/dev_api/openvino/runtime/shared_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SharedBuffer : public ov::AlignedBuffer {
m_allocated_buffer = data;
m_aligned_buffer = data;
m_byte_size = size;
m_offset = 0;
}

virtual ~SharedBuffer() {
Expand Down Expand Up @@ -81,6 +82,26 @@ class OwningSharedStreamBuffer : public SharedStreamBuffer {
return m_shared_obj;
}

std::streamsize xsgetn(char* s, std::streamsize count) override {
auto streamSize = SharedStreamBuffer::xsgetn(s, count);
m_shared_obj->updateOffset(m_offset);
return streamSize;
}

int_type uflow() override {
auto val = SharedStreamBuffer::uflow();
m_shared_obj->updateOffset(m_offset);
return val;
}

pos_type seekoff(off_type off,
std::ios_base::seekdir dir,
std::ios_base::openmode which = std::ios_base::in) override {
auto pos = SharedStreamBuffer::seekoff(off, dir, which);
m_shared_obj->updateOffset(m_offset);
return pos;
}

protected:
std::shared_ptr<ov::AlignedBuffer> m_shared_obj;
};
Expand Down

0 comments on commit 11714e1

Please sign in to comment.