Skip to content

Commit 79d0b6a

Browse files
authored
Qualcomm AI Engine Direct - add more profile event (#10227)
### Summary - add more profile event for important metrics. e.g. RPC execution time - change test cases accordingly ![image](https://github.com/user-attachments/assets/03e5a423-90c7-4e63-970b-6793c1e93915) ### Test plan ```python backends/qualcomm/tests/test_qnn_delegate.py -k TestQNNQuantizedUtils.test_qnn_backend_profile_op -s $DEVICE_ID -m SM8650 -b build-android/```
1 parent 6886974 commit 79d0b6a

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

backends/qualcomm/runtime/backends/QnnProfiler.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ Qnn_ErrorHandle_t QnnProfile::ProfileData(
8484
"ProfileData failed to get events: %d", QNN_GET_ERROR_CODE(error));
8585
return error;
8686
}
87+
88+
auto get_unit = [](QnnProfile_EventUnit_t unit) {
89+
switch (unit) {
90+
case QNN_PROFILE_EVENTUNIT_MICROSEC:
91+
return " (us)";
92+
case QNN_PROFILE_EVENTUNIT_BYTES:
93+
return " (bytes)";
94+
case QNN_PROFILE_EVENTUNIT_COUNT:
95+
return " (count)";
96+
case QNN_PROFILE_EVENTUNIT_BACKEND:
97+
// cycle unit is default appeared
98+
case QNN_PROFILE_EVENTUNIT_CYCLES:
99+
default:
100+
return "";
101+
}
102+
};
87103
QnnProfile_EventData_t event_data;
88104
for (std::uint32_t i = 0; i < num_events; ++i) {
89105
error =
@@ -96,6 +112,16 @@ Qnn_ErrorHandle_t QnnProfile::ProfileData(
96112
QNN_GET_ERROR_CODE(error));
97113
return error;
98114
}
115+
// add events for other important metrics, e.g. RPC execution time
116+
std::string identifier =
117+
std::string(event_data.identifier) + get_unit(event_data.unit);
118+
executorch::runtime::event_tracer_log_profiling_delegate(
119+
event_tracer,
120+
identifier.c_str(),
121+
/*delegate_debug_id=*/
122+
static_cast<executorch::runtime::DebugHandle>(-1),
123+
0,
124+
event_data.value);
99125
// Check an event's sub events only if it relates to graph execution time
100126
// (and its sub events are the individual op executions):
101127
if (backend_->IsProfileEventTypeParentOfNodeTime(event_data.type)) {
@@ -109,6 +135,7 @@ Qnn_ErrorHandle_t QnnProfile::ProfileData(
109135
QNN_GET_ERROR_CODE(error));
110136
return error;
111137
}
138+
112139
QnnProfile_EventData_t sub_event_data;
113140
for (std::uint32_t j = 0; j < num_sub_events; ++j) {
114141
error = qnn_interface.qnn_profile_get_event_data(

backends/qualcomm/tests/test_qnn_delegate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2505,7 +2505,7 @@ def test_qnn_backend_profile_op(self):
25052505
module,
25062506
sample_input,
25072507
expected_partitions=1,
2508-
expected_profile_events=24,
2508+
expected_profile_events=34,
25092509
)
25102510

25112511
def test_qnn_backend_shared_buffer(self):
@@ -3120,7 +3120,7 @@ def test_qnn_backend_profile_op(self):
31203120
module,
31213121
sample_input,
31223122
expected_partitions=1,
3123-
expected_profile_events=25,
3123+
expected_profile_events=35,
31243124
)
31253125

31263126
def test_qnn_backend_shared_buffer(self):

backends/qualcomm/tests/utils.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
to_edge_transform_and_lower_to_qnn,
3131
)
3232
from executorch.devtools import generate_etrecord, Inspector
33+
from executorch.devtools.inspector._inspector_utils import TimeScale
3334
from executorch.examples.qualcomm.utils import (
3435
generate_inputs,
3536
make_output_dir,
@@ -290,7 +291,12 @@ def post_process():
290291
outputs.append(output)
291292

292293
def validate_profile():
293-
inspector = Inspector(etdump_path=etdump_path, etrecord=etrecord_path)
294+
inspector = Inspector(
295+
etdump_path=etdump_path,
296+
etrecord=etrecord_path,
297+
source_time_scale=TimeScale.CYCLES,
298+
target_time_scale=TimeScale.CYCLES,
299+
)
294300
self.assertTrue(
295301
len(inspector.to_dataframe().index) == expected_profile_events
296302
)

0 commit comments

Comments
 (0)