From 9c9cc88e21646e919b3d11fe2d6b946649100ad4 Mon Sep 17 00:00:00 2001 From: Bogdan Pereanu Date: Thu, 30 Jan 2025 07:57:06 +0200 Subject: [PATCH] Make sure that the pipeline is still alive when fences are destroyed Signed-off-by: Bogdan Pereanu --- .../src/backend/src/zero_pipeline.cpp | 76 +++++++++++-------- .../intel_npu/utils/zero/zero_wrappers.hpp | 8 +- .../src/utils/src/zero/zero_wrappers.cpp | 4 +- 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp index c6286709704947..3cf9b205df2abd 100644 --- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp +++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp @@ -41,12 +41,6 @@ Pipeline::Pipeline(const Config& config, profiling_query.create(profiling_pool._handle); } - if (_config.has()) { - _turbo = _config.get(); - } - - _ze_queue_priority = zeroUtils::toZeQueuePriority(_config.get()); - OPENVINO_ASSERT(_sync_output_with_fences || !_config.get(), "In-order execution doesn't work in case synchronization of the inferences is done using events"); @@ -70,8 +64,29 @@ Pipeline::Pipeline(const Config& config, _init_structs->getMutableCommandListVersion() ? true : false)); } + _ze_queue_priority = zeroUtils::toZeQueuePriority(_config.get()); + + if (_config.has()) { + _turbo = _config.get(); + } + + if (config.has()) { + _ze_workload_type = zeroUtils::toZeQueueWorkloadType(config.get()); + } + + _command_queue = CommandQueueManager::getInstance().getCommandQueue(_init_structs, + _ze_queue_priority, + _graph->get_ze_workload_type(), + _group_ordinal, + _turbo); + if (_sync_output_with_fences) { _fences.resize(_number_of_command_lists); + + for (size_t i = 0; i < _number_of_command_lists; i++) { + _logger.debug("Pipeline - getCommandQueue() - create new fence"); + _fences[i] = std::make_unique(*_command_queue); + } } for (size_t i = 0; i < _number_of_command_lists; i++) { @@ -168,41 +183,36 @@ Pipeline::Pipeline(const Config& config, void Pipeline::getCommandQueue() { _logger.debug("Pipeline - getCommandQueue() started"); - _command_queue = CommandQueueManager::getInstance().getCommandQueue(_init_structs, - _ze_queue_priority, - _graph->get_ze_workload_type(), - _group_ordinal, - _turbo); - { - std::lock_guard lock(_mutex); - - if (_ze_workload_type != _graph->get_ze_workload_type()) { - if (_ze_workload_type.has_value()) { - // fences created for the old command queue shall be destroyed and make new ones - if (_sync_output_with_fences) { - for (size_t i = 0; i < _number_of_command_lists; i++) { - if (_fences[i] != nullptr) { - _logger.debug("Pipeline - getCommandQueue() - destroy old fence"); - _fences[i].reset(); - } - } - } + std::lock_guard lock(_mutex); - _logger.debug("Pipeline - getCommandQueue() - free command queue"); - CommandQueueManager::getInstance().freeCommandQueue(_ze_queue_priority, _ze_workload_type, _turbo); + if (_ze_workload_type != _graph->get_ze_workload_type()) { + // fences created for the old command queue shall be destroyed and make new ones + if (_sync_output_with_fences) { + for (size_t i = 0; i < _number_of_command_lists; i++) { + if (_fences[i] != nullptr) { + _logger.debug("Pipeline - getCommandQueue() - destroy old fence"); + _fences[i].reset(); + } } - - _ze_workload_type = _graph->get_ze_workload_type(); } + _command_queue = CommandQueueManager::getInstance().getCommandQueue(_init_structs, + _ze_queue_priority, + _graph->get_ze_workload_type(), + _group_ordinal, + _turbo); + if (_sync_output_with_fences) { for (size_t i = 0; i < _number_of_command_lists; i++) { - if (_fences[i] == nullptr) { - _logger.debug("Pipeline - getCommandQueue() - create new fence"); - _fences[i] = std::make_unique(*_command_queue); - } + _logger.debug("Pipeline - getCommandQueue() - create new fence"); + _fences[i] = std::make_unique(*_command_queue); } } + + _logger.debug("Pipeline - getCommandQueue() - free previous command queue"); + CommandQueueManager::getInstance().freeCommandQueue(_ze_queue_priority, _ze_workload_type, _turbo); + + _ze_workload_type = _graph->get_ze_workload_type(); } _logger.debug("Pipeline - getCommandQueue() completed"); 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 1f5ad106b53530..d85725c530fb14 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 @@ -145,10 +145,6 @@ class CommandQueue { ze_command_queue_handle_t _handle = nullptr; }; -static std::array, workload::WORKLOAD_COUNT>, turbo::TURBO_COUNT>, - priority::PRIORITY_COUNT> - _gloabal_command_queues; - class CommandQueueManager { public: CommandQueueManager(); @@ -173,6 +169,10 @@ class CommandQueueManager { Logger _log; std::mutex _mutex; + + std::array, workload::WORKLOAD_COUNT>, turbo::TURBO_COUNT>, + priority::PRIORITY_COUNT> + _gloabal_command_queues; }; } // namespace intel_npu 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 522144ff0d97ea..a6d7fe812c4169 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 @@ -236,7 +236,7 @@ std::shared_ptr CommandQueueManager::getCommandQueue( [zeroUtils::toWorkloadEnum(workload_type)] ->setWorkloadType(*workload_type); } catch (const std::exception& ex) { - _log.debug("Destroy pipeline if workload type is not supported!"); + _log.error("Destroy pipeline if workload type is not supported!"); _gloabal_command_queues[zeroUtils::toPriorityEnum(priority)][zeroUtils::toTurboEnum(turbo)] [zeroUtils::toWorkloadEnum(workload_type)] .reset(); @@ -255,7 +255,7 @@ void CommandQueueManager::freeCommandQueue(const ze_command_queue_priority_t& pr if (_gloabal_command_queues[zeroUtils::toPriorityEnum(priority)][zeroUtils::toTurboEnum(turbo)] [zeroUtils::toWorkloadEnum(workload_type)] - .use_count() <= 1) { + .use_count() == 1) { _log.debug("Destroy command queue"); _gloabal_command_queues[zeroUtils::toPriorityEnum(priority)][zeroUtils::toTurboEnum(turbo)] [zeroUtils::toWorkloadEnum(workload_type)]