OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPU] Update npu zero ext and use correct stype (#33302)
Bogdan Pereanue496aed4d243
diff --git a/src/plugins/intel_npu/src/backend/src/zero_profiling.cpp b/src/plugins/intel_npu/src/backend/src/zero_profiling.cppindex 8af9c071f38..a0469c451a3 100644--- a/src/plugins/intel_npu/src/backend/src/zero_profiling.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_profiling.cpp@@ -111,7 +111,8 @@ void ProfilingQuery::verifyProfilingProperties() const {return std::to_string(ZE_MAJOR_VERSION(version)) + "." + std::to_string(ZE_MINOR_VERSION(version));};- ze_device_profiling_data_properties_t profProp;+ ze_device_profiling_data_properties_t profProp = {};+ profProp.stype = ZE_STRUCTURE_TYPE_DEVICE_PROFILING_DATA_PROPERTIES;getProfilingProperties(&profProp);const auto currentProfilingVersion = ze_profiling_data_ext_version_t::ZE_PROFILING_DATA_EXT_VERSION_CURRENT;diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cppindex 97cd48232cd..19b0ef84996 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp@@ -221,7 +221,7 @@ bool Graph::release_blob(const Config& config) {}ze_graph_properties_2_t properties = {};- properties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES;+ properties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES_2;_zeroInitStruct->getGraphDdiTable().pfnGetProperties2(_graphDesc._handle, &properties);if (~properties.initStageRequired & ZE_GRAPH_STAGE_INITIALIZE) {diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cppindex 45c80b6a479..b8d8adfe9a9 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/weightless_graph.cpp@@ -581,7 +581,7 @@ void WeightlessGraph::release_init_blob(const size_t initIndex) {}ze_graph_properties_2_t properties = {};- properties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES;+ properties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES_2;_zeroInitStruct->getGraphDdiTable().pfnGetProperties2(_initsGraphDesc.at(initIndex)._handle, &properties);if (~properties.initStageRequired & ZE_GRAPH_STAGE_INITIALIZE) {diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cppindex c9a10212eb1..e59d9fcc258 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp@@ -212,7 +212,7 @@ void ZeGraphExtWrappers::initializeGraph(const GraphDescriptor& graphDescriptor,} else {_logger.debug("Initialize graph based on graph properties for ext version larger than 1.8");ze_graph_properties_2_t properties = {};- properties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES;+ properties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES_2;_logger.debug("initializeGraph - perform pfnGetProperties2");_zeroInitStruct->getGraphDdiTable().pfnGetProperties2(graphDescriptor._handle, &properties);@@ -274,13 +274,14 @@ std::unordered_set<std::string> ZeGraphExtWrappers::queryGraph(SerializedIR sericonst std::string& buildFlags) const {ze_graph_query_network_handle_t hGraphQueryNetwork = nullptr;- ze_graph_desc_2_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES,- nullptr,- ZE_GRAPH_FORMAT_NGRAPH_LITE,- serializedIR.first,- serializedIR.second.get(),- buildFlags.c_str(),- ZE_GRAPH_FLAG_NONE};+ ze_graph_desc_2_t desc = {+ _graphExtVersion < ZE_MAKE_VERSION(1, 16) ? ZE_STRUCTURE_TYPE_GRAPH_DESC : ZE_STRUCTURE_TYPE_GRAPH_DESC_2,+ nullptr,+ ZE_GRAPH_FORMAT_NGRAPH_LITE,+ serializedIR.first,+ serializedIR.second.get(),+ buildFlags.c_str(),+ ZE_GRAPH_FLAG_NONE};_logger.debug("queryGraph - perform pfnQueryNetworkCreate2");auto result = _zeroInitStruct->getGraphDdiTable().pfnQueryNetworkCreate2(_zeroInitStruct->getContext(),@@ -346,7 +347,7 @@ GraphDescriptor ZeGraphExtWrappers::getGraphDescriptor(SerializedIR serializedIRflags |= ZE_GRAPH_FLAG_DISABLE_CACHING;}- ze_graph_desc_2_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES,+ ze_graph_desc_2_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_2,nullptr,ZE_GRAPH_FORMAT_NGRAPH_LITE,serializedIR.first,@@ -378,7 +379,7 @@ GraphDescriptor ZeGraphExtWrappers::getGraphDescriptor(const void* blobData, sizflags |= ZE_GRAPH_FLAG_INPUT_GRAPH_PERSISTENT;}- ze_graph_desc_2_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_PROPERTIES,+ ze_graph_desc_2_t desc = {ZE_STRUCTURE_TYPE_GRAPH_DESC_2,nullptr,ZE_GRAPH_FORMAT_NATIVE,blobSize,@@ -403,7 +404,7 @@ bool ZeGraphExtWrappers::isBlobDataImported(const GraphDescriptor& graphDescriptif (graphDescriptor._memoryPersistent) {ze_graph_properties_3_t graphProperties = {};- graphProperties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES;+ graphProperties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES_3;auto result = _zeroInitStruct->getGraphDdiTable().pfnGetProperties3(graphDescriptor._handle, &graphProperties);THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetProperties3", result, _zeroInitStruct->getGraphDdiTable());@@ -421,7 +422,7 @@ void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle,std::vector<IODescriptor>& outputs) const {if (NotSupportArgumentMetadata(_graphExtVersion)) {ze_graph_argument_properties_3_t arg = {};- arg.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES;+ arg.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES_3;_logger.debug("getMetadata - perform pfnGetArgumentProperties3");auto result =_zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(graphHandle, indexUsedByDriver, &arg);@@ -441,7 +442,7 @@ void ZeGraphExtWrappers::getMetadata(ze_graph_handle_t graphHandle,}} else {ze_graph_argument_properties_3_t arg = {};- arg.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES;+ arg.stype = ZE_STRUCTURE_TYPE_GRAPH_ARGUMENT_PROPERTIES_3;_logger.debug("getMetadata - perform pfnGetArgumentProperties3");auto result =_zeroInitStruct->getGraphDdiTable().pfnGetArgumentProperties3(graphHandle, indexUsedByDriver, &arg);diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hppindex 2bd74caef4d..b3c580d2fce 100644--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_init.hpp@@ -4,18 +4,15 @@#pragma once-#include <ze_api.h>-#include <ze_command_queue_npu_ext.h>-#include <ze_graph_ext.h>#include <ze_intel_npu_uuid.h>#include <memory>#include <mutex>+#include <optional>#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_api.hpp"#include "intel_npu/utils/zero/zero_types.hpp"-#include "intel_npu/utils/zero/zero_utils.hpp"namespace intel_npu {/**@@ -32,36 +29,36 @@ public:~ZeroInitStructsHolder();inline ze_driver_handle_t getDriver() const {- return driver_handle;+ return _driver_handle;}inline ze_device_handle_t getDevice() const {- return device_handle;+ return _device_handle;}inline ze_context_handle_t getContext() const {- return context;+ return _context;}inline ze_graph_dditable_ext_curr_t& getGraphDdiTable() const {- return *graph_dditable_ext_decorator;+ return *_graph_dditable_ext_decorator;}inline ze_command_queue_npu_dditable_ext_curr_t& getCommandQueueDdiTable() const {- return *command_queue_npu_dditable_ext_decorator;+ return *_command_queue_npu_dditable_ext_decorator;}inline ze_graph_profiling_dditable_ext_curr_t& getProfilingDdiTable() const {- return *graph_profiling_npu_dditable_ext_decorator;+ return *_graph_profiling_npu_dditable_ext_decorator;}inline uint32_t getDriverVersion() const {- return driver_properties.driverVersion;+ return _driver_properties.driverVersion;}inline uint32_t getMutableCommandListExtVersion() const {- return mutable_command_list_ext_version;+ return _mutable_command_list_ext_version;}inline ze_api_version_t getZeDrvApiVersion() const {- return ze_drv_api_version;+ return _ze_drv_api_version;}// Helper function to check if extension with <ext_name> exists and its newer than <version>inline bool isExtensionSupported(std::string ext_name, uint32_t version) const {- auto iter = driver_extension_properties.find(ext_name);- if (iter == driver_extension_properties.end()) {+ auto iter = _driver_extension_properties.find(ext_name);+ if (iter == _driver_extension_properties.end()) {return false;} else if (iter->second >= version) {return true;@@ -83,27 +80,29 @@ public:private:void initNpuDriver();+ void getExtensionFunctionAddress(const std::string& name, const uint32_t version, void** function_address);// keep zero_api alive until context is destroyed- std::shared_ptr<ZeroApi> zero_api;+ std::shared_ptr<ZeroApi> _zero_api;- Logger log;+ 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;+ ze_driver_handle_t _driver_handle = nullptr;+ ze_device_handle_t _device_handle = nullptr;- std::map<std::string, uint32_t> driver_extension_properties;- std::unique_ptr<ze_graph_dditable_ext_decorator> graph_dditable_ext_decorator;- std::unique_ptr<ze_command_queue_npu_dditable_ext_decorator> command_queue_npu_dditable_ext_decorator;- std::unique_ptr<ze_graph_profiling_ddi_table_ext_decorator> graph_profiling_npu_dditable_ext_decorator;+ std::map<std::string, uint32_t> _driver_extension_properties;+ std::unique_ptr<ze_graph_dditable_ext_decorator> _graph_dditable_ext_decorator;+ std::unique_ptr<ze_command_queue_npu_dditable_ext_decorator> _command_queue_npu_dditable_ext_decorator;+ std::unique_ptr<ze_graph_profiling_dditable_ext_decorator> _graph_profiling_npu_dditable_ext_decorator;+ std::unique_ptr<ze_driver_npu_dditable_ext_decorator> _driver_npu_dditable_ext_decorator;- ze_driver_properties_t driver_properties = {};- uint32_t mutable_command_list_ext_version = 0;+ ze_driver_properties_t _driver_properties = {};+ uint32_t _mutable_command_list_ext_version = 0;- ze_api_version_t ze_drv_api_version = {};+ ze_api_version_t _ze_drv_api_version = {};- std::unique_ptr<ze_device_graph_properties_t> compiler_properties = nullptr;+ std::optional<ze_device_graph_properties_t> _compiler_properties = std::nullopt;bool _external_memory_standard_allocation_supported = false;bool _external_memory_fd_win32_supported = false;diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hppindex a8bf4ea3b1d..bab80337843 100644--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_types.hpp@@ -6,20 +6,12 @@#include <ze_api.h>#include <ze_command_queue_npu_ext.h>+#include <ze_driver_npu_ext.h>#include <ze_graph_ext.h>#include <ze_graph_profiling_ext.h>#include <string_view>-/**- * @brief Last version of the Command Queue functions used within plugin- */-using ze_command_queue_npu_dditable_ext_last_t = ze_command_queue_npu_dditable_ext_t;-/**- * @brief Last version of the Graph Profiling functions used within plugin- */-using ze_graph_profiling_dditable_ext_last_t = ze_graph_profiling_dditable_ext_t;-/*** @brief Table of Graph Extension functions pointers and function wrappers* @details Use original Graph Extension functions pointers from driver for function from within lower driver versions.@@ -215,6 +207,18 @@ public:throwWhenUnsupported("pfnBuildLogDestroy", ZE_GRAPH_EXT_VERSION_1_12);return _impl->pfnBuildLogDestroy(hGraphBuildLog);}++ // version 1.15+ ze_result_t ZE_APICALL pfnSetArgumentValue2(ze_graph_handle_t hGraph, uint32_t argIndex, const void* pArgValue) {+ throwWhenUnsupported("pfnSetArgumentValue2", ZE_GRAPH_EXT_VERSION_1_15);+ return _impl->pfnSetArgumentValue2(hGraph, argIndex, pArgValue);+ }++ // version 1.16+ ze_result_t ZE_APICALL pfnEvict(ze_graph_handle_t hGraph) {+ throwWhenUnsupported("pfnEvict", ZE_GRAPH_EXT_VERSION_1_16);+ return _impl->pfnEvict(hGraph);+ }};/**@@ -224,7 +228,7 @@ public:*/struct ze_command_queue_npu_dditable_ext_decorator final {private:- ze_command_queue_npu_dditable_ext_last_t* const _impl;+ ze_command_queue_npu_dditable_ext_t* const _impl;const uint32_t _commandQueueExtVersion;ze_command_queue_npu_dditable_ext_decorator(const ze_command_queue_npu_dditable_ext_decorator&) = delete;@@ -246,7 +250,7 @@ private:}public:- ze_command_queue_npu_dditable_ext_decorator(ze_command_queue_npu_dditable_ext_last_t* impl,+ ze_command_queue_npu_dditable_ext_decorator(ze_command_queue_npu_dditable_ext_t* impl,uint32_t commandQueueExtVersion): _impl(impl),_commandQueueExtVersion(commandQueueExtVersion) {}@@ -268,18 +272,18 @@ public:* @brief Graph profiling function pointers* @details Use original Graph profiling functions pointers from driver for function from within lower driver versions.*/-struct ze_graph_profiling_ddi_table_ext_decorator final {+struct ze_graph_profiling_dditable_ext_decorator final {private:- ze_graph_profiling_dditable_ext_last_t* const _impl;+ ze_graph_profiling_dditable_ext_t* const _impl;- ze_graph_profiling_ddi_table_ext_decorator(const ze_graph_profiling_ddi_table_ext_decorator&) = delete;- ze_graph_profiling_ddi_table_ext_decorator(ze_graph_profiling_ddi_table_ext_decorator&&) = delete;+ ze_graph_profiling_dditable_ext_decorator(const ze_graph_profiling_dditable_ext_decorator&) = delete;+ ze_graph_profiling_dditable_ext_decorator(ze_graph_profiling_dditable_ext_decorator&&) = delete;- ze_graph_profiling_ddi_table_ext_decorator& operator=(const ze_graph_profiling_ddi_table_ext_decorator&) = delete;- ze_graph_profiling_ddi_table_ext_decorator& operator=(ze_graph_profiling_ddi_table_ext_decorator&&) = delete;+ ze_graph_profiling_dditable_ext_decorator& operator=(const ze_graph_profiling_dditable_ext_decorator&) = delete;+ ze_graph_profiling_dditable_ext_decorator& operator=(ze_graph_profiling_dditable_ext_decorator&&) = delete;public:- ze_graph_profiling_ddi_table_ext_decorator(ze_graph_profiling_dditable_ext_last_t* impl)+ ze_graph_profiling_dditable_ext_decorator(ze_graph_profiling_dditable_ext_t* impl): _impl(impl),// version 1.0pfnProfilingPoolCreate(_impl->pfnProfilingPoolCreate),@@ -289,7 +293,7 @@ public:pfnProfilingQueryGetData(_impl->pfnProfilingQueryGetData),pfnDeviceGetProfilingDataProperties(_impl->pfnDeviceGetProfilingDataProperties),pfnProfilingLogGetString(_impl->pfnProfilingLogGetString) {}- ~ze_graph_profiling_ddi_table_ext_decorator() = default;+ ~ze_graph_profiling_dditable_ext_decorator() = default;// version 1.0ze_pfnGraphProfilingPoolCreate_ext_t pfnProfilingPoolCreate;@@ -301,6 +305,51 @@ public:ze_pfnGraphProfilingLogGetString_ext_t pfnProfilingLogGetString;};+/**+ * @brief Driver function pointers+ * @details Uses original driver function pointers for functions from lower driver versions.+ */+struct ze_driver_npu_dditable_ext_decorator final {+private:+ ze_driver_npu_dditable_ext_t* const _impl;+ const uint32_t _driverExtVersion;++ ze_driver_npu_dditable_ext_decorator(const ze_driver_npu_dditable_ext_decorator&) = delete;+ ze_driver_npu_dditable_ext_decorator(ze_driver_npu_dditable_ext_decorator&&) = delete;++ ze_driver_npu_dditable_ext_decorator& operator=(const ze_driver_npu_dditable_ext_decorator&) = delete;+ ze_driver_npu_dditable_ext_decorator& operator=(ze_driver_npu_dditable_ext_decorator&&) = delete;++ void throwWhenUnsupported(std::string_view func, uint32_t since) {+ if (_driverExtVersion < since) {+ OPENVINO_THROW("Driver extension function ",+ func,+ " is only available with version ",+ ZE_MAJOR_VERSION(since),+ ".",+ ZE_MINOR_VERSION(since),+ " or later");+ }+ }++public:+ ze_driver_npu_dditable_ext_decorator(ze_driver_npu_dditable_ext_t* impl, uint32_t driverExtVersion)+ : _impl(impl),+ _driverExtVersion(driverExtVersion) {}+ ~ze_driver_npu_dditable_ext_decorator() = default;++ inline uint32_t version() const {+ return _driverExtVersion;+ }++ // version 1.0+ ze_result_t ZE_APICALL pfnGetExtension(ze_driver_handle_t hDriver, ze_driver_extension_npu_ext_t* pExtension) {+ throwWhenUnsupported("pfnGetExtension", ZE_DRIVER_NPU_EXT_VERSION_1_0);+ return _impl->pfnGetExtension(hDriver, pExtension);+ }+};+using ze_graph_dditable_ext_curr_t = ze_graph_dditable_ext_decorator;using ze_command_queue_npu_dditable_ext_curr_t = ze_command_queue_npu_dditable_ext_decorator;-using ze_graph_profiling_dditable_ext_curr_t = ze_graph_profiling_ddi_table_ext_decorator;+using ze_graph_profiling_dditable_ext_curr_t = ze_graph_profiling_dditable_ext_decorator;+using ze_driver_npu_dditable_ext_curr_t = ze_driver_npu_dditable_ext_decorator;diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_init.cppindex b7a36bf5644..32c88abdbcb 100644--- a/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_init.cpp@@ -5,19 +5,24 @@#include "intel_npu/utils/zero/zero_init.hpp"#include <ze_command_queue_npu_ext.h>+#include <ze_driver_npu_ext.h>+#include <ze_graph_ext.h>#include <ze_mem_import_system_memory_ext.h>-#include <mutex>#include <regex>-#ifdef _WIN32+#include "intel_npu/utils/zero/zero_utils.hpp"+namespace {+#ifdef _WIN32constexpr uint32_t WIN_DRIVER_NO_MCL_SUPPORT = 2688;-} // namespace-#endif-namespace {+constexpr uint32_t TARGET_ZE_DRIVER_NPU_EXT_VERSION = ZE_DRIVER_NPU_EXT_VERSION_1_0;+constexpr uint32_t TARGET_ZE_GRAPH_NPU_EXT_VERSION = ZE_GRAPH_EXT_VERSION_1_16;+constexpr uint32_t TARGET_ZE_COMMAND_QUEUE_NPU_EXT_VERSION = ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_1;+constexpr uint32_t TARGET_ZE_PROFILING_NPU_EXT_VERSION = ZE_PROFILING_DATA_EXT_VERSION_1_0;+constexpr uint32_t TARGET_ZE_MUTABLE_COMMAND_LIST_EXT_VERSION = ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_1;constexpr ze_driver_uuid_t uuid = ze_intel_npu_driver_uuid;@@ -59,23 +64,22 @@ namespace intel_npu {void ZeroInitStructsHolder::initNpuDriver() {auto setNpuDriver = [&](uint32_t drivers_count, std::vector<ze_driver_handle_t> all_drivers) {- driver_properties.stype = ZE_STRUCTURE_TYPE_DRIVER_PROPERTIES;- log.debug("ZeroInitStructsHolder::initNpuDriver - get NPU driver");+ _driver_properties.stype = ZE_STRUCTURE_TYPE_DRIVER_PROPERTIES;+ _log.debug("ZeroInitStructsHolder::initNpuDriver - get NPU driver");for (uint32_t i = 0; i < drivers_count; ++i) {- zeDriverGetProperties(all_drivers[i], &driver_properties);-- if (memcmp(&driver_properties.uuid, &uuid, sizeof(uuid)) == 0) {- driver_handle = all_drivers[i];+ zeDriverGetProperties(all_drivers[i], &_driver_properties);+ if (memcmp(&_driver_properties.uuid, &uuid, sizeof(uuid)) == 0) {+ _driver_handle = all_drivers[i];break;}}- if (driver_handle == nullptr) {+ if (_driver_handle == nullptr) {OPENVINO_THROW("NPU driver wasn't found!");}};auto fallbackToZeDriverGet = [&]() {- log.debug("ZeroInitStructsHolder::initNpuDriver - zeInitDrivers not supported, fallback to zeDriverGet");+ _log.debug("ZeroInitStructsHolder::initNpuDriver - zeInitDrivers not supported, fallback to zeDriverGet");uint32_t drivers_count = 0;THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGet", zeDriverGet(&drivers_count, nullptr));@@ -90,7 +94,7 @@ void ZeroInitStructsHolder::initNpuDriver() {zel_version_t loader_version = {};bool get_loader_version = false;try {- log.debug("ZeroInitStructsHolder::initNpuDriver - performing zelGetLoaderVersion");+ _log.debug("ZeroInitStructsHolder::initNpuDriver - performing zelGetLoaderVersion");zel_component_version_t version;auto result = zelGetLoaderVersion(&version);if (result == ZE_RESULT_SUCCESS) {@@ -102,14 +106,13 @@ void ZeroInitStructsHolder::initNpuDriver() {}if (!get_loader_version) {- log.debug("ZeroInitStructsHolder::initNpuDriver - performing zeInit on NPU only");+ _log.debug("ZeroInitStructsHolder::initNpuDriver - performing zeInit on NPU only");THROW_ON_FAIL_FOR_LEVELZERO("zeInit", zeInit(ZE_INIT_FLAG_VPU_ONLY));size_t num_components;auto result = zelLoaderGetVersions(&num_components, nullptr);if (result == ZE_RESULT_SUCCESS) {std::vector<zel_component_version_t> versions(num_components);result = zelLoaderGetVersions(&num_components, versions.data());-if (result == ZE_RESULT_SUCCESS) {for (size_t i = 0; i < num_components; ++i) {if (strncmp(versions[i].component_name, "loader", strlen("loader")) == 0) {@@ -121,10 +124,10 @@ void ZeroInitStructsHolder::initNpuDriver() {}}- log.debug("ZeroInitStructsHolder::initNpuDriver - ze_loader.dll version: %d.%d.%d",- loader_version.major,- loader_version.minor,- loader_version.patch);+ _log.debug("ZeroInitStructsHolder::initNpuDriver - ze_loader.dll version: %d.%d.%d",+ loader_version.major,+ loader_version.minor,+ loader_version.patch);if (loader_version.major > 1 || (loader_version.major == 1 && loader_version.minor > 18) ||(loader_version.major == 1 && loader_version.minor == 18 && loader_version.patch >= 5)) {@@ -154,48 +157,70 @@ void ZeroInitStructsHolder::initNpuDriver() {}ZeroInitStructsHolder::ZeroInitStructsHolder()- : zero_api(ZeroApi::getInstance()),- log("NPUZeroInitStructsHolder", Logger::global().level()) {- log.debug("ZeroInitStructsHolder - initialize NPU Driver");+ : _zero_api(ZeroApi::getInstance()),+ _log("NPUZeroInitStructsHolder", Logger::global().level()) {+ _log.debug("ZeroInitStructsHolder - initialize NPU Driver");initNpuDriver();// Check L0 API version- THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetApiVersion", zeDriverGetApiVersion(driver_handle, &ze_drv_api_version));+ THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetApiVersion", zeDriverGetApiVersion(_driver_handle, &_ze_drv_api_version));- if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(ze_drv_api_version)) {+ if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(_ze_drv_api_version)) {OPENVINO_THROW("Incompatibility between NPU plugin and driver! ","Plugin L0 API major version = ",ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT),", ","Driver L0 API major version = ",- ZE_MAJOR_VERSION(ze_drv_api_version));+ ZE_MAJOR_VERSION(_ze_drv_api_version));}- if (ZE_MINOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MINOR_VERSION(ze_drv_api_version)) {- log.warning("Some features might not be available! "- "Plugin L0 API minor version = %d, Driver L0 API minor version = %d",- ZE_MINOR_VERSION(ZE_API_VERSION_CURRENT),- ZE_MINOR_VERSION(ze_drv_api_version));+ if (ZE_MINOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MINOR_VERSION(_ze_drv_api_version)) {+ _log.warning("Some features might not be available! "+ "Plugin L0 API minor version = %d, Driver L0 API minor version = %d",+ ZE_MINOR_VERSION(ZE_API_VERSION_CURRENT),+ ZE_MINOR_VERSION(_ze_drv_api_version));}uint32_t count = 0;THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionProperties",- zeDriverGetExtensionProperties(driver_handle, &count, nullptr));+ zeDriverGetExtensionProperties(_driver_handle, &count, nullptr));std::vector<ze_driver_extension_properties_t> extProps;extProps.resize(count);THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionProperties",- zeDriverGetExtensionProperties(driver_handle, &count, extProps.data()));+ zeDriverGetExtensionProperties(_driver_handle, &count, extProps.data()));// save the list of extension properties for later searchesfor (auto it = extProps.begin(); it != extProps.end(); ++it) {ze_driver_extension_properties_t p = *it;- driver_extension_properties.emplace(std::string(p.name), p.version);+ _driver_extension_properties.emplace(std::string(p.name), p.version);}- // Query our graph extension version+ // Query npu driver extension version+ std::string driver_ext_name;+ uint32_t driver_ext_version = 0;+ std::tie(driver_ext_version, driver_ext_name) =+ queryDriverExtensionVersion(ZE_DRIVER_NPU_EXT_NAME, TARGET_ZE_DRIVER_NPU_EXT_VERSION, extProps, count);++ _log.debug("NPU driver ext version %d.%d",+ ZE_MAJOR_VERSION(driver_ext_version),+ ZE_MINOR_VERSION(driver_ext_version));++ _ze_driver_npu_dditable_ext_t* driver_npu_dditable_ext = nullptr;+ if (driver_ext_version) {+ THROW_ON_FAIL_FOR_LEVELZERO(+ "zeDriverGetExtensionFunctionAddress " + driver_ext_name,+ zeDriverGetExtensionFunctionAddress(_driver_handle,+ driver_ext_name.c_str(),+ reinterpret_cast<void**>(&driver_npu_dditable_ext)));+ }++ _driver_npu_dditable_ext_decorator =+ std::make_unique<ze_driver_npu_dditable_ext_decorator>(driver_npu_dditable_ext, driver_ext_version);++ // Query npu graph extension versionstd::string graph_ext_name;uint32_t graph_ext_version = 0;- uint32_t target_graph_ext_version = ZE_GRAPH_EXT_VERSION_CURRENT;+ uint32_t target_graph_ext_version = TARGET_ZE_GRAPH_NPU_EXT_VERSION;#if defined(NPU_PLUGIN_DEVELOPER_BUILD)const char* extVersion = std::getenv("NPU_ZE_GRAPH_EXT_VERSION");@@ -207,19 +232,19 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()if (std::regex_match(extVersionString, match, extVersionRegex)) {int major = std::stoi(match[1].str());int minor = std::stoi(match[2].str());- log.debug("Try to find graph ext version: %d.%d instead of %d.%d.",- major,- minor,- ZE_MAJOR_VERSION(target_graph_ext_version),- ZE_MINOR_VERSION(target_graph_ext_version));+ _log.debug("Try to find graph ext version: %d.%d instead of %d.%d.",+ major,+ minor,+ ZE_MAJOR_VERSION(target_graph_ext_version),+ ZE_MINOR_VERSION(target_graph_ext_version));target_graph_ext_version = ZE_MAKE_VERSION(major, minor);}}#endif- log.debug("Try to find graph ext version: %d.%d",- ZE_MAJOR_VERSION(target_graph_ext_version),- ZE_MINOR_VERSION(target_graph_ext_version));+ _log.debug("Try to find graph ext version: %d.%d",+ ZE_MAJOR_VERSION(target_graph_ext_version),+ ZE_MINOR_VERSION(target_graph_ext_version));std::tie(graph_ext_version, graph_ext_name) =queryDriverExtensionVersion(ZE_GRAPH_EXT_NAME, target_graph_ext_version, extProps, count);@@ -236,92 +261,91 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()driver_ext_major_version);}- log.info("Found Driver Version %d.%d, Graph Extension Version %d.%d (%s)",- ZE_MAJOR_VERSION(ze_drv_api_version),- ZE_MINOR_VERSION(ze_drv_api_version),- ZE_MAJOR_VERSION(graph_ext_version),- ZE_MINOR_VERSION(graph_ext_version),- graph_ext_name.c_str());+ _log.info("Found Driver Version %d.%d, Graph Extension Version %d.%d (%s)",+ ZE_MAJOR_VERSION(_ze_drv_api_version),+ ZE_MINOR_VERSION(_ze_drv_api_version),+ ZE_MAJOR_VERSION(graph_ext_version),+ ZE_MINOR_VERSION(graph_ext_version),+ graph_ext_name.c_str());- // Query our command queue extension version+ // Load npu graph extension+ ze_graph_dditable_ext_t* graph_ddi_table_ext = nullptr;+ getExtensionFunctionAddress(graph_ext_name, graph_ext_version, reinterpret_cast<void**>(&graph_ddi_table_ext));+ _graph_dditable_ext_decorator =+ std::make_unique<ze_graph_dditable_ext_decorator>(graph_ddi_table_ext, graph_ext_version);++ // Query npu command queue extension versionstd::string command_queue_ext_name;uint32_t command_queue_ext_version = 0;std::tie(command_queue_ext_version, command_queue_ext_name) =queryDriverExtensionVersion(ZE_COMMAND_QUEUE_NPU_EXT_NAME,- ZE_COMMAND_QUEUE_NPU_EXT_VERSION_CURRENT,+ TARGET_ZE_COMMAND_QUEUE_NPU_EXT_VERSION,extProps,count);- log.debug("NPU command queue version %d.%d",- ZE_MAJOR_VERSION(command_queue_ext_version),- ZE_MINOR_VERSION(command_queue_ext_version));+ _log.debug("NPU command queue version %d.%d",+ ZE_MAJOR_VERSION(command_queue_ext_version),+ ZE_MINOR_VERSION(command_queue_ext_version));- // Load our command queue extension- ze_command_queue_npu_dditable_ext_last_t* _command_queue_npu_dditable_ext = nullptr;+ // Load npu command queue extension+ ze_command_queue_npu_dditable_ext_t* _command_queue_npu_dditable_ext = nullptr;if (command_queue_ext_version) {- THROW_ON_FAIL_FOR_LEVELZERO(- "zeDriverGetExtensionFunctionAddress " + command_queue_ext_name,- zeDriverGetExtensionFunctionAddress(driver_handle,- command_queue_ext_name.c_str(),- reinterpret_cast<void**>(&_command_queue_npu_dditable_ext)));+ getExtensionFunctionAddress(command_queue_ext_name,+ command_queue_ext_version,+ reinterpret_cast<void**>(&_command_queue_npu_dditable_ext));}- command_queue_npu_dditable_ext_decorator =+ _command_queue_npu_dditable_ext_decorator =std::make_unique<ze_command_queue_npu_dditable_ext_decorator>(_command_queue_npu_dditable_ext,command_queue_ext_version);- // Load our graph extension- ze_graph_dditable_ext_t* graph_ddi_table_ext = nullptr;- THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionFunctionAddress",- zeDriverGetExtensionFunctionAddress(driver_handle,- graph_ext_name.c_str(),- reinterpret_cast<void**>(&graph_ddi_table_ext)));- graph_dditable_ext_decorator =- std::make_unique<ze_graph_dditable_ext_decorator>(graph_ddi_table_ext, graph_ext_version);-// Query the mutable command list version#ifdef _WIN32// The 2688 Windows driver version doesn't support as expected the MutableCommandList feature- if (driver_properties.driverVersion != WIN_DRIVER_NO_MCL_SUPPORT) {+ if (_driver_properties.driverVersion != WIN_DRIVER_NO_MCL_SUPPORT) {#endif[[maybe_unused]] std::string mutuable_command_list_ext_name;- std::tie(mutable_command_list_ext_version, mutuable_command_list_ext_name) =+ std::tie(_mutable_command_list_ext_version, mutuable_command_list_ext_name) =queryDriverExtensionVersion(ZE_MUTABLE_COMMAND_LIST_EXP_NAME,- ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_CURRENT,+ TARGET_ZE_MUTABLE_COMMAND_LIST_EXT_VERSION,extProps,count);#ifdef _WIN32}#endif- log.debug("Mutable command list version %d.%d",- ZE_MAJOR_VERSION(mutable_command_list_ext_version),- ZE_MINOR_VERSION(mutable_command_list_ext_version));+ _log.debug("Mutable command list version %d.%d",+ ZE_MAJOR_VERSION(_mutable_command_list_ext_version),+ ZE_MINOR_VERSION(_mutable_command_list_ext_version));- // Load our profiling extension+ // Query npu profiling extension version+ std::string profiling_ext_name;+ uint32_t profiling_ext_version = 0;+ std::tie(profiling_ext_version, profiling_ext_name) =+ queryDriverExtensionVersion(ZE_PROFILING_DATA_EXT_NAME, TARGET_ZE_PROFILING_NPU_EXT_VERSION, extProps, count);++ // Load npu profiling extensionze_graph_profiling_dditable_ext_t* _graph_profiling_ddi_table_ext = nullptr;- THROW_ON_FAIL_FOR_LEVELZERO(- "zeDriverGetExtensionFunctionAddress",- zeDriverGetExtensionFunctionAddress(driver_handle,- "ZE_extension_profiling_data",- reinterpret_cast<void**>(&_graph_profiling_ddi_table_ext)));+ getExtensionFunctionAddress(profiling_ext_name,+ profiling_ext_version,+ reinterpret_cast<void**>(&_graph_profiling_ddi_table_ext));- graph_profiling_npu_dditable_ext_decorator =- std::make_unique<ze_graph_profiling_ddi_table_ext_decorator>(_graph_profiling_ddi_table_ext);+ _graph_profiling_npu_dditable_ext_decorator =+ std::make_unique<ze_graph_profiling_dditable_ext_decorator>(_graph_profiling_ddi_table_ext);uint32_t device_count = 1;- // Get our target device- THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGet", zeDeviceGet(driver_handle, &device_count, &device_handle));+ // Get npu target device+ THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGet", zeDeviceGet(_driver_handle, &device_count, &_device_handle));// Create context - share between the compiler and the backendze_context_desc_t context_desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, 0, 0};- THROW_ON_FAIL_FOR_LEVELZERO("zeContextCreate", zeContextCreate(driver_handle, &context_desc, &context));- log.debug("ZeroInitStructsHolder initialize complete");+ THROW_ON_FAIL_FOR_LEVELZERO("zeContextCreate", zeContextCreate(_driver_handle, &context_desc, &_context));+ _log.debug("ZeroInitStructsHolder initialize complete");// Discover if standard allocation is supportedze_device_external_memory_properties_t external_memory_properties_desc = {};external_memory_properties_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_EXTERNAL_MEMORY_PROPERTIES;- auto res = zeDeviceGetExternalMemoryProperties(device_handle, &external_memory_properties_desc);+ auto res = zeDeviceGetExternalMemoryProperties(_device_handle, &external_memory_properties_desc);if (res == ZE_RESULT_SUCCESS) {#ifdef _WIN32if (external_memory_properties_desc.memoryAllocationImportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32) {@@ -355,34 +379,55 @@ const std::shared_ptr<ZeroInitStructsHolder> ZeroInitStructsHolder::getInstance(ze_device_graph_properties_t ZeroInitStructsHolder::getCompilerProperties() {std::lock_guard<std::mutex> lock(_mutex);- if (!compiler_properties) {+ if (!_compiler_properties.has_value()) {// Obtain compiler-in-driver properties- compiler_properties = std::make_unique<ze_device_graph_properties_t>();- compiler_properties->stype = ZE_STRUCTURE_TYPE_DEVICE_GRAPH_PROPERTIES;+ _compiler_properties.emplace(ze_device_graph_properties_t{});+ _compiler_properties->stype = ZE_STRUCTURE_TYPE_DEVICE_GRAPH_PROPERTIES;auto result =- graph_dditable_ext_decorator->pfnDeviceGetGraphProperties(device_handle, compiler_properties.get());+ _graph_dditable_ext_decorator->pfnDeviceGetGraphProperties(_device_handle, &_compiler_properties.value());THROW_ON_FAIL_FOR_LEVELZERO("pfnDeviceGetGraphProperties", result);}- return *compiler_properties;+ return _compiler_properties.value_or(ze_device_graph_properties_t{});}uint32_t ZeroInitStructsHolder::getCompilerVersion() {- if (!compiler_properties) {+ if (!_compiler_properties.has_value()) {(void)getCompilerProperties();}- return ZE_MAKE_VERSION(compiler_properties->compilerVersion.major, compiler_properties->compilerVersion.minor);+ return ZE_MAKE_VERSION(_compiler_properties->compilerVersion.major, _compiler_properties->compilerVersion.minor);+}++void ZeroInitStructsHolder::getExtensionFunctionAddress(const std::string& name,+ const uint32_t version,+ void** function_address) {+ if (_driver_npu_dditable_ext_decorator->version()) {+ ze_driver_extension_npu_ext_t driver_extension = {ZE_STRUCTURE_TYPE_DRIVER_EXTENSION_NPU_EXT,+ nullptr,+ name.c_str(),+ version,+ function_address};++ THROW_ON_FAIL_FOR_LEVELZERO(+ "pfnGetExtension " + name,+ _driver_npu_dditable_ext_decorator->pfnGetExtension(_driver_handle, &driver_extension));+ } else {+ THROW_ON_FAIL_FOR_LEVELZERO(+ "zeDriverGetExtensionFunctionAddress" + name,+ zeDriverGetExtensionFunctionAddress(_driver_handle, name.c_str(), function_address));+ }}ZeroInitStructsHolder::~ZeroInitStructsHolder() {- if (context) {- log.debug("ZeroInitStructsHolder - performing zeContextDestroy");- auto result = zeContextDestroy(context);- context = nullptr;+ 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");+ _log.warning(+ "zeContextDestroy failed to destroy the context; Level zero context was already destroyed");} else {- log.error("zeContextDestroy failed %#X", uint64_t(result));+ _log.error("zeContextDestroy failed %#X", uint64_t(result));}}}diff --git a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.cpp b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.cppindex 5423346daab..3beed676879 100644--- a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.cpp+++ b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.cpp@@ -5,13 +5,19 @@#include "zero_init_mock.hpp"#include <ze_command_queue_npu_ext.h>+#include <ze_driver_npu_ext.h>+#include <ze_graph_ext.h>#include <ze_mem_import_system_memory_ext.h>-#include "intel_npu/utils/zero/zero_api.hpp"#include "intel_npu/utils/zero/zero_utils.hpp"namespace {+constexpr uint32_t TARGET_ZE_DRIVER_NPU_EXT_VERSION = ZE_DRIVER_NPU_EXT_VERSION_1_0;+constexpr uint32_t TARGET_ZE_COMMAND_QUEUE_NPU_EXT_VERSION = ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_1;+constexpr uint32_t TARGET_ZE_PROFILING_NPU_EXT_VERSION = ZE_PROFILING_DATA_EXT_VERSION_1_0;+constexpr uint32_t TARGET_ZE_MUTABLE_COMMAND_LIST_EXT_VERSION = ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_1;+constexpr ze_driver_uuid_t uuid = ze_intel_npu_driver_uuid;std::tuple<uint32_t, std::string> queryDriverExtensionVersion(const char* extName,@@ -52,23 +58,22 @@ namespace intel_npu {void ZeroInitStructsMock::initNpuDriver() {auto setNpuDriver = [&](uint32_t drivers_count, std::vector<ze_driver_handle_t> all_drivers) {- driver_properties.stype = ZE_STRUCTURE_TYPE_DRIVER_PROPERTIES;- log.debug("ZeroInitStructsHolder::initNpuDriver - get NPU driver");+ _driver_properties.stype = ZE_STRUCTURE_TYPE_DRIVER_PROPERTIES;+ _log.debug("ZeroInitStructsHolder::initNpuDriver - get NPU driver");for (uint32_t i = 0; i < drivers_count; ++i) {- zeDriverGetProperties(all_drivers[i], &driver_properties);-- if (memcmp(&driver_properties.uuid, &uuid, sizeof(uuid)) == 0) {- driver_handle = all_drivers[i];+ zeDriverGetProperties(all_drivers[i], &_driver_properties);+ if (memcmp(&_driver_properties.uuid, &uuid, sizeof(uuid)) == 0) {+ _driver_handle = all_drivers[i];break;}}- if (driver_handle == nullptr) {+ if (_driver_handle == nullptr) {OPENVINO_THROW("NPU driver wasn't found!");}};auto fallbackToZeDriverGet = [&]() {- log.debug("ZeroInitStructsHolder::initNpuDriver - zeInitDrivers not supported, fallback to zeDriverGet");+ _log.debug("ZeroInitStructsHolder::initNpuDriver - zeInitDrivers not supported, fallback to zeDriverGet");uint32_t drivers_count = 0;THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGet", zeDriverGet(&drivers_count, nullptr));@@ -83,7 +88,7 @@ void ZeroInitStructsMock::initNpuDriver() {zel_version_t loader_version = {};bool get_loader_version = false;try {- log.debug("ZeroInitStructsHolder::initNpuDriver - performing zelGetLoaderVersion");+ _log.debug("ZeroInitStructsHolder::initNpuDriver - performing zelGetLoaderVersion");zel_component_version_t version;auto result = zelGetLoaderVersion(&version);if (result == ZE_RESULT_SUCCESS) {@@ -95,14 +100,13 @@ void ZeroInitStructsMock::initNpuDriver() {}if (!get_loader_version) {- log.debug("ZeroInitStructsHolder::initNpuDriver - performing zeInit on NPU only");+ _log.debug("ZeroInitStructsHolder::initNpuDriver - performing zeInit on NPU only");THROW_ON_FAIL_FOR_LEVELZERO("zeInit", zeInit(ZE_INIT_FLAG_VPU_ONLY));size_t num_components;auto result = zelLoaderGetVersions(&num_components, nullptr);if (result == ZE_RESULT_SUCCESS) {std::vector<zel_component_version_t> versions(num_components);result = zelLoaderGetVersions(&num_components, versions.data());-if (result == ZE_RESULT_SUCCESS) {for (size_t i = 0; i < num_components; ++i) {if (strncmp(versions[i].component_name, "loader", strlen("loader")) == 0) {@@ -114,7 +118,7 @@ void ZeroInitStructsMock::initNpuDriver() {}}- log.debug("ZeroInitStructsHolder::initNpuDriver - ze_loader.dll version: %d.%d.%d",+ _log.debug("ZeroInitStructsHolder::initNpuDriver - ze_loader.dll version: %d.%d.%d",loader_version.major,loader_version.minor,loader_version.patch);@@ -147,52 +151,74 @@ void ZeroInitStructsMock::initNpuDriver() {}ZeroInitStructsMock::ZeroInitStructsMock(int extVersion)- : zero_api(ZeroApi::getInstance()),- log("NPUZeroInitStructsMock", Logger::global().level()) {- log.debug("ZeroInitStructsMock - initialize NPU Driver");+ : _zero_api(ZeroApi::getInstance()),+ _log("NPUZeroInitStructsHolder", Logger::global().level()) {+ _log.debug("ZeroInitStructsHolder - initialize NPU Driver");initNpuDriver();// Check L0 API version- THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetApiVersion", zeDriverGetApiVersion(driver_handle, &ze_drv_api_version));+ THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetApiVersion", zeDriverGetApiVersion(_driver_handle, &_ze_drv_api_version));- if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(ze_drv_api_version)) {+ if (ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MAJOR_VERSION(_ze_drv_api_version)) {OPENVINO_THROW("Incompatibility between NPU plugin and driver! ","Plugin L0 API major version = ",ZE_MAJOR_VERSION(ZE_API_VERSION_CURRENT),", ","Driver L0 API major version = ",- ZE_MAJOR_VERSION(ze_drv_api_version));+ ZE_MAJOR_VERSION(_ze_drv_api_version));}- if (ZE_MINOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MINOR_VERSION(ze_drv_api_version)) {- log.warning("Some features might not be available! "- "Plugin L0 API minor version = %d, Driver L0 API minor version = %d",- ZE_MINOR_VERSION(ZE_API_VERSION_CURRENT),- ZE_MINOR_VERSION(ze_drv_api_version));+ if (ZE_MINOR_VERSION(ZE_API_VERSION_CURRENT) != ZE_MINOR_VERSION(_ze_drv_api_version)) {+ _log.warning("Some features might not be available! "+ "Plugin L0 API minor version = %d, Driver L0 API minor version = %d",+ ZE_MINOR_VERSION(ZE_API_VERSION_CURRENT),+ ZE_MINOR_VERSION(_ze_drv_api_version));}uint32_t count = 0;THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionProperties",- zeDriverGetExtensionProperties(driver_handle, &count, nullptr));+ zeDriverGetExtensionProperties(_driver_handle, &count, nullptr));std::vector<ze_driver_extension_properties_t> extProps;extProps.resize(count);THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionProperties",- zeDriverGetExtensionProperties(driver_handle, &count, extProps.data()));+ zeDriverGetExtensionProperties(_driver_handle, &count, extProps.data()));// save the list of extension properties for later searchesfor (auto it = extProps.begin(); it != extProps.end(); ++it) {ze_driver_extension_properties_t p = *it;- driver_extension_properties.emplace(std::string(p.name), p.version);+ _driver_extension_properties.emplace(std::string(p.name), p.version);+ }++ // Query npu driver extension version+ std::string driver_ext_name;+ uint32_t driver_ext_version = 0;+ std::tie(driver_ext_version, driver_ext_name) =+ queryDriverExtensionVersion(ZE_DRIVER_NPU_EXT_NAME, TARGET_ZE_DRIVER_NPU_EXT_VERSION, extProps, count);++ _log.debug("NPU driver ext version %d.%d",+ ZE_MAJOR_VERSION(driver_ext_version),+ ZE_MINOR_VERSION(driver_ext_version));++ _ze_driver_npu_dditable_ext_t* driver_npu_dditable_ext = nullptr;+ if (driver_ext_version) {+ THROW_ON_FAIL_FOR_LEVELZERO(+ "zeDriverGetExtensionFunctionAddress " + driver_ext_name,+ zeDriverGetExtensionFunctionAddress(_driver_handle,+ driver_ext_name.c_str(),+ reinterpret_cast<void**>(&driver_npu_dditable_ext)));}- // Query our graph extension version+ _driver_npu_dditable_ext_decorator =+ std::make_unique<ze_driver_npu_dditable_ext_decorator>(driver_npu_dditable_ext, driver_ext_version);++ // Query npu graph extension versionstd::string graph_ext_name;uint32_t graph_ext_version = 0;uint32_t target_graph_ext_version = extVersion;- log.debug("Try to find graph ext version: %d.%d",- ZE_MAJOR_VERSION(target_graph_ext_version),- ZE_MINOR_VERSION(target_graph_ext_version));+ _log.debug("Try to find graph ext version: %d.%d",+ ZE_MAJOR_VERSION(target_graph_ext_version),+ ZE_MINOR_VERSION(target_graph_ext_version));std::tie(graph_ext_version, graph_ext_name) =queryDriverExtensionVersion(ZE_GRAPH_EXT_NAME, target_graph_ext_version, extProps, count);@@ -209,85 +235,84 @@ ZeroInitStructsMock::ZeroInitStructsMock(int extVersion)driver_ext_major_version);}- log.info("Found Driver Version %d.%d, Graph Extension Version %d.%d (%s)",- ZE_MAJOR_VERSION(ze_drv_api_version),- ZE_MINOR_VERSION(ze_drv_api_version),- ZE_MAJOR_VERSION(graph_ext_version),- ZE_MINOR_VERSION(graph_ext_version),- graph_ext_name.c_str());+ _log.info("Found Driver Version %d.%d, Graph Extension Version %d.%d (%s)",+ ZE_MAJOR_VERSION(_ze_drv_api_version),+ ZE_MINOR_VERSION(_ze_drv_api_version),+ ZE_MAJOR_VERSION(graph_ext_version),+ ZE_MINOR_VERSION(graph_ext_version),+ graph_ext_name.c_str());++ // Load npu graph extension+ ze_graph_dditable_ext_t* graph_ddi_table_ext = nullptr;+ getExtensionFunctionAddress(graph_ext_name, graph_ext_version, reinterpret_cast<void**>(&graph_ddi_table_ext));+ _graph_dditable_ext_decorator =+ std::make_unique<ze_graph_dditable_ext_decorator>(graph_ddi_table_ext, graph_ext_version);- // Query our command queue extension version+ // Query npu command queue extension versionstd::string command_queue_ext_name;uint32_t command_queue_ext_version = 0;std::tie(command_queue_ext_version, command_queue_ext_name) =queryDriverExtensionVersion(ZE_COMMAND_QUEUE_NPU_EXT_NAME,- ZE_COMMAND_QUEUE_NPU_EXT_VERSION_CURRENT,+ TARGET_ZE_COMMAND_QUEUE_NPU_EXT_VERSION,extProps,count);- log.debug("NPU command queue version %d.%d",- ZE_MAJOR_VERSION(command_queue_ext_version),- ZE_MINOR_VERSION(command_queue_ext_version));+ _log.debug("NPU command queue version %d.%d",+ ZE_MAJOR_VERSION(command_queue_ext_version),+ ZE_MINOR_VERSION(command_queue_ext_version));- // Load our command queue extension- ze_command_queue_npu_dditable_ext_last_t* _command_queue_npu_dditable_ext = nullptr;+ // Load npu command queue extension+ ze_command_queue_npu_dditable_ext_t* _command_queue_npu_dditable_ext = nullptr;if (command_queue_ext_version) {- THROW_ON_FAIL_FOR_LEVELZERO(- "zeDriverGetExtensionFunctionAddress " + command_queue_ext_name,- zeDriverGetExtensionFunctionAddress(driver_handle,- command_queue_ext_name.c_str(),- reinterpret_cast<void**>(&_command_queue_npu_dditable_ext)));+ getExtensionFunctionAddress(command_queue_ext_name,+ command_queue_ext_version,+ reinterpret_cast<void**>(&_command_queue_npu_dditable_ext));}- command_queue_npu_dditable_ext_decorator =+ _command_queue_npu_dditable_ext_decorator =std::make_unique<ze_command_queue_npu_dditable_ext_decorator>(_command_queue_npu_dditable_ext,command_queue_ext_version);- // Load our graph extension- ze_graph_dditable_ext_t* graph_ddi_table_ext = nullptr;- THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionFunctionAddress",- zeDriverGetExtensionFunctionAddress(driver_handle,- graph_ext_name.c_str(),- reinterpret_cast<void**>(&graph_ddi_table_ext)));- graph_dditable_ext_decorator =- std::make_unique<ze_graph_dditable_ext_decorator>(graph_ddi_table_ext, graph_ext_version);-// Query the mutable command list version[[maybe_unused]] std::string mutuable_command_list_ext_name;- std::tie(mutable_command_list_ext_version, mutuable_command_list_ext_name) =+ std::tie(_mutable_command_list_ext_version, mutuable_command_list_ext_name) =queryDriverExtensionVersion(ZE_MUTABLE_COMMAND_LIST_EXP_NAME,- ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_CURRENT,+ TARGET_ZE_MUTABLE_COMMAND_LIST_EXT_VERSION,extProps,count);- log.debug("Mutable command list version %d.%d",- ZE_MAJOR_VERSION(mutable_command_list_ext_version),- ZE_MINOR_VERSION(mutable_command_list_ext_version));+ _log.debug("Mutable command list version %d.%d",+ ZE_MAJOR_VERSION(_mutable_command_list_ext_version),+ ZE_MINOR_VERSION(_mutable_command_list_ext_version));++ // Query npu profiling extension version+ std::string profiling_ext_name;+ uint32_t profiling_ext_version = 0;+ std::tie(profiling_ext_version, profiling_ext_name) =+ queryDriverExtensionVersion(ZE_PROFILING_DATA_EXT_NAME, TARGET_ZE_PROFILING_NPU_EXT_VERSION, extProps, count);- // Load our profiling extension+ // Load npu profiling extensionze_graph_profiling_dditable_ext_t* _graph_profiling_ddi_table_ext = nullptr;- THROW_ON_FAIL_FOR_LEVELZERO(- "zeDriverGetExtensionFunctionAddress",- zeDriverGetExtensionFunctionAddress(driver_handle,- "ZE_extension_profiling_data",- reinterpret_cast<void**>(&_graph_profiling_ddi_table_ext)));+ getExtensionFunctionAddress(profiling_ext_name,+ profiling_ext_version,+ reinterpret_cast<void**>(&_graph_profiling_ddi_table_ext));- graph_profiling_npu_dditable_ext_decorator =- std::make_unique<ze_graph_profiling_ddi_table_ext_decorator>(_graph_profiling_ddi_table_ext);+ _graph_profiling_npu_dditable_ext_decorator =+ std::make_unique<ze_graph_profiling_dditable_ext_decorator>(_graph_profiling_ddi_table_ext);uint32_t device_count = 1;- // Get our target device- THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGet", zeDeviceGet(driver_handle, &device_count, &device_handle));+ // Get npu target device+ THROW_ON_FAIL_FOR_LEVELZERO("zeDeviceGet", zeDeviceGet(_driver_handle, &device_count, &_device_handle));// Create context - share between the compiler and the backendze_context_desc_t context_desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, 0, 0};- THROW_ON_FAIL_FOR_LEVELZERO("zeContextCreate", zeContextCreate(driver_handle, &context_desc, &context));- log.debug("ZeroInitStructsMock initialize complete");+ THROW_ON_FAIL_FOR_LEVELZERO("zeContextCreate", zeContextCreate(_driver_handle, &context_desc, &_context));+ _log.debug("ZeroInitStructsHolder initialize complete");// Discover if standard allocation is supportedze_device_external_memory_properties_t external_memory_properties_desc = {};external_memory_properties_desc.stype = ZE_STRUCTURE_TYPE_DEVICE_EXTERNAL_MEMORY_PROPERTIES;- auto res = zeDeviceGetExternalMemoryProperties(device_handle, &external_memory_properties_desc);+ auto res = zeDeviceGetExternalMemoryProperties(_device_handle, &external_memory_properties_desc);if (res == ZE_RESULT_SUCCESS) {#ifdef _WIN32if (external_memory_properties_desc.memoryAllocationImportTypes & ZE_EXTERNAL_MEMORY_TYPE_FLAG_OPAQUE_WIN32) {@@ -306,15 +331,37 @@ ZeroInitStructsMock::ZeroInitStructsMock(int extVersion)}}+void ZeroInitStructsMock::getExtensionFunctionAddress(const std::string& name,+ const uint32_t version,+ void** function_address) {+ if (_driver_npu_dditable_ext_decorator->version()) {+ ze_driver_extension_npu_ext_t driver_extension = {ZE_STRUCTURE_TYPE_DRIVER_EXTENSION_NPU_EXT,+ nullptr,+ name.c_str(),+ version,+ function_address};++ THROW_ON_FAIL_FOR_LEVELZERO(+ "pfnGetExtension " + name,+ _driver_npu_dditable_ext_decorator->pfnGetExtension(_driver_handle, &driver_extension));+ } else {+ THROW_ON_FAIL_FOR_LEVELZERO(+ "zeDriverGetExtensionFunctionAddress" + name,+ zeDriverGetExtensionFunctionAddress(_driver_handle, name.c_str(), function_address));+ }+}+ZeroInitStructsMock::~ZeroInitStructsMock() {- if (context) {- log.debug("ZeroInitStructsMock - performing zeContextDestroy");- auto result = zeContextDestroy(context);+ 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");+ _log.warning(+ "zeContextDestroy failed to destroy the context; Level zero context was already destroyed");} else {- log.error("zeContextDestroy failed %#X", uint64_t(result));+ _log.error("zeContextDestroy failed %#X", uint64_t(result));}}}diff --git a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.hpp b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.hppindex 29bc77fb7da..6367144127f 100644--- a/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.hpp+++ b/src/plugins/intel_npu/tests/functional/internal/compiler_adapter/zero_init_mock.hpp@@ -4,13 +4,11 @@#pragma once-#include <ze_api.h>-#include <ze_command_queue_npu_ext.h>-#include <ze_graph_ext.h>#include <ze_intel_npu_uuid.h>#include <memory>#include <mutex>+#include <optional>#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_api.hpp"@@ -24,26 +22,28 @@ struct ZeroInitStructsMock {~ZeroInitStructsMock();void initNpuDriver();+ void getExtensionFunctionAddress(const std::string& name, const uint32_t version, void** function_address);- std::shared_ptr<intel_npu::ZeroApi> zero_api;+ std::shared_ptr<intel_npu::ZeroApi> _zero_api;- intel_npu::Logger log;+ 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;+ ze_driver_handle_t _driver_handle = nullptr;+ ze_device_handle_t _device_handle = nullptr;- std::map<std::string, uint32_t> driver_extension_properties;- std::unique_ptr<ze_graph_dditable_ext_decorator> graph_dditable_ext_decorator;- std::unique_ptr<ze_command_queue_npu_dditable_ext_decorator> command_queue_npu_dditable_ext_decorator;- std::unique_ptr<ze_graph_profiling_ddi_table_ext_decorator> graph_profiling_npu_dditable_ext_decorator;+ std::map<std::string, uint32_t> _driver_extension_properties;+ std::unique_ptr<ze_graph_dditable_ext_decorator> _graph_dditable_ext_decorator;+ std::unique_ptr<ze_command_queue_npu_dditable_ext_decorator> _command_queue_npu_dditable_ext_decorator;+ std::unique_ptr<ze_graph_profiling_dditable_ext_decorator> _graph_profiling_npu_dditable_ext_decorator;+ std::unique_ptr<ze_driver_npu_dditable_ext_decorator> _driver_npu_dditable_ext_decorator;- ze_driver_properties_t driver_properties = {};- uint32_t mutable_command_list_ext_version = 0;+ ze_driver_properties_t _driver_properties = {};+ uint32_t _mutable_command_list_ext_version = 0;- ze_api_version_t ze_drv_api_version = {};+ ze_api_version_t _ze_drv_api_version = {};- std::unique_ptr<ze_device_graph_properties_t> compiler_properties = nullptr;+ std::optional<ze_device_graph_properties_t> _compiler_properties = std::nullopt;bool _external_memory_standard_allocation_supported = false;bool _external_memory_fd_win32_supported = false;diff --git a/src/plugins/intel_npu/thirdparty/level-zero-ext b/src/plugins/intel_npu/thirdparty/level-zero-extindex 61e4aeb00af..8404c63a88d 160000--- a/src/plugins/intel_npu/thirdparty/level-zero-ext+++ b/src/plugins/intel_npu/thirdparty/level-zero-ext@@ -1 +1 @@-Subproject commit 61e4aeb00afd2a5b6955986269eed3a713c7b562+Subproject commit 8404c63a88d182726038d2b07c219731dada9c21