Skip to content

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

[OV][ITT] Adds support for async inferences and default NPU markers (#34279)

tovinkere1b821af2ded2
diff --git a/src/common/itt/include/openvino/itt.hpp b/src/common/itt/include/openvino/itt.hpp
index e91debe31d2..5bdaab90bdc 100644
--- a/src/common/itt/include/openvino/itt.hpp
+++ b/src/common/itt/include/openvino/itt.hpp
@@ -44,9 +44,11 @@ namespace internal {
domain_t domain(const char* name);
handle_t handle(const char* name);
void taskBegin(domain_t d, handle_t t);
+void taskBegin(domain_t d, handle_t t, const char* key, uint64_t value);
void taskEnd(domain_t d);
void threadName(const char* name);
void regionBegin(domain_t d, handle_t t);
+void regionBegin(domain_t d, handle_t t, const char* key, uint64_t value);
void regionEnd(domain_t d);
void shutdown();
} // namespace internal
@@ -116,6 +118,27 @@ struct ScopedTask {
internal::taskBegin(domain(), taskHandle);
}
+ /**
+ * @brief Constructs a scoped task with an associated key-value metadata pair.
+ *
+ * Creates an ITT (Intel Tracing Technology) scoped task that will automatically
+ * begin upon construction and end when the object goes out of scope (RAII pattern).
+ * This overload allows attaching custom metadata to the task for enhanced profiling.
+ *
+ * @param taskHandle Handle identifying the task type for profiling tools.
+ * @param key String identifier for the metadata attribute (e.g., "InferenceID").
+ * @param value Numeric value associated with the key (e.g., unique request ID).
+ *
+ * @note The task begins immediately upon construction via internal::taskBegin.
+ * @note The key string must remain valid for the duration of the task scope.
+ * @note This constructor is noexcept, ensuring exception safety in profiling code.
+ *
+ * @see ScopedTask(handle_t) for the basic constructor without metadata.
+ */
+ ScopedTask(handle_t taskHandle, const char* key, uint64_t value) noexcept {
+ internal::taskBegin(domain(), taskHandle, key, value);
+ }
+
/**
* @brief The ScopedTask destructor closes or ends the task scope
*/
@@ -144,6 +167,20 @@ struct ScopedRegion {
internal::regionBegin(domain(), handle);
}
+ /**
+ * @brief Constructs a scoped region with metadata for ITT profiling.
+ *
+ * @param handle Region identifier for profiling tools.
+ * @param key Metadata attribute name (e.g., "RequestID").
+ * @param value Metadata numeric value associated with the key.
+ *
+ * @note Region begins immediately and ends when object goes out of scope (RAII).
+ * @note The key string must remain valid for the region's lifetime.
+ */
+ ScopedRegion(handle_t handle, const char* key, uint64_t value) noexcept {
+ internal::regionBegin(domain(), handle, key, value);
+ }
+
/**
* @brief The ScopedRegion destructor closes or ends the region scope
*/
@@ -309,8 +346,15 @@ public:
* @ingroup ov_dev_profiling
* @brief Annotate section of code till scope exit for BASE/FULL modes regardless of profiling filter groups.
* @details In case if handle or taskName absent, the current function name is used.
+ * @note All *_BASE() macros are enabled by default and will be used by supporting toolchains. The strings
+ * used/provided by these calls should follow the following rules:
+ * - Should NOT be deleted or modified to ensure correct visible names in profiling tools
+ * until CVS-179230 is implemented/resolved.
+ * - Should use string literals or constant strings when possible
* @param domain [in] Known at compile time name of module or library (the domain name).
* @param handleOrTaskName [in] The annotation name or handle for section of code. Parameter is optional.
+ * @param metadata_key [in] A metadata element's key as a string. Parameter is optional.
+ * @param metadata_value [in] The metadata value. Parameter is optional.
*/
#define OV_ITT_SCOPED_TASK_BASE(...) OV_PP_OVERLOAD(OV_ITT_SCOPED_TASK_BASE, __VA_ARGS__)
@@ -322,6 +366,12 @@ public:
openvino::itt::ScopedTask<domain> OV_PP_CAT(ittScopedTask, __LINE__)( \
openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)>(taskOrTaskName));
+#define OV_ITT_SCOPED_TASK_BASE_4(domain, taskOrTaskName, metadata_key, metadata_value) \
+ openvino::itt::ScopedTask<domain> OV_PP_CAT(ittScopedTask, __LINE__)( \
+ openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)>(taskOrTaskName), \
+ metadata_key, \
+ metadata_value);
+
/**
* @def OV_ITT_SCOPED_REGION_BASE(domain, handleOrRegionName)
* @ingroup ov_dev_profiling
@@ -329,8 +379,15 @@ public:
* @details In case if handle or regionName absent, the current function name is used.
* @note Implements a region scope (single-active per thread; tasks started within
* the region attach as children).
+ * @note All *_BASE() macros are enabled by default and will be used by supporting toolchains. The strings
+ * used/provided by these calls should follow the following rules:
+ * - Should NOT be deleted or modified to ensure correct visible names in profiling tools
+ * until CVS-179230 is implemented/resolved.
+ * - Should use string literals or constant strings when possible
* @param domain [in] Known at compile time name of module or library (the domain name).
* @param handleOrRegionName [in] The annotation name or handle for section of code. Parameter is optional.
+ * @param metadata_key [in] A metadata element's key as a string. Parameter is optional.
+ * @param metadata_value [in] The metadata value. Parameter is optional.
*/
#define OV_ITT_SCOPED_REGION_BASE(...) OV_PP_OVERLOAD(OV_ITT_SCOPED_REGION_BASE, __VA_ARGS__)
@@ -342,6 +399,12 @@ public:
openvino::itt::ScopedRegion<domain> OV_PP_CAT(ittScopedRegion, __LINE__)( \
openvino::itt::handle<struct OV_PP_CAT(Region, __LINE__)>(regionOrRegionName));
+#define OV_ITT_SCOPED_REGION_BASE_4(domain, regionOrRegionName, metadata_key, metadata_value) \
+ openvino::itt::ScopedRegion<domain> OV_PP_CAT(ittScopedRegion, __LINE__)( \
+ openvino::itt::handle<struct OV_PP_CAT(Region, __LINE__)>(regionOrRegionName), \
+ metadata_key, \
+ metadata_value);
+
/**
* @def OV_ITT_SCOPED_REGION(group, domain, handleOrRegionName)
* @ingroup ov_dev_profiling
diff --git a/src/common/itt/src/itt.cpp b/src/common/itt/src/itt.cpp
index a5ebe811fe8..990f04997c5 100644
--- a/src/common/itt/src/itt.cpp
+++ b/src/common/itt/src/itt.cpp
@@ -45,10 +45,16 @@ static thread_local uint64_t current_region_counter = 0;
static thread_local void* current_region_handle = nullptr;
domain_t domain(const char* name) {
+ if (name == nullptr) {
+ return nullptr;
+ }
return reinterpret_cast<domain_t>(__itt_domain_create(name));
}
handle_t handle(const char* name) {
+ if (name == nullptr) {
+ return nullptr;
+ }
return reinterpret_cast<handle_t>(__itt_string_handle_create(name));
}
@@ -66,6 +72,26 @@ void taskBegin(domain_t d, handle_t t) {
}
}
+void taskBegin(domain_t d, handle_t t, const char* key, uint64_t value) {
+ if (!is_initialized() || d == nullptr || t == nullptr || key == nullptr) {
+ return;
+ }
+ if (!callStackDepth() || call_stack_depth++ < callStackDepth()) {
+ __itt_id parent_id =
+ current_region_counter != 0 ? __itt_id_make(current_region_handle, current_region_counter) : __itt_null;
+ __itt_domain* domain = reinterpret_cast<__itt_domain*>(d);
+ __itt_task_begin(domain, __itt_null, parent_id, reinterpret_cast<__itt_string_handle*>(t));
+ // The task id to which the metadata is assigned to is not available at this point. It will
+ // default to the parent task's ID
+ __itt_metadata_add(domain,
+ __itt_null,
+ __itt_string_handle_create(key),
+ __itt_metadata_u64,
+ 1,
+ static_cast<void*>(const_cast<uint64_t*>(&value)));
+ }
+}
+
void taskEnd(domain_t d) {
if (!is_initialized() || d == nullptr) {
return;
@@ -96,6 +122,26 @@ void regionBegin(domain_t d, handle_t t) {
reinterpret_cast<__itt_string_handle*>(t));
}
+void regionBegin(domain_t d, handle_t t, const char* key, uint64_t value) {
+ if (!is_initialized() || d == nullptr || t == nullptr || key == nullptr) {
+ return;
+ }
+ std::lock_guard<std::mutex> lock(region_mutex);
+ auto region_counter = nextRegionId();
+ current_region_counter = region_counter;
+ current_region_handle = reinterpret_cast<void*>(t);
+ __itt_domain* domain = reinterpret_cast<__itt_domain*>(d);
+ __itt_id region_id = __itt_id_make(current_region_handle, current_region_counter);
+ __itt_region_begin(domain, region_id, __itt_null, reinterpret_cast<__itt_string_handle*>(t));
+ // Associate the <key-value> pair with the region
+ __itt_metadata_add(domain,
+ region_id,
+ __itt_string_handle_create(key),
+ __itt_metadata_u64,
+ 1,
+ static_cast<void*>(const_cast<uint64_t*>(&value)));
+}
+
void regionEnd(domain_t d) {
if (!is_initialized() || d == nullptr) {
return;
@@ -126,12 +172,16 @@ handle_t handle(const char*) {
void taskBegin(domain_t, handle_t) {}
+void taskBegin(domain_t, handle_t, const char*, uint64_t) {}
+
void taskEnd(domain_t) {}
void threadName(const char*) {}
void regionBegin(domain_t, handle_t) {}
+void regionBegin(domain_t, handle_t, const char*, uint64_t) {}
+
void regionEnd(domain_t) {}
void shutdown() {}
diff --git a/src/inference/dev_api/openvino/runtime/iasync_infer_request.hpp b/src/inference/dev_api/openvino/runtime/iasync_infer_request.hpp
index 6faa16c09dc..6d066cc95a7 100644
--- a/src/inference/dev_api/openvino/runtime/iasync_infer_request.hpp
+++ b/src/inference/dev_api/openvino/runtime/iasync_infer_request.hpp
@@ -193,6 +193,7 @@ protected:
Pipeline m_pipeline; //!< Pipeline variable that should be filled by inherited class.
Pipeline m_sync_pipeline; //!< Synchronous pipeline variable that should be filled by inherited class.
+ uint64_t m_infer_id; //!< Id of inference request execution. Should be increased on each inference start.
private:
enum InferState { IDLE, BUSY, CANCELLED, STOP };
diff --git a/src/inference/dev_api/openvino/runtime/plugin_itt.hpp b/src/inference/dev_api/openvino/runtime/plugin_itt.hpp
index e2713d61d9a..fa7e4e4b557 100644
--- a/src/inference/dev_api/openvino/runtime/plugin_itt.hpp
+++ b/src/inference/dev_api/openvino/runtime/plugin_itt.hpp
@@ -16,6 +16,9 @@ namespace itt {
namespace domains {
OV_ITT_DOMAIN(Plugin)
OV_ITT_DOMAIN(PluginLoadTime)
+// Domain to track inference request execution from the higher-level runtime layer.
+// All plugin inference requests share the "ov::phases::inference" domain.
+OV_ITT_DOMAIN(Inference, "ov::phases::inference");
} // namespace domains
} // namespace itt
} // namespace ov
diff --git a/src/inference/src/cpp/core.cpp b/src/inference/src/cpp/core.cpp
index fd8359fee7c..bd48dd01ca6 100644
--- a/src/inference/src/cpp/core.cpp
+++ b/src/inference/src/cpp/core.cpp
@@ -81,7 +81,7 @@ std::map<std::string, Version> Core::get_versions(const std::string& device_name
std::shared_ptr<ov::Model> Core::read_model(const std::filesystem::path& model_path,
const std::filesystem::path& bin_path,
const ov::AnyMap& properties) const {
- OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::OV, "Read model");
+ OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::Phases, "Read model");
OV_CORE_CALL_STATEMENT(return _impl->read_model(model_path, bin_path, properties););
}
@@ -213,6 +213,8 @@ void Core::add_extension(const std::vector<std::shared_ptr<ov::Extension>>& exte
CompiledModel Core::import_model(std::istream& modelStream, const std::string& device_name, const AnyMap& config) {
OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::Phases, "Import Model");
+ // Preserving the old task for conditional compilation and not on by default
+ OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::import_model");
OV_CORE_CALL_STATEMENT({
auto exec = _impl->import_model(modelStream, device_name, config);
return {exec._ptr, exec._so};
@@ -221,7 +223,8 @@ CompiledModel Core::import_model(std::istream& modelStream, const std::string& d
CompiledModel Core::import_model(std::istream& modelStream, const RemoteContext& context, const AnyMap& config) {
OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::Phases, "Import Model");
-
+ // Preserving the old task for conditional compilation and not on by default
+ OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::import_model");
OV_CORE_CALL_STATEMENT({
auto exec = _impl->import_model(modelStream, ov::SoPtr<ov::IRemoteContext>{context._impl, context._so}, config);
return {exec._ptr, exec._so};
@@ -230,6 +233,8 @@ CompiledModel Core::import_model(std::istream& modelStream, const RemoteContext&
CompiledModel Core::import_model(const ov::Tensor& model, const std::string& device_name, const AnyMap& config) {
OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::Phases, "Import Model");
+ // Preserving the old task for conditional compilation and not on by default
+ OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::import_model");
OV_CORE_CALL_STATEMENT({
auto exec = _impl->import_model(model, device_name, config);
return {exec._ptr, exec._so};
@@ -238,7 +243,8 @@ CompiledModel Core::import_model(const ov::Tensor& model, const std::string& dev
CompiledModel Core::import_model(const ov::Tensor& model, const RemoteContext& context, const AnyMap& config) {
OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::Phases, "Import Model");
-
+ // Preserving the old task for conditional compilation and not on by default
+ OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::import_model");
OV_CORE_CALL_STATEMENT({
auto exec = _impl->import_model(model, ov::SoPtr<ov::IRemoteContext>{context._impl, context._so}, config);
return {exec._ptr, exec._so};
diff --git a/src/inference/src/dev/iasync_infer_request.cpp b/src/inference/src/dev/iasync_infer_request.cpp
index c1b5395c972..323ebab688c 100644
--- a/src/inference/src/dev/iasync_infer_request.cpp
+++ b/src/inference/src/dev/iasync_infer_request.cpp
@@ -4,14 +4,20 @@
#include "openvino/runtime/iasync_infer_request.hpp"
+#include <atomic>
#include <memory>
#include "openvino/runtime/isync_infer_request.hpp"
#include "openvino/runtime/ivariable_state.hpp"
+#include "openvino/runtime/plugin_itt.hpp"
#include "openvino/runtime/threading/immediate_executor.hpp"
#include "openvino/runtime/threading/istreams_executor.hpp"
#include "openvino/runtime/variable_state.hpp"
+/// @brief Thread-safe global counter for unique inference request IDs that
+/// are needed for asynchronous inference.
+static std::atomic<uint64_t> g_inference_uid = {1};
+
namespace {
struct ImmediateStreamsExecutor : public ov::threading::ITaskExecutor {
@@ -37,7 +43,8 @@ ov::IAsyncInferRequest::~IAsyncInferRequest() {
ov::IAsyncInferRequest::IAsyncInferRequest(const std::shared_ptr<IInferRequest>& request,
const std::shared_ptr<ov::threading::ITaskExecutor>& task_executor,
const std::shared_ptr<ov::threading::ITaskExecutor>& callback_executor)
- : m_sync_request(request),
+ : m_infer_id(0),
+ m_sync_request(request),
m_request_executor(task_executor),
m_callback_executor(callback_executor) {
if (m_request_executor && m_sync_request)
@@ -119,6 +126,7 @@ void ov::IAsyncInferRequest::start_async_thread_unsafe() {
void ov::IAsyncInferRequest::run_first_stage(const Pipeline::iterator itBeginStage,
const Pipeline::iterator itEndStage,
const std::shared_ptr<ov::threading::ITaskExecutor> callbackExecutor) {
+ m_infer_id = g_inference_uid++;
auto& firstStageExecutor = std::get<Stage_e::EXECUTOR>(*itBeginStage);
OPENVINO_ASSERT(nullptr != firstStageExecutor);
firstStageExecutor->run(make_next_stage_task(itBeginStage, itEndStage, std::move(callbackExecutor)));
@@ -130,6 +138,8 @@ ov::threading::Task ov::IAsyncInferRequest::make_next_stage_task(
const std::shared_ptr<ov::threading::ITaskExecutor> callbackExecutor) {
return std::bind(
[this, itStage, itEndStage](std::shared_ptr<ov::threading::ITaskExecutor>& callbackExecutor) mutable {
+ // Propagate the inference ID through all subsequent stages for this instance of the pipeline
+ OV_ITT_SCOPED_REGION_BASE(ov::itt::domains::Inference, "Inference::pipeline", "InferenceID", m_infer_id);
std::exception_ptr currentException = nullptr;
auto& thisStage = *itStage;
auto itNextStage = itStage + 1;
diff --git a/src/inference/src/itt.hpp b/src/inference/src/itt.hpp
index 883fac52a99..636a52c8dcd 100644
--- a/src/inference/src/itt.hpp
+++ b/src/inference/src/itt.hpp
@@ -18,7 +18,7 @@ namespace domains {
OV_ITT_DOMAIN(OV, "ov");
OV_ITT_DOMAIN(ReadTime, "ov::ReadTime");
OV_ITT_DOMAIN(LoadTime, "ov::LoadTime");
-// Domain used for marking phases in the runtime
+// Domain used for marking high-level phases in the runtime
OV_ITT_DOMAIN(Phases, "ov::phases");
} // namespace domains
} // namespace itt
diff --git a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
index 7d12c15f716..25ab54658a2 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
@@ -717,6 +717,7 @@ void ZeroInferRequest::update_states_if_memory_changed() {
}
void ZeroInferRequest::infer() {
+ OV_ITT_SCOPED_TASK_BASE(itt::domains::InferenceNPU, "SyncInferenceNPU");
if (_config.get<RUN_INFERENCES_SEQUENTIALLY>()) {
OPENVINO_THROW("Only start async is supported when RUN_INFERENCES_SEQUENTIALLY is enabled!");
}
@@ -727,6 +728,9 @@ void ZeroInferRequest::infer() {
void ZeroInferRequest::infer_async() {
_logger.debug("InferRequest::infer_async started");
+ // TASK_BASE marker is always on by default
+ OV_ITT_SCOPED_TASK_BASE(itt::domains::InferenceNPU, "Inference::start");
+ // This task chain marker will only be available when ENABLE_PROFILING_ITT=FULL
OV_ITT_TASK_CHAIN(ZERO_INFER, itt::domains::LevelZeroBackend, "infer_async", "start");
prepare_inputs();
prepare_outputs();
@@ -876,6 +880,7 @@ void ZeroInferRequest::prepare_outputs() {
}
void ZeroInferRequest::get_result() {
+ OV_ITT_SCOPED_TASK_BASE(itt::domains::InferenceNPU, "Inference::get_result");
OV_ITT_TASK_CHAIN(ZERO_RESULT, itt::domains::LevelZeroBackend, "get_result", "pull");
_logger.debug("InferRequest::get_result start");
_pipeline->pull();
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 762909981fd..6a619ca5bb6 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
@@ -251,7 +251,11 @@ void Pipeline::push() {
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
+ OV_ITT_SCOPED_TASK_BASE(itt::domains::InferenceNPU,
+ "Pipeline::push",
+ "CommandListID",
+ (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));
@@ -268,6 +272,12 @@ void Pipeline::pull() {
OV_ITT_TASK_CHAIN(ZERO_PIPELINE_IP_PULL, itt::domains::LevelZeroBackend, "Pipeline", "pull");
for (size_t i = 0; i < _command_lists.size(); ++i) {
+ // Emit a marker for pipeline::pull() with the command list handle as the metadata
+ // so it can be correlated with the corresponding push() marker in the timeline
+ OV_ITT_SCOPED_TASK_BASE(itt::domains::InferenceNPU,
+ "Pipeline::pull",
+ "CommandListID",
+ (uintptr_t)_command_lists.at(i)->handle());
if (_sync_output_with_fences) {
_fences.at(i)->hostSynchronize();
} else {
@@ -283,6 +293,7 @@ void Pipeline::pull() {
};
void Pipeline::reset() const {
+ OV_ITT_SCOPED_TASK_BASE(itt::domains::InferenceNPU, "Pipeline::reset");
_logger.debug("Pipeline - rest() started");
for (size_t i = 0; i < _command_lists.size(); ++i) {
diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/itt.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/itt.hpp
index 873ff09d6d1..17a824407a9 100644
--- a/src/plugins/intel_npu/src/common/include/intel_npu/common/itt.hpp
+++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/itt.hpp
@@ -12,7 +12,9 @@ namespace domains {
OV_ITT_DOMAIN(NPUPlugin);
OV_ITT_DOMAIN(LevelZeroBackend);
-
+// Domain namespace to define NPU Inference phase tasks
+OV_ITT_DOMAIN(InferenceNPU, "ov::phases::npu::inference");
+OV_ITT_DOMAIN(NPUOps, "ov::op::npu");
} // namespace domains
} // namespace itt
} // namespace intel_npu