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/runtime/Logging.h> 11 #include <executorch/backends/qualcomm/runtime/backends/QnnImplementation.h> 12 #include <executorch/backends/qualcomm/runtime/backends/QnnLogger.h> 13 14 #include <vector> 15 16 #include "HTP/QnnHtpCommon.h" 17 #include "QnnBackend.h" 18 #include "QnnCommon.h" 19 #include "QnnTypes.h" 20 namespace executorch { 21 namespace backends { 22 namespace qnn { 23 // qnn backend 24 class QnnBackend { 25 public: QnnBackend(const QnnImplementation & implementation,QnnLogger * logger)26 explicit QnnBackend( 27 const QnnImplementation& implementation, 28 QnnLogger* logger) 29 : handle_(nullptr), implementation_(implementation), logger_(logger) {} 30 31 virtual ~QnnBackend(); IsProfileEventTypeParentOfNodeTime(QnnProfile_EventType_t)32 virtual bool IsProfileEventTypeParentOfNodeTime( 33 QnnProfile_EventType_t /*event_type*/) { 34 return false; 35 } 36 37 executorch::runtime::Error Configure(); 38 BackendValidateOpConfig(const Qnn_OpConfig_t & op_config)39 Qnn_ErrorHandle_t BackendValidateOpConfig(const Qnn_OpConfig_t& op_config) { 40 return implementation_.GetQnnInterface().qnn_backend_validate_op_config( 41 handle_, op_config); 42 }; 43 GetHandle()44 Qnn_BackendHandle_t GetHandle() { 45 return handle_; 46 } 47 48 executorch::runtime::Error VerifyQNNSDKVersion( 49 const QnnExecuTorchBackendType backend_id); 50 51 protected: 52 virtual Qnn_Version_t GetExpectedBackendVersion() const = 0; MakeConfig(std::vector<const QnnBackend_Config_t * > & config)53 virtual executorch::runtime::Error MakeConfig( 54 std::vector<const QnnBackend_Config_t*>& config) { 55 return executorch::runtime::Error::Ok; 56 }; 57 58 private: 59 Qnn_BackendHandle_t handle_; 60 const QnnImplementation& implementation_; 61 QnnLogger* logger_; 62 executorch::runtime::Error VersionChecker( 63 const Qnn_Version_t& qnn_version, 64 const Qnn_Version_t& expected, 65 const std::string& prefix); 66 }; 67 } // namespace qnn 68 } // namespace backends 69 } // namespace executorch 70