Skip to content

Commit

Permalink
Fix for blob being freed at the end of core.impot_model function
Browse files Browse the repository at this point in the history
  • Loading branch information
MirceaDan99 committed Dec 10, 2024
1 parent e2c1b93 commit 6b5a462
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/core/dev_api/openvino/runtime/shared_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ namespace ov {
template <typename T>
class SharedBuffer : public ov::AlignedBuffer {
public:

SharedBuffer(const SharedBuffer&) = delete;
SharedBuffer(SharedBuffer&&) = default;
SharedBuffer& operator=(const SharedBuffer&) = delete;
SharedBuffer& operator=(SharedBuffer&&) = default;

SharedBuffer(char* data, size_t size, const T& shared_object) : _shared_object(shared_object) {
m_allocated_buffer = data;
m_aligned_buffer = data;
Expand Down
14 changes: 11 additions & 3 deletions src/plugins/intel_npu/src/al/src/config/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <sstream>

#include "intel_npu/config/common.hpp"
#include "openvino/util/mmap_object.hpp"
#include "openvino/runtime/properties.hpp"
#include "openvino/runtime/shared_buffer.hpp"

using namespace intel_npu;
using namespace ov::intel_npu;
Expand Down Expand Up @@ -158,16 +160,22 @@ std::string intel_npu::WORKLOAD_TYPE::toString(const ov::WorkloadType& val) {
}

//
// WORKLOAD_TYPE
// CACHED_MODEL_BUFFER
//

std::shared_ptr<ov::AlignedBuffer> intel_npu::CACHED_MODEL_BUFFER::parse(std::string_view val) {
std::istringstream ss = std::istringstream(std::string(val));
void* modelBufferPtr;

ss >> modelBufferPtr;

return std::shared_ptr<ov::AlignedBuffer>(static_cast<ov::AlignedBuffer*>(modelBufferPtr));
// If we don't "steal" below resources from the casted ov::AlignedBuffer, parsed blob will be freed
// after core.import_model causing problems at inference.get_profiling_info()
auto* modelBufferSO = dynamic_cast<ov::SharedBuffer<std::shared_ptr<ov::MappedMemory>>*>(static_cast<ov::AlignedBuffer*>(modelBufferPtr));
std::shared_ptr<ov::MappedMemory> mappedMemorySOPtr;
auto modelBufferSOPtr = std::make_shared<ov::SharedBuffer<std::shared_ptr<ov::MappedMemory>>>(nullptr, 0, mappedMemorySOPtr);
*modelBufferSOPtr = std::move(*modelBufferSO);

return modelBufferSOPtr;
}

std::string intel_npu::CACHED_MODEL_BUFFER::toString(const std::shared_ptr<ov::AlignedBuffer>& val) {
Expand Down

0 comments on commit 6b5a462

Please sign in to comment.