Skip to content

Commit db50830

Browse files
committed
Fix issue with deallocation from different .so on Linux platforms
Signed-off-by: Bogdan Pereanu <[email protected]>
1 parent f4ddce2 commit db50830

File tree

13 files changed

+13
-74
lines changed

13 files changed

+13
-74
lines changed

src/plugins/intel_npu/src/backend/include/zero_backend.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace intel_npu {
1515
class ZeroEngineBackend final : public IEngineBackend {
1616
public:
1717
ZeroEngineBackend();
18-
~ZeroEngineBackend();
18+
~ZeroEngineBackend() override = default;
1919
const std::shared_ptr<IDevice> getDevice() const override;
2020
const std::shared_ptr<IDevice> getDevice(const std::string&) const override;
2121
const std::string getName() const override {

src/plugins/intel_npu/src/backend/include/zero_tensor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ZeroTensor final : public ov::ITensor {
6969
void prevent_reuse();
7070
bool can_be_reused();
7171

72-
~ZeroTensor() override;
72+
~ZeroTensor() override = default;
7373

7474
private:
7575
void update_strides() const;

src/plugins/intel_npu/src/backend/src/zero_backend.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,4 @@ const std::shared_ptr<ZeroInitStructsHolder> ZeroEngineBackend::getInitStructs()
143143
return _initStruct;
144144
}
145145

146-
ZeroEngineBackend::~ZeroEngineBackend() {
147-
if (_initStruct != nullptr) {
148-
_devices.clear();
149-
_initStruct->destroy();
150-
}
151-
}
152-
153146
} // namespace intel_npu

src/plugins/intel_npu/src/backend/src/zero_tensor.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,4 @@ bool ZeroTensor::can_be_reused() {
204204
return _can_be_reused;
205205
}
206206

207-
ZeroTensor::~ZeroTensor() {
208-
// make sure that the mem ref is destroyed before destroying the zero context
209-
_mem_ref = {};
210-
_init_structs->destroy();
211-
}
212-
213207
} // namespace intel_npu

src/plugins/intel_npu/src/plugin/include/remote_context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class RemoteContextImpl : public ov::IRemoteContext {
2121
public:
2222
RemoteContextImpl(const ov::SoPtr<IEngineBackend>& engineBackend, const ov::AnyMap& remote_properties = {});
2323

24-
~RemoteContextImpl();
24+
~RemoteContextImpl() override = default;
2525

2626
/**
2727
* @brief Returns name of a device on which underlying object is allocated.

src/plugins/intel_npu/src/plugin/src/remote_context.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,4 @@ std::shared_ptr<ov::IRemoteContext> RemoteContextImpl::get_this_shared_ptr() {
117117
return shared_from_this();
118118
}
119119

120-
RemoteContextImpl::~RemoteContextImpl() {
121-
_init_structs->destroy();
122-
}
123-
124120
} // namespace intel_npu

src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <ze_intel_npu_uuid.h>
1111

1212
#include <memory>
13-
#include <mutex>
1413

1514
#include "intel_npu/utils/logger/logger.hpp"
1615
#include "intel_npu/utils/zero/zero_api.hpp"
@@ -82,15 +81,8 @@ class ZeroInitStructsHolder final {
8281

8382
static const std::shared_ptr<ZeroInitStructsHolder> getInstance();
8483

85-
static void destroy();
86-
8784
private:
8885
void initNpuDriver();
89-
static std::weak_ptr<ZeroInitStructsHolder>& getInstanceStorage();
90-
// Static mutex for synchronization
91-
static std::mutex& getMutex();
92-
93-
void destroy_context();
9486

9587
// keep zero_api alive until context is destroyed
9688
std::shared_ptr<ZeroApi> zero_api;

src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_remote_tensor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ZeroRemoteTensor final : public ov::IRemoteTensor {
7171
void* get_original_memory() const;
7272
ze_context_handle_t get_zero_context_handle() const;
7373

74-
~ZeroRemoteTensor() override;
74+
~ZeroRemoteTensor() override = default;
7575

7676
private:
7777
void allocate(const size_t bytes);

src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ze_command_queue_npu_ext.h>
88
#include <ze_mem_import_system_memory_ext.h>
99

10+
#include <mutex>
1011
#include <regex>
1112

1213
#include "intel_npu/utils/zero/zero_utils.hpp"
@@ -365,40 +366,19 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()
365366
}
366367

367368
const std::shared_ptr<ZeroInitStructsHolder> ZeroInitStructsHolder::getInstance() {
368-
std::lock_guard<std::mutex> lock(getMutex());
369-
auto instance = getInstanceStorage().lock();
369+
static std::mutex mutex;
370+
static std::weak_ptr<ZeroInitStructsHolder> weak_instance;
371+
372+
std::lock_guard<std::mutex> lock(mutex);
373+
auto instance = weak_instance.lock();
370374
if (!instance) {
371375
instance = std::make_shared<ZeroInitStructsHolder>();
372-
getInstanceStorage() = instance;
376+
weak_instance = instance;
373377
}
374378
return instance;
375379
}
376380

377-
void ZeroInitStructsHolder::destroy() {
378-
std::lock_guard<std::mutex> lock(getMutex());
379-
auto instance = getInstanceStorage().lock();
380-
if (instance && instance.use_count() == 2) {
381-
instance->destroy_context();
382-
// reset weak pointer
383-
getInstanceStorage().reset();
384-
// reset shared pointer
385-
instance.reset();
386-
}
387-
// don't destroy if ref count is higher than 2.
388-
// one is after getInstanceStorage().lock() and another one is hold by the caller
389-
}
390-
391-
std::weak_ptr<ZeroInitStructsHolder>& ZeroInitStructsHolder::getInstanceStorage() {
392-
static std::weak_ptr<ZeroInitStructsHolder> weak_instance;
393-
return weak_instance;
394-
}
395-
396-
std::mutex& ZeroInitStructsHolder::getMutex() {
397-
static std::mutex mutex;
398-
return mutex;
399-
}
400-
401-
void ZeroInitStructsHolder::destroy_context() {
381+
ZeroInitStructsHolder::~ZeroInitStructsHolder() {
402382
if (context) {
403383
if (context_npu_dditable_ext_decorator->version() >= ZE_MAKE_VERSION(1, 0)) {
404384
context_options &= ~(ZE_NPU_CONTEXT_OPTION_ENABLE_IDLE_OPTIMIZATIONS);
@@ -421,8 +401,4 @@ void ZeroInitStructsHolder::destroy_context() {
421401
}
422402
}
423403

424-
ZeroInitStructsHolder::~ZeroInitStructsHolder() {
425-
destroy_context();
426-
}
427-
428404
} // namespace intel_npu

src/plugins/intel_npu/src/utils/src/zero/zero_mem.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ ZeroMem::~ZeroMem() {
133133
uint64_t(result),
134134
ze_result_to_description(result).c_str());
135135
}
136-
137-
_init_structs->destroy();
138136
}
139137

140138
} // namespace intel_npu

0 commit comments

Comments
 (0)