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] Use single command queue (#34785)
Bogdan Pereanuf703916a25d2
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hppindex 9238765aa9a..3400c312979 100644--- a/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp+++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp@@ -1517,4 +1517,18 @@ struct DISABLE_IDLE_MEMORY_PRUNING final : OptionBase<DISABLE_IDLE_MEMORY_PRUNIN}};+struct SHARED_COMMON_QUEUE final : OptionBase<SHARED_COMMON_QUEUE, bool> {+ static std::string_view key() {+ return ov::intel_npu::shared_common_queue.name();+ }++ static bool defaultValue() {+ return true;+ }++ static OptionMode mode() {+ return OptionMode::RunTime;+ }+};+} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hppindex 1253691fda4..9d5de026c07 100644--- a/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp+++ b/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp@@ -450,5 +450,14 @@ static constexpr ov::Property<bool> import_raw_blob{"NPU_IMPORT_RAW_BLOB"};*/static constexpr ov::Property<bool> export_raw_blob{"NPU_EXPORT_RAW_BLOB"};+/**+ * @brief [Only for NPU Plugin]+ * Type: boolean, default is true.+ * This option allows to enable/disable the usage of a shared common queue for all compiled models. If set to false,+ * each compiled model will have its own common queue. This option is added for enabling the isolation of compiled+ * models from each other, which can be required for some use cases.+ */+static constexpr ov::Property<bool> shared_common_queue{"NPU_SHARED_COMMON_QUEUE"};+} // namespace intel_npu} // namespace ovdiff --git a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hppindex 6ab8f55b603..c088ee3fb55 100644--- a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp@@ -60,6 +60,7 @@ protected:*/size_t _batch_size;+ std::shared_ptr<CommandQueue> _command_queue = nullptr;std::vector<std::unique_ptr<Fence>> _fences;std::shared_ptr<EventPool> _event_pool;std::vector<std::shared_ptr<Event>> _events;diff --git a/src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cppindex 3c109b32192..618393eda46 100644--- a/src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_dynamic_pipeline.cpp@@ -14,6 +14,7 @@#include "intel_npu/prefix.hpp"#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_api.hpp"+#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"#include "intel_npu/utils/zero/zero_remote_tensor.hpp"#include "intel_npu/utils/zero/zero_types.hpp"@@ -77,9 +78,8 @@ DynamicPipeline::DynamicPipeline(const std::shared_ptr<ZeroInitStructsHolder>& iif (_sync_output_with_fences) {_fences.reserve(_batch_size);-for (size_t i = 0; i < _batch_size; i++) {- _fences.emplace_back(std::make_unique<Fence>(_graph->get_command_queue()));+ _fences.emplace_back(std::make_unique<Fence>(_command_queue));}}@@ -181,7 +181,19 @@ void DynamicPipeline::push() {auto* dynamicGraph = dynamic_cast<IDynamicGraph*>(_graph.get());OPENVINO_ASSERT(dynamicGraph != nullptr, "Failed to cast graph to IDynamicGraph");- auto commandQueueHandle = _graph->get_command_queue()->handle();+ const auto command_queue_desc = _graph->get_command_queue_desc();+ const bool command_queue_version_changed = (command_queue_desc.key != _command_queue->desc().key);+ if (command_queue_version_changed) {+ _command_queue = ZeroCmdQueuePool::getInstance().getCommandQueue(_init_structs, command_queue_desc);++ if (_sync_output_with_fences) {+ for (size_t i = 0; i < _fences.size(); i++) {+ _fences[i] = std::make_unique<Fence>(_command_queue);+ }+ }+ }++ auto commandQueueHandle = _command_queue->handle();for (size_t i = 0; i < _command_lists.size(); ++i) {OV_ITT_TASK_CHAIN(ZERO_PIPELINE_IP_PUSH, itt::domains::LevelZeroBackend, "Pipeline", "push");diff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cppindex 254737c835f..4b2e4797945 100644--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp@@ -10,6 +10,7 @@#include "intel_npu/common/itt.hpp"#include "intel_npu/config/options.hpp"#include "intel_npu/utils/logger/logger.hpp"+#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"#include "intel_npu/utils/zero/zero_types.hpp"namespace {@@ -56,6 +57,8 @@ IPipeline::IPipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,_config.get<RUN_INFERENCES_SEQUENTIALLY>()),_pipeline_unique_id_per_graph(get_graph_unique_id_or_throw(graph)),_logger(logName, _config.get<LOG_LEVEL>()) {+ _command_queue = ZeroCmdQueuePool::getInstance().getCommandQueue(_init_structs, _graph->get_command_queue_desc());+bool perf_count_enabled = _config.has<PERF_COUNT>() && _config.get<PERF_COUNT>();std::optional<bool> compiled_with_profiling = _graph->is_profiling_blob();@@ -159,19 +162,18 @@ Pipeline::Pipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,}}- _command_lists.reserve(_batch_size);- for (size_t i = 0; i < _batch_size; i++) {- _command_lists.emplace_back(std::make_unique<CommandList>(_init_structs));- }-if (_sync_output_with_fences) {_fences.reserve(_batch_size);-for (size_t i = 0; i < _batch_size; i++) {- _fences.emplace_back(std::make_unique<Fence>(_graph->get_command_queue()));+ _fences.emplace_back(std::make_unique<Fence>(_command_queue));}}+ _command_lists.reserve(_batch_size);+ for (size_t i = 0; i < _batch_size; i++) {+ _command_lists.emplace_back(std::make_unique<CommandList>(_init_structs));+ }+for (size_t i = 0; i < _batch_size; i++) {_logger.debug("Pipeline - set args for command list number: %zu", i);size_t io_index = 0;@@ -283,6 +285,18 @@ void Pipeline::push() {_graph->set_last_submitted_id(_pipeline_unique_id_per_graph);}+ const auto command_queue_desc = _graph->get_command_queue_desc();+ const bool command_queue_version_changed = (command_queue_desc.key != _command_queue->desc().key);+ if (command_queue_version_changed) {+ _command_queue = ZeroCmdQueuePool::getInstance().getCommandQueue(_init_structs, command_queue_desc);++ if (_sync_output_with_fences) {+ for (size_t i = 0; i < _fences.size(); i++) {+ _fences[i] = std::make_unique<Fence>(_command_queue);+ }+ }+ }+for (size_t i = 0; i < _command_lists.size(); ++i) {_command_lists.at(i)->close();// Emit a marker for pipeline::push() with the command list handle as the metadata@@ -292,9 +306,9 @@ void Pipeline::push() {(uintptr_t)_command_lists.at(i)->handle());OV_ITT_TASK_CHAIN(ZERO_PIPELINE_IP_PUSH, itt::domains::LevelZeroBackend, "Pipeline", "push");if (_sync_output_with_fences) {- _graph->get_command_queue()->executeCommandList(*_command_lists.at(i), *_fences.at(i));+ _command_queue->executeCommandList(*_command_lists.at(i), *_fences.at(i));} else {- _graph->get_command_queue()->executeCommandList(*_command_lists.at(i));+ _command_queue->executeCommandList(*_command_lists.at(i));}}diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hppindex 2c477d061c7..faa0d139b88 100644--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp@@ -48,9 +48,8 @@ public:virtual void update_network_name(std::string_view name);- virtual const std::shared_ptr<CommandQueue>& get_command_queue() const;-- virtual void set_workload_type(const ov::WorkloadType workloadType) const;+ virtual CommandQueueDesc get_command_queue_desc() const;+ virtual void set_workload_type(const ov::WorkloadType workloadType);std::mutex& get_mutex() {return _initialize_mutex;diff --git a/src/plugins/intel_npu/src/common/src/igraph.cpp b/src/plugins/intel_npu/src/common/src/igraph.cppindex 2b16038ad8f..c916efe89f9 100644--- a/src/plugins/intel_npu/src/common/src/igraph.cpp+++ b/src/plugins/intel_npu/src/common/src/igraph.cpp@@ -50,11 +50,11 @@ void IGraph::update_network_name(std::string_view) {OPENVINO_THROW("update_network_name not implemented");}-const std::shared_ptr<CommandQueue>& IGraph::get_command_queue() const {- OPENVINO_THROW("get_command_queue not implemented");+CommandQueueDesc IGraph::get_command_queue_desc() const {+ OPENVINO_THROW("get_command_queue_desc not implemented");}-void IGraph::set_workload_type(const ov::WorkloadType) const {+void IGraph::set_workload_type(const ov::WorkloadType) {OPENVINO_THROW("set_workload_type not implemented");}diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hppindex 5ca8f99baac..2cda38aaaa6 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp@@ -6,6 +6,8 @@#include <ze_graph_ext.h>+#include <mutex>+#include "intel_npu/common/idynamic_graph.hpp"#include "intel_npu/network_metadata.hpp"#include "intel_npu/utils/zero/zero_init.hpp"@@ -125,9 +127,8 @@ public:void update_network_name(std::string_view name) override;- const std::shared_ptr<CommandQueue>& get_command_queue() const override;-- void set_workload_type(const ov::WorkloadType workloadType) const override;+ CommandQueueDesc get_command_queue_desc() const override;+ void set_workload_type(const ov::WorkloadType workloadType) override;void set_batch_size(std::size_t batch) override;@@ -170,8 +171,8 @@ private:*/uint64_t _num_of_subgraphs = 1;- mutable std::mutex _commandQueueMutex;- std::shared_ptr<CommandQueue> _commandQueue;+ mutable std::mutex _commandQueueDescMutex;+ CommandQueueDesc _commandQueueDesc;std::vector<std::shared_ptr<Event>> _lastSubmittedEvent;std::optional<ov::Tensor> _blob;diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hppindex 482c269a737..c65976e33d1 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp@@ -8,6 +8,8 @@#include <ze_graph_ext.h>+#include <mutex>+#include "intel_npu/common/igraph.hpp"#include "intel_npu/utils/zero/zero_init.hpp"#include "openvino/runtime/so_ptr.hpp"@@ -40,9 +42,8 @@ public:void update_network_name(std::string_view name) override;- const std::shared_ptr<CommandQueue>& get_command_queue() const override;-- void set_workload_type(const ov::WorkloadType workloadType) const override;+ CommandQueueDesc get_command_queue_desc() const override;+ void set_workload_type(const ov::WorkloadType workloadType) override;void set_last_submitted_event(const std::shared_ptr<Event>& event, size_t indexOfCommandList) override;const std::shared_ptr<Event>& get_last_submitted_event(size_t indexOfCommandList) const override;@@ -72,8 +73,8 @@ protected:GraphDescriptor _graphDesc;NetworkMetadata _metadata;- mutable std::mutex _commandQueueMutex;- std::shared_ptr<CommandQueue> _commandQueue;+ mutable std::mutex _commandQueueDescMutex;+ CommandQueueDesc _commandQueueDesc;std::vector<std::shared_ptr<Event>> _lastSubmittedEvent;std::optional<ov::Tensor> _blob;diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hppindex 2252a0b6993..66377944a6b 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp@@ -4,7 +4,6 @@#pragma once-#include <ze_api.h>#include <ze_graph_ext.h>#include <memory>diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cppindex 5d624950eff..1e51009a2c8 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp@@ -13,6 +13,7 @@#include "intel_npu/prefix.hpp"#include "intel_npu/utils/utils.hpp"#include "intel_npu/utils/zero/zero_api.hpp"+#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"#include "openvino/runtime/make_tensor.hpp"namespace intel_npu {@@ -489,29 +490,26 @@ void DynamicGraph::update_network_name(std::string_view name) {_metadata.name = name;}-const std::shared_ptr<CommandQueue>& DynamicGraph::get_command_queue() const {- return _commandQueue;+CommandQueueDesc DynamicGraph::get_command_queue_desc() const {+ std::lock_guard<std::mutex> lock(_commandQueueDescMutex);+ return _commandQueueDesc;}-void DynamicGraph::set_workload_type(const ov::WorkloadType workloadType) const {- std::lock_guard<std::mutex> lock(_commandQueueMutex);- if (_commandQueue == nullptr) {+void DynamicGraph::set_workload_type(const ov::WorkloadType workloadType) {+ if (_zeroInitStruct == nullptr) {return;}- ze_command_queue_workload_type_t zeWorkloadType;- switch (workloadType) {- case ov::WorkloadType::DEFAULT:- zeWorkloadType = ze_command_queue_workload_type_t::ZE_WORKLOAD_TYPE_DEFAULT;- break;- case ov::WorkloadType::EFFICIENT:- zeWorkloadType = ze_command_queue_workload_type_t::ZE_WORKLOAD_TYPE_BACKGROUND;- break;- default:- OPENVINO_THROW("Unknown value for WorkloadType!");+ std::lock_guard<std::mutex> lock(_commandQueueDescMutex);+ auto zeWorkloadType = zeroUtils::toZeQueueWorkloadType(workloadType);+ if (_commandQueueDesc.workload == zeWorkloadType) {+ return;}+ _commandQueueDesc.workload = zeWorkloadType;- _commandQueue->setWorkloadType(zeWorkloadType);+ const ZeroCmdQueueKey key{_zeroInitStruct->getContext(), _zeroInitStruct->getDevice(), _commandQueueDesc};+ const auto queueKeyHash = ZeroCmdQueueKeyHash{}(key);+ _commandQueueDesc.key = static_cast<uint64_t>(queueKeyHash);}void DynamicGraph::set_argument_value(uint32_t argi, const void* argv) const {@@ -554,34 +552,39 @@ void DynamicGraph::initialize_impl(const FilteredConfig& config) {return;}- if (_commandQueue == nullptr) {- _logger.debug("Graph initialize without graph handle");+ _logger.debug("Graph initialize without graph handle");- uint32_t commandQueueOptions = 0;- if (config.has<TURBO>() && config.get<TURBO>()) {- OPENVINO_ASSERT(_zeroInitStruct->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 0),- "Turbo is not supported by the current driver");- commandQueueOptions = commandQueueOptions | ZE_NPU_COMMAND_QUEUE_OPTION_TURBO;- }- OPENVINO_ASSERT(!(_zeroInitStruct->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&- config.has<RUN_INFERENCES_SEQUENTIALLY>() && config.get<RUN_INFERENCES_SEQUENTIALLY>()),+ uint32_t commandQueueOptions = 0;+ if (config.has<TURBO>() && config.get<TURBO>()) {+ OPENVINO_ASSERT(_zeroInitStruct->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 0),+ "Turbo is not supported by the current driver");+ _logger.debug("Set ZE_NPU_COMMAND_QUEUE_OPTION_TURBO in command queue options");+ commandQueueOptions = commandQueueOptions | ZE_NPU_COMMAND_QUEUE_OPTION_TURBO;+ }+ if (config.has<RUN_INFERENCES_SEQUENTIALLY>() && config.get<RUN_INFERENCES_SEQUENTIALLY>()) {+ OPENVINO_ASSERT(_zeroInitStruct->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 1),"Running inferences sequentially is not supported by the current driver");+ _logger.debug("Set ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC in command queue options");+ commandQueueOptions = commandQueueOptions | ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC;+ }- {- std::lock_guard<std::mutex> lock(_commandQueueMutex);- _commandQueue = std::make_shared<CommandQueue>(_zeroInitStruct,- zeroUtils::toZeQueuePriority(config.get<MODEL_PRIORITY>()),- commandQueueOptions);- }+ {+ std::lock_guard<std::mutex> lock(_commandQueueDescMutex);+ _commandQueueDesc = CommandQueueDesc{+ zeroUtils::toZeQueuePriority(config.get<MODEL_PRIORITY>()),+ config.has<WORKLOAD_TYPE>() ? zeroUtils::toZeQueueWorkloadType(config.get<WORKLOAD_TYPE>()) : std::nullopt,+ commandQueueOptions,+ this,+ config.get<SHARED_COMMON_QUEUE>()};- if (config.has<WORKLOAD_TYPE>()) {- set_workload_type(config.get<WORKLOAD_TYPE>());- }+ const ZeroCmdQueueKey key{_zeroInitStruct->getContext(), _zeroInitStruct->getDevice(), _commandQueueDesc};+ const auto queueKeyHash = ZeroCmdQueueKeyHash{}(key);+ _commandQueueDesc.key = static_cast<uint64_t>(queueKeyHash);+ }- _logger.debug("Graph initialize finish");+ _logger.debug("Graph initialize finish");- _batchSize = determine_batch_size();- }+ _batchSize = determine_batch_size();// To ensure that the initialization of the graph does not exit prematurely due to nullptrs_init_completed.store(true, std::memory_order_release);@@ -668,10 +671,6 @@ DynamicGraph::~DynamicGraph() {if (!_lastSubmittedEvent.empty()) {_lastSubmittedEvent.clear();}-- if (_commandQueue != nullptr) {- _commandQueue.reset();- }}void DynamicGraph::execute(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct,diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cppindex 8046526edd1..abe10558a74 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp@@ -10,6 +10,7 @@#include "intel_npu/config/options.hpp"#include "intel_npu/utils/utils.hpp"#include "intel_npu/utils/zero/zero_api.hpp"+#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"#include "openvino/runtime/make_tensor.hpp"namespace intel_npu {@@ -49,29 +50,26 @@ void Graph::update_network_name(std::string_view name) {_metadata.name = name;}-const std::shared_ptr<CommandQueue>& Graph::get_command_queue() const {- return _commandQueue;+CommandQueueDesc Graph::get_command_queue_desc() const {+ std::lock_guard<std::mutex> lock(_commandQueueDescMutex);+ return _commandQueueDesc;}-void Graph::set_workload_type(const ov::WorkloadType workloadType) const {- std::lock_guard<std::mutex> lock(_commandQueueMutex);- if (_commandQueue == nullptr) {+void Graph::set_workload_type(const ov::WorkloadType workloadType) {+ if (_zeroInitStruct == nullptr) {return;}- ze_command_queue_workload_type_t zeWorkloadType;- switch (workloadType) {- case ov::WorkloadType::DEFAULT:- zeWorkloadType = ze_command_queue_workload_type_t::ZE_WORKLOAD_TYPE_DEFAULT;- break;- case ov::WorkloadType::EFFICIENT:- zeWorkloadType = ze_command_queue_workload_type_t::ZE_WORKLOAD_TYPE_BACKGROUND;- break;- default:- OPENVINO_THROW("Unknown value for WorkloadType!");+ std::lock_guard<std::mutex> lock(_commandQueueDescMutex);+ auto zeWorkloadType = zeroUtils::toZeQueueWorkloadType(workloadType);+ if (_commandQueueDesc.workload == zeWorkloadType) {+ return;}+ _commandQueueDesc.workload = zeWorkloadType;- _commandQueue->setWorkloadType(zeWorkloadType);+ const ZeroCmdQueueKey key{_zeroInitStruct->getContext(), _zeroInitStruct->getDevice(), _commandQueueDesc};+ const auto queueKeyHash = ZeroCmdQueueKeyHash{}(key);+ _commandQueueDesc.key = static_cast<uint64_t>(queueKeyHash);}ze_graph_handle_t Graph::get_handle() const {@@ -180,14 +178,18 @@ void Graph::initialize_impl(const FilteredConfig& config) {}{- std::lock_guard<std::mutex> lock(_commandQueueMutex);- _commandQueue = std::make_shared<CommandQueue>(_zeroInitStruct,- zeroUtils::toZeQueuePriority(config.get<MODEL_PRIORITY>()),- commandQueueOptions);- }-- if (config.has<WORKLOAD_TYPE>()) {- set_workload_type(config.get<WORKLOAD_TYPE>());+ std::lock_guard<std::mutex> lock(_commandQueueDescMutex);+ _commandQueueDesc = CommandQueueDesc{+ zeroUtils::toZeQueuePriority(config.get<MODEL_PRIORITY>()),+ config.has<WORKLOAD_TYPE>() ? zeroUtils::toZeQueueWorkloadType(config.get<WORKLOAD_TYPE>()) : std::nullopt,+ commandQueueOptions,+ this,+ config.get<SHARED_COMMON_QUEUE>(),+ };++ const ZeroCmdQueueKey key{_zeroInitStruct->getContext(), _zeroInitStruct->getDevice(), _commandQueueDesc};+ const auto queueKeyHash = ZeroCmdQueueKeyHash{}(key);+ _commandQueueDesc.key = static_cast<uint64_t>(queueKeyHash);}_zeGraphExt->initializeGraph(_graphDesc);@@ -340,10 +342,6 @@ Graph::~Graph() {if (!_lastSubmittedEvent.empty()) {_lastSubmittedEvent.clear();}-- if (_commandQueue != nullptr) {- _commandQueue.reset();- }}} // namespace intel_npudiff --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 21aaaced8de..1dcb96ffa4e 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@@ -12,6 +12,7 @@#include "intel_npu/config/options.hpp"#include "intel_npu/prefix.hpp"#include "intel_npu/utils/utils.hpp"+#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"#include "openvino/core/memory_util.hpp"#include "openvino/core/model.hpp"#include "openvino/core/rt_info/weightless_caching_attributes.hpp"@@ -313,23 +314,13 @@ void WeightlessGraph::initialize_impl(const FilteredConfig& config) {commandQueueOptions = commandQueueOptions | ZE_NPU_COMMAND_QUEUE_OPTION_TURBO;}}-- _initsCommandQueue = std::make_shared<CommandQueue>(_zeroInitStruct,- zeroUtils::toZeQueuePriority(config.get<MODEL_PRIORITY>()),- commandQueueOptions);-- if (config.has<WORKLOAD_TYPE>()) {- switch (config.get<WORKLOAD_TYPE>()) {- case ov::WorkloadType::DEFAULT:- _initsCommandQueue->setWorkloadType(ze_command_queue_workload_type_t::ZE_WORKLOAD_TYPE_DEFAULT);- break;- case ov::WorkloadType::EFFICIENT:- _initsCommandQueue->setWorkloadType(ze_command_queue_workload_type_t::ZE_WORKLOAD_TYPE_BACKGROUND);- break;- default:- OPENVINO_THROW("Unknown value for WorkloadType!");- }- }+ CommandQueueDesc commandQueueDesc{+ zeroUtils::toZeQueuePriority(config.get<MODEL_PRIORITY>()),+ config.has<WORKLOAD_TYPE>() ? zeroUtils::toZeQueueWorkloadType(config.get<WORKLOAD_TYPE>()) : std::nullopt,+ commandQueueOptions,+ this,+ config.get<SHARED_COMMON_QUEUE>()};+ _initsCommandQueue = ZeroCmdQueuePool::getInstance().getCommandQueue(_zeroInitStruct, commandQueueDesc);#if USE_SINGLE_THREADED_RUN_INITrun_init_single_threaded();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 82c916b8396..5032e16e399 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@@ -9,6 +9,7 @@#include "intel_npu/prefix.hpp"#include "intel_npu/utils/utils.hpp"#include "intel_npu/utils/zero/zero_api.hpp"+#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"#include "intel_npu/utils/zero/zero_result.hpp"#include "intel_npu/utils/zero/zero_utils.hpp"#include "intel_npu/utils/zero/zero_wrappers.hpp"@@ -276,9 +277,9 @@ void ZeGraphExtWrappers::initializeGraph(const GraphDescriptor& graphDescriptor)void ZeGraphExtWrappers::initializeGraphThroughCommandList(ze_graph_handle_t graphHandle) const {_logger.debug("initializeGraphThroughCommandList init start - create graphCommandList");CommandList graphCommandList(_zeroInitStruct);- _logger.debug("initializeGraphThroughCommandList - create graphCommandQueue");- std::shared_ptr<CommandQueue> graphCommandQueue =- std::make_shared<CommandQueue>(_zeroInitStruct, ZE_COMMAND_QUEUE_PRIORITY_NORMAL, false);+ _logger.debug("initializeGraphThroughCommandList - get commandQueue");+ const auto graphCommandQueue = ZeroCmdQueuePool::getInstance().getCommandQueue(_zeroInitStruct, CommandQueueDesc{});+_logger.debug("initializeGraphThroughCommandList - create fence");Fence fence(graphCommandQueue);diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cppindex 75c0e82d5b6..a552dd6a160 100644--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp@@ -258,6 +258,7 @@ void init_config(const IEngineBackend* backend, OptionsDesc& options, FilteredCoREGISTER_OPTION(WS_COMPILE_CALL_NUMBER);REGISTER_OPTION(MODEL_SERIALIZER_VERSION);REGISTER_OPTION(ENABLE_STRIDES_FOR);+ REGISTER_OPTION(SHARED_COMMON_QUEUE);if (backend) {if (backend->isCommandQueueExtSupported()) {diff --git a/src/plugins/intel_npu/src/plugin/src/properties.cpp b/src/plugins/intel_npu/src/plugin/src/properties.cppindex d7c2f256dd5..a9d3590cca5 100644--- a/src/plugins/intel_npu/src/plugin/src/properties.cpp+++ b/src/plugins/intel_npu/src/plugin/src/properties.cpp@@ -557,6 +557,7 @@ void Properties::registerPluginProperties() {TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::model_serializer_version, MODEL_SERIALIZER_VERSION);TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::enable_strides_for, ENABLE_STRIDES_FOR);TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::disable_idle_memory_prunning, DISABLE_IDLE_MEMORY_PRUNING);+ TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::shared_common_queue, SHARED_COMMON_QUEUE);TRY_REGISTER_CUSTOMFUNC_PROPERTY(ov::intel_npu::stepping, STEPPING, [&](const Config& config) {if (!config.has<STEPPING>()) {@@ -759,6 +760,7 @@ void Properties::registerCompiledModelProperties() {TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::enable_strides_for, ENABLE_STRIDES_FOR);TRY_REGISTER_VARPUB_PROPERTY(ov::intel_npu::batch_mode, BATCH_MODE, false);+ TRY_REGISTER_VARPUB_PROPERTY(ov::intel_npu::shared_common_queue, SHARED_COMMON_QUEUE, false);TRY_REGISTER_CUSTOM_PROPERTY(ov::workload_type,WORKLOAD_TYPE,diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_cmd_queue_pool.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_cmd_queue_pool.hppnew file mode 100644index 00000000000..024e4caffe4--- /dev/null+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_cmd_queue_pool.hpp@@ -0,0 +1,84 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <ze_api.h>+#include <ze_command_queue_npu_ext.h>++#include <memory>+#include <mutex>+#include <unordered_map>++#include "intel_npu/utils/zero/zero_wrappers.hpp"++namespace intel_npu {++/// Fully-qualified key that uniquely identifies a CommandQueue configuration.+struct ZeroCmdQueueKey {+ ze_context_handle_t context = nullptr;+ ze_device_handle_t device = nullptr;+ CommandQueueDesc desc;++ bool operator==(const ZeroCmdQueueKey& other) const {+ if (context != other.context || device != other.device) {+ return false;+ }+ return desc == other.desc;+ }+};++struct ZeroCmdQueueKeyHash {+ size_t operator()(const ZeroCmdQueueKey& key) const {+ // Initial 64-bit seed for deterministic key mixing.+ static constexpr uint64_t kFnvOffsetBasis64 = 1469598103934665603ULL;+ // 64-bit golden-ratio constant used by boost-style hash combine.+ static constexpr uint64_t kHashCombineConstant64 = 0x9e3779b97f4a7c15ULL;++ uint64_t hash = kFnvOffsetBasis64;+ const auto hash_combine = [&hash](const uint64_t value) {+ // Mix each field into the running hash; suitable for unordered_map use.+ hash ^= value + kHashCombineConstant64 + (hash << 6) + (hash >> 2);+ };+ hash_combine(std::hash<void*>{}(key.context));+ hash_combine(std::hash<void*>{}(key.device));+ hash_combine(static_cast<uint64_t>(key.desc.priority));+ if (key.desc.workload.has_value()) {+ hash_combine(1ULL);+ hash_combine(static_cast<uint64_t>(key.desc.workload.value()));+ } else {+ hash_combine(0ULL);+ }+ hash_combine(static_cast<uint64_t>(key.desc.options));+ if (key.desc.options & ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC || !key.desc.shared_common_queue) {+ OPENVINO_ASSERT(key.desc.owner_tag != nullptr,+ "owner_tag must not be null when ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC is set");+ hash_combine(std::hash<const void*>{}(key.desc.owner_tag));+ }++ return static_cast<size_t>(hash);+ }+};++class ZeroCmdQueuePool : public std::enable_shared_from_this<ZeroCmdQueuePool> {+public:+ ZeroCmdQueuePool(const ZeroCmdQueuePool& other) = delete;+ ZeroCmdQueuePool(ZeroCmdQueuePool&& other) = delete;+ void operator=(const ZeroCmdQueuePool&) = delete;+ void operator=(ZeroCmdQueuePool&&) = delete;++ static ZeroCmdQueuePool& getInstance();++ std::shared_ptr<CommandQueue> getCommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,+ const CommandQueueDesc& command_queue_desc);++private:+ ZeroCmdQueuePool();++ std::unordered_map<ZeroCmdQueueKey, std::weak_ptr<CommandQueue>, ZeroCmdQueueKeyHash> _pool;++ std::mutex _mutex;+};++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_mem_pool.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_mem_pool.hppindex 5600c26fe73..5140e4e19cf 100644--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_mem_pool.hpp+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_mem_pool.hpp@@ -21,7 +21,6 @@ namespace intel_npu {*/class ZeroMemPool final {public:- ZeroMemPool();ZeroMemPool(const ZeroMemPool& other) = delete;ZeroMemPool(ZeroMemPool&& other) = delete;void operator=(const ZeroMemPool&) = delete;@@ -71,6 +70,8 @@ public:const bool is_input = false);private:+ ZeroMemPool();+std::shared_ptr<ZeroMem> import_standard_allocation(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,const void* data,const size_t bytes,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 c20e613b2fc..c906b1f1b89 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@@ -66,6 +66,17 @@ static inline ze_command_queue_priority_t toZeQueuePriority(const ov::hint::Prio}}+static inline std::optional<ze_command_queue_workload_type_t> toZeQueueWorkloadType(const ov::WorkloadType val) {+ switch (val) {+ case ov::WorkloadType::DEFAULT:+ return std::optional<ze_command_queue_workload_type_t>{ZE_WORKLOAD_TYPE_DEFAULT};+ case ov::WorkloadType::EFFICIENT:+ return std::optional<ze_command_queue_workload_type_t>{ZE_WORKLOAD_TYPE_BACKGROUND};+ default:+ OPENVINO_THROW("Incorrect workload type.");+ }+}+static inline ov::element::Type_t toOVElementType(const ze_graph_argument_precision_t zeElementType) {switch (zeElementType) {case ZE_GRAPH_ARGUMENT_PRECISION_UNKNOWN:diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_wrappers.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_wrappers.hppindex 492696aef38..f74a220b0da 100644--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_wrappers.hpp+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_wrappers.hpp@@ -5,6 +5,9 @@#pragma once#include <ze_api.h>+#include <ze_command_queue_npu_ext.h>++#include <optional>#include "intel_npu/utils/logger/logger.hpp"#include "intel_npu/utils/zero/zero_init.hpp"@@ -15,6 +18,34 @@ namespace intel_npu {class CommandList;class CommandQueue;+struct CommandQueueDesc {+ ze_command_queue_priority_t priority = ZE_COMMAND_QUEUE_PRIORITY_NORMAL;+ std::optional<ze_command_queue_workload_type_t> workload = std::nullopt;+ uint32_t options = 0;+ const void* owner_tag = nullptr;+ bool shared_common_queue = true;+ uint64_t key = 0;++ bool operator==(const CommandQueueDesc& other) const {+ if (priority != other.priority || workload != other.workload || options != other.options ||+ shared_common_queue != other.shared_common_queue) {+ return false;+ }+ // pointer is only meaningful when the device-sync flag is active+ const bool use_owner_tag = (options & ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC) != 0 || !shared_common_queue;+ const bool other_use_owner_tag =+ (other.options & ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC) != 0 || !other.shared_common_queue;+ if (use_owner_tag || other_use_owner_tag) {+ // when owner_tag participates in the key, require it to be non-null and equal on both sides+ if (owner_tag == nullptr || other.owner_tag == nullptr || owner_tag != other.owner_tag) {+ return false;+ }+ }++ return true;+ }+};+class EventPool {public:EventPool() = delete;@@ -121,9 +152,7 @@ private:class CommandQueue {public:CommandQueue() = delete;- CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,- const ze_command_queue_priority_t& priority,- const uint32_t command_queue_options = 0);+ CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& init_structs, const CommandQueueDesc& desc);CommandQueue(const CommandQueue&) = delete;CommandQueue(CommandQueue&&) = delete;CommandQueue& operator=(const CommandQueue&) = delete;@@ -131,15 +160,19 @@ public:void executeCommandList(CommandList& command_list) const;void executeCommandList(CommandList& command_list, Fence& fence) const;- void setWorkloadType(ze_command_queue_workload_type_t workloadType) const;~CommandQueue();inline ze_command_queue_handle_t handle() const {return _handle;}+ inline CommandQueueDesc desc() const {+ return _desc;+ }private:std::shared_ptr<ZeroInitStructsHolder> _init_structs;+ CommandQueueDesc _desc;+Logger _log;ze_command_queue_handle_t _handle = nullptr;diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_cmd_queue_pool.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_cmd_queue_pool.cppnew file mode 100644index 00000000000..96fb9762f2e--- /dev/null+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_cmd_queue_pool.cpp@@ -0,0 +1,57 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"++#include "intel_npu/utils/zero/zero_utils.hpp"++namespace intel_npu {++ZeroCmdQueuePool::ZeroCmdQueuePool() {}++ZeroCmdQueuePool& ZeroCmdQueuePool::getInstance() {+ // Use a shared_ptr so the pool is properly destroyed at static teardown.+ // CommandQueue deleters hold a weak_ptr and gracefully skip cleanup if the+ // pool is already gone (static-destruction-order safety without leaking).+ static std::shared_ptr<ZeroCmdQueuePool> instance{new ZeroCmdQueuePool()};+ return *instance;+}++std::shared_ptr<CommandQueue> ZeroCmdQueuePool::getCommandQueue(+ const std::shared_ptr<ZeroInitStructsHolder>& init_structs,+ const CommandQueueDesc& command_queue_desc) {+ ZeroCmdQueueKey key{init_structs->getContext(), init_structs->getDevice(), command_queue_desc};++ std::lock_guard<std::mutex> lock(_mutex);+ auto it = _pool.find(key);+ if (it != _pool.end()) {+ auto obj = it->second.lock();+ if (obj) {+ return obj;+ }+ }++ auto weak_self = weak_from_this();+ auto new_obj = std::shared_ptr<CommandQueue>(new CommandQueue(init_structs, command_queue_desc),+ [weak_self, key](CommandQueue* ptr) {+ if (auto pool = weak_self.lock()) {+ std::lock_guard<std::mutex> lock(pool->_mutex);+ // Only erase if the slot still refers to the now-expired+ // object. If another thread already replaced the entry with a+ // new live object, lock() will return non-null and we must+ // leave that entry alone.+ auto it = pool->_pool.find(key);+ if (it != pool->_pool.end() && !it->second.lock()) {+ pool->_pool.erase(it);+ }+ }+ delete ptr;+ });++ _pool.insert_or_assign(key, new_obj);++ return new_obj;+}++} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cppindex ad4f699d8e3..eb03a8eb50e 100644--- a/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp@@ -71,29 +71,40 @@ CommandList::CommandList(const std::shared_ptr<ZeroInitStructsHolder>& init_stru"zeCommandListCreate",zeCommandListCreate(_init_structs->getContext(), _init_structs->getDevice(), &desc, &_handle));- uint32_t mutable_command_list_ext_version = _init_structs->getMutableCommandListExtVersion();- if (mutable_command_list_ext_version >= ZE_MAKE_VERSION(1, 0)) {- ze_mutable_command_id_exp_desc_t mutable_cmd_id_desc = {};-- mutable_cmd_id_desc.stype = ZE_STRUCTURE_TYPE_MUTABLE_COMMAND_ID_EXP_DESC;-- if (mutable_command_list_ext_version >= ZE_MAKE_VERSION(1, 1)) {- mutable_cmd_id_desc.flags = ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENTS;- } else {- mutable_cmd_id_desc.flags = ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED;- };-- auto result = zeCommandListGetNextCommandIdExp(_handle, &mutable_cmd_id_desc, &_command_id);- if (result == ZE_RESULT_ERROR_INVALID_ENUMERATION) {- // If ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENTS is not supported by the driver, try again with- // ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED- mutable_cmd_id_desc.flags = ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED;-- THROW_ON_FAIL_FOR_LEVELZERO("zeCommandListGetNextCommandIdExp",- zeCommandListGetNextCommandIdExp(_handle, &mutable_cmd_id_desc, &_command_id))- } else {- THROW_ON_FAIL_FOR_LEVELZERO("zeCommandListGetNextCommandIdExp", result)+ try {+ uint32_t mutable_command_list_ext_version = _init_structs->getMutableCommandListExtVersion();+ if (mutable_command_list_ext_version >= ZE_MAKE_VERSION(1, 0)) {+ ze_mutable_command_id_exp_desc_t mutable_cmd_id_desc = {};++ mutable_cmd_id_desc.stype = ZE_STRUCTURE_TYPE_MUTABLE_COMMAND_ID_EXP_DESC;++ if (mutable_command_list_ext_version >= ZE_MAKE_VERSION(1, 1)) {+ mutable_cmd_id_desc.flags = ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENTS;+ } else {+ mutable_cmd_id_desc.flags = ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED;+ };++ auto result = zeCommandListGetNextCommandIdExp(_handle, &mutable_cmd_id_desc, &_command_id);+ if (result == ZE_RESULT_ERROR_INVALID_ENUMERATION) {+ // If ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENTS is not supported by the driver, try again with+ // ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED+ mutable_cmd_id_desc.flags = ZE_MUTABLE_COMMAND_EXP_FLAG_GRAPH_ARGUMENT_DEPRECATED;++ THROW_ON_FAIL_FOR_LEVELZERO(+ "zeCommandListGetNextCommandIdExp",+ zeCommandListGetNextCommandIdExp(_handle, &mutable_cmd_id_desc, &_command_id));+ } else {+ THROW_ON_FAIL_FOR_LEVELZERO("zeCommandListGetNextCommandIdExp", result);+ }+ }+ } catch (...) {+ auto result = zeCommandListDestroy(_handle);+ _handle = nullptr;+ if (ZE_RESULT_SUCCESS != result) {+ _log.error("zeCommandListDestroy failed %#X", uint64_t(result));}++ throw;}}void CommandList::reset() const {@@ -192,38 +203,55 @@ void CommandList::updateMutableCommandListWithStrides(uint32_t index,zeCommandListUpdateMutableCommandsExp(_handle, &mutable_commands_exp_desc_t));}-CommandQueue::CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,- const ze_command_queue_priority_t& priority,- const uint32_t command_queue_options)+CommandQueue::CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& init_structs, const CommandQueueDesc& desc): _init_structs(init_structs),+ _desc(desc),_log("CommandQueue", Logger::global().level()) {- ze_command_queue_desc_t queue_desc = {ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC,- nullptr,- _init_structs->getCommandQueueGroupOrdinal(),- 0,- 0,- ZE_COMMAND_QUEUE_MODE_DEFAULT,- priority};+ ze_command_queue_desc_t ze_queue_desc = {ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC,+ nullptr,+ _init_structs->getCommandQueueGroupOrdinal(),+ 0,+ 0,+ ZE_COMMAND_QUEUE_MODE_DEFAULT,+ _desc.priority};ze_command_queue_desc_npu_ext_t turbo_cfg = {};ze_command_queue_desc_npu_ext_2_t command_queue_desc = {};- if (command_queue_options) {+ if (_desc.options) {if (_init_structs->getCommandQueueDdiTable().version() == ZE_MAKE_VERSION(1, 0)) {turbo_cfg.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC_NPU_EXT;- turbo_cfg.turbo = command_queue_options & ZE_NPU_COMMAND_QUEUE_OPTION_TURBO;-- queue_desc.pNext = &turbo_cfg;+ turbo_cfg.turbo = _desc.options & ZE_NPU_COMMAND_QUEUE_OPTION_TURBO;+ ze_queue_desc.pNext = &turbo_cfg;} else if (_init_structs->getCommandQueueDdiTable().version() > ZE_MAKE_VERSION(1, 0)) {command_queue_desc.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC_NPU_EXT_2;- command_queue_desc.options = command_queue_options;-- queue_desc.pNext = &command_queue_desc;+ command_queue_desc.options = _desc.options;+ ze_queue_desc.pNext = &command_queue_desc;}}THROW_ON_FAIL_FOR_LEVELZERO("zeCommandQueueCreate",- zeCommandQueueCreate(_init_structs->getContext(), _init_structs->getDevice(), &queue_desc, &_handle));+ zeCommandQueueCreate(_init_structs->getContext(), _init_structs->getDevice(), &ze_queue_desc, &_handle));++ if (_desc.workload.has_value()) {+ try {+ if (_init_structs->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 0)) {+ THROW_ON_FAIL_FOR_LEVELZERO(+ "zeSetWorkloadType",+ _init_structs->getCommandQueueDdiTable().pfnSetWorkloadType(_handle, _desc.workload.value()));+ } else {+ OPENVINO_THROW("The WorkloadType property is not supported by the current Driver Version!");+ }+ } catch (...) {+ auto result = zeCommandQueueDestroy(_handle);+ _handle = nullptr;+ if (ZE_RESULT_SUCCESS != result) {+ _log.error("zeCommandQueueDestroy failed %#X", uint64_t(result));+ }++ throw;+ }+ }}void CommandQueue::executeCommandList(CommandList& command_list) const {THROW_ON_FAIL_FOR_LEVELZERO("zeCommandQueueExecuteCommandLists",@@ -233,16 +261,6 @@ void CommandQueue::executeCommandList(CommandList& command_list, Fence& fence) cTHROW_ON_FAIL_FOR_LEVELZERO("zeCommandQueueExecuteCommandLists",zeCommandQueueExecuteCommandLists(_handle, 1, &command_list._handle, fence.handle()));}--void CommandQueue::setWorkloadType(ze_command_queue_workload_type_t workloadType) const {- if (_init_structs->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 0)) {- THROW_ON_FAIL_FOR_LEVELZERO("zeSetWorkloadType",- _init_structs->getCommandQueueDdiTable().pfnSetWorkloadType(_handle, workloadType));- } else {- OPENVINO_THROW("The WorkloadType property is not supported by the current Driver Version!");- }-}-CommandQueue::~CommandQueue() {auto result = zeCommandQueueDestroy(_handle);if (ZE_RESULT_SUCCESS != result) {diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer.hpp b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer.hppindex 4586c7cea34..cf330226e3f 100644--- a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer.hpp+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/compile_and_infer.hpp@@ -7,6 +7,7 @@#include <gtest/gtest.h>#include <algorithm>+#include <chrono>#include <common_test_utils/test_assertions.hpp>#include <exception>#include <mutex>@@ -15,6 +16,7 @@#include <vector>#include "common_test_utils/ov_tensor_utils.hpp"+#include "intel_npu/npu_private_properties.hpp"#include "intel_npu/utils/zero/zero_init.hpp"#include "openvino/core/except.hpp"#include "openvino/opsets/opset8.hpp"@@ -301,6 +303,172 @@ TEST_P(OVCompileAndInferRequestMultiThreading, CreateInferRequestsAndRunOnDiffer}}+TEST_P(OVCompileAndInferRequestMultiThreading, CreateInferRequestsAndRunOnDifferentThreadsWithWorkloadType) {+ if (!isCommandQueueExtSupported()) {+ GTEST_SKIP() << "Workload type update is not supported with current driver.\n";+ }++ configuration[intel_npu::defer_weights_load.name()] = true;+ OV_ASSERT_NO_THROW(execNet = core->compile_model(function, target_device, configuration));++ int num_threads = 32;+ std::vector<std::thread> threads;+ std::vector<std::exception_ptr> exceptions;+ std::mutex exceptions_mutex;++ for (int i = 0; i < num_threads; ++i) {+ threads.emplace_back([this, &exceptions, &exceptions_mutex, i]() {+ try {+ // Stagger threads to desynchronize property setting and expose race conditions+ std::this_thread::sleep_for(std::chrono::milliseconds(i % 10));+ if (i % 2 == 0) {+ execNet.set_property(ov::workload_type(WorkloadType::DEFAULT));+ } else {+ execNet.set_property(ov::workload_type(WorkloadType::EFFICIENT));+ }+ auto req = execNet.create_infer_request();+ req.infer();+ } catch (...) {+ std::lock_guard<std::mutex> lock(exceptions_mutex);+ exceptions.emplace_back(std::current_exception());+ }+ });+ }++ for (auto& thread : threads) {+ thread.join();+ }++ if (!exceptions.empty()) {+ try {+ std::rethrow_exception(exceptions.front());+ } catch (const std::exception& ex) {+ FAIL() << ex.what();+ } catch (...) {+ FAIL() << "Unknown exception occurred in one of the threads.";+ }+ }+}++TEST_P(OVCompileAndInferRequestMultiThreading,+ CompileModelCreateInferRequestsAndRunOnDifferentThreadsWithWorkloadType) {+ if (!isCommandQueueExtSupported()) {+ GTEST_SKIP() << "Workload type update is not supported with current driver.\n";+ }++ configuration[intel_npu::defer_weights_load.name()] = true;++ int num_threads = 32;+ std::vector<std::thread> threads;+ std::vector<std::exception_ptr> exceptions;+ std::vector<ov::CompiledModel> compiled_models(num_threads);+ std::mutex exceptions_mutex;++ for (int i = 0; i < num_threads; ++i) {+ threads.emplace_back([this, &exceptions, &exceptions_mutex, &compiled_models, i]() {+ try {+ compiled_models[i] = core->compile_model(function, target_device, configuration);+ // Stagger threads to desynchronize property setting and expose race conditions+ std::this_thread::sleep_for(std::chrono::milliseconds(i % 10));+ if (i % 2 == 0) {+ compiled_models[i].set_property(ov::workload_type(WorkloadType::DEFAULT));+ } else {+ compiled_models[i].set_property(ov::workload_type(WorkloadType::EFFICIENT));+ }+ auto req = compiled_models[i].create_infer_request();+ req.infer();+ } catch (...) {+ std::lock_guard<std::mutex> lock(exceptions_mutex);+ exceptions.emplace_back(std::current_exception());+ }+ });+ }++ for (auto& thread : threads) {+ thread.join();+ }++ if (!exceptions.empty()) {+ try {+ std::rethrow_exception(exceptions.front());+ } catch (const std::exception& ex) {+ FAIL() << ex.what();+ } catch (...) {+ FAIL() << "Unknown exception occurred in one of the threads.";+ }+ }++ for (int i = 0; i < num_threads; ++i) {+ if (i % 2 == 0) {+ ASSERT_EQ(compiled_models[i].get_property(ov::workload_type.name()).as<WorkloadType>(),+ WorkloadType::DEFAULT);+ } else {+ ASSERT_EQ(compiled_models[i].get_property(ov::workload_type.name()).as<WorkloadType>(),+ WorkloadType::EFFICIENT);+ }+ }+}++TEST_P(OVCompileAndInferRequestMultiThreading,+ CompileModelCreateInferRequestsAndRunOnDifferentThreadsWithWorkloadTypeAndSharedCommonQueueDisabled) {+ if (!isCommandQueueExtSupported()) {+ GTEST_SKIP() << "Workload type update is not supported with current driver.\n";+ }++ configuration[intel_npu::defer_weights_load.name()] = true;+ configuration[intel_npu::shared_common_queue.name()] = false;++ int num_threads = 32;+ std::vector<std::thread> threads;+ std::vector<std::exception_ptr> exceptions;+ std::vector<ov::CompiledModel> compiled_models(num_threads);+ std::mutex exceptions_mutex;++ for (int i = 0; i < num_threads; ++i) {+ threads.emplace_back([this, &exceptions, &exceptions_mutex, &compiled_models, i]() {+ try {+ compiled_models[i] = core->compile_model(function, target_device, configuration);+ // Stagger threads to desynchronize property setting and expose race conditions+ std::this_thread::sleep_for(std::chrono::milliseconds(i % 10));+ if (i % 2 == 0) {+ compiled_models[i].set_property(ov::workload_type(WorkloadType::DEFAULT));+ } else {+ compiled_models[i].set_property(ov::workload_type(WorkloadType::EFFICIENT));+ }+ auto req = compiled_models[i].create_infer_request();+ req.infer();+ } catch (...) {+ std::lock_guard<std::mutex> lock(exceptions_mutex);+ exceptions.emplace_back(std::current_exception());+ }+ });+ }++ for (auto& thread : threads) {+ thread.join();+ }++ if (!exceptions.empty()) {+ try {+ std::rethrow_exception(exceptions.front());+ } catch (const std::exception& ex) {+ FAIL() << ex.what();+ } catch (...) {+ FAIL() << "Unknown exception occurred in one of the threads.";+ }+ }++ for (int i = 0; i < num_threads; ++i) {+ if (i % 2 == 0) {+ ASSERT_EQ(compiled_models[i].get_property(ov::workload_type.name()).as<WorkloadType>(),+ WorkloadType::DEFAULT);+ } else {+ ASSERT_EQ(compiled_models[i].get_property(ov::workload_type.name()).as<WorkloadType>(),+ WorkloadType::EFFICIENT);+ }+ }+}+using OVCompileAndInferRequestTurbo = OVCompileAndInferRequest;TEST_P(OVCompileAndInferRequestTurbo, CompiledModelTurbo) {diff --git a/src/plugins/intel_npu/tests/functional/internal/plugin/test_properties.hpp b/src/plugins/intel_npu/tests/functional/internal/plugin/test_properties.hppindex 8a8127e915f..ebea7ac69b4 100644--- a/src/plugins/intel_npu/tests/functional/internal/plugin/test_properties.hpp+++ b/src/plugins/intel_npu/tests/functional/internal/plugin/test_properties.hpp@@ -170,6 +170,7 @@ public:REGISTER_OPTION(WS_COMPILE_CALL_NUMBER);REGISTER_OPTION(MODEL_SERIALIZER_VERSION);REGISTER_OPTION(ENABLE_STRIDES_FOR);+ REGISTER_OPTION(SHARED_COMMON_QUEUE);if (backend) {if (backend->isCommandQueueExtSupported()) {diff --git a/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_cmd_queue_pool_tests.cpp b/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_cmd_queue_pool_tests.cppnew file mode 100644index 00000000000..643e7c29766--- /dev/null+++ b/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_cmd_queue_pool_tests.cpp@@ -0,0 +1,14 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "internal/utils/zero/zero_cmd_queue_pool_tests.hpp"++#include "common/utils.hpp"++using namespace ov::test::behavior;++INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTest,+ ZeroCmdQueuePoolTests,+ ::testing::Values(ov::test::utils::DEVICE_NPU),+ ZeroCmdQueuePoolTests::getTestCaseName);diff --git a/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_cmd_queue_pool_tests.hpp b/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_cmd_queue_pool_tests.hppnew file mode 100644index 00000000000..8bd7dd63945--- /dev/null+++ b/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_cmd_queue_pool_tests.hpp@@ -0,0 +1,401 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <gmock/gmock-matchers.h>+#include <gmock/gmock.h>+#include <gtest/gtest.h>+#include <ze_api.h>+#include <ze_command_queue_npu_ext.h>++#include <algorithm>+#include <array>+#include <atomic>+#include <cstddef>+#include <exception>+#include <memory>+#include <mutex>+#include <random>+#include <sstream>+#include <thread>+#include <vector>++#include "common/npu_test_env_cfg.hpp"+#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"+#include "intel_npu/utils/zero/zero_init.hpp"+#include "intel_npu/utils/zero/zero_wrappers.hpp"+#include "shared_test_classes/base/ov_behavior_test_utils.hpp"++using ::testing::AllOf;+using ::testing::HasSubstr;++namespace ov {+namespace test {+namespace behavior {+class ZeroCmdQueuePoolTests : public ov::test::behavior::OVPluginTestBase,+ public testing::WithParamInterface<std::string> {+protected:+ ov::AnyMap configuration;+ std::shared_ptr<::intel_npu::ZeroInitStructsHolder> init_struct;++public:+ static std::string getTestCaseName(const testing::TestParamInfo<std::string>& obj) {+ std::string target_device;+ ov::AnyMap configuration;+ target_device = obj.param;+ std::replace(target_device.begin(), target_device.end(), ':', '_');++ std::ostringstream result;+ result << "targetDevice=" << target_device << "_";+ result << "targetPlatform=" << ov::test::utils::getTestsPlatformFromEnvironmentOr(target_device) << "_";+ if (!configuration.empty()) {+ for (auto& configItem : configuration) {+ result << "configItem=" << configItem.first << "_";+ configItem.second.print(result);+ }+ }++ return result.str();+ }++ void SetUp() override {+ target_device = this->GetParam();++ SKIP_IF_CURRENT_TEST_IS_DISABLED()+ OVPluginTestBase::SetUp();++ init_struct = ::intel_npu::ZeroInitStructsHolder::getInstance();+ }++ void TearDown() override {+ init_struct = nullptr;+ APIBaseTest::TearDown();+ }+};++TEST_P(ZeroCmdQueuePoolTests, SetWorkloadType) {+ ::intel_npu::CommandQueueDesc command_queue_desc{ZE_COMMAND_QUEUE_PRIORITY_NORMAL, ZE_WORKLOAD_TYPE_BACKGROUND};++ if (init_struct->getCommandQueueDdiTable().version() > 0) {+ OV_ASSERT_NO_THROW(+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc));+ } else {+ OV_EXPECT_THROW_HAS_SUBSTRING(+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc),+ ov::Exception,+ "The WorkloadType property is not supported by the current Driver Version!");+ }+}++TEST_P(ZeroCmdQueuePoolTests, PoolReusabilityTest) {+ // Test that the pool correctly reuses queues after weak_ptr cleanup+ ::intel_npu::CommandQueueDesc command_queue_desc{ZE_COMMAND_QUEUE_PRIORITY_NORMAL};++ // First allocation+ std::shared_ptr<::intel_npu::CommandQueue> queue1 =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc);+ EXPECT_NE(queue1, nullptr);++ // Second allocation with same descriptor should return the same instance (while ref is held)+ std::shared_ptr<::intel_npu::CommandQueue> queue2 =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc);+ EXPECT_EQ(queue1.get(), queue2.get()) << "Same descriptor should return pooled queue while alive";++ // Release first reference+ queue1.reset();++ std::shared_ptr<::intel_npu::CommandQueue> queue3 =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc);+ EXPECT_NE(queue3, nullptr) << "Should always be able to allocate a queue";+ EXPECT_EQ(queue2.get(), queue3.get()) << "Same descriptor should return pooled queue while alive";++ queue2.reset();+ queue3.reset();+}++TEST_P(ZeroCmdQueuePoolTests, PoolReusabilityDisabledTest) {+ // Test that the pool correctly reuses queues after weak_ptr cleanup+ int pointer1 = 1; // Just a dummy pointer value for testing+ ::intel_npu::CommandQueueDesc command_queue_desc1{ZE_COMMAND_QUEUE_PRIORITY_NORMAL,+ std::nullopt,+ 0,+ &pointer1,+ false};++ // First allocation+ std::shared_ptr<::intel_npu::CommandQueue> queue1 =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc1);+ EXPECT_NE(queue1, nullptr);++ int pointer2 = 2; // Just a dummy pointer value for testing+ ::intel_npu::CommandQueueDesc command_queue_desc2{ZE_COMMAND_QUEUE_PRIORITY_NORMAL,+ std::nullopt,+ 0,+ &pointer2,+ false};++ // Second allocation with same descriptor should return the same instance (while ref is held)+ std::shared_ptr<::intel_npu::CommandQueue> queue2 =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc2);+ EXPECT_NE(queue2, nullptr) << "Should always be able to allocate a queue";+ EXPECT_NE(queue1.get(), queue2.get()) << "Same descriptor with different owner_tag should not return the same "+ "pooled queue when shared_common_queue is false";++ int pointer3 = 3; // Just a dummy pointer value for testing+ ::intel_npu::CommandQueueDesc command_queue_desc3{ZE_COMMAND_QUEUE_PRIORITY_NORMAL,+ std::nullopt,+ 0,+ &pointer3,+ false};++ std::shared_ptr<::intel_npu::CommandQueue> queue3 =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc3);+ EXPECT_NE(queue3, nullptr) << "Should always be able to allocate a queue";+ EXPECT_NE(queue1.get(), queue3.get()) << "Same descriptor with different owner_tag should not return the same "+ "pooled queue when shared_common_queue is false";+ EXPECT_NE(queue2.get(), queue3.get()) << "Same descriptor with different owner_tag should not return the same "+ "pooled queue when shared_common_queue is false";++ queue1.reset();+ queue2.reset();+ queue3.reset();+}++TEST_P(ZeroCmdQueuePoolTests, AllCommandQueueOptionsCombinations) {+ if (init_struct->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1)) {+ GTEST_SKIP() << "Not all the command queue options are supported by the current driver.\n";+ }++ // Exhaustively test all combinations of command queue creation options+ std::vector<ze_command_queue_priority_t> priorities{ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW,+ ZE_COMMAND_QUEUE_PRIORITY_NORMAL,+ ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH};++ std::vector<_ze_command_queue_workload_type_t> workload_types{ZE_WORKLOAD_TYPE_DEFAULT,+ ZE_WORKLOAD_TYPE_BACKGROUND};++ std::vector<uint32_t> option_combinations{+ 0,+ ZE_NPU_COMMAND_QUEUE_OPTION_TURBO,+ ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC,+ ZE_NPU_COMMAND_QUEUE_OPTION_TURBO | ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC};++ int successful_allocations = 0;++ for (auto priority : priorities) {+ for (auto workload_type : workload_types) {+ for (auto options : option_combinations) {+ ::intel_npu::CommandQueueDesc cmd_desc{priority, workload_type, options};+ if (options & ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC) {+ static int owner = 1; // Just a dummy pointer value for testing+ cmd_desc.owner_tag = &owner;+ }+ auto cmd_queue = ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, cmd_desc);++ EXPECT_NE(cmd_queue, nullptr) << "Failed to allocate command queue for priority=" << (int)priority+ << " workload_type=" << (int)workload_type << " options=" << options;+ successful_allocations++;++ // Verify we get the same instance for the same descriptor+ auto cmd_queue2 = ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, cmd_desc);+ EXPECT_EQ(cmd_queue.get(), cmd_queue2.get()) << "Same descriptor should return the same pooled queue";+ }+ }+ }++ const int all_combinations =+ static_cast<int>(priorities.size() * workload_types.size() * option_combinations.size());+ EXPECT_EQ(all_combinations, 24) << "Expected 3 priorities * 2 workload types * 4 option combinations";+ EXPECT_EQ(successful_allocations, all_combinations)+ << "The test must cover and create all command queue combinations exactly once";+}++TEST_P(ZeroCmdQueuePoolTests, CreateDifferentCommandQueueForEachDeviceSyncOption) {+ if (init_struct->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1)) {+ GTEST_SKIP()+ << "ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC command queue option is not supported by the current driver.\n";+ }++ int owner_a = 1;+ int owner_b = 2;++ // With DEVICE_SYNC enabled, owner_tag participates in the pool key.+ ::intel_npu::CommandQueueDesc device_sync_desc_a{ZE_COMMAND_QUEUE_PRIORITY_NORMAL,+ ZE_WORKLOAD_TYPE_DEFAULT,+ ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC,+ &owner_a};+ auto queue_device_sync_a_1 =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, device_sync_desc_a);+ auto queue_device_sync_a_2 =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, device_sync_desc_a);++ EXPECT_NE(queue_device_sync_a_1, nullptr);+ EXPECT_EQ(queue_device_sync_a_1.get(), queue_device_sync_a_2.get())+ << "Same DEVICE_SYNC owner_tag should reuse the same pooled queue";++ ::intel_npu::CommandQueueDesc device_sync_desc_b{ZE_COMMAND_QUEUE_PRIORITY_NORMAL,+ ZE_WORKLOAD_TYPE_DEFAULT,+ ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC,+ &owner_b};+ auto queue_device_sync_b =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, device_sync_desc_b);++ EXPECT_NE(queue_device_sync_b, nullptr);+ EXPECT_NE(queue_device_sync_a_1.get(), queue_device_sync_b.get())+ << "Different DEVICE_SYNC owner_tag pointers should create different pooled queues";++ // Without DEVICE_SYNC, owner_tag must not affect pooling.+ ::intel_npu::CommandQueueDesc no_device_sync_desc_a{ZE_COMMAND_QUEUE_PRIORITY_NORMAL,+ ZE_WORKLOAD_TYPE_DEFAULT,+ 0,+ &owner_a};+ ::intel_npu::CommandQueueDesc no_device_sync_desc_b{ZE_COMMAND_QUEUE_PRIORITY_NORMAL,+ ZE_WORKLOAD_TYPE_DEFAULT,+ 0,+ &owner_b};+ auto queue_no_device_sync_a =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, no_device_sync_desc_a);+ auto queue_no_device_sync_b =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, no_device_sync_desc_b);++ EXPECT_NE(queue_no_device_sync_a, nullptr);+ EXPECT_EQ(queue_no_device_sync_a.get(), queue_no_device_sync_b.get())+ << "owner_tag should be ignored when DEVICE_SYNC option is not set";+}++TEST_P(ZeroCmdQueuePoolTests, MultiThreadingTest) {+ if (init_struct->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 0)) {+ GTEST_SKIP() << "Workload type and turbo options are not supported by the current driver.\n";+ }++ // Systematically cover all combinations of priorities, workload types, and turbo+ // Priorities: LOW (0), HIGH (1), NORMAL (2) = 3 options+ // Workload types: BACKGROUND (0), DEFAULT (1) = 2 options (when version > 0)+ // Turbo options: without TURBO (0), with TURBO (1) = 2 options (when version > 0)+ // Total combinations: 3 * 2 * 2 = 12 (with version > 0) or 3 (with version <= 0)++ constexpr int threads_no = 256;+ std::array<std::thread, threads_no> threads;+ std::vector<std::shared_ptr<::intel_npu::CommandQueue>> queue_refs(threads_no);+ std::mutex results_mutex;+ int successful_allocations = 0;++ for (int i = 0; i < threads_no; ++i) {+ threads[i] = std::thread([&, i]() -> void {+ // Cycle through all priority options+ ze_command_queue_priority_t priority;+ int priority_idx = i % 3;+ if (priority_idx == 0) {+ priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW;+ } else if (priority_idx == 1) {+ priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH;+ } else {+ priority = ZE_COMMAND_QUEUE_PRIORITY_NORMAL;+ }++ _ze_command_queue_workload_type_t workload_type = ZE_WORKLOAD_TYPE_DEFAULT;+ uint32_t commandQueueOptions = 0;++ // Cycle through workload types (2 options)+ int workload_idx = (i / 3) % 2;+ workload_type = (workload_idx == 0) ? ZE_WORKLOAD_TYPE_BACKGROUND : ZE_WORKLOAD_TYPE_DEFAULT;++ // Cycle through command queue options (2 options: with/without TURBO)+ int options_idx = (i / 6) % 2;+ if (options_idx == 0) {+ commandQueueOptions = commandQueueOptions | ZE_NPU_COMMAND_QUEUE_OPTION_TURBO;+ }+ // else: no options (commandQueueOptions = 0)++ ::intel_npu::CommandQueueDesc command_queue_desc{priority, workload_type, commandQueueOptions};+ auto cmd_queue =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc);++ {+ std::lock_guard<std::mutex> lock(results_mutex);+ queue_refs[i] = cmd_queue;+ successful_allocations++;+ }+ });+ }++ for (int i = 0; i < threads_no; ++i) {+ threads[i].join();+ }++ // Verify that all threads successfully obtained command queues+ EXPECT_GT(successful_allocations, 0) << "At least some command queues should be allocated";++ // Verify that we attempted allocations with different parameters+ int unique_combinations_requested = 12;+ int threads_per_combination = threads_no / unique_combinations_requested;+ EXPECT_GE(successful_allocations, threads_per_combination)+ << "Should have successfully allocated at least one thread per combination type";++ // Keep refs alive for the duration and then let them be cleaned up+ queue_refs.clear();+}++TEST_P(ZeroCmdQueuePoolTests, MultiThreadingTestWithDestroyCmdQueue) {+ if (init_struct->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 0)) {+ GTEST_SKIP() << "Workload type and turbo options are not supported by the current driver.\n";+ }++ constexpr int threads_no = 128;+ constexpr int iterations_per_thread = 16;+ std::array<std::thread, threads_no> threads;+ std::atomic<int> successful_cycles{0};++ for (int i = 0; i < threads_no; ++i) {+ threads[i] = std::thread([&, i]() -> void {+ for (int iteration = 0; iteration < iterations_per_thread; ++iteration) {+ // Cycle through all priority options+ ze_command_queue_priority_t priority;+ const int priority_idx = (i + iteration) % 3;+ if (priority_idx == 0) {+ priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW;+ } else if (priority_idx == 1) {+ priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH;+ } else {+ priority = ZE_COMMAND_QUEUE_PRIORITY_NORMAL;+ }++ _ze_command_queue_workload_type_t workload_type = ZE_WORKLOAD_TYPE_DEFAULT;+ uint32_t commandQueueOptions = 0;++ // Cycle through workload types (2 options)+ const int workload_idx = ((i + iteration) / 3) % 2;+ workload_type = (workload_idx == 0) ? ZE_WORKLOAD_TYPE_BACKGROUND : ZE_WORKLOAD_TYPE_DEFAULT;++ // Cycle through command queue options (2 options: with/without TURBO)+ const int options_idx = ((i + iteration) / 6) % 2;+ if (options_idx == 0) {+ commandQueueOptions = commandQueueOptions | ZE_NPU_COMMAND_QUEUE_OPTION_TURBO;+ }+ // else: no options (commandQueueOptions = 0)++ ::intel_npu::CommandQueueDesc command_queue_desc{priority, workload_type, commandQueueOptions};+ auto cmd_queue =+ ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc);+ ASSERT_NE(cmd_queue, nullptr);++ // Explicitly release right after creation to stress the pool deleter path.+ cmd_queue.reset();+ ++successful_cycles;+ }+ });+ }++ for (int i = 0; i < threads_no; ++i) {+ threads[i].join();+ }++ EXPECT_EQ(successful_cycles.load(), threads_no * iterations_per_thread)+ << "All create/destroy cycles must complete";+}++} // namespace behavior+} // namespace test+} // namespace ov