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 #pragma once 9 10 #include <executorch/backends/qualcomm/qc_binary_info_generated.h> 11 #include <executorch/backends/qualcomm/runtime/Logging.h> 12 #include <executorch/backends/qualcomm/runtime/backends/QnnBackendCache.h> 13 #include <executorch/backends/qualcomm/runtime/backends/QnnBackendCommon.h> 14 #include <executorch/backends/qualcomm/runtime/backends/QnnDeviceCommon.h> 15 16 #include <memory> 17 namespace executorch { 18 namespace backends { 19 namespace qnn { 20 class QnnContext { 21 public: QnnContext(const QnnImplementation & implementation,QnnBackend * backend,QnnDevice * device,QnnBackendCache * cache)22 explicit QnnContext( 23 const QnnImplementation& implementation, 24 QnnBackend* backend, 25 QnnDevice* device, 26 QnnBackendCache* cache) 27 : handle_(nullptr), 28 implementation_(implementation), 29 backend_(backend), 30 device_(device), 31 cache_(cache) {} 32 33 virtual ~QnnContext(); 34 executorch::runtime::Error Configure(); 35 GetHandle()36 Qnn_ContextHandle_t GetHandle() const { 37 return handle_; 38 } 39 GetGraphNames()40 std::vector<std::string> inline GetGraphNames() { 41 return cache_->GetGraphNames(); 42 } 43 GetGraphInputs(const std::string & graph_name)44 std::vector<Qnn_Tensor_t> inline GetGraphInputs( 45 const std::string& graph_name) { 46 return cache_->GetGraphInputs(graph_name); 47 } GetGraphOutputs(const std::string & graph_name)48 std::vector<Qnn_Tensor_t> inline GetGraphOutputs( 49 const std::string& graph_name) { 50 return cache_->GetGraphOutputs(graph_name); 51 } GetCacheState()52 QnnBackendCache::CacheState GetCacheState() const { 53 return cache_->GetCacheState(); 54 }; 55 56 executorch::runtime::Error GetContextBinary( 57 QnnExecuTorchContextBinary& qnn_executorch_context_binary); 58 59 protected: MakeConfig(std::vector<const QnnContext_Config_t * > & config)60 virtual executorch::runtime::Error MakeConfig( 61 std::vector<const QnnContext_Config_t*>& config) { 62 return executorch::runtime::Error::Ok; 63 }; AfterConfigure()64 virtual executorch::runtime::Error AfterConfigure() { 65 return executorch::runtime::Error::Ok; 66 }; 67 68 private: 69 Qnn_ContextHandle_t handle_; 70 const QnnImplementation& implementation_; 71 QnnBackend* backend_; 72 QnnDevice* device_; 73 QnnBackendCache* cache_; 74 std::vector<uint8_t> binary_buffer_; 75 flatbuffers::FlatBufferBuilder builder_; 76 }; 77 } // namespace qnn 78 } // namespace backends 79 } // namespace executorch 80