Skip to content

Commit 63299b7

Browse files
limintangfacebook-github-bot
authored andcommitted
Write QNN context binary to file when profiling level is detailed (pytorch#6745)
Summary: Pull Request resolved: pytorch#6745 Reviewed By: billmguo Differential Revision: D65694854
1 parent ee74d06 commit 63299b7

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

backends/qualcomm/runtime/QnnManager.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,23 @@ Error QnnManager::Compile(
530530
qnn_executorch_context_binary) == Error::Ok,
531531
Internal,
532532
"Fail to get context binary.");
533+
534+
// Write context binary to file for debugging purpose
535+
auto qnn_profile_level =
536+
backend_params_ptr_->qnn_graph_ptr_->GetProfile()->GetQnnProfileLevel();
537+
if (qnn_profile_level == QNN_PROFILE_LEVEL_DETAILED) {
538+
static const char* binary_file = "/tmp/qnn_context_binary.bin";
539+
std::ofstream fout(binary_file, std::ios::binary);
540+
fout.write(
541+
reinterpret_cast<const char*>(qnn_executorch_context_binary.buffer),
542+
qnn_executorch_context_binary.nbytes);
543+
544+
if (!fout) {
545+
QNN_EXECUTORCH_LOG_WARN(
546+
"Failed to write QNN context binary to file %s", binary_file);
547+
}
548+
fout.close();
549+
}
533550
}
534551

535552
return Error::Ok;

backends/qualcomm/runtime/backends/QnnProfiler.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,19 @@ QnnProfile::QnnProfile(
2020
if (profile_level != QnnExecuTorchProfileLevel::kProfileOff) {
2121
const QnnInterface& qnn_interface = implementation_.GetQnnInterface();
2222

23-
QnnProfile_Level_t qnnProfileLevel = 0;
2423
if (profile_level == QnnExecuTorchProfileLevel::kProfileBasic) {
25-
qnnProfileLevel = QNN_PROFILE_LEVEL_BASIC;
24+
qnnProfileLevel_ = QNN_PROFILE_LEVEL_BASIC;
2625
} else if (
2726
profile_level == QnnExecuTorchProfileLevel::kProfileDetailed ||
2827
profile_level == QnnExecuTorchProfileLevel::kProfileOptrace) {
29-
qnnProfileLevel = QNN_PROFILE_LEVEL_DETAILED;
28+
qnnProfileLevel_ = QNN_PROFILE_LEVEL_DETAILED;
3029
} else {
3130
QNN_EXECUTORCH_LOG_WARN("Invalid profile level");
3231
return;
3332
}
3433

3534
Qnn_ErrorHandle_t error = qnn_interface.qnn_profile_create(
36-
backend_->GetHandle(), qnnProfileLevel, &handle_);
35+
backend_->GetHandle(), qnnProfileLevel_, &handle_);
3736
if (error != QNN_SUCCESS) {
3837
QNN_EXECUTORCH_LOG_WARN(
3938
"Failed to create profile_handle for backend "

backends/qualcomm/runtime/backends/QnnProfiler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ class QnnProfile {
2929
return handle_;
3030
}
3131

32+
const QnnProfile_Level_t& GetQnnProfileLevel() const {
33+
return qnnProfileLevel_;
34+
}
35+
3236
private:
3337
Qnn_ProfileHandle_t handle_;
38+
QnnProfile_Level_t qnnProfileLevel_ = 0;
3439
const QnnImplementation& implementation_;
3540
QnnBackend* backend_;
3641
};

0 commit comments

Comments
 (0)