Skip to content

Commit 6086d6e

Browse files
authored
Support optrace
Differential Revision: D64941627 Pull Request resolved: #6535
1 parent 1bde32c commit 6086d6e

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

backends/qualcomm/runtime/backends/QnnFunctionInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class QnnInterface {
7070
DEFINE_SHIM_FUNCTION_INTERFACE(log_set_log_level, logSetLogLevel);
7171
// --------- QnnProfile ---------
7272
DEFINE_SHIM_FUNCTION_INTERFACE(profile_create, profileCreate);
73+
DEFINE_SHIM_FUNCTION_INTERFACE(profile_set_config, profileSetConfig);
7374
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_events, profileGetEvents);
7475
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_sub_events, profileGetSubEvents);
7576
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_event_data, profileGetEventData);

backends/qualcomm/runtime/backends/QnnGraphCommon.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class QnnGraph {
5252

5353
Qnn_ErrorHandle_t GraphFinalize() {
5454
return implementation_.GetQnnInterface().qnn_graph_finalize(
55-
handle_, nullptr /* profile_handle */, nullptr /* signal_handle */);
55+
handle_, profile_->GetHandle(), nullptr /* signal_handle */);
5656
};
5757
Qnn_ErrorHandle_t ProfileExecuteData(
5858
executorch::runtime::EventTracer* event_tracer) {
@@ -62,6 +62,10 @@ class QnnGraph {
6262
return handle_;
6363
}
6464

65+
QnnProfile* GetProfile() {
66+
return profile_.get();
67+
}
68+
6569
protected:
6670
virtual executorch::runtime::Error MakeConfig(
6771
std::vector<const QnnGraph_Config_t*>& config) {

backends/qualcomm/runtime/backends/QnnProfiler.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,20 @@ QnnProfile::QnnProfile(
1919
: handle_(nullptr), implementation_(implementation), backend_(backend) {
2020
if (profile_level != QnnExecuTorchProfileLevel::kProfileOff) {
2121
const QnnInterface& qnn_interface = implementation_.GetQnnInterface();
22+
23+
QnnProfile_Level_t qnnProfileLevel = 0;
24+
if (profile_level == QnnExecuTorchProfileLevel::kProfileBasic) {
25+
qnnProfileLevel = QNN_PROFILE_LEVEL_BASIC;
26+
} else if (profile_level == QnnExecuTorchProfileLevel::kProfileDetailed
27+
|| profile_level == QnnExecuTorchProfileLevel::kProfileOptrace) {
28+
qnnProfileLevel = QNN_PROFILE_LEVEL_DETAILED;
29+
} else {
30+
QNN_EXECUTORCH_LOG_WARN("Invalid profile level");
31+
return;
32+
}
33+
2234
Qnn_ErrorHandle_t error = qnn_interface.qnn_profile_create(
23-
backend_->GetHandle(), static_cast<int>(profile_level), &handle_);
35+
backend_->GetHandle(), qnnProfileLevel, &handle_);
2436
if (error != QNN_SUCCESS) {
2537
QNN_EXECUTORCH_LOG_WARN(
2638
"Failed to create profile_handle for backend "
@@ -31,6 +43,27 @@ QnnProfile::QnnProfile(
3143
// ignore error and continue to create backend handle...
3244
handle_ = nullptr;
3345
}
46+
47+
if (profile_level == QnnExecuTorchProfileLevel::kProfileOptrace) {
48+
if (handle_ == nullptr) {
49+
QNN_EXECUTORCH_LOG_WARN("Prfoile handle is null, cannot enable optrace");
50+
return;
51+
}
52+
53+
QnnProfile_Config_t qnnProfileConfig = QNN_PROFILE_CONFIG_INIT;
54+
qnnProfileConfig.option = QNN_PROFILE_CONFIG_OPTION_ENABLE_OPTRACE;
55+
std::array<const QnnProfile_Config_t*, 2> profileConfigs = {
56+
&qnnProfileConfig, nullptr};
57+
error = qnn_interface.qnn_profile_set_config(handle_, profileConfigs.data());
58+
59+
if (error != QNN_SUCCESS) {
60+
QNN_EXECUTORCH_LOG_WARN(
61+
"Failed to set optrace for backend "
62+
" %u, error=%d",
63+
qnn_interface.GetBackendId(),
64+
QNN_GET_ERROR_CODE(error));
65+
}
66+
}
3467
}
3568
}
3669

backends/qualcomm/serialization/qnn_compile_spec_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class QnnExecuTorchProfileLevel(IntEnum):
115115
kProfileOff = 0
116116
kProfileBasic = 1
117117
kProfileDetailed = 2
118+
kProfileOptrace = 3
118119

119120

120121
@dataclass

backends/qualcomm/serialization/schema.fbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ enum QnnExecuTorchProfileLevel: int {
135135
kProfileOff = 0,
136136
kProfileBasic,
137137
kProfileDetailed,
138+
kProfileOptrace,
138139
}
139140

140141
/// QNN backends currently supported

backends/qualcomm/utils/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ def generate_qnn_executorch_compiler_spec(
770770
online_prepare: bool = False,
771771
dump_intermediate_outputs: bool = False,
772772
profile: bool = False,
773+
optrace: bool = False,
773774
shared_buffer: bool = False,
774775
is_from_context_binary: bool = False,
775776
) -> List[CompileSpec]:
@@ -831,7 +832,11 @@ def generate_qnn_executorch_compiler_spec(
831832
if saver:
832833
qnn_executorch_options.library_path = "libQnnSaver.so"
833834

834-
if profile:
835+
if optrace:
836+
qnn_executorch_options.profile_level = (
837+
QnnExecuTorchProfileLevel.kProfileOptrace
838+
)
839+
elif profile:
835840
qnn_executorch_options.profile_level = (
836841
QnnExecuTorchProfileLevel.kProfileDetailed
837842
)

0 commit comments

Comments
 (0)