Skip to content

Commit

Permalink
Prepare BlobContainerAlignedBuffer for OV versioning metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
MirceaDan99 committed Jan 13, 2025
1 parent 082c52d commit 56eeee9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@ class BlobContainerVector : public BlobContainer {

class BlobContainerAlignedBuffer : public BlobContainer {
public:
BlobContainerAlignedBuffer(const std::shared_ptr<ov::AlignedBuffer>& blobSO, size_t offset)
BlobContainerAlignedBuffer(const std::shared_ptr<ov::AlignedBuffer>& blobSO,
size_t ovHeaderOffset,
size_t metadataSize)
: _ownershipBlob(blobSO),
_offset(offset) {}
_ovHeaderOffset(ovHeaderOffset),
_metadataSize(metadataSize) {}

void* get_ptr() override {
return _ownershipBlob->get_ptr(_offset);
return _ownershipBlob->get_ptr(_ovHeaderOffset);
}

size_t size() const override {
return _ownershipBlob->size();
// remove OV header offset and metadata from blob size
return _ownershipBlob->size() - _ovHeaderOffset - _metadataSize;
}

bool release_from_memory() override {
Expand All @@ -64,7 +68,8 @@ class BlobContainerAlignedBuffer : public BlobContainer {

private:
std::shared_ptr<ov::AlignedBuffer> _ownershipBlob;
size_t _offset;
size_t _ovHeaderOffset;
size_t _metadataSize;
};

} // namespace intel_npu
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PluginGraph::PluginGraph(const std::shared_ptr<ZeGraphExtWrappers>& zeGraphExt,
initialize(config);
}

void PluginGraph::export_blob(std::ostream& stream) const {
size_t PluginGraph::export_blob(std::ostream& stream) const {
stream.write(reinterpret_cast<const char*>(_blobPtr->get_ptr()), _blobPtr->size());

if (!stream) {
Expand Down
10 changes: 7 additions & 3 deletions src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,15 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, c
CompilerAdapterFactory compilerAdapterFactory;
auto compiler = compilerAdapterFactory.getCompiler(_backends->getIEngineBackend(), localConfig);

auto storedMeta = read_metadata_from(stream);
if (!storedMeta->is_compatible()) {
OPENVINO_THROW("Incompatible blob version!");
}

std::unique_ptr<BlobContainer> blobPtr;
auto graphSize = storedMeta->get_blob_size();

if (modelBuffer == nullptr) {
auto graphSize = getFileSize(stream);

std::vector<uint8_t> blob(graphSize);
stream.read(reinterpret_cast<char*>(blob.data()), graphSize);
if (!stream) {
Expand All @@ -804,7 +808,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, c

blobPtr = std::make_unique<BlobContainerVector>(std::move(blob));
} else {
blobPtr = std::make_unique<BlobContainerAlignedBuffer>(modelBuffer, stream.tellg());
blobPtr = std::make_unique<BlobContainerAlignedBuffer>(modelBuffer, stream.tellg(), graphSize);
}

auto graph = compiler->parse(std::move(blobPtr), localConfig);
Expand Down

0 comments on commit 56eeee9

Please sign in to comment.