File tree Expand file tree Collapse file tree 7 files changed +30
-9
lines changed
src/plugins/intel_npu/src
include/intel_npu/utils/zero Expand file tree Collapse file tree 7 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ namespace intel_npu {
1515class ZeroEngineBackend final : public IEngineBackend {
1616public:
1717 ZeroEngineBackend ();
18- virtual ~ZeroEngineBackend ();
18+ ~ZeroEngineBackend () override = default ;
19+
1920 const std::shared_ptr<IDevice> getDevice () const override ;
2021 const std::shared_ptr<IDevice> getDevice (const std::string&) const override ;
2122 const std::string getName () const override {
Original file line number Diff line number Diff line change @@ -37,8 +37,6 @@ bool ZeroEngineBackend::isLUIDExtSupported() const {
3737 return _initStruct->isExtensionSupported (std::string (ZE_DEVICE_LUID_EXT_NAME), ZE_MAKE_VERSION (1 , 0 ));
3838}
3939
40- ZeroEngineBackend::~ZeroEngineBackend () = default ;
41-
4240const std::shared_ptr<IDevice> ZeroEngineBackend::getDevice () const {
4341 if (_devices.empty ()) {
4442 _logger.debug (" ZeroEngineBackend - getDevice() returning empty list" );
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ class RemoteContextImpl : public ov::IRemoteContext {
2121public:
2222 RemoteContextImpl (const ov::SoPtr<IEngineBackend>& engineBackend, const ov::AnyMap& remote_properties = {});
2323
24+ ~RemoteContextImpl () override = default ;
25+
2426 /* *
2527 * @brief Returns name of a device on which underlying object is allocated.
2628 * @return A device name string in fully specified format `<device_name>[.<device_id>[.<tile_id>]]` (e.g. GPU.0.1).
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ class ZeroApi {
7878
7979 ~ZeroApi () = default ;
8080
81- static const std::shared_ptr<ZeroApi>& getInstance ();
81+ static const std::shared_ptr<ZeroApi> getInstance ();
8282
8383#define symbol_statement (symbol ) decltype (&::symbol) symbol;
8484 symbols_list ();
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ class ZeroInitStructsHolder final {
7979 return _external_memory_fd_win32_supported;
8080 }
8181
82- static const std::shared_ptr<ZeroInitStructsHolder>& getInstance ();
82+ static const std::shared_ptr<ZeroInitStructsHolder> getInstance ();
8383
8484private:
8585 void initNpuDriver ();
Original file line number Diff line number Diff line change 44
55#include " intel_npu/utils/zero/zero_api.hpp"
66
7+ #include < mutex>
8+
79#include " openvino/util/file_util.hpp"
810#include " openvino/util/shared_object.hpp"
911
@@ -49,8 +51,16 @@ ZeroApi::ZeroApi() {
4951#undef symbol_statement
5052}
5153
52- const std::shared_ptr<ZeroApi>& ZeroApi::getInstance () {
53- static std::shared_ptr<ZeroApi> instance = std::make_shared<ZeroApi>();
54+ const std::shared_ptr<ZeroApi> ZeroApi::getInstance () {
55+ static std::mutex mutex;
56+ static std::weak_ptr<ZeroApi> weak_instance;
57+
58+ std::lock_guard<std::mutex> lock (mutex);
59+ auto instance = weak_instance.lock ();
60+ if (!instance) {
61+ instance = std::make_shared<ZeroApi>();
62+ weak_instance = instance;
63+ }
5464 return instance;
5565}
5666
Original file line number Diff line number Diff line change 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"
@@ -331,15 +332,24 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()
331332 }
332333}
333334
334- const std::shared_ptr<ZeroInitStructsHolder>& ZeroInitStructsHolder::getInstance () {
335- static std::shared_ptr<ZeroInitStructsHolder> instance = std::make_shared<ZeroInitStructsHolder>();
335+ const std::shared_ptr<ZeroInitStructsHolder> ZeroInitStructsHolder::getInstance () {
336+ static std::mutex mutex;
337+ static std::weak_ptr<ZeroInitStructsHolder> weak_instance;
338+
339+ std::lock_guard<std::mutex> lock (mutex);
340+ auto instance = weak_instance.lock ();
341+ if (!instance) {
342+ instance = std::make_shared<ZeroInitStructsHolder>();
343+ weak_instance = instance;
344+ }
336345 return instance;
337346}
338347
339348ZeroInitStructsHolder::~ZeroInitStructsHolder () {
340349 if (context) {
341350 log.debug (" ZeroInitStructsHolder - performing zeContextDestroy" );
342351 auto result = zeContextDestroy (context);
352+ context = nullptr ;
343353 if (result != ZE_RESULT_SUCCESS) {
344354 if (result == ZE_RESULT_ERROR_UNINITIALIZED) {
345355 log.warning (" zeContextDestroy failed to destroy the context; Level zero context was already destroyed" );
You can’t perform that action at this time.
0 commit comments