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_compiler_spec_generated.h> 11 #include <executorch/backends/qualcomm/runtime/QnnExecuTorch.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/QnnContextCommon.h> 15 #include <executorch/backends/qualcomm/runtime/backends/QnnDeviceCommon.h> 16 #include <executorch/backends/qualcomm/runtime/backends/QnnGraphCommon.h> 17 #include <executorch/backends/qualcomm/runtime/backends/QnnImplementation.h> 18 #include <executorch/backends/qualcomm/runtime/backends/QnnLogger.h> 19 #include <executorch/backends/qualcomm/runtime/backends/QnnMemManager.h> 20 #include <executorch/backends/qualcomm/runtime/backends/htpbackend/HtpBackend.h> 21 #include <executorch/backends/qualcomm/runtime/backends/htpbackend/HtpBackendCache.h> 22 #include <executorch/backends/qualcomm/runtime/backends/htpbackend/HtpContext.h> 23 #include <executorch/backends/qualcomm/runtime/backends/htpbackend/HtpDevice.h> 24 #include <executorch/backends/qualcomm/runtime/backends/htpbackend/HtpGraph.h> 25 26 #include <memory> 27 namespace executorch { 28 namespace backends { 29 namespace qnn { 30 typedef enum { UNINITIALIZED, INITIALIZED } BackendInitializeState; 31 32 // @brief Struct containing all handles for a given QNN backend 33 typedef struct BackendConfigParameters { 34 std::unique_ptr<QnnBackend> qnn_backend_ptr_; 35 BackendInitializeState backend_init_state_; 36 std::unique_ptr<QnnContext> qnn_context_ptr_; 37 std::unique_ptr<QnnDevice> qnn_device_ptr_; 38 std::unique_ptr<QnnGraph> qnn_graph_ptr_; 39 std::unique_ptr<QnnMemManager> qnn_mem_manager_ptr_; 40 std::unique_ptr<QnnBackendCache> qnn_backend_cache_ptr_; 41 42 // Default ctor BackendConfigParametersBackendConfigParameters43 BackendConfigParameters() 44 : qnn_backend_ptr_(nullptr), 45 backend_init_state_(BackendInitializeState::UNINITIALIZED), 46 qnn_context_ptr_(nullptr), 47 qnn_device_ptr_(nullptr), 48 qnn_graph_ptr_(nullptr), 49 qnn_mem_manager_ptr_(nullptr), 50 qnn_backend_cache_ptr_(nullptr) {} 51 // Default dtor ~BackendConfigParametersBackendConfigParameters52 ~BackendConfigParameters() { 53 qnn_graph_ptr_.reset(); 54 qnn_backend_cache_ptr_.reset(); 55 qnn_mem_manager_ptr_.reset(); 56 qnn_context_ptr_.reset(); 57 qnn_device_ptr_.reset(); 58 qnn_backend_ptr_.reset(); 59 backend_init_state_ = BackendInitializeState::UNINITIALIZED; 60 } 61 62 } BackendConfigParameters; 63 64 class QnnBackendFactory { 65 public: 66 std::unique_ptr<BackendConfigParameters> Create( 67 const QnnImplementation& implementation, 68 QnnLogger* logger, 69 const QnnExecuTorchContextBinary& qnn_context_blob, 70 const QnnExecuTorchOptions* options); 71 }; 72 } // namespace qnn 73 } // namespace backends 74 } // namespace executorch 75