Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Zero backend and compiler adapter to share single L0 context (#26016)

KianYong Gan5f5f0279bed2
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp
index 25361c0dc95..f3e96e8650b 100644
--- a/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp
+++ b/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp
@@ -112,6 +112,9 @@ struct NetworkMetadata final {
size_t numStreams = 1;
+ // Used primarily in the CID path to pass the level zero graph handle from compiler to the backend executor
+ void* graphHandle = nullptr;
+
/**
* @brief Binds the (state input, state output) and (dynamic tensor, shape tensor) pairs using the
* "relatedDescriptorIndex" attribute.
@@ -135,6 +138,7 @@ struct NetworkDescription final {
NetworkDescription(std::vector<uint8_t>&& compiledNetwork, NetworkMetadata&& metadata)
: compiledNetwork(std::move(compiledNetwork)),
metadata(std::move(metadata)) {}
+ NetworkDescription(NetworkMetadata&& metadata) : metadata(std::move(metadata)) {}
// Force move semantics to prevent blob copies
NetworkDescription(const NetworkDescription&) = delete;
NetworkDescription(NetworkDescription&&) = default;
@@ -196,6 +200,13 @@ public:
const std::vector<uint8_t>& network,
const Config& config) const = 0;
+ // Driver compiler can use this to release graphHandle, if we do not have executor
+ virtual void release([[maybe_unused]] std::shared_ptr<const NetworkDescription> networkDescription){};
+
+ virtual std::vector<uint8_t> getCompiledNetwork(std::shared_ptr<const NetworkDescription> networkDescription) {
+ return networkDescription->compiledNetwork;
+ }
+
protected:
virtual ~ICompiler() = default;
};
diff --git a/src/plugins/intel_npu/src/backend/include/zero_backend.hpp b/src/plugins/intel_npu/src/backend/include/zero_backend.hpp
index 2dcc5c85a43..71d6a20512b 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_backend.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_backend.hpp
@@ -29,6 +29,11 @@ public:
bool isCommandQueueExtSupported() const override;
void* getContext() const override;
+ void* getDriverHandle() const;
+ void* getDeviceHandle() const;
+ char* getGraphExtName();
+ ze_graph_dditable_ext_last_t* getGraphDDITableExt();
+
void updateInfo(const Config& config) override;
private:
diff --git a/src/plugins/intel_npu/src/backend/include/zero_init.hpp b/src/plugins/intel_npu/src/backend/include/zero_init.hpp
index 0e300ff7df7..4128ec6120f 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_init.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_init.hpp
@@ -37,6 +37,12 @@ public:
inline ze_context_handle_t getContext() const {
return context;
}
+ inline char* getGraphExtName() const {
+ return graphExtName;
+ }
+ inline ze_graph_dditable_ext_last_t* getGraphDDITableExt() {
+ return graph_ddi_table_ext;
+ }
inline ze_graph_dditable_ext_curr_t* getGraphDdiTable() const {
return graph_dditable_ext_decorator.get();
}
@@ -60,9 +66,12 @@ private:
static const ze_driver_uuid_t uuid;
Logger log;
+ ze_context_handle_t context = nullptr;
ze_driver_handle_t driver_handle = nullptr;
ze_device_handle_t device_handle = nullptr;
- ze_context_handle_t context = nullptr;
+ char* graphExtName;
+ ze_graph_dditable_ext_last_t* graph_ddi_table_ext = nullptr;
+
std::unique_ptr<ze_graph_dditable_ext_decorator> graph_dditable_ext_decorator;
ze_command_queue_npu_dditable_ext_curr_t* _command_queue_npu_dditable_ext = nullptr;
ze_graph_profiling_dditable_ext_t* _graph_profiling_ddi_table_ext = nullptr;
diff --git a/src/plugins/intel_npu/src/backend/include/zero_types.hpp b/src/plugins/intel_npu/src/backend/include/zero_types.hpp
index 06b4818197a..b6f1251f1ce 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_types.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_types.hpp
@@ -13,7 +13,7 @@
/**
* @brief Last version of Table of Graph Extension functions used within plugin
*/
-using ze_graph_dditable_ext_last_t = ze_graph_dditable_ext_1_5_t;
+using ze_graph_dditable_ext_last_t = ze_graph_dditable_ext_1_6_t;
/**
* @brief Table of Graph Extension functions pointers and function wrappers
@@ -125,6 +125,13 @@ public:
throwWhenUnsupported("pfnQueryContextMemory", ZE_GRAPH_EXT_VERSION_1_5);
return _impl->pfnQueryContextMemory(hContext, type, query);
}
+
+ // version 1.6
+ ze_result_t ZE_APICALL pfnDeviceGetGraphProperties2(ze_device_handle_t hDevice,
+ ze_device_graph_properties_2_t* pDeviceGraphProperties) {
+ throwWhenUnsupported("pfnDeviceGetGraphProperties2", ZE_GRAPH_EXT_VERSION_1_6);
+ return _impl->pfnDeviceGetGraphProperties2(hDevice, pDeviceGraphProperties);
+ }
};
using ze_graph_dditable_ext_curr_t = ze_graph_dditable_ext_decorator;
diff --git a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp b/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
index 2911f89cd6b..10cd8249a97 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
@@ -68,6 +68,22 @@ void* ZeroEngineBackend::getContext() const {
return _instance->getContext();
}
+void* ZeroEngineBackend::getDriverHandle() const {
+ return _instance->getDriver();
+}
+
+void* ZeroEngineBackend::getDeviceHandle() const {
+ return _instance->getDevice();
+}
+
+char* ZeroEngineBackend::getGraphExtName() {
+ return _instance->getGraphExtName();
+}
+
+ze_graph_dditable_ext_last_t* ZeroEngineBackend::getGraphDDITableExt() {
+ return _instance->getGraphDDITableExt();
+}
+
void ZeroEngineBackend::updateInfo(const Config& config) {
_logger.setLevel(config.get<LOG_LEVEL>());
if (_devices.size() > 0) {
diff --git a/src/plugins/intel_npu/src/backend/src/zero_executor.cpp b/src/plugins/intel_npu/src/backend/src/zero_executor.cpp
index 194ce7024ac..69603b18c04 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_executor.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_executor.cpp
@@ -49,39 +49,48 @@ ZeroExecutor::ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& i
_initStructs->getCommandQueueDdiTable(),
_config,
group_ordinal)}} {
- _logger.debug("ZeroExecutor::ZeroExecutor init start - create graph_command_list");
+ _logger.debug("create graph_command_list");
OV_ITT_SCOPED_TASK(itt::domains::LevelZeroBackend, "Executor::ZeroExecutor");
CommandList graph_command_list(_initStructs->getDevice(),
_initStructs->getContext(),
_initStructs->getGraphDdiTable(),
_config,
_group_ordinal);
- _logger.debug("ZeroExecutor::ZeroExecutor - create graph_command_queue");
+ _logger.debug("create graph_command_queue");
CommandQueue graph_command_queue(_initStructs->getDevice(),
_initStructs->getContext(),
ZE_COMMAND_QUEUE_PRIORITY_NORMAL,
_initStructs->getCommandQueueDdiTable(),
_config,
_group_ordinal);
- _logger.debug("ZeroExecutor::ZeroExecutor - create fence");
+ _logger.debug("create fence");
Fence fence(graph_command_queue, _config);
- _logger.debug("ZeroExecutor::ZeroExecutor - create graph");
OV_ITT_TASK_CHAIN(ZERO_EXECUTOR_GRAPH, itt::domains::LevelZeroBackend, "Executor::ZeroExecutor", "graphCreate");
- ze_graph_desc_t desc{ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES,
- nullptr,
- ZE_GRAPH_FORMAT_NATIVE,
- _networkDesc->compiledNetwork.size(),
- _networkDesc->compiledNetwork.data(),
- nullptr};
- zeroUtils::throwOnFail(
- "pfnCreate",
- _graph_ddi_table_ext->pfnCreate(_initStructs->getContext(), _initStructs->getDevice(), &desc, &_graph));
+ // _graph is a nullptr for CIP path, a new handle will be obtained from the driver based on the given
+ // compiledNetwork _graph gets (reuses) graphHandle from the compiler for CID path
+ if (_networkDesc->metadata.graphHandle == nullptr) {
+ _logger.debug("create graph handle on executor");
+ ze_graph_desc_t desc{ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES,
+ nullptr,
+ ZE_GRAPH_FORMAT_NATIVE,
+ _networkDesc->compiledNetwork.size(),
+ _networkDesc->compiledNetwork.data(),
+ nullptr};
+
+ zeroUtils::throwOnFail(
+ "pfnCreate",
+ _graph_ddi_table_ext->pfnCreate(_initStructs->getContext(), _initStructs->getDevice(), &desc, &_graph));
+
+ } else {
+ _logger.debug("reuse graph handle created from compiler");
+ _graph = static_cast<ze_graph_handle_t>(_networkDesc->metadata.graphHandle);
+ }
OV_ITT_TASK_NEXT(ZERO_EXECUTOR_GRAPH, "pfnGetProperties");
+ _logger.debug("performing pfnGetProperties");
zeroUtils::throwOnFail("pfnGetProperties", _graph_ddi_table_ext->pfnGetProperties(_graph, &_props));
-
auto targetDriverExtVersion = _initStructs->getDriverExtVersion();
if (targetDriverExtVersion <= ZE_GRAPH_EXT_VERSION_1_1) {
OPENVINO_THROW("Incompatibility between the NPU plugin and driver! The driver version is too old, please "
@@ -89,7 +98,7 @@ ZeroExecutor::ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& i
}
OV_ITT_TASK_NEXT(ZERO_EXECUTOR_GRAPH, "pfnGetArgumentProperties3");
- _logger.debug("ZeroExecutor::ZeroExecutor - performing pfnGetArgumentProperties3");
+ _logger.debug("performing pfnGetArgumentProperties3");
for (uint32_t index = 0; index < _props.numGraphArgs; ++index) {
ze_graph_argument_properties_3_t arg3;
zeroUtils::throwOnFail("pfnGetArgumentProperties3",
@@ -103,17 +112,17 @@ ZeroExecutor::ZeroExecutor(const std::shared_ptr<const ZeroInitStructsHolder>& i
}
OV_ITT_TASK_NEXT(ZERO_EXECUTOR_GRAPH, "appendGraphInitialize");
- _logger.debug("ZeroExecutor::ZeroExecutor - performing appendGraphInitialize");
+ _logger.debug("performing appendGraphInitialize");
graph_command_list.appendGraphInitialize(_graph);
- _logger.debug("ZeroExecutor::ZeroExecutor - closing graph command list");
+ _logger.debug("closing graph command list");
graph_command_list.close();
OV_ITT_TASK_NEXT(ZERO_EXECUTOR_GRAPH, "queue_execute");
- _logger.debug("ZeroExecutor::ZeroExecutor - performing executeCommandList");
+ _logger.debug("performing executeCommandList");
graph_command_queue.executeCommandList(graph_command_list, fence);
- _logger.debug("ZeroExecutor::ZeroExecutor - performing hostSynchronize");
+ _logger.debug("performing hostSynchronize");
fence.hostSynchronize();
- _logger.debug("ZeroExecutor::ZeroExecutor - hostSynchronize completed");
+ _logger.debug("hostSynchronize completed");
if (config.has<WORKLOAD_TYPE>()) {
setWorkloadType(config.get<WORKLOAD_TYPE>());
@@ -151,6 +160,7 @@ void ZeroExecutor::mutexUnlock() const {
}
ZeroExecutor::~ZeroExecutor() {
+ _logger.debug("~ZeroExecutor() - pfnDestroy _graph ");
auto result = _graph_ddi_table_ext->pfnDestroy(_graph);
if (ZE_RESULT_SUCCESS != result) {
_logger.error("_graph_ddi_table_ext->pfnDestroy failed %#X", uint64_t(result));
diff --git a/src/plugins/intel_npu/src/backend/src/zero_init.cpp b/src/plugins/intel_npu/src/backend/src/zero_init.cpp
index 7ed1c66c009..d992f67b5eb 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_init.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_init.cpp
@@ -167,7 +167,6 @@ ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder",
}
// Load our graph extension
- ze_graph_dditable_ext_last_t* graph_ddi_table_ext = nullptr;
zeroUtils::throwOnFail("zeDriverGetExtensionFunctionAddress",
zeDriverGetExtensionFunctionAddress(driver_handle,
graph_ext_name.c_str(),
@@ -201,6 +200,7 @@ ZeroInitStructsHolder::ZeroInitStructsHolder() : log("NPUZeroInitStructsHolder",
// Get our target device
zeroUtils::throwOnFail("zeDeviceGet", zeDeviceGet(driver_handle, &device_count, &device_handle));
+ // Create context - share between the compiler and the backend
ze_context_desc_t context_desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, 0, 0};
zeroUtils::throwOnFail("zeContextCreate", zeContextCreate(driver_handle, &context_desc, &context));
log.debug("ZeroInitStructsHolder initialize complete");
diff --git a/src/plugins/intel_npu/src/compiler/CMakeLists.txt b/src/plugins/intel_npu/src/compiler/CMakeLists.txt
index ffbbc2bba53..3f478de4f3e 100644
--- a/src/plugins/intel_npu/src/compiler/CMakeLists.txt
+++ b/src/plugins/intel_npu/src/compiler/CMakeLists.txt
@@ -26,6 +26,7 @@ target_link_libraries(${TARGET_NAME}
openvino::npu_al
PRIVATE
openvino_npu_zero_result_parser
+ openvino_npu_level_zero_backend
openvino::runtime
openvino::runtime::dev
ze_loader
diff --git a/src/plugins/intel_npu/src/compiler/include/driver_compiler_adapter.hpp b/src/plugins/intel_npu/src/compiler/include/driver_compiler_adapter.hpp
index b405114c9c1..3f02cecd2b0 100644
--- a/src/plugins/intel_npu/src/compiler/include/driver_compiler_adapter.hpp
+++ b/src/plugins/intel_npu/src/compiler/include/driver_compiler_adapter.hpp
@@ -8,6 +8,7 @@
#include "intel_npu/al/icompiler.hpp"
#include "intel_npu/utils/logger/logger.hpp"
+#include "npu.hpp"
namespace intel_npu {
namespace driverCompilerAdapter {
@@ -18,7 +19,7 @@ namespace driverCompilerAdapter {
*/
class LevelZeroCompilerAdapter final : public ICompiler {
public:
- LevelZeroCompilerAdapter();
+ LevelZeroCompilerAdapter(std::shared_ptr<IEngineBackend> iEngineBackend);
uint32_t getSupportedOpsetVersion() const override final;
@@ -33,12 +34,15 @@ public:
const std::vector<uint8_t>& network,
const Config& config) const override final;
+ void release(std::shared_ptr<const NetworkDescription> networkDescription) override;
+
+ std::vector<uint8_t> getCompiledNetwork(std::shared_ptr<const NetworkDescription> networkDescription) override;
+
private:
/**
* @brief Separate externals calls to separate class
*/
std::shared_ptr<ICompiler> apiAdapter;
- ze_driver_handle_t _driverHandle = nullptr;
Logger _logger;
};
diff --git a/src/plugins/intel_npu/src/compiler/include/zero_compiler_in_driver.hpp b/src/plugins/intel_npu/src/compiler/include/zero_compiler_in_driver.hpp
index 18042250e46..fd7c656e814 100644
--- a/src/plugins/intel_npu/src/compiler/include/zero_compiler_in_driver.hpp
+++ b/src/plugins/intel_npu/src/compiler/include/zero_compiler_in_driver.hpp
@@ -11,6 +11,7 @@
#include "intel_npu/al/icompiler.hpp"
#include "intel_npu/utils/logger/logger.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
+#include "zero_executor.hpp"
namespace intel_npu {
namespace driverCompilerAdapter {
@@ -48,7 +49,10 @@ using SerializedIR = std::pair<size_t, std::shared_ptr<uint8_t>>;
template <typename TableExtension>
class LevelZeroCompilerInDriver final : public ICompiler {
public:
- LevelZeroCompilerInDriver(const char* extName, ze_driver_handle_t driverHandle);
+ LevelZeroCompilerInDriver(ze_driver_handle_t driverHandle,
+ ze_device_handle_t deviceHandle,
+ ze_context_handle_t zeContext,
+ ze_graph_dditable_ext_last_t* graph_ddi_table_ext);
LevelZeroCompilerInDriver(const LevelZeroCompilerInDriver&) = delete;
LevelZeroCompilerInDriver& operator=(const LevelZeroCompilerInDriver&) = delete;
~LevelZeroCompilerInDriver() override;
@@ -94,6 +98,10 @@ public:
*/
static std::string serializeIOInfo(const std::shared_ptr<const ov::Model>& model, const bool useIndices);
+ void release(std::shared_ptr<const NetworkDescription> networkDescription) override;
+
+ std::vector<uint8_t> getCompiledNetwork(std::shared_ptr<const NetworkDescription> networkDescription) override;
+
private:
NetworkMetadata getNetworkMeta(ze_graph_handle_t graphHandle) const;
@@ -176,32 +184,5 @@ private:
Logger _logger;
};
-template <typename TableExtension>
-LevelZeroCompilerInDriver<TableExtension>::LevelZeroCompilerInDriver(const char* extName,
- ze_driver_handle_t driverHandle)
- : _driverHandle(driverHandle),
- _logger("LevelZeroCompilerInDriver", Logger::global().level()) {
- // Load our graph extension
- auto result =
- zeDriverGetExtensionFunctionAddress(_driverHandle, extName, reinterpret_cast<void**>(&_graphDdiTableExt));
-
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("Failed to initialize zeDriver. Error code: ", std::hex, result);
- }
-
- uint32_t deviceCount = 1;
- // Get our target device
- result = zeDeviceGet(_driverHandle, &deviceCount, &_deviceHandle);
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("Failed to get device. Error code: ", std::hex, result);
- }
-
- ze_context_desc_t contextDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
- result = zeContextCreate(_driverHandle, &contextDesc, &_context);
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("Failed to initialize context for device. Error code: ", std::hex, result);
- }
-}
-
} // namespace driverCompilerAdapter
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler/src/driver_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler/src/driver_compiler_adapter.cpp
index 6543b1199b7..e7d955c4345 100644
--- a/src/plugins/intel_npu/src/compiler/src/driver_compiler_adapter.cpp
+++ b/src/plugins/intel_npu/src/compiler/src/driver_compiler_adapter.cpp
@@ -9,174 +9,72 @@
#include "intel_npu/utils/zero/zero_api.hpp"
#include "intel_npu/utils/zero/zero_result.hpp"
#include "ze_intel_npu_uuid.h"
+#include "zero_backend.hpp"
#include "zero_compiler_in_driver.hpp"
+#include "zero_init.hpp"
namespace intel_npu {
namespace driverCompilerAdapter {
-LevelZeroCompilerAdapter::LevelZeroCompilerAdapter() : _logger("LevelZeroCompilerAdapter", Logger::global().level()) {
- _logger.debug("initialize zeAPI start");
- auto result = zeInit(ZE_INIT_FLAG_VPU_ONLY);
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("L0 initialize zeAPI",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result));
- }
- uint32_t drivers = 0;
- result = zeDriverGet(&drivers, nullptr);
-
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("L0 zeDriverGet get count",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result));
- }
+LevelZeroCompilerAdapter::LevelZeroCompilerAdapter(std::shared_ptr<IEngineBackend> iEngineBackend)
+ : _logger("LevelZeroCompilerAdapter", Logger::global().level()) {
+ _logger.debug("initialize LevelZeroCompilerAdapter start");
- std::vector<ze_driver_handle_t> allDrivers(drivers);
- result = zeDriverGet(&drivers, allDrivers.data());
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("L0 zeDriverGet get drivers",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result));
+ std::shared_ptr<ZeroEngineBackend> zeroBackend = nullptr;
+ zeroBackend = std::dynamic_pointer_cast<ZeroEngineBackend>(iEngineBackend);
+ if (!zeroBackend) {
+ OPENVINO_THROW("LevelZeroCompilerAdapter init failed to cast zeroBackend, zeroBackend is a nullptr");
}
- const ze_driver_uuid_t uuid = ze_intel_npu_driver_uuid;
- ze_driver_properties_t props = {};
- props.stype = ZE_STRUCTURE_TYPE_DRIVER_PROPERTIES;
- // Get our target driver
- for (uint32_t i = 0; i < drivers; ++i) {
- result = zeDriverGetProperties(allDrivers[i], &props);
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("L0 zeDriverGetProperties",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result));
- }
- if (memcmp(&props.uuid, &uuid, sizeof(uuid)) == 0) {
- _driverHandle = allDrivers[i];
- break;
- }
- }
+ uint32_t driverExtVersion = zeroBackend->getDriverExtVersion();
- if (_driverHandle == nullptr) {
- OPENVINO_THROW("LevelZeroCompilerAdapter: Failed to get properties about zeDriver");
- return;
- }
-
- // query the extension properties
- uint32_t count = 0;
- result = zeDriverGetExtensionProperties(_driverHandle, &count, nullptr);
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("L0 zeDriverGetExtensionProperties get count",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result));
- }
- std::vector<ze_driver_extension_properties_t> extProps;
- extProps.resize(count);
- result = zeDriverGetExtensionProperties(_driverHandle, &count, extProps.data());
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("L0 zeDriverGetExtensionProperties get properties",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result));
- }
- const char* graphExtName = nullptr;
- uint32_t targetVersion = 0;
- for (uint32_t i = 0; i < count; ++i) {
- auto& property = extProps[i];
-
- if (strncmp(property.name, ZE_GRAPH_EXT_NAME, strlen(ZE_GRAPH_EXT_NAME)) != 0) {
- continue;
- }
-
- // If the driver version is latest, will just use its name.
- if (property.version == ZE_GRAPH_EXT_VERSION_CURRENT) {
- graphExtName = property.name;
- targetVersion = property.version;
- break;
- }
-
- // Use the latest version supported by the driver.
- if (property.version > targetVersion) {
- graphExtName = property.name;
- targetVersion = property.version;
- }
- }
+ ze_context_handle_t zeContext = static_cast<ze_context_handle_t>(zeroBackend->getContext());
+ ze_driver_handle_t driverHandle = static_cast<ze_driver_handle_t>(zeroBackend->getDriverHandle());
+ ze_device_handle_t deviceHandle = static_cast<ze_device_handle_t>(zeroBackend->getDeviceHandle());
+ ze_graph_dditable_ext_last_t* graph_ddi_table_ext = zeroBackend->getGraphDDITableExt();
- if (graphExtName == nullptr) {
- OPENVINO_THROW("LevelZeroCompilerAdapter: Failed to find Graph extension in NPU Driver");
+ if (driverHandle == nullptr) {
+ OPENVINO_THROW("LevelZeroCompilerAdapter failed to get properties about zeDriver");
}
- const uint16_t adapterMajorVersion = 1;
- uint16_t driverMajorVersion = ZE_MAJOR_VERSION(targetVersion);
- if (adapterMajorVersion != driverMajorVersion) {
- OPENVINO_THROW("LevelZeroCompilerAdapter: adapterMajorVersion: ",
- adapterMajorVersion,
- " and driverMajorVersion: ",
- driverMajorVersion,
- " mismatch!");
+ _logger.info("LevelZeroCompilerAdapter creating adapter using driverExtVersion");
+
+ switch (driverExtVersion) {
+ case ZE_GRAPH_EXT_VERSION_1_3:
+ apiAdapter = std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_3_t>>(driverHandle,
+ deviceHandle,
+ zeContext,
+ graph_ddi_table_ext);
+ break;
+ case ZE_GRAPH_EXT_VERSION_1_4:
+ apiAdapter = std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_4_t>>(driverHandle,
+ deviceHandle,
+ zeContext,
+ graph_ddi_table_ext);
+ break;
+ case ZE_GRAPH_EXT_VERSION_1_5:
+ apiAdapter = std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_5_t>>(driverHandle,
+ deviceHandle,
+ zeContext,
+ graph_ddi_table_ext);
+ break;
+ case ZE_GRAPH_EXT_VERSION_1_6:
+ apiAdapter = std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_6_t>>(driverHandle,
+ deviceHandle,
+ zeContext,
+ graph_ddi_table_ext);
+ break;
+ default:
+ apiAdapter = std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_2_t>>(driverHandle,
+ deviceHandle,
+ zeContext,
+ graph_ddi_table_ext);
+ break;
}
-#if defined(NPU_PLUGIN_DEVELOPER_BUILD)
- auto adapterManualConfig = std::getenv("ADAPTER_MANUAL_CONFIG");
- if (adapterManualConfig != nullptr) {
- if (strcmp(adapterManualConfig, "ZE_extension_graph_1_6") == 0) {
- _logger.info("With ADAPTER_MANUAL_CONFIG. Using ZE_GRAPH_EXT_VERSION_1_6");
- targetVersion = ZE_GRAPH_EXT_VERSION_1_6;
- } else if (strcmp(adapterManualConfig, "ZE_extension_graph_1_5") == 0) {
- _logger.info("With ADAPTER_MANUAL_CONFIG. Using ZE_GRAPH_EXT_VERSION_1_5");
- targetVersion = ZE_GRAPH_EXT_VERSION_1_5;
- } else if (strcmp(adapterManualConfig, "ZE_extension_graph_1_4") == 0) {
- _logger.info("With ADAPTER_MANUAL_CONFIG. Using ZE_GRAPH_EXT_VERSION_1_4");
- targetVersion = ZE_GRAPH_EXT_VERSION_1_4;
- } else if (strcmp(adapterManualConfig, "ZE_extension_graph_1_3") == 0) {
- _logger.info("With ADAPTER_MANUAL_CONFIG. Using ZE_GRAPH_EXT_VERSION_1_3");
- targetVersion = ZE_GRAPH_EXT_VERSION_1_3;
- } else if (strcmp(adapterManualConfig, "ZE_extension_graph_1_2") == 0) {
- _logger.info("With ADAPTER_MANUAL_CONFIG. Using ZE_GRAPH_EXT_VERSION_1_2");
- targetVersion = ZE_GRAPH_EXT_VERSION_1_2;
- } else {
- OPENVINO_THROW("Using unsupported ADAPTER_MANUAL_CONFIG!");
- }
- }
-#endif
- if (ZE_GRAPH_EXT_VERSION_1_3 == targetVersion) {
- _logger.info("Using ZE_GRAPH_EXT_VERSION_1_3");
- apiAdapter =
- std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_3_t>>(graphExtName, _driverHandle);
- } else if (ZE_GRAPH_EXT_VERSION_1_4 == targetVersion) {
- _logger.info("Using ZE_GRAPH_EXT_VERSION_1_4");
- apiAdapter =
- std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_4_t>>(graphExtName, _driverHandle);
- } else if (ZE_GRAPH_EXT_VERSION_1_5 == targetVersion) {
- _logger.info("Using ZE_GRAPH_EXT_VERSION_1_5");
- apiAdapter =
- std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_5_t>>(graphExtName, _driverHandle);
- } else if (ZE_GRAPH_EXT_VERSION_1_6 == targetVersion) {
- _logger.info("Using ZE_GRAPH_EXT_VERSION_1_6");
- apiAdapter =
- std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_6_t>>(graphExtName, _driverHandle);
- } else {
- _logger.info("Using ZE_GRAPH_EXT_VERSION_1_2");
- apiAdapter =
- std::make_shared<LevelZeroCompilerInDriver<ze_graph_dditable_ext_1_2_t>>(graphExtName, _driverHandle);
- }
- _logger.debug("initialize zeAPI end");
+ _logger.info("initialize LevelZeroCompilerAdapter complete, using driverExtVersion: %d.%d",
+ ZE_MAJOR_VERSION(driverExtVersion),
+ ZE_MINOR_VERSION(driverExtVersion));
}
uint32_t LevelZeroCompilerAdapter::getSupportedOpsetVersion() const {
@@ -206,5 +104,16 @@ std::vector<ov::ProfilingInfo> LevelZeroCompilerAdapter::process_profiling_outpu
OPENVINO_THROW("Profiling post-processing is not implemented.");
}
+void LevelZeroCompilerAdapter::release(std::shared_ptr<const NetworkDescription> networkDescription) {
+ _logger.info("release - using adapter to release networkDescription");
+ apiAdapter->release(networkDescription);
+}
+
+std::vector<uint8_t> LevelZeroCompilerAdapter::getCompiledNetwork(
+ std::shared_ptr<const NetworkDescription> networkDescription) {
+ _logger.info("getCompiledNetwork - using adapter to perform getCompiledNetwork(networkDescription)");
+ return apiAdapter->getCompiledNetwork(networkDescription);
+}
+
} // namespace driverCompilerAdapter
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp b/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp
index 7137c83f20d..8a60833c3c7 100644
--- a/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp
+++ b/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp
@@ -179,14 +179,19 @@ std::string rankToLegacyLayoutString(const size_t rank) {
namespace intel_npu {
namespace driverCompilerAdapter {
+template <typename TableExtension>
+LevelZeroCompilerInDriver<TableExtension>::LevelZeroCompilerInDriver(ze_driver_handle_t driverHandle,
+ ze_device_handle_t deviceHandle,
+ ze_context_handle_t zeContext,
+ ze_graph_dditable_ext_last_t* graph_ddi_table_ext)
+ : _driverHandle(driverHandle),
+ _deviceHandle(deviceHandle),
+ _context(zeContext),
+ _graphDdiTableExt(reinterpret_cast<TableExtension*>(graph_ddi_table_ext)),
+ _logger("LevelZeroCompilerInDriver", Logger::global().level()) {}
+
template <typename TableExtension>
LevelZeroCompilerInDriver<TableExtension>::~LevelZeroCompilerInDriver() {
- if (_context) {
- auto result = zeContextDestroy(_context);
- if (ZE_RESULT_SUCCESS != result) {
- _logger.error("zeContextDestroy failed %#X", uint64_t(result));
- }
- }
_logger.debug("LevelZeroCompilerInDriver obj destroyed");
}
@@ -339,6 +344,67 @@ std::string LevelZeroCompilerInDriver<TableExtension>::serializeIOInfo(const std
outputsPrecisionSS.str() + VALUES_SEPARATOR.data() + outputsLayoutSS.str();
}
+template <typename TableExtension>
+void LevelZeroCompilerInDriver<TableExtension>::release(std::shared_ptr<const NetworkDescription> networkDescription) {
+ _logger.debug("performing release networkDescription");
+ if (networkDescription->metadata.graphHandle != nullptr) {
+ _logger.debug("release - graphHandle is not nullptr");
+ ze_graph_handle_t graphHandle = static_cast<ze_graph_handle_t>(networkDescription->metadata.graphHandle);
+ _logger.debug("release - pfnDestroy graphHandle");
+ auto result = _graphDdiTableExt->pfnDestroy(graphHandle);
+
+ if (ZE_RESULT_SUCCESS != result) {
+ _logger.error("failed to release graph handle. L0 pfnDestroy result: %s, code %#X",
+ ze_result_to_string(result).c_str(),
+ uint64_t(result));
+ }
+ }
+ _logger.debug("release completed");
+}
+
+template <typename TableExtension>
+std::vector<uint8_t> LevelZeroCompilerInDriver<TableExtension>::getCompiledNetwork(
+ std::shared_ptr<const NetworkDescription> networkDescription) {
+ if (networkDescription->metadata.graphHandle != nullptr && networkDescription->compiledNetwork.size() == 0) {
+ _logger.info("LevelZeroCompilerInDriver getCompiledNetwork get blob from graphHandle");
+ ze_graph_handle_t graphHandle = static_cast<ze_graph_handle_t>(networkDescription->metadata.graphHandle);
+
+ // Get blob size first
+ size_t blobSize = -1;
+
+ auto result = _graphDdiTableExt->pfnGetNativeBinary(graphHandle, &blobSize, nullptr);
+
+ OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS,
+ "Failed to compile network. L0 pfnGetNativeBinary get blob size",
+ " result: ",
+ ze_result_to_string(result),
+ ", code 0x",
+ std::hex,
+ uint64_t(result),
+ ". ",
+ getLatestBuildError());
+
+ std::vector<uint8_t> blob(blobSize);
+ // Get blob data
+ result = _graphDdiTableExt->pfnGetNativeBinary(graphHandle, &blobSize, blob.data());
+
+ OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS,
+ "Failed to compile network. L0 pfnGetNativeBinary get blob data",
+ " result: ",
+ ze_result_to_string(result),
+ ", code 0x",
+ std::hex,
+ uint64_t(result),
+ ". ",
+ getLatestBuildError());
+ _logger.info("LevelZeroCompilerInDriver getCompiledNetwork returning blob");
+ return blob;
+ } else {
+ _logger.info("return the blob from network description");
+ return networkDescription->compiledNetwork;
+ }
+}
+
template <typename TableExtension>
std::string LevelZeroCompilerInDriver<TableExtension>::serializeConfig(
const Config& config,
@@ -620,8 +686,18 @@ ze_result_t LevelZeroCompilerInDriver<TableExtension>::seriazlideIRModelAndQuery
ZE_GRAPH_FLAG_NONE};
// Create querynetwork handle
+ _logger.debug("seriazlideIRModelAndQueryNetworkCreateV2 - performing pfnQueryNetworkCreate2");
ze_result_t result = _graphDdiTableExt->pfnQueryNetworkCreate2(_context, _deviceHandle, &desc, &hGraphQueryNetwork);
+ if (ZE_RESULT_SUCCESS != result) {
+ OPENVINO_THROW("L0 seriazlideIRModelAndQueryNetworkCreateV2",
+ " result: ",
+ ze_result_to_string(result),
+ ", code 0x",
+ std::hex,
+ uint64_t(result));
+ }
+
return result;
}
@@ -765,8 +841,19 @@ ze_result_t LevelZeroCompilerInDriver<TableExtension>::createGraph(const ze_grap
buildFlags.c_str(),
flags};
+ _logger.debug("createGraph - performing pfnCreate2");
// Create querynetwork handle
- return _graphDdiTableExt->pfnCreate2(_context, _deviceHandle, &desc, graph);
+ auto result = _graphDdiTableExt->pfnCreate2(_context, _deviceHandle, &desc, graph);
+ if (ZE_RESULT_SUCCESS != result) {
+ OPENVINO_THROW("L0 pfnCreate2",
+ " result: ",
+ ze_result_to_string(result),
+ ", code 0x",
+ std::hex,
+ uint64_t(result));
+ }
+
+ return result;
}
template <typename TableExtension>
ze_result_t LevelZeroCompilerInDriver<TableExtension>::seriazlideIRModelAndCreateGraph(
@@ -797,6 +884,15 @@ ze_result_t LevelZeroCompilerInDriver<TableExtension>::seriazlideIRModelAndCreat
_logger.info("compileIR Using extension version: %s", typeid(TableExtension).name());
ze_result_t result = createGraph(format, serializedIR, buildFlags, flags, &graphHandle);
+
+ if (ZE_RESULT_SUCCESS != result) {
+ OPENVINO_THROW("Failed to create graph. L0 createGraph",
+ " result: ",
+ ze_result_to_string(result),
+ ", code 0x",
+ std::hex,
+ uint64_t(result));
+ }
return result;
}
@@ -831,51 +927,13 @@ NetworkDescription LevelZeroCompilerInDriver<TableExtension>::compile(const std:
". ",
getLatestBuildError());
- // Get blob size first
- size_t blobSize = -1;
-
- result = _graphDdiTableExt->pfnGetNativeBinary(graphHandle, &blobSize, nullptr);
-
- OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS,
- "Failed to compile network. L0 pfnGetNativeBinary get blob size",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result),
- ". ",
- getLatestBuildError());
-
- std::vector<uint8_t> blob(blobSize);
- // Get blob data
- result = _graphDdiTableExt->pfnGetNativeBinary(graphHandle, &blobSize, blob.data());
-
- OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS,
- "Failed to compile network. L0 pfnGetNativeBinary get blob data",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result),
- ". ",
- getLatestBuildError());
-
auto networkMeta = getNetworkMeta(graphHandle);
networkMeta.name = model->get_friendly_name();
- result = _graphDdiTableExt->pfnDestroy(graphHandle);
-
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("Failed to compile network. L0 pfnDestroy",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result));
- }
-
_logger.debug("compile end");
- return NetworkDescription(std::move(blob), std::move(networkMeta));
+
+ auto networkDescription = NetworkDescription(std::move(networkMeta));
+ return networkDescription;
}
template <typename TableExtension>
@@ -913,17 +971,6 @@ NetworkMetadata LevelZeroCompilerInDriver<TableExtension>::parse(const std::vect
const auto networkMeta = getNetworkMeta(graphHandle);
OV_ITT_TASK_NEXT(PARSE_BLOB, "NetworkDescription");
- auto result = _graphDdiTableExt->pfnDestroy(graphHandle);
-
- if (ZE_RESULT_SUCCESS != result) {
- OPENVINO_THROW("L0 pfnDestroy",
- " result: ",
- ze_result_to_string(result),
- ", code 0x",
- std::hex,
- uint64_t(result));
- }
-
_logger.debug("parse end");
return networkMeta;
}
@@ -1107,6 +1154,8 @@ NetworkMetadata LevelZeroCompilerInDriver<TableExtension>::getNetworkMeta(ze_gra
// TODO: support this information in CiD [track: E#33479]
meta.numStreams = 1;
meta.bindRelatedDescriptors();
+ // Store the graph handle as a void pointer, return the same graphHandle to backend for ZeroExecutor
+ meta.graphHandle = static_cast<void*>(graphHandle);
return meta;
}
diff --git a/src/plugins/intel_npu/src/plugin/include/backends.hpp b/src/plugins/intel_npu/src/plugin/include/backends.hpp
index e27471ea77b..5718ef01524 100644
--- a/src/plugins/intel_npu/src/plugin/include/backends.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/backends.hpp
@@ -28,6 +28,7 @@ public:
std::shared_ptr<IDevice> getDevice(const std::string& specificName = "") const;
std::shared_ptr<IDevice> getDevice(const ov::AnyMap& paramMap) const;
std::vector<std::string> getAvailableDevicesNames() const;
+ ov::SoPtr<IEngineBackend> getIEngineBackend();
std::string getBackendName() const;
uint32_t getDriverVersion() const;
uint32_t getDriverExtVersion() const;
diff --git a/src/plugins/intel_npu/src/plugin/include/compiled_model.hpp b/src/plugins/intel_npu/src/plugin/include/compiled_model.hpp
index 0608e83e4e7..1e4a2463750 100644
--- a/src/plugins/intel_npu/src/plugin/include/compiled_model.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/compiled_model.hpp
@@ -49,17 +49,24 @@ public:
const std::shared_ptr<const ov::IPlugin>& plugin,
const std::shared_ptr<const NetworkDescription>& networkDescription,
const std::shared_ptr<IDevice>& device,
- const std::optional<ov::SoPtr<ICompiler>>& compiler,
+ const ov::SoPtr<ICompiler>& compiler,
const Config& config);
CompiledModel(const CompiledModel&) = delete;
CompiledModel& operator=(const CompiledModel&) = delete;
+ ~CompiledModel() override;
+
std::shared_ptr<ov::IAsyncInferRequest> create_infer_request() const override;
std::shared_ptr<ov::ISyncInferRequest> create_sync_infer_request() const override;
+ // For CID path mean it get the blob from compiler through pfnGetNativeBinary using
+ // networkDescription->metadata.graphHandle.
+
+ // For CIP path mean it get the blob from
+ // networkDescription->compiledNetwork.
void export_model(std::ostream& stream) const override;
std::shared_ptr<const ov::Model> get_runtime_model() const override;
@@ -93,7 +100,7 @@ private:
std::map<std::string, std::tuple<bool, ov::PropertyMutability, std::function<ov::Any(const Config&)>>> _properties;
std::vector<ov::PropertyName> _supportedProperties;
- std::optional<ov::SoPtr<ICompiler>> _compiler;
+ const ov::SoPtr<ICompiler> _compiler;
};
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/plugin/include/compiler.hpp b/src/plugins/intel_npu/src/plugin/include/compiler.hpp
index 65982ada17d..8a82647f12b 100644
--- a/src/plugins/intel_npu/src/plugin/include/compiler.hpp
+++ b/src/plugins/intel_npu/src/plugin/include/compiler.hpp
@@ -6,6 +6,7 @@
#pragma once
+#include "backends.hpp"
#include "intel_npu/al/icompiler.hpp"
#include "intel_npu/utils/logger/logger.hpp"
#include "npu_private_properties.hpp" // AL
@@ -13,6 +14,7 @@
namespace intel_npu {
-ov::SoPtr<ICompiler> createCompiler(ov::intel_npu::CompilerType compilerType);
+ov::SoPtr<ICompiler> createCompiler(std::shared_ptr<intel_npu::NPUBackends> npuBackends,
+ ov::intel_npu::CompilerType compilerType);
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/plugin/src/backends.cpp b/src/plugins/intel_npu/src/plugin/src/backends.cpp
index 7ad5b13ef30..9fff7f67ffc 100644
--- a/src/plugins/intel_npu/src/plugin/src/backends.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/backends.cpp
@@ -131,6 +131,10 @@ NPUBackends::NPUBackends(const std::vector<AvailableBackends>& backendRegistry,
}
}
+ov::SoPtr<IEngineBackend> NPUBackends::getIEngineBackend() {
+ return _backend;
+}
+
std::string NPUBackends::getBackendName() const {
if (_backend != nullptr) {
return _backend->getName();
diff --git a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
index d584c62704f..914879feee3 100644
--- a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp
@@ -51,12 +51,13 @@ CompiledModel::CompiledModel(const std::shared_ptr<const ov::Model>& model,
_config(config),
_logger("CompiledModel", config.get<LOG_LEVEL>()),
_device(device),
- _compiler(profiling ? std::optional(compiler) : std::nullopt) {
+ _compiler(compiler) {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "CompiledModel::CompiledModel");
OPENVINO_ASSERT(compiler != nullptr, "NPU CompiledModel: the pointer towards the compiler object is null");
try {
- _networkPtr = std::make_shared<const NetworkDescription>(compiler->compile(model, config));
+ _logger.debug("performing compile and expecting a network description");
+ _networkPtr = std::make_shared<const NetworkDescription>(_compiler->compile(model, config));
} catch (const std::exception& ex) {
OPENVINO_THROW(ex.what());
} catch (...) {
@@ -78,7 +79,7 @@ CompiledModel::CompiledModel(const std::shared_ptr<const ov::Model>& model,
const std::shared_ptr<const ov::IPlugin>& plugin,
const std::shared_ptr<const NetworkDescription>& networkDescription,
const std::shared_ptr<IDevice>& device,
- const std::optional<ov::SoPtr<ICompiler>>& compiler,
+ const ov::SoPtr<ICompiler>& compiler,
const Config& config)
: ICompiledModel(model, plugin),
_networkPtr(networkDescription),
@@ -101,6 +102,15 @@ CompiledModel::CompiledModel(const std::shared_ptr<const ov::Model>& model,
OV_ITT_TASK_SKIP(COMPILED_MODEL);
}
+CompiledModel::~CompiledModel() {
+ _logger.debug("~CompiledModel()");
+ // Call compiler to destroy graphHandle only if no executor created
+ if (_executorPtr == nullptr) {
+ _logger.debug("~CompiledModel() - _executorPtr is a nullptr, compiler release _executorPtr");
+ _compiler->release(_networkPtr);
+ }
+}
+
std::shared_ptr<ov::IAsyncInferRequest> CompiledModel::create_infer_request() const {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "CompiledModel::create_infer_request");
@@ -128,17 +138,18 @@ std::shared_ptr<ov::ISyncInferRequest> CompiledModel::create_sync_infer_request(
}
void CompiledModel::export_model(std::ostream& stream) const {
- const auto& blob = _networkPtr->compiledNetwork;
+ _logger.debug("CompiledModel::export_model");
+ const auto&& blob = _compiler->getCompiledNetwork(_networkPtr);
stream.write(reinterpret_cast<const char*>(blob.data()), blob.size());
+ std::stringstream str;
+ str << "Blob size: " << blob.size() << ", hash: " << std::hex << hash(blob);
+ _logger.info(str.str().c_str());
+
if (!stream) {
_logger.error("Write blob to stream failed. Blob is broken!");
} else {
_logger.info("Write blob to stream successfully.");
}
-
- std::stringstream str;
- str << "Blob size: " << blob.size() << ", hash: " << std::hex << hash(blob);
- _logger.info(str.str().c_str());
}
std::shared_ptr<const ov::Model> CompiledModel::get_runtime_model() const {
@@ -185,10 +196,7 @@ const Config& CompiledModel::get_config() const {
}
const ov::SoPtr<ICompiler>& CompiledModel::get_compiler() const {
- if (_compiler.has_value()) {
- return _compiler.value();
- }
- OPENVINO_THROW("PERF_COUNT property is not set");
+ return _compiler;
}
void CompiledModel::configure_stream_executors() {
diff --git a/src/plugins/intel_npu/src/plugin/src/compiler.cpp b/src/plugins/intel_npu/src/plugin/src/compiler.cpp
index f7f35d53a61..d772de84023 100644
--- a/src/plugins/intel_npu/src/plugin/src/compiler.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/compiler.cpp
@@ -50,10 +50,14 @@ ov::SoPtr<ICompiler> loadCompiler(const std::string& libpath) {
return ov::SoPtr<ICompiler>(compiler, compilerSO);
}
-ov::SoPtr<ICompiler> createCompilerAdapter(const Logger& log) {
+ov::SoPtr<ICompiler> createCompilerAdapter(std::shared_ptr<NPUBackends> npuBackends, const Logger& log) {
log.info("Driver compiler will be used.");
#ifdef ENABLE_DRIVER_COMPILER_ADAPTER
- const auto compilerInterface = std::make_shared<driverCompilerAdapter::LevelZeroCompilerAdapter>();
+ if (npuBackends->getBackendName() != "LEVEL0") {
+ OPENVINO_THROW("NPU Compiler Adapter must be used with LEVEL0 backend");
+ }
+ const auto compilerInterface =
+ std::make_shared<driverCompilerAdapter::LevelZeroCompilerAdapter>(npuBackends->getIEngineBackend()._ptr);
return ov::SoPtr<ICompiler>(compilerInterface);
#else
OPENVINO_THROW("NPU Compiler Adapter is not enabled");
@@ -67,12 +71,14 @@ ov::SoPtr<ICompiler> createNPUCompiler(const Logger& log) {
return loadCompiler(libPath);
}
-ov::SoPtr<ICompiler> createCompilerImpl(ov::intel_npu::CompilerType compilerType, const Logger& log) {
+ov::SoPtr<ICompiler> createCompilerImpl(std::shared_ptr<NPUBackends> npuBackends,
+ ov::intel_npu::CompilerType compilerType,
+ const Logger& log) {
switch (compilerType) {
case ov::intel_npu::CompilerType::MLIR:
return createNPUCompiler(log);
case ov::intel_npu::CompilerType::DRIVER:
- return createCompilerAdapter(log);
+ return createCompilerAdapter(npuBackends, log);
default:
OPENVINO_THROW("Invalid NPU_COMPILER_TYPE");
}
@@ -80,11 +86,13 @@ ov::SoPtr<ICompiler> createCompilerImpl(ov::intel_npu::CompilerType compilerType
} // namespace
-ov::SoPtr<ICompiler> intel_npu::createCompiler(ov::intel_npu::CompilerType compilerType) {
+ov::SoPtr<ICompiler> intel_npu::createCompiler(std::shared_ptr<intel_npu::NPUBackends> npuBackends,
+ ov::intel_npu::CompilerType compilerType) {
OV_ITT_SCOPED_TASK(itt::domains::NPUPlugin, "intel_npu::createCompiler");
auto logger = Logger::global().clone("createCompiler");
try {
- return createCompilerImpl(compilerType, logger);
+ logger.debug("performing createCompilerImpl");
+ return createCompilerImpl(npuBackends, compilerType, logger);
} catch (const std::exception& ex) {
OPENVINO_THROW("Got an error during compiler creation: ", ex.what());
} catch (...) {
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index e9c8aa2bab7..30e5ccf9324 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -685,10 +685,8 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
OV_ITT_TASK_NEXT(PLUGIN_COMPILE_MODEL, "compile");
std::shared_ptr<ov::ICompiledModel> compiledModel;
-
try {
bool profiling = localConfig.get<PERF_COUNT>();
-
compiledModel = std::make_shared<CompiledModel>(model,
shared_from_this(),
device,
@@ -766,15 +764,13 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, c
const std::shared_ptr<ov::Model> modelDummy = create_dummy_model(meta.inputs, meta.outputs);
- bool profiling = localConfig.get<PERF_COUNT>();
-
auto networkDescription = std::make_shared<const NetworkDescription>(std::move(blob), std::move(meta));
compiledModel = std::make_shared<CompiledModel>(modelDummy,
shared_from_this(),
networkDescription,
device,
- profiling ? std::optional(compiler) : std::nullopt,
+ compiler,
localConfig);
} catch (const std::exception& ex) {
OPENVINO_THROW("Can't import network: ", ex.what());
@@ -822,7 +818,8 @@ ov::SupportedOpsMap Plugin::query_model(const std::shared_ptr<const ov::Model>&
ov::SoPtr<ICompiler> Plugin::getCompiler(const Config& config) const {
auto compilerType = config.get<COMPILER_TYPE>();
- return createCompiler(compilerType);
+ _logger.debug("performing createCompiler");
+ return createCompiler(_backends, compilerType);
}
std::atomic<int> Plugin::_compiledModelLoadCounter{1};