Skip to content

Commit

Permalink
Refine logging for execution plan print (#19777)
Browse files Browse the repository at this point in the history
### Refine logging for execution plan print

Printing NodeIndex only is not enough for us to debug the execution
order.

keep original behaviour for ORT_MINIMAL_BUILD build in case of any CPU
memory concerns.



### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
  • Loading branch information
pengwa authored Mar 14, 2024
1 parent 0be0791 commit 409b811
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
11 changes: 10 additions & 1 deletion onnxruntime/core/framework/allocation_planner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,12 @@ class PlannerImpl {
execution_plan.emplace_back(std::make_unique<SequentialExecutionPlan::LogicStream>(node_device_mem_location));
// 2. add steps to the execution plan
for (auto node_index : stream_nodes_[0]) {
#if defined(ORT_MINIMAL_BUILD)
execution_plan[0]->steps_.emplace_back(std::make_unique<LaunchKernelStep>(node_index));
#else
execution_plan[0]->steps_.emplace_back(std::make_unique<LaunchKernelStep>(node_index,
graph_viewer_.GetNode(node_index)->Name()));
#endif
}
} else {
// graph with no nodes. e.g. subgraph of If might return the input as-is or a constant value from an initializer
Expand Down Expand Up @@ -1980,8 +1985,12 @@ class PlannerImpl {
// add dependency for model graph
dependence_graph_[it->Index()].insert(node_index);
}
// push launch kernel command
// push launch kernel command
#if defined(ORT_MINIMAL_BUILD)
execution_plan[i]->steps_.emplace_back(std::make_unique<LaunchKernelStep>(node_index));
#else
execution_plan[i]->steps_.emplace_back(std::make_unique<LaunchKernelStep>(node_index, graph_viewer_.GetNode(node_index)->Name()));
#endif
// check if any notification generated by this node, if yes, push a activate
auto notification_it = node_to_notification.find(node_index);
if (notification_it != node_to_notification.end()) {
Expand Down
40 changes: 27 additions & 13 deletions onnxruntime/core/framework/execution_steps.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include "core/framework/execution_steps.h"
#include "core/framework/sequential_executor.h"

namespace onnxruntime {

BarrierStep::BarrierStep(size_t id, NodeIndex node_index) : SequentialExecutionPlan::ExecutionStep(node_index),
barrier_id_{id} {}

Expand All @@ -16,8 +19,8 @@ Status BarrierStep::Execute(StreamExecutionContext& ctx,
}

std::string BarrierStep::ToString() const {
return ::onnxruntime::MakeString("Set a barrier with id: ",
barrier_id_, ", count: ", 2, ".");
// Set a barrier with id: barrier_id_, count: 2.
return MakeString("Barrier - BarrierId: ", barrier_id_, ", Count: ", 2);
}

WaitOnEPStep::WaitOnEPStep(WaitNotificationFn handle,
Expand All @@ -42,11 +45,17 @@ Status WaitOnEPStep::Execute(StreamExecutionContext& ctx,
}

std::string WaitOnEPStep::ToString() const {
return ::onnxruntime::MakeString("WaitOnEPStep: wait on notification with id: ",
notification_idx_, ". ");
// Wait on notification with notification_idx_
return MakeString("WaitOnEP - NotificationId: ", notification_idx_);
}

LaunchKernelStep::LaunchKernelStep(NodeIndex index) : SequentialExecutionPlan::ExecutionStep(index) {}
#if defined(ORT_MINIMAL_BUILD)
LaunchKernelStep::LaunchKernelStep(NodeIndex index)
: SequentialExecutionPlan::ExecutionStep(index) {}
#else
LaunchKernelStep::LaunchKernelStep(NodeIndex index, std::string_view node_name)
: SequentialExecutionPlan::ExecutionStep(index), node_name_(node_name) {}
#endif

Status LaunchKernelStep::Execute(StreamExecutionContext& ctx,
size_t stream_idx,
Expand All @@ -61,13 +70,17 @@ Status LaunchKernelStep::Execute(StreamExecutionContext& ctx,
return Status::OK();
}
#endif
onnxruntime::Status status = ExecuteKernel(ctx, node_index_, stream_idx, terminate_flag, session_scope);
Status status = ExecuteKernel(ctx, node_index_, stream_idx, terminate_flag, session_scope);
continue_flag = status.IsOK();
return status;
}

std::string LaunchKernelStep::ToString() const {
return ::onnxruntime::MakeString("Launch kernel with node id: ", node_index_, ". ");
#if defined(ORT_MINIMAL_BUILD)
return MakeString("LaunchKernel - ", "NodeIndex: ", node_index_);
#else
return MakeString("LaunchKernel - ", "NodeIndex: ", node_index_, ", Name: ", node_name_);
#endif
}

ActivateNotificationStep::ActivateNotificationStep(
Expand All @@ -89,12 +102,12 @@ Status ActivateNotificationStep::Execute(StreamExecutionContext& ctx,
}

std::string ActivateNotificationStep::ToString() const {
return ::onnxruntime::MakeString("ActivateNotificationStep: activate notification with id: ",
notification_idx_, ". ");
// Activate notification with id: notification_idx_
return MakeString("ActivateNotification - NotificationId: ", notification_idx_);
}

TriggerDownstreamStep::TriggerDownstreamStep(size_t trigger_point_index, NodeIndex node_index) : SequentialExecutionPlan::ExecutionStep(node_index),
trigger_point_index_(trigger_point_index) {}
TriggerDownstreamStep::TriggerDownstreamStep(size_t trigger_point_index, NodeIndex node_index)
: SequentialExecutionPlan::ExecutionStep(node_index), trigger_point_index_(trigger_point_index) {}

Status TriggerDownstreamStep::Execute(StreamExecutionContext& ctx,
size_t /*stream_idx*/,
Expand All @@ -107,7 +120,8 @@ Status TriggerDownstreamStep::Execute(StreamExecutionContext& ctx,
}

std::string TriggerDownstreamStep::ToString() const {
return ::onnxruntime::MakeString("TriggerDownstreamStep: trigger downstream of trigger point: ",
trigger_point_index_, ".");
// Trigger downstream of trigger point: trigger_point_index_.
return MakeString("TriggerDownstream - TriggerPointIndex: ", trigger_point_index_);
}

} // namespace onnxruntime
9 changes: 9 additions & 0 deletions onnxruntime/core/framework/execution_steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ class WaitOnEPStep : public SequentialExecutionPlan::ExecutionStep {

class LaunchKernelStep : public SequentialExecutionPlan::ExecutionStep {
public:
#if defined(ORT_MINIMAL_BUILD)
LaunchKernelStep(NodeIndex index);
#else
LaunchKernelStep(NodeIndex index, std::string_view node_name);
#endif

Status Execute(StreamExecutionContext& ctx,
size_t stream_idx,
Expand All @@ -53,6 +57,11 @@ class LaunchKernelStep : public SequentialExecutionPlan::ExecutionStep {
bool& continue_flag) override;

std::string ToString() const override;

#if !defined(ORT_MINIMAL_BUILD)
private:
std::string node_name_;
#endif
};

class ActivateNotificationStep : public SequentialExecutionPlan::ExecutionStep {
Expand Down

0 comments on commit 409b811

Please sign in to comment.