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] Pipeline profiling part refactor (#37876)
Alexandru Enache48ba4151b97a
diff --git a/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp b/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hppindex e329e3a4bb6..c6e57f641fd 100644--- a/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_dynamic_pipeline.hpp@@ -157,6 +157,8 @@ public:size_t batch_index,const std::shared_ptr<ov::ITensor>& userTensor = nullptr) override;+ std::vector<ov::ProfilingInfo> get_profiling_info() const override;+// Predicts VM runtime output shapes for the given input/output tensors. A nullptr tensor entry falls// back to the graph metadata max shape. Uses the pipeline's own graph handle and VM execution context,// which is the same context reused by execute_vm_runtime.diff --git a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hppindex f63bae15a79..da4422a8d52 100644--- a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp@@ -38,13 +38,11 @@ public:size_t batch_index,const std::shared_ptr<ov::ITensor>& userTensor = nullptr) = 0;- std::vector<ov::ProfilingInfo> get_profiling_info() const;+ virtual std::vector<ov::ProfilingInfo> get_profiling_info() const = 0;virtual ~IPipeline() = default;protected:- void enable_profiling();-// Helper function handling strides for Zero Pipeline and ZeroDynamicPipeline. Stateless regarding pipeline// instances, hence staticstatic std::vector<size_t> get_strides(const std::vector<size_t>& strides_in_bytes,@@ -55,9 +53,6 @@ protected:std::shared_ptr<IGraph> _graph;const Config _config;- std::unique_ptr<zeroProfiling::ProfilingQuery> _profiling_query;- std::shared_ptr<zeroProfiling::NpuInferProfiling> _npu_profiling;-/*** @brief Indicates how many command lists will be used inside the pipeline.* @details Leveraging multiple command lists implies distributing the input/output buffers accross the batch axis@@ -105,7 +100,13 @@ public:size_t batch_index,const std::shared_ptr<ov::ITensor>& userTensor = nullptr) override;+ std::vector<ov::ProfilingInfo> get_profiling_info() const override;+private:+ void configure_profiling();++ std::unique_ptr<zeroProfiling::ProfilingQuery> _profiling_query;+ std::shared_ptr<zeroProfiling::NpuInferProfiling> _npu_profiling;std::vector<std::unique_ptr<CommandList>> _command_lists;};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 9023eef7b8d..8da5e737080 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@@ -614,14 +614,17 @@ void DynamicPipeline::pull() {} else {_events.front()->hostSynchronize();}- /// sample npu timestamps if feature was activated- if (_npu_profiling != nullptr) {- _npu_profiling->sampleNpuTimestamps();- }_logger.debug("pull - completed");}+std::vector<ov::ProfilingInfo> DynamicPipeline::get_profiling_info() const {+ if (_config.has<PERF_COUNT>() && _config.get<PERF_COUNT>()) {+ _logger.warning("get_profiling_info - profiling is not supported for dynamic graphs");+ }+ return {};+}+void DynamicPipeline::reset() const {_logger.debug("reset - started");if (!use_npu_vm_runtime_v2_api(_apiVersion)) {diff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cppindex 2fd1a39151d..ff2c35e05fb 100644--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp@@ -73,6 +73,20 @@ IPipeline::IPipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,_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());+}++void Pipeline::configure_profiling() {+ const auto enable_profiling = [this]() {+ auto profiling_pool =+ std::make_shared<zeroProfiling::ProfilingPool>(_init_structs, _graph, zeroProfiling::POOL_SIZE);+ _profiling_query = std::make_unique<zeroProfiling::ProfilingQuery>(_init_structs, 0);++ if (profiling_pool->create()) {+ _profiling_query->create(profiling_pool);+ } else {+ _logger.warning("enable_profiling - failed to create profiling pool, profiling will not be available");+ }+ };bool perf_count_enabled = _config.has<PERF_COUNT>() && _config.get<PERF_COUNT>();std::optional<bool> compiled_with_profiling = _graph->is_profiling_blob();@@ -113,9 +127,9 @@ IPipeline::IPipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,enable_profiling();} // else appendGraphExecute will fail in case the model was compiled with profiling enabled}-};+}-std::vector<ov::ProfilingInfo> IPipeline::get_profiling_info() const {+std::vector<ov::ProfilingInfo> Pipeline::get_profiling_info() const {_logger.debug("get_profiling_info - started");if (!_config.has<PERF_COUNT>() || !_config.get<PERF_COUNT>()) {_logger.warning("get_profiling_info - completed with empty result");@@ -140,18 +154,6 @@ std::vector<ov::ProfilingInfo> IPipeline::get_profiling_info() const {}}-void IPipeline::enable_profiling() {- auto profiling_pool =- std::make_shared<zeroProfiling::ProfilingPool>(_init_structs, _graph, zeroProfiling::POOL_SIZE);- _profiling_query = std::make_unique<zeroProfiling::ProfilingQuery>(_init_structs, 0);-- if (profiling_pool->create()) {- _profiling_query->create(profiling_pool);- } else {- _logger.warning("enable_profiling - failed to create profiling pool, profiling will not be available");- }-}-Pipeline::Pipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,const std::shared_ptr<IGraph>& graph,const Config& config,@@ -163,6 +165,9 @@ Pipeline::Pipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,_logger.debug("Pipeline - initialization started, batch size: %i", _batch_size);+ // must run before the command lists are built below: populates _npu_profiling/_profiling_query+ configure_profiling();+if (_run_inferences_sequentially) {_graph->resize_last_submitted_event(_batch_size);}