xref: /aosp_15_r20/external/executorch/backends/qualcomm/runtime/backends/QnnSysFunctionInterface.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 #pragma once
9 
10 #include "System/QnnSystemInterface.h"
11 
12 #include <utility>
13 
14 #define DEFINE_SHIM_FUNCTION_SYS_INTERFACE(F, pointer_name)                  \
15   template <typename... Args>                                                \
16   inline auto qnn_##F(Args... args) const {                                  \
17     return (qnn_sys_interface_->QNN_SYSTEM_INTERFACE_VER_NAME.pointer_name)( \
18         std::forward<Args>(args)...);                                        \
19   }
20 namespace executorch {
21 namespace backends {
22 namespace qnn {
23 using QnnSystemInterfaceGetProvidersFn =
24     decltype(QnnSystemInterface_getProviders);
25 
26 class QnnSystemInterface {
27  public:
28   QnnSystemInterface() = default;
29 
SetQnnSystemInterface(const QnnSystemInterface_t * qnn_sys_interface)30   void SetQnnSystemInterface(const QnnSystemInterface_t* qnn_sys_interface) {
31     qnn_sys_interface_ = qnn_sys_interface;
32   }
33 
IsLoaded()34   bool IsLoaded() const {
35     return qnn_sys_interface_ != nullptr;
36   }
37 
38   DEFINE_SHIM_FUNCTION_SYS_INTERFACE(
39       system_context_create,
40       systemContextCreate);
41   DEFINE_SHIM_FUNCTION_SYS_INTERFACE(
42       system_context_get_binary_info,
43       systemContextGetBinaryInfo);
44   DEFINE_SHIM_FUNCTION_SYS_INTERFACE(system_context_free, systemContextFree);
45 
46  private:
47   const QnnSystemInterface_t* qnn_sys_interface_{nullptr};
48 };
49 } // namespace qnn
50 } // namespace backends
51 } // namespace executorch
52