Skip to content

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

[NPU] Disable shared common queue feature (#36264)

Bogdan Pereanua7ba8ebc6d11
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.hpp
index 334251bb08e..191ec179fe2 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
@@ -1508,7 +1508,7 @@ struct SHARED_COMMON_QUEUE final : OptionBase<SHARED_COMMON_QUEUE, bool> {
}
static bool defaultValue() {
- return true;
+ return false;
}
static OptionMode mode() {
diff --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.hpp
index d39e98b22b1..6bbdaaf2a9a 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
@@ -442,7 +442,7 @@ static constexpr ov::Property<bool> export_raw_blob{"NPU_EXPORT_RAW_BLOB"};
/**
* @brief [Only for NPU Plugin]
- * Type: boolean, default is true.
+ * Type: boolean, default is false.
* 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.
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.hpp
index 871316ab5c1..8a6b3439257 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
@@ -12,6 +12,7 @@
#include "intel_npu/common/network_metadata.hpp"
#include "intel_npu/utils/vm/npu_vm_runtime_api.hpp"
#include "intel_npu/utils/zero/zero_init.hpp"
+#include "intel_npu/utils/zero/zero_wrappers.hpp"
#include "openvino/runtime/so_ptr.hpp"
namespace intel_npu {
@@ -208,6 +209,11 @@ private:
NetworkMetadata _metadata;
+ // Preserve previous behavior: when shared common queue is disabled and a new queue is created due to a priority
+ // change, keep the same workload type to avoid creating a queue with an unexpected workload.
+ std::optional<ov::WorkloadType> _workloadType = std::nullopt;
+ std::shared_ptr<CommandQueue> _commandQueue = nullptr;
+
/**
* @brief Stores the number of subgraphs for dynamic models
* @note the number of subgraphs will be one for static models
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp
index 4484fa36f7b..18ac0ccbae4 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp
@@ -12,6 +12,7 @@
#include "intel_npu/common/igraph.hpp"
#include "intel_npu/utils/zero/zero_init.hpp"
+#include "intel_npu/utils/zero/zero_wrappers.hpp"
#include "openvino/runtime/so_ptr.hpp"
#include "ze_graph_ext_wrappers.hpp"
@@ -79,6 +80,11 @@ protected:
GraphDescriptor _graphDesc;
NetworkMetadata _metadata;
+ // Preserve previous behavior: when shared common queue is disabled and a new queue is created due to a priority
+ // change, keep the same workload type to avoid creating a queue with an unexpected workload.
+ std::optional<ov::WorkloadType> _workloadType = std::nullopt;
+ std::shared_ptr<CommandQueue> _commandQueue = nullptr;
+
mutable std::mutex _commandQueueDescMutex;
CommandQueueDesc _commandQueueDesc;
std::vector<std::shared_ptr<Event>> _lastSubmittedEvent;
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.cpp
index 5dd5fca726a..65ddf32522a 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
@@ -535,6 +535,16 @@ void DynamicGraph::set_workload_type(const ov::WorkloadType workloadType) {
std::lock_guard<std::mutex> lock(_commandQueueDescMutex);
auto zeWorkloadType = zeroUtils::toZeQueueWorkloadType(workloadType);
+
+ if (_commandQueue && zeWorkloadType.has_value()) {
+ // When shared common queue is disabled, workload type is set per command queue.
+ // Update the existing queue if it has already been created.
+ _commandQueue->setWorkloadType(zeWorkloadType.value());
+ _workloadType = workloadType;
+
+ return;
+ }
+
if (_commandQueueDesc.workload() == zeWorkloadType) {
return;
}
@@ -552,6 +562,18 @@ void DynamicGraph::set_model_priority(const ov::hint::Priority modelPriority) {
return;
}
_commandQueueDesc.set_priority(zeModelPriority);
+
+ if (_commandQueue) {
+ // When shared common queue is disabled, workload type is set per command queue.
+ // Recreate the queue with the new priority while preserving the current workload type.
+ if (_workloadType.has_value()) {
+ auto zeWorkloadType = zeroUtils::toZeQueueWorkloadType(_workloadType.value());
+ _commandQueueDesc.set_workload(zeWorkloadType);
+ _workloadType = std::nullopt; // Clear the cached workload type after applying it to the new queue
+ }
+
+ _commandQueue = ZeroCmdQueuePool::getInstance().getCommandQueue(_zeroInitStruct, _commandQueueDesc);
+ }
}
void DynamicGraph::set_argument_value(uint32_t argi, const void* argv) const {
@@ -618,6 +640,11 @@ void DynamicGraph::initialize_impl(const FilteredConfig& config) {
commandQueueOptions,
this,
config.get<SHARED_COMMON_QUEUE>()};
+
+ if (config.get<SHARED_COMMON_QUEUE>() == false) {
+ // Keep it alive per compiled model when the shared common queue feature is disabled.
+ _commandQueue = ZeroCmdQueuePool::getInstance().getCommandQueue(_zeroInitStruct, _commandQueueDesc);
+ }
}
_logger.debug("Graph initialize finish");
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
index 40800c2af42..1fe9c0d31f9 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp
@@ -66,6 +66,16 @@ void Graph::set_workload_type(const ov::WorkloadType workloadType) {
std::lock_guard<std::mutex> lock(_commandQueueDescMutex);
auto zeWorkloadType = zeroUtils::toZeQueueWorkloadType(workloadType);
+
+ if (_commandQueue && zeWorkloadType.has_value()) {
+ // When shared common queue is disabled, workload type is set per command queue.
+ // Update the existing queue if it has already been created.
+ _commandQueue->setWorkloadType(zeWorkloadType.value());
+ _workloadType = workloadType;
+
+ return;
+ }
+
if (_commandQueueDesc.workload() == zeWorkloadType) {
return;
}
@@ -83,6 +93,18 @@ void Graph::set_model_priority(const ov::hint::Priority modelPriority) {
return;
}
_commandQueueDesc.set_priority(zeModelPriority);
+
+ if (_commandQueue) {
+ // When shared common queue is disabled, workload type is set per command queue.
+ // Recreate the queue with the new priority while preserving the current workload type.
+ if (_workloadType.has_value()) {
+ auto zeWorkloadType = zeroUtils::toZeQueueWorkloadType(_workloadType.value());
+ _commandQueueDesc.set_workload(zeWorkloadType);
+ _workloadType = std::nullopt; // Clear the cached workload type after applying it to the new queue
+ }
+
+ _commandQueue = ZeroCmdQueuePool::getInstance().getCommandQueue(_zeroInitStruct, _commandQueueDesc);
+ }
}
ze_graph_handle_t Graph::get_handle() const {
@@ -197,6 +219,11 @@ void Graph::initialize_impl(const FilteredConfig& config) {
this,
config.get<SHARED_COMMON_QUEUE>(),
};
+
+ if (config.get<SHARED_COMMON_QUEUE>() == false) {
+ // Keep it alive per compiled model when the shared common queue feature is disabled.
+ _commandQueue = ZeroCmdQueuePool::getInstance().getCommandQueue(_zeroInitStruct, _commandQueueDesc);
+ }
}
_zeGraphExt->initializeGraph(_graphDesc);
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.hpp
index 348406d85d0..622f49478a0 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
@@ -148,6 +148,7 @@ public:
CommandQueue& operator=(const CommandQueue&) = delete;
CommandQueue& operator=(CommandQueue&&) = delete;
+ void setWorkloadType(ze_command_queue_workload_type_t workloadType) const;
void executeCommandList(CommandList& command_list) const;
void executeCommandList(CommandList& command_list, Fence& fence) const;
~CommandQueue();
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_wrappers.cpp
index 1aad3f49070..dd8f441c31b 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
@@ -324,13 +324,7 @@ CommandQueue::CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& init_st
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!");
- }
+ setWorkloadType(_desc.workload().value());
} catch (...) {
auto result = zeCommandQueueDestroy(_handle);
_handle = nullptr;
@@ -342,6 +336,15 @@ CommandQueue::CommandQueue(const std::shared_ptr<ZeroInitStructsHolder>& init_st
}
}
}
+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!");
+ }
+}
+
void CommandQueue::executeCommandList(CommandList& command_list) const {
THROW_ON_FAIL_FOR_LEVELZERO("zeCommandQueueExecuteCommandLists",
zeCommandQueueExecuteCommandLists(_handle, 1, &command_list._handle, nullptr));
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.hpp
index 66f0518b6e0..8ed99daf1bc 100644
--- 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.hpp
@@ -93,13 +93,38 @@ TEST_P(ZeroCmdQueuePoolTests, SetWorkloadType) {
}
}
-TEST_P(ZeroCmdQueuePoolTests, PoolReusabilityTest) {
- // Test that the pool correctly reuses queues after weak_ptr cleanup
+TEST_P(ZeroCmdQueuePoolTests, SetWorkloadTypeOnExistingQueue) {
+ if (init_struct->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 0)) {
+ GTEST_SKIP() << "The WorkloadType property is not supported by the current driver.\n";
+ }
+
+ int owner = 1;
::intel_npu::CommandQueueDesc command_queue_desc{ZE_COMMAND_QUEUE_PRIORITY_NORMAL,
- std::nullopt,
+ ZE_WORKLOAD_TYPE_DEFAULT,
0,
- nullptr,
- true};
+ &owner,
+ false};
+
+ auto cmd_queue = ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc);
+ ASSERT_NE(cmd_queue, nullptr);
+
+ OV_ASSERT_NO_THROW(cmd_queue->setWorkloadType(ZE_WORKLOAD_TYPE_BACKGROUND));
+ OV_ASSERT_NO_THROW(cmd_queue->setWorkloadType(ZE_WORKLOAD_TYPE_DEFAULT));
+}
+
+TEST_P(ZeroCmdQueuePoolTests, SharedCommonQueueDisabledRequiresOwnerTag) {
+ OV_EXPECT_THROW_HAS_SUBSTRING((::intel_npu::CommandQueueDesc{ZE_COMMAND_QUEUE_PRIORITY_NORMAL,
+ std::nullopt,
+ 0,
+ nullptr,
+ false}),
+ ov::Exception,
+ "owner_tag must not be null");
+}
+
+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, std::nullopt, 0, nullptr, true};
// First allocation
std::shared_ptr<::intel_npu::CommandQueue> queue1 =
@@ -171,6 +196,60 @@ TEST_P(ZeroCmdQueuePoolTests, PoolReusabilityDisabledTest) {
queue3.reset();
}
+TEST_P(ZeroCmdQueuePoolTests, SharedCommonQueueDisabledUsesNewQueueWhenDescriptorChanges) {
+ int owner = 1;
+
+ ::intel_npu::CommandQueueDesc base_desc{ZE_COMMAND_QUEUE_PRIORITY_NORMAL, std::nullopt, 0, &owner, false};
+ auto base_queue = ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, base_desc);
+ auto same_base_queue = ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, base_desc);
+
+ ASSERT_NE(base_queue, nullptr);
+ ASSERT_EQ(base_queue.get(), same_base_queue.get()) << "Same descriptor and owner_tag should reuse the same queue";
+
+ ::intel_npu::CommandQueueDesc priority_desc{
+ ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH,
+ std::nullopt,
+ 0,
+ &owner,
+ false,
+ };
+ auto priority_queue = ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, priority_desc);
+
+ ASSERT_NE(priority_queue, nullptr);
+ EXPECT_NE(base_queue.get(), priority_queue.get())
+ << "Changing model priority should create a different queue for shared_common_queue=false";
+
+ if (init_struct->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 0)) {
+ ::intel_npu::CommandQueueDesc workload_desc{
+ ZE_COMMAND_QUEUE_PRIORITY_NORMAL,
+ ZE_WORKLOAD_TYPE_BACKGROUND,
+ 0,
+ &owner,
+ false,
+ };
+ auto workload_queue = ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, workload_desc);
+
+ ASSERT_NE(workload_queue, nullptr);
+ EXPECT_NE(base_queue.get(), workload_queue.get())
+ << "Changing workload type should create a different queue for shared_common_queue=false";
+ }
+
+ if (init_struct->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 1)) {
+ ::intel_npu::CommandQueueDesc option_desc{
+ ZE_COMMAND_QUEUE_PRIORITY_NORMAL,
+ std::nullopt,
+ ZE_NPU_COMMAND_QUEUE_OPTION_DEVICE_SYNC,
+ &owner,
+ false,
+ };
+ auto option_queue = ::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, option_desc);
+
+ ASSERT_NE(option_queue, nullptr);
+ EXPECT_NE(base_queue.get(), option_queue.get())
+ << "Changing command queue options should create a different queue for shared_common_queue=false";
+ }
+}
+
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";
@@ -319,7 +398,11 @@ TEST_P(ZeroCmdQueuePoolTests, MultiThreadingTest) {
}
// else: no options (commandQueueOptions = 0)
- ::intel_npu::CommandQueueDesc command_queue_desc{priority, workload_type, commandQueueOptions, nullptr, true};
+ ::intel_npu::CommandQueueDesc command_queue_desc{priority,
+ workload_type,
+ commandQueueOptions,
+ nullptr,
+ true};
auto cmd_queue =
::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc);
@@ -387,10 +470,10 @@ TEST_P(ZeroCmdQueuePoolTests, MultiThreadingTestWithDestroyCmdQueue) {
// else: no options (commandQueueOptions = 0)
::intel_npu::CommandQueueDesc command_queue_desc{priority,
- workload_type,
- commandQueueOptions,
- nullptr,
- true};
+ workload_type,
+ commandQueueOptions,
+ nullptr,
+ true};
auto cmd_queue =
::intel_npu::ZeroCmdQueuePool::getInstance().getCommandQueue(init_struct, command_queue_desc);
ASSERT_NE(cmd_queue, nullptr);