Skip to content

Commit e9d99ec

Browse files
committed
Add log to narrow down the issue
1 parent ee7d388 commit e9d99ec

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

backends/qualcomm/runtime/QnnExecuTorchBackend.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <executorch/backends/qualcomm/runtime/QnnExecuTorchBackend.h>
1212
#include <executorch/backends/qualcomm/runtime/QnnManager.h>
1313
#include <executorch/backends/qualcomm/runtime/backends/QnnCustomProtocol.h>
14+
#include <chrono>
15+
#include <iostream>
1416

1517
namespace executorch {
1618
namespace backends {
@@ -27,12 +29,22 @@ using executorch::runtime::FreeableBuffer;
2729
using executorch::runtime::MemoryAllocator;
2830
using executorch::runtime::Result;
2931

32+
void QnnExecuTorchBackend::print_profile() const {
33+
std::cout << "=================QnnExecuTorchBackend.cpp Profiling Time=================" << std::endl;
34+
std::cout << "QnnExecuTorchBackend::init(): " << std::chrono::duration_cast<std::chrono::milliseconds>(qnn_executorch_backend_init_end - qnn_executorch_backend_init_start).count() << " ms" << std::endl;
35+
std::cout << "Create QNN Manager: " << std::chrono::duration_cast<std::chrono::milliseconds>(qnn_manager_create_end - qnn_manager_create_start).count() << " ms" << std::endl;
36+
std::cout << "qnn_manager->Init(): " << std::chrono::duration_cast<std::chrono::milliseconds>(qnn_manager_init_end - qnn_manager_init_start).count() << " ms" << std::endl;
37+
std::cout << "qnn_manager->AllocateTensor(): " << std::chrono::duration_cast<std::chrono::milliseconds>(qnn_manager_allocate_tensor_end - qnn_manager_allocate_tensor_start).count() << " ms" << std::endl;
38+
}
39+
3040
// ========== Public method implementations =========================
3141
constexpr const char* QNN_COMPILE_SPEC = "qnn_compile_spec";
3242
Result<DelegateHandle*> QnnExecuTorchBackend::init(
3343
BackendInitContext& context,
3444
FreeableBuffer* processed,
3545
ArrayRef<CompileSpec> compile_specs) const {
46+
qnn_executorch_backend_init_start = std::chrono::high_resolution_clock::now();
47+
QNN_EXECUTORCH_LOG_INFO("QnnExecuTorchBackend::init start");
3648
// covert SizedBuffer to qnn ExecuTorch option
3749
QnnExecuTorchContextBinary qnn_context_blob;
3850
const qnn_delegate::QnnExecuTorchOptions* qnn_executorch_options = nullptr;
@@ -64,6 +76,7 @@ Result<DelegateHandle*> QnnExecuTorchBackend::init(
6476
QNN_EXECUTORCH_LOG_WARN("unknown argument: %s", compile_spec.key);
6577
}
6678

79+
qnn_manager_create_start = std::chrono::high_resolution_clock::now();
6780
// Create QnnManager
6881
MemoryAllocator* runtime_allocator = context.get_runtime_allocator();
6982
QnnManager* qnn_manager =
@@ -72,7 +85,7 @@ Result<DelegateHandle*> QnnExecuTorchBackend::init(
7285
// NOTE: Since we use placement new and since this type is not trivially
7386
// destructible, we must call the destructor manually in destroy().
7487
new (qnn_manager) QnnManager(qnn_executorch_options, qnn_context_blob);
75-
88+
qnn_manager_create_end = std::chrono::high_resolution_clock::now();
7689
// TODO: this is a temporal solution for multi-graph support, will be
7790
// removed once framework starts to accept runtime configuration
7891
// ---
@@ -84,30 +97,38 @@ Result<DelegateHandle*> QnnExecuTorchBackend::init(
8497
QNN_EXECUTORCH_LOG_INFO(
8598
"Use cached delegate handle for current method: %s",
8699
context.get_method_name());
100+
qnn_executorch_backend_init_end = std::chrono::high_resolution_clock::now();
101+
print_profile();
87102
return iter->second;
88103
}
89104

105+
qnn_manager_init_start = std::chrono::high_resolution_clock::now();
90106
ET_CHECK_OR_RETURN_ERROR(
91107
qnn_manager->Init() == Error::Ok,
92108
Internal,
93109
"Fail to initialize Qnn Manager");
110+
qnn_manager_init_end = std::chrono::high_resolution_clock::now();
94111

95112
if (qnn_manager->IsOnlinePrepare()) {
96113
ET_CHECK_OR_RETURN_ERROR(
97114
qnn_manager->CompileQcir() == Error::Ok,
98115
Internal,
99116
"Fail to compile binary in qcir format");
100117
} else {
118+
qnn_manager_allocate_tensor_start = std::chrono::high_resolution_clock::now();
101119
for (const std::string& graph_name : qnn_manager->GetGraphNames()) {
102120
ET_CHECK_OR_RETURN_ERROR(
103121
qnn_manager->AllocateTensor(graph_name) == Error::Ok,
104122
Internal,
105123
"Fail to allocate tensor");
106124
}
125+
qnn_manager_allocate_tensor_end = std::chrono::high_resolution_clock::now();
107126
}
108127
add_cached_delegate(signature, qnn_manager);
109128
// This backend does not need its processed data after Init.
110129
processed->Free();
130+
qnn_executorch_backend_init_end = std::chrono::high_resolution_clock::now();
131+
print_profile();
111132
return qnn_manager;
112133
}
113134

backends/qualcomm/runtime/QnnExecuTorchBackend.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class QnnExecuTorchBackend final
2323
public:
2424
~QnnExecuTorchBackend(){};
2525

26+
void print_profile() const;
27+
2628
executorch::runtime::Result<executorch::runtime::DelegateHandle*> init(
2729
executorch::runtime::BackendInitContext& context,
2830
executorch::runtime::FreeableBuffer* processed,
@@ -49,6 +51,15 @@ class QnnExecuTorchBackend final
4951
delegate_map_;
5052
mutable std::unordered_map<executorch::runtime::DelegateHandle*, std::int64_t>
5153
delegate_map_rev_;
54+
mutable std::chrono::high_resolution_clock::time_point qnn_executorch_backend_init_start;
55+
mutable std::chrono::high_resolution_clock::time_point qnn_executorch_backend_init_end;
56+
mutable std::chrono::high_resolution_clock::time_point qnn_manager_create_start;
57+
mutable std::chrono::high_resolution_clock::time_point qnn_manager_create_end;
58+
mutable std::chrono::high_resolution_clock::time_point qnn_manager_init_start;
59+
mutable std::chrono::high_resolution_clock::time_point qnn_manager_init_end;
60+
mutable std::chrono::high_resolution_clock::time_point qnn_manager_allocate_tensor_start;
61+
mutable std::chrono::high_resolution_clock::time_point qnn_manager_allocate_tensor_end;
62+
5263
};
5364

5465
} // namespace qnn

backends/qualcomm/runtime/QnnManager.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <cstring>
2020
#include <fstream>
2121
#include <string>
22+
#include <chrono>
23+
#include <iostream>
2224

2325
namespace executorch {
2426
namespace backends {
@@ -98,6 +100,15 @@ QnnManager::QnnManager(
98100
backend_params_ptr_ = std::make_unique<BackendConfigParameters>();
99101
}
100102

103+
void QnnManager::print_profile() {
104+
std::cout << "=================QnnManager.cpp Profiling Time=================" << std::endl;
105+
std::cout << "backend_params_ptr_->qnn_backend_cache_ptr_->Configure(): " << std::chrono::duration_cast<std::chrono::milliseconds>(qnn_backend_ptr_configure_start - qnn_backend_cache_ptr_configure_start).count() << " ms" << std::endl;
106+
std::cout << "backend_params_ptr_->qnn_backend_ptr_->Configure(): " << std::chrono::duration_cast<std::chrono::milliseconds>(qnn_device_ptr_configure_start - qnn_backend_ptr_configure_start).count() << " ms" << std::endl;
107+
std::cout << "backend_params_ptr_->qnn_device_ptr_->Configure(): " << std::chrono::duration_cast<std::chrono::milliseconds>(qnn_context_ptr_configure_start - qnn_device_ptr_configure_start).count() << " ms" << std::endl;
108+
std::cout << "backend_params_ptr_->qnn_context_ptr_->Configure(): " << std::chrono::duration_cast<std::chrono::milliseconds>(qnn_graph_ptr_configure_start - qnn_context_ptr_configure_start).count() << " ms" << std::endl;
109+
std::cout << "backend_params_ptr_->qnn_graph_ptr_->Configure(): " << std::chrono::duration_cast<std::chrono::milliseconds>(qnn_graph_ptr_configure_end - qnn_graph_ptr_configure_start).count() << " ms" << std::endl;
110+
}
111+
101112
Error QnnManager::LoadQnnLibrary() {
102113
Error ret = qnn_loaded_backend_.Load(nullptr);
103114
return ret;
@@ -291,22 +302,27 @@ Error QnnManager::Init() {
291302
backend_params_ptr_ != nullptr,
292303
Internal,
293304
"Failed to load Qnn backend.");
305+
qnn_backend_cache_ptr_configure_start = std::chrono::high_resolution_clock::now();
294306
ET_CHECK_OR_RETURN_ERROR(
295307
backend_params_ptr_->qnn_backend_cache_ptr_->Configure() == Error::Ok,
296308
Internal,
297309
"Fail to configure Qnn backend cache");
310+
qnn_backend_ptr_configure_start = std::chrono::high_resolution_clock::now();
298311
ET_CHECK_OR_RETURN_ERROR(
299312
backend_params_ptr_->qnn_backend_ptr_->Configure() == Error::Ok,
300313
Internal,
301314
"Fail to configure Qnn backend");
315+
qnn_device_ptr_configure_start = std::chrono::high_resolution_clock::now();
302316
ET_CHECK_OR_RETURN_ERROR(
303317
backend_params_ptr_->qnn_device_ptr_->Configure() == Error::Ok,
304318
Internal,
305319
"Fail to configure Qnn device");
320+
qnn_context_ptr_configure_start = std::chrono::high_resolution_clock::now();
306321
ET_CHECK_OR_RETURN_ERROR(
307322
backend_params_ptr_->qnn_context_ptr_->Configure() == Error::Ok,
308323
Internal,
309324
"Fail to configure Qnn context");
325+
qnn_graph_ptr_configure_start = std::chrono::high_resolution_clock::now();
310326
for (const std::string& graph_name :
311327
backend_params_ptr_->qnn_context_ptr_->GetGraphNames()) {
312328
ET_CHECK_OR_RETURN_ERROR(
@@ -315,6 +331,7 @@ Error QnnManager::Init() {
315331
Internal,
316332
"Fail to configure Qnn graph");
317333
}
334+
qnn_graph_ptr_configure_end = std::chrono::high_resolution_clock::now();
318335

319336
backend_params_ptr_->backend_init_state_ =
320337
BackendInitializeState::INITIALIZED;
@@ -444,6 +461,7 @@ Error QnnManager::ProfileExecuteData(
444461
}
445462

446463
void QnnManager::Destroy() {
464+
print_profile();
447465
QNN_EXECUTORCH_LOG_INFO("Destroy Qnn backend parameters");
448466
backend_params_ptr_.reset(new BackendConfigParameters());
449467
logger_.reset();

backends/qualcomm/runtime/QnnManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace backends {
2323
namespace qnn {
2424
class QnnManager {
2525
public:
26+
void print_profile();
2627
// Construct QnnManager
2728
explicit QnnManager(
2829
const QnnExecuTorchOptions* options,
@@ -147,6 +148,12 @@ class QnnManager {
147148
{Qnn_DataType_t::QNN_DATATYPE_UFIXED_POINT_16,
148149
executorch::aten::ScalarType::UInt16},
149150
};
151+
std::chrono::high_resolution_clock::time_point qnn_backend_cache_ptr_configure_start;
152+
std::chrono::high_resolution_clock::time_point qnn_backend_ptr_configure_start;
153+
std::chrono::high_resolution_clock::time_point qnn_device_ptr_configure_start;
154+
std::chrono::high_resolution_clock::time_point qnn_context_ptr_configure_start;
155+
std::chrono::high_resolution_clock::time_point qnn_graph_ptr_configure_start;
156+
std::chrono::high_resolution_clock::time_point qnn_graph_ptr_configure_end;
150157
};
151158
} // namespace qnn
152159
} // namespace backends

0 commit comments

Comments
 (0)