xref: /aosp_15_r20/external/executorch/backends/qualcomm/runtime/backends/htpbackend/HtpContext.h (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 #pragma once
10 
11 #include <executorch/backends/qualcomm/runtime/backends/QnnBackendCommon.h>
12 #include <executorch/backends/qualcomm/runtime/backends/QnnContextCommon.h>
13 #include <executorch/backends/qualcomm/runtime/backends/htpbackend/HtpContextCustomConfig.h>
14 
15 namespace executorch {
16 namespace backends {
17 namespace qnn {
18 
19 class HtpContext : public QnnContext {
20  public:
HtpContext(const QnnImplementation & implementation,QnnBackend * backend,QnnDevice * device,QnnBackendCache * cache,const QnnExecuTorchHtpBackendOptions * htp_options)21   HtpContext(
22       const QnnImplementation& implementation,
23       QnnBackend* backend,
24       QnnDevice* device,
25       QnnBackendCache* cache,
26       const QnnExecuTorchHtpBackendOptions* htp_options)
27       : QnnContext(implementation, backend, device, cache) {
28     htp_context_custom_config_ =
29         std::make_unique<HtpContextCustomConfig>(this, htp_options);
30   }
~HtpContext()31   ~HtpContext() {}
32 
GetSpillFillHandle()33   Qnn_ContextHandle_t GetSpillFillHandle() const {
34     return sf_handle_;
35   }
36 
37  protected:
38   executorch::runtime::Error MakeConfig(
39       std::vector<const QnnContext_Config_t*>& config) override;
40   executorch::runtime::Error AfterConfigure() override;
41 
42  private:
43   std::vector<QnnContext_Config_t> context_config_;
44   std::unique_ptr<HtpContextCustomConfig> htp_context_custom_config_;
45   // this is shared between all partitions inside one pte
46   static inline Qnn_ContextHandle_t sf_handle_ = 0x0;
47 };
48 
49 } // namespace qnn
50 } // namespace backends
51 } // namespace executorch
52