Skip to content

Qualcomm AI Engine Direct - add more profile event #10227

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

Merged
merged 2 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions backends/qualcomm/runtime/backends/QnnProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ Qnn_ErrorHandle_t QnnProfile::ProfileData(
"ProfileData failed to get events: %d", QNN_GET_ERROR_CODE(error));
return error;
}

auto get_unit = [](QnnProfile_EventUnit_t unit) {
switch (unit) {
case QNN_PROFILE_EVENTUNIT_MICROSEC:
return " (us)";
case QNN_PROFILE_EVENTUNIT_BYTES:
return " (bytes)";
case QNN_PROFILE_EVENTUNIT_COUNT:
return " (count)";
case QNN_PROFILE_EVENTUNIT_BACKEND:
// cycle unit is default appeared
case QNN_PROFILE_EVENTUNIT_CYCLES:
default:
return "";
}
};
QnnProfile_EventData_t event_data;
for (std::uint32_t i = 0; i < num_events; ++i) {
error =
Expand All @@ -96,6 +112,16 @@ Qnn_ErrorHandle_t QnnProfile::ProfileData(
QNN_GET_ERROR_CODE(error));
return error;
}
// add events for other important metrics, e.g. RPC execution time
std::string identifier =
std::string(event_data.identifier) + get_unit(event_data.unit);
executorch::runtime::event_tracer_log_profiling_delegate(
event_tracer,
identifier.c_str(),
/*delegate_debug_id=*/
static_cast<executorch::runtime::DebugHandle>(-1),
0,
event_data.value);
// Check an event's sub events only if it relates to graph execution time
// (and its sub events are the individual op executions):
if (backend_->IsProfileEventTypeParentOfNodeTime(event_data.type)) {
Expand All @@ -109,6 +135,7 @@ Qnn_ErrorHandle_t QnnProfile::ProfileData(
QNN_GET_ERROR_CODE(error));
return error;
}

QnnProfile_EventData_t sub_event_data;
for (std::uint32_t j = 0; j < num_sub_events; ++j) {
error = qnn_interface.qnn_profile_get_event_data(
Expand Down
4 changes: 2 additions & 2 deletions backends/qualcomm/tests/test_qnn_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,7 @@ def test_qnn_backend_profile_op(self):
module,
sample_input,
expected_partitions=1,
expected_profile_events=24,
expected_profile_events=34,
)

def test_qnn_backend_shared_buffer(self):
Expand Down Expand Up @@ -3109,7 +3109,7 @@ def test_qnn_backend_profile_op(self):
module,
sample_input,
expected_partitions=1,
expected_profile_events=25,
expected_profile_events=35,
)

def test_qnn_backend_shared_buffer(self):
Expand Down
8 changes: 7 additions & 1 deletion backends/qualcomm/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
to_edge_transform_and_lower_to_qnn,
)
from executorch.devtools import generate_etrecord, Inspector
from executorch.devtools.inspector._inspector_utils import TimeScale
from executorch.examples.qualcomm.utils import (
generate_inputs,
make_output_dir,
Expand Down Expand Up @@ -290,7 +291,12 @@ def post_process():
outputs.append(output)

def validate_profile():
inspector = Inspector(etdump_path=etdump_path, etrecord=etrecord_path)
inspector = Inspector(
etdump_path=etdump_path,
etrecord=etrecord_path,
source_time_scale=TimeScale.CYCLES,
target_time_scale=TimeScale.CYCLES,
)
self.assertTrue(
len(inspector.to_dataframe().index) == expected_profile_events
)
Expand Down
Loading