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] Improve handling profiling (#33644)
Alexandru Enache1ac3890787e2
diff --git a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hppindex 6843ac7cba6..f37893b52a9 100644--- a/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp+++ b/src/plugins/intel_npu/src/backend/include/zero_pipeline.hpp@@ -5,7 +5,6 @@#pragma once#include "intel_npu/common/igraph.hpp"-#include "intel_npu/utils/zero/zero_utils.hpp"#include "intel_npu/utils/zero/zero_wrappers.hpp"#include "zero_profiling.hpp"#include "zero_tensor.hpp"@@ -59,7 +58,11 @@ protected:std::shared_ptr<EventPool> _event_pool;std::vector<std::shared_ptr<Event>> _events;bool _sync_output_with_fences = true;+ uint32_t _extension_version;Logger _logger;++private:+ void enable_profiling();};} // namespace intel_npudiff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cppindex 4669b4499dc..dc023b53ac8 100644--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp@@ -9,10 +9,7 @@#include "intel_npu/common/itt.hpp"#include "intel_npu/config/options.hpp"-#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_remote_tensor.hpp"#include "intel_npu/utils/zero/zero_types.hpp"namespace {@@ -54,33 +51,54 @@ Pipeline::Pipeline(const Config& config,_logger.debug("Pipeline - initialize started, number_of_command_lists %i", _number_of_command_lists);- if (_init_structs->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&- _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {+ _extension_version = _init_structs->getCommandQueueDdiTable().version();+ if (_extension_version < ZE_MAKE_VERSION(1, 1) && _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {_graph->resize_last_submitted_event(_number_of_command_lists);}OPENVINO_ASSERT(_sync_output_with_fences || !_config.get<RUN_INFERENCES_SEQUENTIALLY>() ||- _init_structs->getCommandQueueDdiTable().version() >= ZE_MAKE_VERSION(1, 1),+ _extension_version >= ZE_MAKE_VERSION(1, 1),"In-order execution doesn't work in case synchronization of the inferences is done using events");- if (_config.has<PERF_COUNT>() && _config.get<PERF_COUNT>()) {- auto profiling_pool =- std::make_shared<zeroProfiling::ProfilingPool>(_init_structs, _graph, zeroProfiling::POOL_SIZE);- _profiling_query = std::make_unique<zeroProfiling::ProfilingQuery>(_init_structs, 0);+ bool perf_count_enabled = _config.has<PERF_COUNT>() && _config.get<PERF_COUNT>();+ std::optional<bool> compiled_with_profiling = graph->is_profiling_blob();- if (profiling_pool->create()) {- _profiling_query->create(profiling_pool);- }-- if (_config.get<PROFILING_TYPE>() == ov::intel_npu::ProfilingType::INFER) {- _logger.debug("ZeroInferRequest::ZeroInferRequest - profiling type == ov::intel_npu::ProfilingType::INFER");+ if (_config.get<PROFILING_TYPE>() == ov::intel_npu::ProfilingType::INFER) {+ if (perf_count_enabled) {+ _logger.debug("Profiling type == ov::intel_npu::ProfilingType::INFER");_npu_profiling =std::make_shared<zeroProfiling::NpuInferProfiling>(_init_structs, _config.get<LOG_LEVEL>());+ if (compiled_with_profiling.value_or(false)) {+ _logger.warning(+ "Model was compiled with layer profiling enabled, but the current profiling type is 'INFER'");+ enable_profiling();+ }+ } else if (compiled_with_profiling.value_or(false)) {+ _logger.warning(+ "Model was compiled with layer profiling enabled, PERF_COUNT is NOT set and timestamps will "+ "not be extracted");+ enable_profiling();}+ } else {+ if (compiled_with_profiling.has_value()) {+ if (perf_count_enabled && !compiled_with_profiling.value()) {+ OPENVINO_THROW("Model was not compiled with profiling enabled");+ }++ if (compiled_with_profiling.value()) {+ if (!perf_count_enabled) {+ _logger.warning("Model was compiled with layer profiling enabled, PERF_COUNT is NOT set and "+ "statistics will not be extracted");+ }+ enable_profiling();+ }+ } else if (perf_count_enabled) { // unable to determine if it was compiled with profiling enabled+ enable_profiling();+ } // else appendGraphExecute will fail in case the model was compiled with profiling enabled}- if (!_sync_output_with_fences || (_init_structs->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&- _config.get<RUN_INFERENCES_SEQUENTIALLY>())) {+ if (!_sync_output_with_fences ||+ (_extension_version < ZE_MAKE_VERSION(1, 1) && _config.get<RUN_INFERENCES_SEQUENTIALLY>())) {_event_pool =std::make_shared<EventPool>(_init_structs->getDevice(),_init_structs->getContext(),@@ -163,8 +181,7 @@ Pipeline::Pipeline(const Config& config,++io_index;}- if (_init_structs->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&- _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {+ if (_extension_version < ZE_MAKE_VERSION(1, 1) && _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {if (_graph->get_last_submitted_event(i)) {_graph->get_last_submitted_event(i)->AppendWaitOnEvent(*_command_lists.at(i));}@@ -185,8 +202,7 @@ Pipeline::Pipeline(const Config& config,_command_lists.at(i)->appendNpuTimestamp(reinterpret_cast<uint64_t*>(_npu_profiling->npu_ts_infer_end));}- if (_init_structs->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&- _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {+ if (_extension_version < ZE_MAKE_VERSION(1, 1) && _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {if (_graph->get_last_submitted_event(i)) {_graph->get_last_submitted_event(i)->AppendEventReset(*_command_lists.at(i));}@@ -207,8 +223,7 @@ Pipeline::Pipeline(const Config& config,void Pipeline::push() {_logger.debug("Pipeline - push() started");- if (_init_structs->getCommandQueueDdiTable().version() < ZE_MAKE_VERSION(1, 1) &&- _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {+ if (_extension_version < ZE_MAKE_VERSION(1, 1) && _config.get<RUN_INFERENCES_SEQUENTIALLY>()) {if (_id) {auto previousIndex = _graph->get_last_submitted_id();@@ -331,4 +346,14 @@ std::vector<ov::ProfilingInfo> Pipeline::get_profiling_info() const {}}+void Pipeline::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);+ }+}+} // namespace intel_npudiff --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 325e944870f..120f399fc79 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@@ -71,6 +71,8 @@ public:virtual void set_last_submitted_id(uint32_t id_index) = 0;virtual uint32_t get_last_submitted_id() const = 0;+ virtual std::optional<bool> is_profiling_blob() const = 0;+protected:// Used to protect zero pipeline creation in the graph. The pipeline should be created only once per graph when the// first inference starts runningdiff --git a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hppindex 903e9f27c52..20c35acac62 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/graph.hpp@@ -61,6 +61,8 @@ public:void set_last_submitted_id(uint32_t id_index) override;uint32_t get_last_submitted_id() const override;+ std::optional<bool> is_profiling_blob() const override;+~Graph() override;protected:diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cppindex c801b7c007c..3d120ed18fc 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/graph.cpp@@ -270,6 +270,20 @@ uint32_t Graph::get_last_submitted_id() const {return _lastSubmittedId;}+std::optional<bool> Graph::is_profiling_blob() const {+ if (_zeroInitStruct->getGraphDdiTable().version() < ZE_MAKE_VERSION(1, 16)) {+ _logger.debug("Cannot determine if the blob was compiled for profiling");+ return std::nullopt;+ }+ ze_graph_properties_3_t graphProperties = {};+ graphProperties.stype = ZE_STRUCTURE_TYPE_GRAPH_PROPERTIES_3;++ auto result = _zeroInitStruct->getGraphDdiTable().pfnGetProperties3(get_handle(), &graphProperties);+ THROW_ON_FAIL_FOR_LEVELZERO_EXT("pfnGetArgumentProperties3", result, _zeroInitStruct->getGraphDdiTable());++ return graphProperties.flags & ZE_GRAPH_PROPERTIES_FLAG_PROFILING_ENABLED;+}+std::optional<size_t> Graph::determine_batch_size() {if (!_metadata.outputs.at(0).shapeFromIRModel.has_value()) {_logger.debug("Batching on the plugin is not used, batching is handled by the compiler");diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_run.cpp b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_run.cppindex a0df07b8ac7..94a198df44b 100644--- a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_run.cpp+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_run.cpp@@ -19,6 +19,15 @@ INSTANTIATE_TEST_SUITE_P(compatibility_smoke_BehaviorTest,::testing::ValuesIn(configsInferRequestRunTests)),InferRequestRunTests::getTestCaseName);+const std::vector<ov::AnyMap> profilingConfigs{{ov::intel_npu::profiling_type(ov::intel_npu::ProfilingType::MODEL)},+ {ov::intel_npu::profiling_type(ov::intel_npu::ProfilingType::INFER)}};++INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,+ ProfilingBlob,+ ::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),+ ::testing::ValuesIn(profilingConfigs)),+ InferRequestRunTests::getTestCaseName);+INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTest,RandomTensorOverZeroTensorRunTests,::testing::Combine(::testing::Values(ov::test::utils::DEVICE_NPU),diff --git a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_run.hpp b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_run.hppindex cb7351dce2a..9caa8e8ecc7 100644--- a/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_run.hpp+++ b/src/plugins/intel_npu/tests/functional/behavior/ov_infer_request/infer_request_run.hpp@@ -19,11 +19,13 @@#include "common/utils.hpp"#include "intel_npu/npu_private_properties.hpp"#include "intel_npu/utils/zero/zero_init.hpp"+#include "intel_npu/utils/zero/zero_types.hpp"#include "openvino/core/any.hpp"#include "openvino/core/node_vector.hpp"#include "openvino/opsets/opset8.hpp"#include "openvino/runtime/compiled_model.hpp"#include "openvino/runtime/core.hpp"+#include "openvino/runtime/intel_npu/properties.hpp"#include "shared_test_classes/base/ov_behavior_test_utils.hpp"using CompilationParams = std::tuple<std::string, // Device name@@ -188,6 +190,86 @@ TEST_P(InferRequestRunTests, MultipleExecutorStreamsTestsAsyncInfers) {}}+using ProfilingBlob = InferRequestRunTests;++TEST_P(ProfilingBlob, NoProfilingCompileProfilingImport) {+ std::shared_ptr<::intel_npu::ZeroInitStructsHolder> initStructs =+ std::make_shared<::intel_npu::ZeroInitStructsHolder>();+ if (initStructs->getGraphDdiTable().version() < ZE_MAKE_VERSION(1, 16)) {+ std::cout << "Skip since driver extension version is lower than expected\n";+ GTEST_SKIP();+ }+ ov::CompiledModel compiled_model;++ configuration[ov::enable_profiling.name()] = false;+ OV_ASSERT_NO_THROW(compiled_model = core->compile_model(ov_model, target_device, configuration));++ std::stringstream export_stream;+ compiled_model.export_model(export_stream);++ configuration[ov::enable_profiling.name()] = true;+ OV_ASSERT_NO_THROW(compiled_model = core->import_model(export_stream, target_device, configuration));++ ov::InferRequest inferReq;++ OV_ASSERT_NO_THROW(inferReq = compiled_model.create_infer_request());++ if (configuration.find(ov::intel_npu::profiling_type.name())->second == ov::intel_npu::ProfilingType::MODEL) {+ ASSERT_ANY_THROW(inferReq.infer());+ } else {+ OV_ASSERT_NO_THROW(inferReq.infer());+ }+}++TEST_P(ProfilingBlob, ProfilingCompileNoProfilingImport) {+ std::shared_ptr<::intel_npu::ZeroInitStructsHolder> initStructs =+ std::make_shared<::intel_npu::ZeroInitStructsHolder>();+ if (initStructs->getGraphDdiTable().version() < ZE_MAKE_VERSION(1, 16)) {+ std::cout << "Skip since driver extension version is lower than expected\n";+ GTEST_SKIP();+ }+ ov::CompiledModel compiled_model;++ configuration[ov::enable_profiling.name()] = true;+ OV_ASSERT_NO_THROW(compiled_model = core->compile_model(ov_model, target_device, configuration));++ std::stringstream export_stream;+ compiled_model.export_model(export_stream);++ configuration[ov::enable_profiling.name()] = false;+ OV_ASSERT_NO_THROW(compiled_model = core->import_model(export_stream, target_device, configuration));++ ov::InferRequest inferReq;++ OV_ASSERT_NO_THROW(inferReq = compiled_model.create_infer_request());++ OV_ASSERT_NO_THROW(inferReq.infer());+}++TEST_P(ProfilingBlob, ProfilingCompileProfilingImport) {+ std::shared_ptr<::intel_npu::ZeroInitStructsHolder> initStructs =+ std::make_shared<::intel_npu::ZeroInitStructsHolder>();+ if (initStructs->getGraphDdiTable().version() < ZE_MAKE_VERSION(1, 16)) {+ std::cout << "Skip since driver extension version is lower than expected\n";+ GTEST_SKIP();+ }+ ov::CompiledModel compiled_model;++ configuration[ov::enable_profiling.name()] = true;+ OV_ASSERT_NO_THROW(compiled_model = core->compile_model(ov_model, target_device, configuration));++ std::stringstream export_stream;+ compiled_model.export_model(export_stream);++ OV_ASSERT_NO_THROW(compiled_model = core->import_model(export_stream, target_device, configuration));++ ov::InferRequest inferReq;++ OV_ASSERT_NO_THROW(inferReq = compiled_model.create_infer_request());++ OV_ASSERT_NO_THROW(inferReq.infer());+}+TEST_P(InferRequestRunTests, MultipleExecutorTestsSyncInfers) {SKIP_IF_CURRENT_TEST_IS_DISABLED();ov::CompiledModel compiled_model;@@ -479,7 +561,7 @@ TEST_P(BatchingRunTests, CheckBatchingSupportInfer) {TEST_P(BatchingRunTests, CheckBatchingSupportAsync) {SKIP_IF_CURRENT_TEST_IS_DISABLED();- ov::CompiledModel compiled_model;+ ov::CompiledModel compiled_model;ov::InferRequest inference_request;auto batch_shape = Shape{4, 2, 32, 32};std::shared_ptr<ov::Model> ov_model_batch = createModel(element::f32, batch_shape, "N...");diff --git a/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml b/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xmlindex 0d8ec13ee65..fefeb76cbb7 100644--- a/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml+++ b/src/plugins/intel_npu/tests/functional/shared_tests_instances/npu_skip_func_tests.xml@@ -874,7 +874,6 @@ Example:<filter>.*CompileModelLoadFromCacheTest.*NPU_TURBO.*</filter><filter>.*CompileModelLoadFromCacheTest.*NPU_QDQ_OPTIMIZATION.*</filter><filter>.*CompileModelLoadFromCacheTest.*NPU_QDQ_OPTIMIZATION_AGGRESSIVE.*</filter>-</filters></skip_config>