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
1517namespace executorch {
1618namespace backends {
@@ -27,12 +29,22 @@ using executorch::runtime::FreeableBuffer;
2729using executorch::runtime::MemoryAllocator;
2830using 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 =========================
3141constexpr const char * QNN_COMPILE_SPEC = " qnn_compile_spec" ;
3242Result<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
0 commit comments