-
Notifications
You must be signed in to change notification settings - Fork 3k
[OV][ITT] Enhance ITT MACROS to accept metadata for ID propagation - Redux #33639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
29a4bfa
58ecfe5
ca698fc
9ffcf50
7406de7
550863d
30bef83
930b2d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,10 +43,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 (!is_initialized() || name == nullptr) { | ||
| return nullptr; | ||
| } | ||
| return reinterpret_cast<domain_t>(__itt_domain_create(name)); | ||
| } | ||
|
|
||
| handle_t handle(const char* name) { | ||
| if (!is_initialized() || name == nullptr) { | ||
| return nullptr; | ||
| } | ||
| return reinterpret_cast<handle_t>(__itt_string_handle_create(name)); | ||
| } | ||
|
|
||
|
|
@@ -64,6 +70,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 ? key : "unknown"), | ||
| __itt_metadata_u64, | ||
| 1, | ||
| static_cast<void*>(const_cast<uint64_t*>(&value))); | ||
| } | ||
| } | ||
|
|
||
| void taskEnd(domain_t d) { | ||
| if (!is_initialized() || d == nullptr) { | ||
| return; | ||
|
|
@@ -94,6 +120,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 ? key : "unknown"), | ||
|
||
| __itt_metadata_u64, | ||
| 1, | ||
| static_cast<void*>(const_cast<uint64_t*>(&value))); | ||
| } | ||
|
|
||
| void regionEnd(domain_t d) { | ||
| if (!is_initialized() || d == nullptr) { | ||
| return; | ||
|
|
@@ -120,12 +166,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) {} | ||
|
|
||
| #endif // ENABLE_PROFILING_ITT | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,22 @@ | |
|
|
||
| #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" | ||
|
|
||
| // Only enable tracking of the pipeline stages when base or full profiling is enabled | ||
| #if defined(ENABLE_PROFILING_ITT_FULL) || defined(ENABLE_PROFILING_ITT_BASE) | ||
| #define INITIALIZE_ID_COUNTER m_infer_id = 0 | ||
| #define UPDATE_ID_COUNTER m_infer_id = g_uid++ | ||
| #define USE_ID_COUNTER m_infer_id | ||
| #else | ||
| #define INITIALIZE_ID_COUNTER | ||
| #define UPDATE_ID_COUNTER | ||
| #define USE_ID_COUNTER | ||
| #endif | ||
|
|
||
| namespace { | ||
|
|
||
| struct ImmediateStreamsExecutor : public ov::threading::ITaskExecutor { | ||
|
|
@@ -30,6 +42,11 @@ struct ImmediateStreamsExecutor : public ov::threading::ITaskExecutor { | |
|
|
||
| } // namespace | ||
|
|
||
| #if defined(ENABLE_PROFILING_ITT_FULL) || defined(ENABLE_PROFILING_ITT_BASE) | ||
| /// @brief Thread-safe counter for unique inference request IDs. | ||
| std::atomic<uint64_t> g_uid = {1}; | ||
| #endif | ||
|
|
||
| ov::IAsyncInferRequest::~IAsyncInferRequest() { | ||
| stop_and_wait(); | ||
| } | ||
|
|
@@ -40,6 +57,7 @@ ov::IAsyncInferRequest::IAsyncInferRequest(const std::shared_ptr<IInferRequest>& | |
| : m_sync_request(request), | ||
| m_request_executor(task_executor), | ||
| m_callback_executor(callback_executor) { | ||
| INITIALIZE_ID_COUNTER; | ||
praasz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (m_request_executor && m_sync_request) | ||
| m_pipeline = {{m_request_executor, [this] { | ||
| m_sync_request->infer(); | ||
|
|
@@ -119,6 +137,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) { | ||
| UPDATE_ID_COUNTER; | ||
| 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 +149,13 @@ 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 { | ||
| #if defined(ENABLE_PROFILING_ITT_FULL) || defined(ENABLE_PROFILING_ITT_BASE) | ||
| // 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); // DO NOT MODIFY! | ||
|
||
| #endif | ||
| std::exception_ptr currentException = nullptr; | ||
| auto& thisStage = *itStage; | ||
| auto itNextStage = itStage + 1; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,9 @@ 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment is not descriptive. "Phases" of which process are being marked here? |
||
| // DO NOT MODIFY OR DELETE! | ||
| OV_ITT_DOMAIN(Phases, "ov::phases"); | ||
| } // namespace domains | ||
| } // namespace itt | ||
| } // namespace ov | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is key == nullptr possible on this line? We have checked if key is null or not on line 74