-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add enable_profiling in runoptions #26846
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: main
Are you sure you want to change the base?
Changes from all commits
c48efdb
fdda5f5
e44263d
5f0a9aa
f941581
e7ba277
0839b1b
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 |
|---|---|---|
|
|
@@ -77,7 +77,7 @@ | |
| void EndTimeAndRecordEvent(EventCategory category, | ||
| const std::string& event_name, | ||
| const TimePoint& start_time, | ||
| const std::initializer_list<std::pair<std::string, std::string>>& event_args = {}, | ||
| std::unordered_map<std::string, std::string> event_args = {}, | ||
|
Check warning on line 80 in onnxruntime/core/common/profiler.h
|
||
|
Member
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. |
||
| bool sync_gpu = false); | ||
|
|
||
| /* | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,8 +155,8 @@ std::string ComposeSeriesName(const GraphViewer& graph_viewer) { | |
| class SessionScope { | ||
| public: | ||
| friend class KernelScope; | ||
| SessionScope(const SessionState& session_state, const ExecutionFrame& frame) | ||
| : session_state_(session_state) | ||
| SessionScope(const SessionState& session_state, const ExecutionFrame& frame, profiling::Profiler* run_profiler = nullptr) | ||
|
Member
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. |
||
| : session_state_(session_state), run_profiler_(run_profiler) | ||
| #if !defined(ORT_MINIMAL_BUILD) && defined(ORT_MEMORY_PROFILE) | ||
| , | ||
| frame_(frame) | ||
|
|
@@ -173,12 +173,16 @@ class SessionScope { | |
| #endif | ||
| #ifdef DEBUG_NODE_INPUTS_OUTPUTS | ||
| , | ||
| dump_context_{ | ||
| session_state_.GetGraphExecutionCounter(), 0} | ||
| dump_context_{session_state_.GetGraphExecutionCounter(), 0} | ||
| #endif | ||
| { | ||
| if (session_state_.Profiler().IsEnabled()) { | ||
| session_start_ = session_state.Profiler().Start(); | ||
| const bool session_profiling_enabled = session_state_.Profiler().IsEnabled(); | ||
| const bool run_profiling_enabled = IsRunProfilingEnabled(); | ||
|
|
||
| if (session_profiling_enabled) { | ||
| session_start_ = session_state_.Profiler().Start(); | ||
| } else if (run_profiling_enabled) { | ||
| session_start_ = run_profiler_->Start(); | ||
| } | ||
|
|
||
| auto& logger = session_state_.Logger(); | ||
|
|
@@ -225,9 +229,15 @@ class SessionScope { | |
| } | ||
| #endif | ||
|
|
||
| if (session_state_.Profiler().IsEnabled()) { | ||
| const bool session_profiling_enabled = session_state_.Profiler().IsEnabled(); | ||
| const bool run_profiling_enabled = run_profiler_ && run_profiler_->IsEnabled(); | ||
|
|
||
| if (session_profiling_enabled) { | ||
| session_state_.Profiler().EndTimeAndRecordEvent(profiling::SESSION_EVENT, "SequentialExecutor::Execute", session_start_); | ||
| } else if (run_profiling_enabled) { | ||
| StopEvent(profiling::SESSION_EVENT, "SequentialExecutor::Execute", session_start_); | ||
| } | ||
|
Member
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. Can we wrap this into a function StopProfilingIfEnabled() |
||
|
|
||
| #if !defined(ORT_MINIMAL_BUILD) && defined(ORT_MEMORY_PROFILE) | ||
| auto& logger = session_state_.Logger(); | ||
| for (auto i : frame_.GetStaticMemorySizeInfo()) { | ||
|
|
@@ -252,8 +262,24 @@ class SessionScope { | |
| } | ||
| #endif | ||
|
|
||
| bool IsRunProfilingEnabled() const { | ||
| return run_profiler_ && run_profiler_->IsEnabled(); | ||
| } | ||
|
|
||
| void StopEvent(profiling::EventCategory category, | ||
| const std::string& event_name, | ||
| const TimePoint& start_time, | ||
| std::unordered_map<std::string, std::string> event_args = {}) { | ||
| if (!run_profiler_) return; | ||
| run_profiler_->EndTimeAndRecordEvent(category, | ||
| event_name, | ||
| start_time, | ||
| std::move(event_args)); | ||
| } | ||
|
|
||
| private: | ||
| const SessionState& session_state_; | ||
| profiling::Profiler* run_profiler_; | ||
| TimePoint session_start_; | ||
| #if !defined(ORT_MINIMAL_BUILD) && defined(ORT_MEMORY_PROFILE) | ||
| const ExecutionFrame& frame_; | ||
|
|
@@ -340,16 +366,21 @@ class KernelScope { | |
| utils::DumpNodeInputs(dump_context_, kernel_context_, kernel_.Node(), session_state_, session_scope_.dump_analysis_); | ||
| #endif | ||
|
|
||
| #ifdef ENABLE_NVTX_PROFILE | ||
| node_compute_range_.Begin(); | ||
| #endif | ||
| const bool session_profiling_enabled = session_state_.Profiler().IsEnabled(); | ||
| const bool run_profiling_enabled = session_scope_.IsRunProfilingEnabled(); | ||
|
|
||
| if (session_state_.Profiler().IsEnabled()) { | ||
| if (session_profiling_enabled || run_profiling_enabled) { | ||
| auto& node = kernel.Node(); | ||
| node_name_ = node.Name().empty() ? MakeString(node.OpType(), "_", node.Index()) : node.Name(); | ||
| concurrency::ThreadPool::StartProfiling(session_state_.GetThreadPool()); | ||
| VLOGS(session_state_.Logger(), 1) << "Computing kernel: " << node_name_; | ||
| kernel_begin_time_ = session_state_.Profiler().Start(); | ||
|
|
||
| if (session_profiling_enabled) { | ||
| kernel_begin_time_ = session_state_.Profiler().Start(); | ||
| } else { | ||
| kernel_begin_time_ = session_scope_.run_profiler_->Start(); | ||
| } | ||
|
Member
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. Can we wrap this into a SessionScopt method?
Contributor
Author
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. Thanks. Added |
||
|
|
||
| CalculateTotalInputSizes(&kernel_context, &kernel_, | ||
| input_activation_sizes_, input_parameter_sizes_, | ||
| node_name_, input_type_shape_); | ||
|
|
@@ -363,26 +394,37 @@ class KernelScope { | |
| node_compute_range_.End(); | ||
| #endif | ||
|
|
||
| if (session_state_.Profiler().IsEnabled()) { | ||
| auto& profiler = session_state_.Profiler(); | ||
| const bool session_profiling_enabled = session_state_.Profiler().IsEnabled(); | ||
| const bool run_profiling_enabled = session_scope_.IsRunProfilingEnabled(); | ||
|
|
||
| if (session_profiling_enabled || run_profiling_enabled) { | ||
| std::string output_type_shape_; | ||
| CalculateTotalOutputSizes(&kernel_context_, total_output_sizes_, node_name_, output_type_shape_); | ||
| profiler.EndTimeAndRecordEvent(profiling::NODE_EVENT, | ||
| node_name_ + "_kernel_time", | ||
| kernel_begin_time_, | ||
| // Log additional operation args / info. | ||
| { | ||
| {"op_name", kernel_.KernelDef().OpName()}, | ||
| {"provider", kernel_.KernelDef().Provider()}, | ||
| {"node_index", std::to_string(kernel_.Node().Index())}, | ||
| {"activation_size", std::to_string(input_activation_sizes_)}, | ||
| {"parameter_size", std::to_string(input_parameter_sizes_)}, | ||
| {"output_size", std::to_string(total_output_sizes_)}, | ||
| {"input_type_shape", input_type_shape_}, | ||
| {"output_type_shape", output_type_shape_}, | ||
| {"thread_scheduling_stats", | ||
| concurrency::ThreadPool::StopProfiling(session_state_.GetThreadPool())}, | ||
| }); | ||
|
|
||
| std::unordered_map<std::string, std::string> event_args = { | ||
| {"op_name", kernel_.KernelDef().OpName()}, | ||
| {"provider", kernel_.KernelDef().Provider()}, | ||
| {"node_index", std::to_string(kernel_.Node().Index())}, | ||
| {"activation_size", std::to_string(input_activation_sizes_)}, | ||
| {"parameter_size", std::to_string(input_parameter_sizes_)}, | ||
| {"output_size", std::to_string(total_output_sizes_)}, | ||
| {"input_type_shape", input_type_shape_}, | ||
| {"output_type_shape", output_type_shape_}, | ||
| {"thread_scheduling_stats", | ||
| concurrency::ThreadPool::StopProfiling(session_state_.GetThreadPool())}, | ||
| }; | ||
|
|
||
| if (session_profiling_enabled) { | ||
| session_state_.Profiler().EndTimeAndRecordEvent(profiling::NODE_EVENT, | ||
| node_name_ + "_kernel_time", | ||
| kernel_begin_time_, | ||
| std::move(event_args)); | ||
| } else if (run_profiling_enabled) { | ||
| session_scope_.StopEvent(profiling::NODE_EVENT, | ||
| node_name_ + "_kernel_time", | ||
| kernel_begin_time_, | ||
| std::move(event_args)); | ||
| } | ||
| } | ||
|
|
||
| #ifdef ONNXRUNTIME_ENABLE_INSTRUMENT | ||
|
|
@@ -588,7 +630,8 @@ onnxruntime::Status ExecuteThePlan(const SessionState& session_state, gsl::span< | |
| #endif | ||
| const bool& terminate_flag, | ||
| const bool only_execute_path_to_fetches, | ||
| bool single_thread_mode) { | ||
| bool single_thread_mode, | ||
| profiling::Profiler* run_profiler) { | ||
| auto* execution_plan = session_state.GetExecutionPlan(); | ||
| VLOGS(logger, 0) << "Number of streams: " << execution_plan->execution_plan.size(); | ||
| int32_t valid_streams = 0; | ||
|
|
@@ -631,7 +674,7 @@ onnxruntime::Status ExecuteThePlan(const SessionState& session_state, gsl::span< | |
| ORT_UNUSED_PARAMETER(only_execute_path_to_fetches); | ||
| #endif | ||
|
|
||
| SessionScope session_scope(session_state, ctx.GetExecutionFrame()); | ||
| SessionScope session_scope(session_state, ctx.GetExecutionFrame(), run_profiler); | ||
|
|
||
| auto* tp = single_thread_mode ? nullptr : session_state.GetInterOpThreadPool(); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.