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] Check table ext versions only after the plugin negotiates with the driver (#38907)
Bogdan Pereanu285976a07db2
diff --git a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp b/src/plugins/intel_npu/src/backend/src/zero_backend.cppindex 87d73853898..69dec5c1b48 100644--- a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_backend.cpp@@ -26,19 +26,19 @@ uint32_t ZeroEngineBackend::getDriverVersion() const {}uint32_t ZeroEngineBackend::getGraphExtVersion() const {- return _initStruct->getGraphDdiTable().version();+ return _initStruct->getGraphExtVersion();}bool ZeroEngineBackend::isCommandQueueExtSupported() const {- return _initStruct->isExtensionSupported(std::string(ZE_COMMAND_QUEUE_NPU_EXT_NAME), ZE_MAKE_VERSION(1, 0));+ return _initStruct->isCommandQueueExtSupported();}bool ZeroEngineBackend::isLUIDExtSupported() const {- return _initStruct->isExtensionSupported(std::string(ZE_DEVICE_LUID_EXT_NAME), ZE_MAKE_VERSION(1, 0));+ return _initStruct->isLUIDExtSupported();}bool ZeroEngineBackend::isContextExtSupported() const {- return _initStruct->isExtensionSupported(std::string(ZE_CONTEXT_NPU_EXT_NAME), ZE_MAKE_VERSION(1, 0));+ return _initStruct->isContextExtSupported();}const std::shared_ptr<IDevice> ZeroEngineBackend::getDevice() const {diff --git a/src/plugins/intel_npu/src/backend/src/zero_device.cpp b/src/plugins/intel_npu/src/backend/src/zero_device.cppindex bb2ca33fe36..979151ee07a 100644--- a/src/plugins/intel_npu/src/backend/src/zero_device.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_device.cpp@@ -20,7 +20,7 @@ ZeroDevice::ZeroDevice(const std::shared_ptr<ZeroInitStructsHolder>& initStructs_device_properties.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES;// Get LUID info, if supported- if (_initStructs->isExtensionSupported(std::string(ZE_DEVICE_LUID_EXT_NAME), ZE_MAKE_VERSION(1, 0))) {+ if (_initStructs->isLUIDExtSupported()) {_device_luid.stype = ZE_STRUCTURE_TYPE_DEVICE_LUID_EXT_PROPERTIES;_device_properties.pNext = &_device_luid;}@@ -156,13 +156,14 @@ uint64_t ZeroDevice::getTotalMemSize() const {// For drivers with graph_extension < 1.9 we report fixed 2GB max allocation size (old drivers don't support more)// For drivers with graph_extension > 1.9 we report the value they return- if (_initStructs->isExtensionSupported(std::string(ZE_GRAPH_EXT_NAME), ZE_MAKE_VERSION(1, 9))) {+ const uint32_t graph_ext_version = _initStructs->getGraphExtVersion();+ if (graph_ext_version >= ZE_MAKE_VERSION(1, 9)) {// we are safe here, can return the value directly from driverreturn query.total;}#if defined(_WIN32) || defined(__CYGWIN__)// Special case for windows drivers with graph_extension v 1.8- if (_initStructs->isExtensionSupported(std::string("ZE_extension_graph_1_8"), ZE_MAKE_VERSION(1, 8))) {+ if (graph_ext_version == ZE_MAKE_VERSION(1, 8)) {// query here returns total system memory in KB, which we need to// divide by 2 (OS limitation) and convert to bytesreturn (query.total << 9);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 39a8ac446a8..77319e74be7 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@@ -7,9 +7,12 @@#include <ze_intel_npu_uuid.h>#include <atomic>+#include <map>#include <memory>#include <mutex>#include <optional>+#include <string>+#include <string_view>#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_api.hpp"@@ -56,21 +59,23 @@ public:inline uint32_t getDriverVersion() const {return _driver_properties.driverVersion;}+ inline uint32_t getGraphExtVersion() const {+ return _graph_dditable_ext_decorator->version();+ }inline uint32_t getMutableCommandListExtVersion() const {- return _mutable_command_list_ext_version;+ return getExtensionVersion(ZE_MUTABLE_COMMAND_LIST_EXP_NAME);}inline ze_api_version_t getZeDrvApiVersion() const {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()) {- return false;- } else if (iter->second >= version) {- return true;- }- return false;+ inline bool isCommandQueueExtSupported() const {+ return isExtensionSupported(ZE_COMMAND_QUEUE_NPU_EXT_NAME);+ }+ inline bool isLUIDExtSupported() const {+ return isExtensionSupported(ZE_DEVICE_LUID_EXT_NAME);+ }+ inline bool isContextExtSupported() const {+ return isExtensionSupported(ZE_CONTEXT_NPU_EXT_NAME);}inline bool isExternalMemoryStandardAllocationSupported() const {return _external_memory_standard_allocation_supported;@@ -79,7 +84,7 @@ public:return _external_memory_fd_win32_supported;}inline bool isCommandQueueSetPrioritySupported() const {- return _command_queue_set_priority_supported;+ return isExtensionSupported(ZE_COMMAND_QUEUE_SET_PRIORITY_EXT_NAME);}inline uint32_t getCommandQueueGroupOrdinal() const {return _command_queue_group_ordinal;@@ -108,6 +113,15 @@ private:return _zero_mem_pool;}+ // Returns the version negotiated between plugin and driver for <ext_name>, or 0 if the extension is not supported+ inline uint32_t getExtensionVersion(std::string_view ext_name) const {+ auto iter = _supported_extensions.find(ext_name);+ return iter == _supported_extensions.end() ? 0 : iter->second;+ }+ inline bool isExtensionSupported(std::string_view ext_name) const {+ return getExtensionVersion(ext_name) != 0;+ }+// keep zero_api alive until context is destroyedstd::shared_ptr<ZeroApi> _zero_api;@@ -117,26 +131,24 @@ private:ze_driver_handle_t _driver_handle = nullptr;ze_device_handle_t _device_handle = nullptr;- std::map<std::string, uint32_t> _driver_extension_properties;+ // Extensions supported by both plugin and driver, keyed by the canonical extension name (without version suffix).+ // The value is the negotiated version: the plugin target version, or an older version if the driver doesn't+ // support the target one. Extensions with a major version different from the plugin target are not stored.+ std::map<std::string, uint32_t, std::less<>> _supported_extensions;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;std::unique_ptr<ze_context_npu_dditable_ext_decorator> _context_npu_dditable_ext_decorator;- ze_driver_properties_t _driver_properties = {};- uint32_t _mutable_command_list_ext_version = 0;-ze_api_version_t _ze_drv_api_version = {};-+ ze_driver_properties_t _driver_properties = {};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;- bool _command_queue_set_priority_supported = false;uint32_t _context_options = 0;-uint32_t _command_queue_group_ordinal = 0;// Per-context global registry for ZeroMem tracking.diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hppindex 1f5a55b6026..df9465d09a1 100644--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp@@ -8,7 +8,11 @@#include <limits.h>#include <ze_graph_ext.h>+#include <cstring>#include <optional>+#include <string>+#include <tuple>+#include <vector>#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_api.hpp"@@ -254,5 +258,53 @@ static inline uint32_t findCommandQueueGroupOrdinal(return 0;}+static inline bool isExtensionNameMatching(const char* propertyName, const char* extName) {+ if (strcmp(propertyName, extName) == 0) {+ return true;+ }++ // Older drivers use specific names for different graph ext versions, e.g.: ZE_extension_graph_1_1+ if (strcmp(extName, ZE_GRAPH_EXT_NAME) != 0) {+ return false;+ }++ const size_t extNameLen = strlen(extName);+ return strncmp(propertyName, extName, extNameLen) == 0 && propertyName[extNameLen] == '_' &&+ propertyName[extNameLen + 1] >= '0' && propertyName[extNameLen + 1] <= '9';+}++static inline std::tuple<uint32_t, std::string> queryDriverExtensionVersion(+ const char* extName,+ uint32_t extCurrentVersion,+ const std::vector<ze_driver_extension_properties_t>& extProps,+ uint32_t count) {+ const char* functionExtName = nullptr;+ uint32_t targetVersion = 0;++ for (uint32_t i = 0; i < count; ++i) {+ const auto& property = extProps[i];++ if (!isExtensionNameMatching(property.name, extName)) {+ continue;+ }++ if (property.version >= extCurrentVersion) {+ functionExtName = property.name;+ targetVersion = extCurrentVersion;+ break;+ }++ // Use the latest version supported by the driver - We need to go through all the properties for older drivers+ // that use specific names for different graph ext versions, e.g.: ZE_extension_graph_1_1,+ // ZE_extension_graph_1_2+ if (property.version > targetVersion) {+ functionExtName = property.name;+ targetVersion = property.version;+ }+ }++ return std::make_tuple(targetVersion, functionExtName ? functionExtName : "");+}+} // namespace zeroUtils} // namespace intel_npudiff --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 2a38fe17a3b..11daf46ce98 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@@ -28,39 +28,21 @@ constexpr uint32_t TARGET_ZE_CONTEXT_NPU_EXT_VERSION = ZE_CONTEXT_NPU_EXT_VERSIOconstexpr uint32_t TARGET_ZE_MUTABLE_COMMAND_LIST_EXT_VERSION = ZE_MUTABLE_COMMAND_LIST_EXP_VERSION_1_1;constexpr uint32_t TARGET_ZE_EXTERNAL_MEMMAP_SYSMEM_EXT_VERSION = ZE_EXTERNAL_MEMMAP_SYSMEM_EXT_VERSION_1_0;constexpr uint32_t TARGET_ZE_COMMAND_QUEUE_SET_PRIORITY_EXT_VERSION = ZE_COMMAND_QUEUE_SET_PRIORITY_EXT_VERSION_1_0;+constexpr uint32_t TARGET_ZE_DEVICE_LUID_EXT_VERSION = ZE_DEVICE_LUID_EXT_VERSION_1_0;constexpr ze_driver_uuid_t uuid = ze_intel_npu_driver_uuid;-std::tuple<uint32_t, std::string> queryDriverExtensionVersion(const char* extName,- uint32_t extCurrentVersion,- std::vector<ze_driver_extension_properties_t>& extProps,- uint32_t count) {- const char* functionExtName = nullptr;- uint32_t targetVersion = 0;+using intel_npu::zeroUtils::queryDriverExtensionVersion;- for (uint32_t i = 0; i < count; ++i) {- auto& property = extProps[i];-- if (strncmp(property.name, extName, strlen(extName)) != 0) {- continue;- }-- if (property.version >= extCurrentVersion) {- functionExtName = property.name;- targetVersion = extCurrentVersion;- break;- }-- // Use the latest version supported by the driver - We need to go through all the properties for older drivers- // that use specific names for different graph ext versions, e.g.: ZE_extension_graph_1_1,- // ZE_extension_graph_1_2- if (property.version > targetVersion) {- functionExtName = property.name;- targetVersion = property.version;- }+void saveSupportedExtension(std::map<std::string, uint32_t, std::less<>>& supportedExtensions,+ const char* extName,+ uint32_t extVersion,+ uint32_t extTargetVersion) {+ if (extVersion == 0 || ZE_MAJOR_VERSION(extVersion) != ZE_MAJOR_VERSION(extTargetVersion)) {+ return;}- return std::make_tuple(targetVersion, functionExtName ? functionExtName : "");+ supportedExtensions[extName] = extVersion;}} // namespace@@ -205,17 +187,15 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionProperties",zeDriverGetExtensionProperties(_driver_handle, &count, extProps.data()));- // save the list of extension properties for later searches- for (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);- }-// Query npu driver extension versionstd::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);+ saveSupportedExtension(_supported_extensions,+ ZE_DRIVER_NPU_EXT_NAME,+ driver_ext_version,+ TARGET_ZE_DRIVER_NPU_EXT_VERSION);_log.debug("NPU driver ext version %d.%d",ZE_MAJOR_VERSION(driver_ext_version),@@ -276,6 +256,7 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()"; discovered driver graph extension has major version ",driver_ext_major_version);}+ saveSupportedExtension(_supported_extensions, ZE_GRAPH_EXT_NAME, graph_ext_version, target_graph_ext_version);_log.info("Found Driver Version %d.%d, Graph Extension Version %d.%d (%s)",ZE_MAJOR_VERSION(_ze_drv_api_version),@@ -298,6 +279,10 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()TARGET_ZE_COMMAND_QUEUE_NPU_EXT_VERSION,extProps,count);+ saveSupportedExtension(_supported_extensions,+ ZE_COMMAND_QUEUE_NPU_EXT_NAME,+ command_queue_ext_version,+ TARGET_ZE_COMMAND_QUEUE_NPU_EXT_VERSION);_log.debug("NPU command queue version %d.%d",ZE_MAJOR_VERSION(command_queue_ext_version),@@ -316,11 +301,12 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()command_queue_ext_version);// Query the mutable command list version+ uint32_t mutable_command_list_ext_version = 0;#ifdef _WIN32// The 2688 Windows driver version doesn't support as expected the MutableCommandList featureif (_driver_properties.driverVersion != WIN_DRIVER_NO_MCL_SUPPORT) {#endif- std::tie(_mutable_command_list_ext_version, std::ignore) =+ std::tie(mutable_command_list_ext_version, std::ignore) =queryDriverExtensionVersion(ZE_MUTABLE_COMMAND_LIST_EXP_NAME,TARGET_ZE_MUTABLE_COMMAND_LIST_EXT_VERSION,extProps,@@ -328,16 +314,24 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()#ifdef _WIN32}#endif+ saveSupportedExtension(_supported_extensions,+ ZE_MUTABLE_COMMAND_LIST_EXP_NAME,+ mutable_command_list_ext_version,+ TARGET_ZE_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));+ ZE_MAJOR_VERSION(mutable_command_list_ext_version),+ ZE_MINOR_VERSION(mutable_command_list_ext_version));// Query npu profiling extension versionstd::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);+ saveSupportedExtension(_supported_extensions,+ ZE_PROFILING_DATA_EXT_NAME,+ profiling_ext_version,+ TARGET_ZE_PROFILING_NPU_EXT_VERSION);// Load npu profiling extensionze_graph_profiling_dditable_ext_t* graph_profiling_ddi_table_ext = nullptr;@@ -353,6 +347,10 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()uint32_t context_ext_version = 0;std::tie(context_ext_version, context_ext_name) =queryDriverExtensionVersion(ZE_CONTEXT_NPU_EXT_NAME, TARGET_ZE_CONTEXT_NPU_EXT_VERSION, extProps, count);+ saveSupportedExtension(_supported_extensions,+ ZE_CONTEXT_NPU_EXT_NAME,+ context_ext_version,+ TARGET_ZE_CONTEXT_NPU_EXT_VERSION);_log.debug("NPU context version %d.%d",ZE_MAJOR_VERSION(context_ext_version),@@ -407,6 +405,10 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()TARGET_ZE_EXTERNAL_MEMMAP_SYSMEM_EXT_VERSION,extProps,count);+ saveSupportedExtension(_supported_extensions,+ ZE_EXTERNAL_MEMORY_MAPPING_EXT_NAME,+ external_memory_mapping_ext_version,+ TARGET_ZE_EXTERNAL_MEMMAP_SYSMEM_EXT_VERSION);_log.debug("External memory mapping version %d.%d",ZE_MAJOR_VERSION(external_memory_mapping_ext_version),@@ -422,14 +424,26 @@ ZeroInitStructsHolder::ZeroInitStructsHolder()TARGET_ZE_COMMAND_QUEUE_SET_PRIORITY_EXT_VERSION,extProps,count);+ saveSupportedExtension(_supported_extensions,+ ZE_COMMAND_QUEUE_SET_PRIORITY_EXT_NAME,+ command_queue_set_priority_ext_version,+ TARGET_ZE_COMMAND_QUEUE_SET_PRIORITY_EXT_VERSION);_log.debug("Command queue set priority extension version %d.%d",ZE_MAJOR_VERSION(command_queue_set_priority_ext_version),ZE_MINOR_VERSION(command_queue_set_priority_ext_version));- if (command_queue_set_priority_ext_version > 0) {- _command_queue_set_priority_supported = true;- }+ uint32_t device_luid_ext_version = 0;+ std::tie(device_luid_ext_version, std::ignore) =+ queryDriverExtensionVersion(ZE_DEVICE_LUID_EXT_NAME, TARGET_ZE_DEVICE_LUID_EXT_VERSION, extProps, count);+ saveSupportedExtension(_supported_extensions,+ ZE_DEVICE_LUID_EXT_NAME,+ device_luid_ext_version,+ TARGET_ZE_DEVICE_LUID_EXT_VERSION);++ _log.debug("Device LUID extension version %d.%d",+ ZE_MAJOR_VERSION(device_luid_ext_version),+ ZE_MINOR_VERSION(device_luid_ext_version));_command_queue_group_ordinal =zeroUtils::findCommandQueueGroupOrdinal(_device_handle, ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE);diff --git a/src/plugins/intel_npu/tests/functional/common/zero_init_mock.cpp b/src/plugins/intel_npu/tests/functional/common/zero_init_mock.cppindex e15701b8ca9..77f3a7c09b5 100644--- a/src/plugins/intel_npu/tests/functional/common/zero_init_mock.cpp+++ b/src/plugins/intel_npu/tests/functional/common/zero_init_mock.cpp@@ -15,36 +15,17 @@ namespace {constexpr ze_driver_uuid_t uuid = ze_intel_npu_driver_uuid;-std::tuple<uint32_t, std::string> queryDriverExtensionVersion(const char* extName,- uint32_t extCurrentVersion,- std::vector<ze_driver_extension_properties_t>& extProps,- uint32_t count) {- const char* functionExtName = nullptr;- uint32_t targetVersion = 0;-- for (uint32_t i = 0; i < count; ++i) {- auto& property = extProps[i];-- if (strncmp(property.name, extName, strlen(extName)) != 0) {- continue;- }-- if (property.version >= extCurrentVersion) {- functionExtName = property.name;- targetVersion = extCurrentVersion;- break;- }+using intel_npu::zeroUtils::queryDriverExtensionVersion;- // Use the latest version supported by the driver - We need to go through all the properties for older drivers- // that use specific names for different graph ext versions, e.g.: ZE_extension_graph_1_1,- // ZE_extension_graph_1_2- if (property.version > targetVersion) {- functionExtName = property.name;- targetVersion = property.version;- }+void saveSupportedExtension(std::map<std::string, uint32_t, std::less<>>& supportedExtensions,+ const char* extName,+ uint32_t extVersion,+ uint32_t extTargetVersion) {+ if (extVersion == 0 || ZE_MAJOR_VERSION(extVersion) != ZE_MAJOR_VERSION(extTargetVersion)) {+ return;}- return std::make_tuple(targetVersion, functionExtName ? functionExtName : "");+ supportedExtensions[extName] = extVersion;}} // namespace@@ -190,17 +171,12 @@ ZeroInitStructsMock::ZeroInitStructsMock(uint32_t zeDriverNpuExtVersion,THROW_ON_FAIL_FOR_LEVELZERO("zeDriverGetExtensionProperties",zeDriverGetExtensionProperties(_driver_handle, &count, extProps.data()));- // save the list of extension properties for later searches- for (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);- }-// Query npu driver extension versionstd::string driver_ext_name;uint32_t driver_ext_version = 0;std::tie(driver_ext_version, driver_ext_name) =queryDriverExtensionVersion(ZE_DRIVER_NPU_EXT_NAME, zeDriverNpuExtVersion, extProps, count);+ saveSupportedExtension(_supported_extensions, ZE_DRIVER_NPU_EXT_NAME, driver_ext_version, zeDriverNpuExtVersion);_log.debug("NPU driver ext version %d.%d",ZE_MAJOR_VERSION(driver_ext_version),@@ -241,6 +217,7 @@ ZeroInitStructsMock::ZeroInitStructsMock(uint32_t zeDriverNpuExtVersion,"; discovered driver graph extension has major version ",driver_ext_major_version);}+ saveSupportedExtension(_supported_extensions, ZE_GRAPH_EXT_NAME, graph_ext_version, target_graph_ext_version);_log.info("Found Driver Version %d.%d, Graph Extension Version %d.%d (%s)",ZE_MAJOR_VERSION(_ze_drv_api_version),@@ -260,6 +237,10 @@ ZeroInitStructsMock::ZeroInitStructsMock(uint32_t zeDriverNpuExtVersion,uint32_t command_queue_ext_version = 0;std::tie(command_queue_ext_version, command_queue_ext_name) =queryDriverExtensionVersion(ZE_COMMAND_QUEUE_NPU_EXT_NAME, zeCommandQueueNpuExtVersion, extProps, count);+ saveSupportedExtension(_supported_extensions,+ ZE_COMMAND_QUEUE_NPU_EXT_NAME,+ command_queue_ext_version,+ zeCommandQueueNpuExtVersion);_log.debug("NPU command queue version %d.%d",ZE_MAJOR_VERSION(command_queue_ext_version),@@ -278,19 +259,27 @@ ZeroInitStructsMock::ZeroInitStructsMock(uint32_t zeDriverNpuExtVersion,command_queue_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) =+ uint32_t mutable_command_list_ext_version = 0;+ std::tie(mutable_command_list_ext_version, std::ignore) =queryDriverExtensionVersion(ZE_MUTABLE_COMMAND_LIST_EXP_NAME, zeMutableCommandListExtVersion, extProps, count);+ saveSupportedExtension(_supported_extensions,+ ZE_MUTABLE_COMMAND_LIST_EXP_NAME,+ mutable_command_list_ext_version,+ zeMutableCommandListExtVersion);_log.debug("Mutable command list version %d.%d",- ZE_MAJOR_VERSION(_mutable_command_list_ext_version),- ZE_MINOR_VERSION(_mutable_command_list_ext_version));+ ZE_MAJOR_VERSION(mutable_command_list_ext_version),+ ZE_MINOR_VERSION(mutable_command_list_ext_version));// Query npu profiling extension versionstd::string profiling_ext_name;uint32_t profiling_ext_version = 0;std::tie(profiling_ext_version, profiling_ext_name) =queryDriverExtensionVersion(ZE_PROFILING_DATA_EXT_NAME, zeProfilingNpuExtVersion, extProps, count);+ saveSupportedExtension(_supported_extensions,+ ZE_PROFILING_DATA_EXT_NAME,+ profiling_ext_version,+ zeProfilingNpuExtVersion);// Load npu profiling extensionze_graph_profiling_dditable_ext_t* graph_profiling_ddi_table_ext = nullptr;@@ -306,6 +295,7 @@ ZeroInitStructsMock::ZeroInitStructsMock(uint32_t zeDriverNpuExtVersion,uint32_t context_ext_version = 0;std::tie(context_ext_version, context_ext_name) =queryDriverExtensionVersion(ZE_CONTEXT_NPU_EXT_NAME, zeContextNpuExtVersion, extProps, count);+ saveSupportedExtension(_supported_extensions, ZE_CONTEXT_NPU_EXT_NAME, context_ext_version, zeContextNpuExtVersion);_log.debug("NPU context version %d.%d",ZE_MAJOR_VERSION(context_ext_version),@@ -360,6 +350,10 @@ ZeroInitStructsMock::ZeroInitStructsMock(uint32_t zeDriverNpuExtVersion,zeExternalMemMapSysMemExtVersion,extProps,count);+ saveSupportedExtension(_supported_extensions,+ ZE_EXTERNAL_MEMORY_MAPPING_EXT_NAME,+ external_memory_mapping_ext_version,+ zeExternalMemMapSysMemExtVersion);_log.debug("External memory mapping version %d.%d",ZE_MAJOR_VERSION(external_memory_mapping_ext_version),@@ -375,14 +369,25 @@ ZeroInitStructsMock::ZeroInitStructsMock(uint32_t zeDriverNpuExtVersion,zeCommandQueueSetPriorityExtVersion,extProps,count);+ saveSupportedExtension(_supported_extensions,+ ZE_COMMAND_QUEUE_SET_PRIORITY_EXT_NAME,+ command_queue_set_priority_ext_version,+ zeCommandQueueSetPriorityExtVersion);_log.debug("Command queue set priority extension version %d.%d",ZE_MAJOR_VERSION(command_queue_set_priority_ext_version),ZE_MINOR_VERSION(command_queue_set_priority_ext_version));- if (command_queue_set_priority_ext_version > 0) {- _command_queue_set_priority_supported = true;- }+ uint32_t device_luid_ext_version = 0;+ std::tie(device_luid_ext_version, std::ignore) =+ queryDriverExtensionVersion(ZE_DEVICE_LUID_EXT_NAME,+ intel_npu::test_constants::TARGET_ZE_DEVICE_LUID_EXT_VERSION,+ extProps,+ count);+ saveSupportedExtension(_supported_extensions,+ ZE_DEVICE_LUID_EXT_NAME,+ device_luid_ext_version,+ intel_npu::test_constants::TARGET_ZE_DEVICE_LUID_EXT_VERSION);_command_queue_group_ordinal =zeroUtils::findCommandQueueGroupOrdinal(_device_handle, ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE);diff --git a/src/plugins/intel_npu/tests/functional/common/zero_init_mock.hpp b/src/plugins/intel_npu/tests/functional/common/zero_init_mock.hppindex 2934a86bdf1..e12f1e5dc5c 100644--- a/src/plugins/intel_npu/tests/functional/common/zero_init_mock.hpp+++ b/src/plugins/intel_npu/tests/functional/common/zero_init_mock.hpp@@ -28,6 +28,7 @@ inline constexpr uint32_t TARGET_ZE_MUTABLE_COMMAND_LIST_EXT_VERSION = ZE_MUTABLinline constexpr uint32_t TARGET_ZE_EXTERNAL_MEMMAP_SYSMEM_EXT_VERSION = ZE_EXTERNAL_MEMMAP_SYSMEM_EXT_VERSION_1_0;inline constexpr uint32_t TARGET_ZE_COMMAND_QUEUE_SET_PRIORITY_EXT_VERSION =ZE_COMMAND_QUEUE_SET_PRIORITY_EXT_VERSION_1_0;+inline constexpr uint32_t TARGET_ZE_DEVICE_LUID_EXT_VERSION = ZE_DEVICE_LUID_EXT_VERSION_1_0;} // namespace test_constantsstruct ZeroInitStructsMock {@@ -66,26 +67,21 @@ private:ze_driver_handle_t _driver_handle = nullptr;ze_device_handle_t _device_handle = nullptr;- std::map<std::string, uint32_t> _driver_extension_properties;+ std::map<std::string, uint32_t, std::less<>> _supported_extensions;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;std::unique_ptr<ze_context_npu_dditable_ext_decorator> _context_npu_dditable_ext_decorator;- ze_driver_properties_t _driver_properties = {};- uint32_t _mutable_command_list_ext_version = 0;-ze_api_version_t _ze_drv_api_version = {};-+ ze_driver_properties_t _driver_properties = {};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;- bool _command_queue_set_priority_supported = false;- // unused but must stay: keeps layout identical to ZeroInitStructsHolder for reinterpret_pointer_cast+uint32_t _context_options = 0;-uint32_t _command_queue_group_ordinal = 0;ZeroMemPool _zero_mem_pool;diff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txtindex dc8da851866..fec89e8b8e5 100644--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt@@ -181,6 +181,7 @@ target_sources(${TARGET_NAME} PRIVATE${CMAKE_CURRENT_SOURCE_DIR}/npu/device_helpers_test.cpp${CMAKE_CURRENT_SOURCE_DIR}/npu/option_support_cache_test.cpp${CMAKE_CURRENT_SOURCE_DIR}/npu/state_tensor_binding_test.cpp+ ${CMAKE_CURRENT_SOURCE_DIR}/npu/zero_extension_query_test.cpp${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_graph_options_test.cpp${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_set_property_test.cpp${CMAKE_CURRENT_SOURCE_DIR}/npuw/flux2_compiled_model_test.cppdiff --git a/src/plugins/intel_npu/tests/unit/npu/zero_extension_query_test.cpp b/src/plugins/intel_npu/tests/unit/npu/zero_extension_query_test.cppnew file mode 100644index 00000000000..0ed3037e0cc--- /dev/null+++ b/src/plugins/intel_npu/tests/unit/npu/zero_extension_query_test.cpp@@ -0,0 +1,125 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gtest/gtest.h>+#include <level_zero/ze_api.h>+#include <ze_command_queue_npu_ext.h>+#include <ze_driver_npu_ext.h>++#include <cstring>+#include <string>+#include <vector>++#include "intel_npu/utils/zero/zero_utils.hpp"++using intel_npu::zeroUtils::isExtensionNameMatching;+using intel_npu::zeroUtils::queryDriverExtensionVersion;++namespace {++ze_driver_extension_properties_t makeExtension(const std::string& name, uint32_t version) {+ ze_driver_extension_properties_t property = {};+ std::strncpy(property.name, name.c_str(), sizeof(property.name) - 1);+ property.version = version;+ return property;+}++std::tuple<uint32_t, std::string> query(const char* extName,+ uint32_t targetVersion,+ const std::vector<ze_driver_extension_properties_t>& extProps) {+ return queryDriverExtensionVersion(extName, targetVersion, extProps, static_cast<uint32_t>(extProps.size()));+}++} // namespace++TEST(ZeroExtensionNameMatching, ExactNameMatches) {+ EXPECT_TRUE(isExtensionNameMatching(ZE_GRAPH_EXT_NAME, ZE_GRAPH_EXT_NAME));+ EXPECT_TRUE(isExtensionNameMatching(ZE_DRIVER_NPU_EXT_NAME, ZE_DRIVER_NPU_EXT_NAME));+ EXPECT_TRUE(isExtensionNameMatching(ZE_COMMAND_QUEUE_NPU_EXT_NAME, ZE_COMMAND_QUEUE_NPU_EXT_NAME));+}++TEST(ZeroExtensionNameMatching, GraphExtAcceptsVersionedNames) {+ EXPECT_TRUE(isExtensionNameMatching("ZE_extension_graph_1_1", ZE_GRAPH_EXT_NAME));+ EXPECT_TRUE(isExtensionNameMatching("ZE_extension_graph_1_2", ZE_GRAPH_EXT_NAME));+ EXPECT_TRUE(isExtensionNameMatching("ZE_extension_graph_1_19", ZE_GRAPH_EXT_NAME));+}++TEST(ZeroExtensionNameMatching, GraphExtRejectsNonVersionedSuffixes) {+ EXPECT_FALSE(isExtensionNameMatching("ZE_extension_graph_profiling", ZE_GRAPH_EXT_NAME));+ EXPECT_FALSE(isExtensionNameMatching("ZE_extension_graph_", ZE_GRAPH_EXT_NAME));+ EXPECT_FALSE(isExtensionNameMatching("ZE_extension_graphs", ZE_GRAPH_EXT_NAME));+ EXPECT_FALSE(isExtensionNameMatching("ZE_extension_graph1_1", ZE_GRAPH_EXT_NAME));+ EXPECT_FALSE(isExtensionNameMatching("ZE_extension_gra", ZE_GRAPH_EXT_NAME));+}++TEST(ZeroExtensionNameMatching, NonGraphExtRequiresExactName) {+ EXPECT_FALSE(isExtensionNameMatching("ZE_extension_driver_npu_1_1", ZE_DRIVER_NPU_EXT_NAME));+ EXPECT_FALSE(isExtensionNameMatching("ZE_extension_command_queue_npu_ext", ZE_COMMAND_QUEUE_NPU_EXT_NAME));+ EXPECT_FALSE(isExtensionNameMatching("ZE_extension_command_queue", ZE_COMMAND_QUEUE_NPU_EXT_NAME));+}++TEST(ZeroExtensionQuery, ReturnsTargetVersionWhenDriverIsNewer) {+ const std::vector<ze_driver_extension_properties_t> extProps = {+ makeExtension(ZE_DRIVER_NPU_EXT_NAME, ZE_DRIVER_NPU_EXT_VERSION_1_0),+ makeExtension(ZE_GRAPH_EXT_NAME, ZE_MAKE_VERSION(1, 25)),+ };++ const auto [version, name] = query(ZE_GRAPH_EXT_NAME, ZE_GRAPH_EXT_VERSION_1_19, extProps);+ EXPECT_EQ(version, static_cast<uint32_t>(ZE_GRAPH_EXT_VERSION_1_19));+ EXPECT_EQ(name, ZE_GRAPH_EXT_NAME);+}++TEST(ZeroExtensionQuery, PicksLatestVersionedGraphExtForOlderDriver) {+ const std::vector<ze_driver_extension_properties_t> extProps = {+ makeExtension("ZE_extension_graph_1_1", ZE_MAKE_VERSION(1, 1)),+ makeExtension("ZE_extension_graph_1_3", ZE_MAKE_VERSION(1, 3)),+ makeExtension("ZE_extension_graph_1_2", ZE_MAKE_VERSION(1, 2)),+ };++ const auto [version, name] = query(ZE_GRAPH_EXT_NAME, ZE_GRAPH_EXT_VERSION_1_19, extProps);+ EXPECT_EQ(version, static_cast<uint32_t>(ZE_MAKE_VERSION(1, 3)));+ EXPECT_EQ(name, "ZE_extension_graph_1_3");+}++TEST(ZeroExtensionQuery, IgnoresOtherExtensionsSharingGraphPrefix) {+ const std::vector<ze_driver_extension_properties_t> extProps = {+ makeExtension("ZE_extension_graph_profiling", ZE_MAKE_VERSION(1, 30)),+ makeExtension("ZE_extension_graph_1_2", ZE_MAKE_VERSION(1, 2)),+ };++ const auto [version, name] = query(ZE_GRAPH_EXT_NAME, ZE_GRAPH_EXT_VERSION_1_19, extProps);+ EXPECT_EQ(version, static_cast<uint32_t>(ZE_MAKE_VERSION(1, 2)));+ EXPECT_EQ(name, "ZE_extension_graph_1_2");+}++TEST(ZeroExtensionQuery, NonGraphExtIgnoresNamesWithSuffix) {+ const std::vector<ze_driver_extension_properties_t> extProps = {+ makeExtension(std::string(ZE_COMMAND_QUEUE_NPU_EXT_NAME) + "_1_1", ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_1),+ };++ const auto [version, name] = query(ZE_COMMAND_QUEUE_NPU_EXT_NAME, ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_1, extProps);+ EXPECT_EQ(version, 0u);+ EXPECT_TRUE(name.empty());+}++TEST(ZeroExtensionQuery, NonGraphExtFindsExactName) {+ const std::vector<ze_driver_extension_properties_t> extProps = {+ makeExtension(ZE_GRAPH_EXT_NAME, ZE_GRAPH_EXT_VERSION_1_19),+ makeExtension(ZE_COMMAND_QUEUE_NPU_EXT_NAME, ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_0),+ };++ const auto [version, name] = query(ZE_COMMAND_QUEUE_NPU_EXT_NAME, ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_1, extProps);+ EXPECT_EQ(version, static_cast<uint32_t>(ZE_COMMAND_QUEUE_NPU_EXT_VERSION_1_0));+ EXPECT_EQ(name, ZE_COMMAND_QUEUE_NPU_EXT_NAME);+}++TEST(ZeroExtensionQuery, ReturnsEmptyWhenExtensionMissing) {+ const std::vector<ze_driver_extension_properties_t> extProps = {+ makeExtension(ZE_DRIVER_NPU_EXT_NAME, ZE_DRIVER_NPU_EXT_VERSION_1_0),+ };++ const auto [version, name] = query(ZE_GRAPH_EXT_NAME, ZE_GRAPH_EXT_VERSION_1_19, extProps);+ EXPECT_EQ(version, 0u);+ EXPECT_TRUE(name.empty());+}