Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace intel_npu {
class ZeroEngineBackend final : public IEngineBackend {
public:
ZeroEngineBackend();
virtual ~ZeroEngineBackend();
~ZeroEngineBackend() override = default;

const std::shared_ptr<IDevice> getDevice() const override;
const std::shared_ptr<IDevice> getDevice(const std::string&) const override;
const std::string getName() const override {
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/intel_npu/src/backend/src/zero_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ bool ZeroEngineBackend::isLUIDExtSupported() const {
return _initStruct->isExtensionSupported(std::string(ZE_DEVICE_LUID_EXT_NAME), ZE_MAKE_VERSION(1, 0));
}

ZeroEngineBackend::~ZeroEngineBackend() = default;

const std::shared_ptr<IDevice> ZeroEngineBackend::getDevice() const {
if (_devices.empty()) {
_logger.debug("ZeroEngineBackend - getDevice() returning empty list");
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/intel_npu/src/plugin/include/remote_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class RemoteContextImpl : public ov::IRemoteContext {
public:
RemoteContextImpl(const ov::SoPtr<IEngineBackend>& engineBackend, const ov::AnyMap& remote_properties = {});

~RemoteContextImpl() override = default;

/**
* @brief Returns name of a device on which underlying object is allocated.
* @return A device name string in fully specified format `<device_name>[.<device_id>[.<tile_id>]]` (e.g. GPU.0.1).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ZeroApi {

~ZeroApi() = default;

static const std::shared_ptr<ZeroApi>& getInstance();
static const std::shared_ptr<ZeroApi> getInstance();

#define symbol_statement(symbol) decltype(&::symbol) symbol;
symbols_list();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ZeroInitStructsHolder final {
return _external_memory_fd_win32_supported;
}

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

private:
void initNpuDriver();
Expand Down
14 changes: 12 additions & 2 deletions src/plugins/intel_npu/src/utils/src/zero/zero_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "intel_npu/utils/zero/zero_api.hpp"

#include <mutex>

#include "openvino/util/file_util.hpp"
#include "openvino/util/shared_object.hpp"

Expand Down Expand Up @@ -49,8 +51,16 @@ ZeroApi::ZeroApi() {
#undef symbol_statement
}

const std::shared_ptr<ZeroApi>& ZeroApi::getInstance() {
static std::shared_ptr<ZeroApi> instance = std::make_shared<ZeroApi>();
const std::shared_ptr<ZeroApi> ZeroApi::getInstance() {
static std::mutex mutex;
static std::weak_ptr<ZeroApi> weak_instance;

std::lock_guard<std::mutex> lock(mutex);
auto instance = weak_instance.lock();
if (!instance) {
instance = std::make_shared<ZeroApi>();
weak_instance = instance;
}
return instance;
}

Expand Down
14 changes: 12 additions & 2 deletions src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ze_command_queue_npu_ext.h>
#include <ze_mem_import_system_memory_ext.h>

#include <mutex>
#include <regex>

#include "intel_npu/utils/zero/zero_utils.hpp"
Expand Down Expand Up @@ -331,15 +332,24 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()
}
}

const std::shared_ptr<ZeroInitStructsHolder>& ZeroInitStructsHolder::getInstance() {
static std::shared_ptr<ZeroInitStructsHolder> instance = std::make_shared<ZeroInitStructsHolder>();
const std::shared_ptr<ZeroInitStructsHolder> ZeroInitStructsHolder::getInstance() {
static std::mutex mutex;
static std::weak_ptr<ZeroInitStructsHolder> weak_instance;

std::lock_guard<std::mutex> lock(mutex);
auto instance = weak_instance.lock();
if (!instance) {
instance = std::make_shared<ZeroInitStructsHolder>();
weak_instance = instance;
}
return instance;
}

ZeroInitStructsHolder::~ZeroInitStructsHolder() {
if (context) {
log.debug("ZeroInitStructsHolder - performing zeContextDestroy");
auto result = zeContextDestroy(context);
context = nullptr;
if (result != ZE_RESULT_SUCCESS) {
if (result == ZE_RESULT_ERROR_UNINITIALIZED) {
log.warning("zeContextDestroy failed to destroy the context; Level zero context was already destroyed");
Expand Down
Loading