xref: /aosp_15_r20/external/executorch/backends/qualcomm/runtime/backends/htpbackend/HtpContext.cpp (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright (c) Qualcomm Innovation Center, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <executorch/backends/qualcomm/runtime/Logging.h>
10 #include <executorch/backends/qualcomm/runtime/backends/htpbackend/HtpContext.h>
11 
12 #include "HTP/QnnHtpCommon.h"
13 #include "Saver/QnnSaverCommon.h"
14 
15 namespace executorch {
16 namespace backends {
17 namespace qnn {
18 
19 using executorch::runtime::Error;
20 
MakeConfig(std::vector<const QnnContext_Config_t * > & config)21 Error HtpContext::MakeConfig(std::vector<const QnnContext_Config_t*>& config) {
22   const std::vector<QnnContext_CustomConfig_t>& context_custom_config =
23       htp_context_custom_config_->CreateContextCustomConfig();
24 
25   uint32_t num_custom_configs = context_custom_config.size();
26   context_config_.resize(num_custom_configs);
27   // +1 for null terminated
28   config.reserve(num_custom_configs + 1);
29 
30   for (std::size_t i = 0; i < num_custom_configs; ++i) {
31     context_config_[i].option = QNN_CONTEXT_CONFIG_OPTION_CUSTOM;
32     context_config_[i].customConfig = context_custom_config[i];
33     config.push_back(&context_config_[i]);
34   }
35 
36   config.push_back(nullptr);
37   return Error::Ok;
38 }
39 
AfterConfigure()40 Error HtpContext::AfterConfigure() {
41   // update sf_handle with first context handle encounterded as group handle
42   // TODO: should handle the thread safety if needed
43   if (sf_handle_ == 0x0) {
44     sf_handle_ = GetHandle();
45   }
46   return Error::Ok;
47 }
48 
49 } // namespace qnn
50 } // namespace backends
51 } // namespace executorch
52