|
| 1 | +# Copyright (c) Qualcomm Innovation Center, Inc. |
| 2 | +# All rights reserved |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +set(CMAKE_CXX_STANDARD 17) |
| 8 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 9 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 10 | + |
| 11 | +# |
| 12 | +# get path |
| 13 | +# |
| 14 | +get_filename_component(EXECUTORCH_SOURCE_DIR |
| 15 | + "${CMAKE_CURRENT_LIST_DIR}/../.." |
| 16 | + ABSOLUTE) |
| 17 | +get_filename_component(QNN_EXECUTORCH_ROOT_DIR |
| 18 | + ${CMAKE_CURRENT_LIST_DIR} |
| 19 | + ABSOLUTE) |
| 20 | +# Let files say "include <executorch/path/to/header.h>". |
| 21 | +get_filename_component(_common_include_directories |
| 22 | + "${EXECUTORCH_SOURCE_DIR}/.." |
| 23 | + ABSOLUTE) |
| 24 | + |
| 25 | +if(NOT DEFINED QNN_SDK_ROOT) |
| 26 | + message(FATAL_ERROR |
| 27 | + "Please define QNN_SDK_ROOT, e.g. cmake <..> -DQNN_SDK_ROOT=<...>") |
| 28 | +elseif(CMAKE_TOOLCHAIN_FILE MATCHES ".*ios\.toolchain\.cmake$") |
| 29 | + message(FATAL_ERROR |
| 30 | + "ios is not supported by Qualcomm AI Engine Direct") |
| 31 | +endif() |
| 32 | + |
| 33 | +message(STATUS "Using qnn sdk root ${QNN_SDK_ROOT}") |
| 34 | +message(STATUS "Using EXECUTORCH_SOURCE_DIR ${EXECUTORCH_SOURCE_DIR}") |
| 35 | + |
| 36 | +if(${ANDROID}) |
| 37 | + find_library(android_log log) |
| 38 | +endif() |
| 39 | + |
| 40 | +add_compile_options("-Wall" "-Werror" "-Wno-sign-compare") |
| 41 | + |
| 42 | +# GNU emit wanring for ignored attributes |
| 43 | +# Unfortunately, we use [[maybe_unused]] which can be ignored by GNU. |
| 44 | +# So we make it a warning, not an error in GNU. |
| 45 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 46 | + add_compile_options("-Wno-error=attributes") |
| 47 | +endif() |
| 48 | + |
| 49 | +if(CMAKE_BUILD_TYPE STREQUAL "Release") |
| 50 | + # strip symbols |
| 51 | + add_link_options("-s") |
| 52 | + # hide dynamic symbols |
| 53 | + set(CMAKE_C_VISIBILITY_PRESET hidden) |
| 54 | + set(CMAKE_CXX_VISIBILITY_PRESET hidden) |
| 55 | + |
| 56 | + # --gc-sections is added by torch. |
| 57 | + add_compile_definitions("-O3" "-ffunction-sections" "-fdata-sections") |
| 58 | +endif() |
| 59 | + |
| 60 | + |
| 61 | +include_directories( |
| 62 | + BEFORE |
| 63 | + ${_common_include_directories} |
| 64 | +) |
| 65 | +include_directories( |
| 66 | + BEFORE |
| 67 | + ${QNN_SDK_ROOT}/include/QNN |
| 68 | +) |
| 69 | + |
| 70 | +# |
| 71 | +# declare targets |
| 72 | +# |
| 73 | +add_library(executorch_backend INTERFACE) |
| 74 | +add_library(qnn_executorch_backend STATIC) |
| 75 | +add_library(qnn_executorch_header INTERFACE) |
| 76 | +add_library(qnn_manager STATIC) |
| 77 | +add_library(qnn_function_interface INTERFACE) |
| 78 | +add_library(qnn_implementation STATIC) |
| 79 | +add_library(qnn_sys_function_interface INTERFACE) |
| 80 | +add_library(qnn_sys_implementation STATIC) |
| 81 | +add_library(qnn_logger STATIC) |
| 82 | +add_library(qnn_device STATIC) |
| 83 | +add_library(qnn_context STATIC) |
| 84 | +add_library(qnn_backend_cache STATIC) |
| 85 | +add_library(qnn_graph STATIC) |
| 86 | +add_library(qnn_backend STATIC) |
| 87 | +add_library(qnn_factory STATIC) |
| 88 | +add_library(qnn_header INTERFACE) |
| 89 | +add_library(qnn_logging STATIC) |
| 90 | +add_library(wrappers STATIC) |
| 91 | +add_library(utils STATIC) |
| 92 | + |
| 93 | +# |
| 94 | +# declare dependency |
| 95 | +# |
| 96 | +target_link_libraries(wrappers |
| 97 | + PRIVATE |
| 98 | + qnn_header |
| 99 | +) |
| 100 | +target_link_libraries(qnn_function_interface |
| 101 | + INTERFACE |
| 102 | + qnn_header |
| 103 | +) |
| 104 | +target_link_libraries(qnn_implementation |
| 105 | + PRIVATE |
| 106 | + qnn_function_interface |
| 107 | + qnn_header |
| 108 | + qnn_logging |
| 109 | + ${CMAKE_DL_LIBS} |
| 110 | +) |
| 111 | +target_link_libraries(qnn_sys_function_interface |
| 112 | + INTERFACE |
| 113 | + qnn_header |
| 114 | +) |
| 115 | +target_link_libraries(qnn_sys_implementation |
| 116 | + PRIVATE |
| 117 | + qnn_sys_function_interface |
| 118 | + qnn_header |
| 119 | + qnn_logging |
| 120 | + ${CMAKE_DL_LIBS} |
| 121 | +) |
| 122 | +target_link_libraries(qnn_logger |
| 123 | + PRIVATE |
| 124 | + qnn_implementation |
| 125 | + ${android_log} |
| 126 | +) |
| 127 | +target_link_libraries(qnn_backend |
| 128 | + PRIVATE |
| 129 | + qnn_implementation |
| 130 | + qnn_logger |
| 131 | +) |
| 132 | +target_link_libraries(qnn_device |
| 133 | + PRIVATE |
| 134 | + qnn_implementation |
| 135 | + qnn_logger |
| 136 | + utils |
| 137 | +) |
| 138 | +target_link_libraries(qnn_backend_cache |
| 139 | + PRIVATE |
| 140 | + qnn_sys_implementation |
| 141 | +) |
| 142 | +target_link_libraries(qnn_context |
| 143 | + PRIVATE |
| 144 | + qnn_implementation |
| 145 | + qnn_logger |
| 146 | + qnn_backend |
| 147 | + qnn_device |
| 148 | + qnn_backend_cache |
| 149 | +) |
| 150 | +target_link_libraries(qnn_graph |
| 151 | + PRIVATE |
| 152 | + qnn_implementation |
| 153 | + qnn_context |
| 154 | +) |
| 155 | +target_link_libraries(qnn_factory |
| 156 | + PUBLIC |
| 157 | + qnn_header |
| 158 | + PRIVATE |
| 159 | + qnn_backend |
| 160 | + qnn_device |
| 161 | + qnn_context |
| 162 | + qnn_graph |
| 163 | +) |
| 164 | +target_link_libraries(qnn_manager |
| 165 | + PRIVATE |
| 166 | + qnn_factory |
| 167 | + wrappers |
| 168 | +) |
| 169 | +target_link_libraries(qnn_executorch_backend |
| 170 | + PRIVATE |
| 171 | + qnn_executorch_header |
| 172 | + qnn_manager |
| 173 | + executorch |
| 174 | +) |
| 175 | + |
| 176 | +# |
| 177 | +# add linker option |
| 178 | +# |
| 179 | +target_link_options_shared_lib(qnn_executorch_backend) |
| 180 | + |
| 181 | +# |
| 182 | +# add sources |
| 183 | +# |
| 184 | +add_subdirectory( |
| 185 | + ${QNN_EXECUTORCH_ROOT_DIR}/runtime |
| 186 | + ${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch |
| 187 | +) |
| 188 | +add_subdirectory( |
| 189 | + ${QNN_EXECUTORCH_ROOT_DIR}/runtime/backends |
| 190 | + ${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/backends |
| 191 | +) |
| 192 | +add_subdirectory( |
| 193 | + ${QNN_EXECUTORCH_ROOT_DIR}/aot/wrappers |
| 194 | + ${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/wrappers |
| 195 | +) |
| 196 | + |
| 197 | +# QNN pybind |
| 198 | +if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") |
| 199 | + add_subdirectory(${EXECUTORCH_SOURCE_DIR}/third-party/pybind11 |
| 200 | + ${CMAKE_CURRENT_BINARY_DIR}/pybind11) |
| 201 | + add_library(PyQnnManagerAdaptor MODULE) |
| 202 | + add_library(PyQnnWrapperAdaptor MODULE) |
| 203 | + |
| 204 | + target_link_libraries(PyQnnManagerAdaptor |
| 205 | + PRIVATE |
| 206 | + pybind11::module |
| 207 | + pybind11::lto |
| 208 | + qnn_manager |
| 209 | + qnn_executorch_header |
| 210 | + executorch |
| 211 | + ) |
| 212 | + target_link_libraries(PyQnnWrapperAdaptor |
| 213 | + PRIVATE |
| 214 | + pybind11::module |
| 215 | + pybind11::lto |
| 216 | + wrappers |
| 217 | + qnn_logging |
| 218 | + qnn_executorch_header |
| 219 | + ) |
| 220 | + |
| 221 | + pybind11_extension(PyQnnManagerAdaptor) |
| 222 | + pybind11_extension(PyQnnWrapperAdaptor) |
| 223 | + if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo) |
| 224 | + # Strip unnecessary sections of the binary |
| 225 | + pybind11_strip(PyQnnManagerAdaptor) |
| 226 | + pybind11_strip(PyQnnWrapperAdaptor) |
| 227 | + endif() |
| 228 | + |
| 229 | + add_subdirectory( |
| 230 | + ${QNN_EXECUTORCH_ROOT_DIR}/aot/python |
| 231 | + ${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/python |
| 232 | + ) |
| 233 | +endif() |
0 commit comments