-
Notifications
You must be signed in to change notification settings - Fork 526
/
Copy pathCMakeLists.txt
274 lines (251 loc) · 8.55 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# Copyright (c) Qualcomm Innovation Center, Inc.
# Copyright 2025 Arm Limited and/or its affiliates.
# All rights reserved
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#
# get path
#
get_filename_component(
EXECUTORCH_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE
)
get_filename_component(
QNN_EXECUTORCH_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR} ABSOLUTE
)
# Let files say "include <executorch/path/to/header.h>".
get_filename_component(
_common_include_directories "${EXECUTORCH_SOURCE_DIR}/.." ABSOLUTE
)
if(NOT DEFINED QNN_SDK_ROOT)
message(
FATAL_ERROR
"Please define QNN_SDK_ROOT, e.g. cmake <..> -DQNN_SDK_ROOT=<...>"
)
elseif(CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$")
message(FATAL_ERROR "ios is not supported by Qualcomm AI Engine Direct")
endif()
message(STATUS "Using qnn sdk root ${QNN_SDK_ROOT}")
message(STATUS "Using EXECUTORCH_SOURCE_DIR ${EXECUTORCH_SOURCE_DIR}")
if(${ANDROID})
find_library(android_log log)
endif()
set(qcir_schema_include_dir ${CMAKE_CURRENT_LIST_DIR}/aot/ir)
set(qcir_schema_output ${qcir_schema_include_dir}/qcir_generated.h)
add_custom_command(
OUTPUT qcir_schema_output
COMMAND ${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
${qcir_schema_include_dir} ${qcir_schema_include_dir}/qcir.fbs
DEPENDS flatc
COMMENT "Generating qualcomm ir schema headers"
VERBATIM
)
add_compile_options("-Wall" "-Werror" "-Wno-sign-compare")
add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS)
# GNU emit wanring for ignored attributes Unfortunately, we use [[maybe_unused]]
# which can be ignored by GNU. So we make it a warning, not an error in GNU.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options("-Wno-error=attributes")
add_link_options("-flto=auto")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
# strip symbols
add_link_options("-s")
# --gc-sections is added by torch.
add_compile_options("-O3" "-ffunction-sections" "-fdata-sections" "-frtti")
endif()
include_directories(
BEFORE ${_common_include_directories} ${QNN_SDK_ROOT}/include/QNN
${EXECUTORCH_SOURCE_DIR}/third-party/flatbuffers/include
${EXECUTORCH_SOURCE_DIR}/runtime/core/portable_type/c10
)
set(_qnn_schema__srcs
backends/qualcomm/serialization/qc_compiler_spec.fbs
)
set(_qnn_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include")
# Paths to headers generated from the .fbs files.
set(_qnn_schema__outputs)
foreach(fbs_file ${_qnn_schema__srcs})
string(REGEX REPLACE "serialization/([^/]+)[.]fbs$" "\\1_generated.h"
generated "${fbs_file}"
)
list(APPEND _qnn_schema__outputs
"${_qnn_schema__include_dir}/executorch/${generated}"
)
endforeach()
# Generate the headers from the .fbs files.
add_custom_command(
OUTPUT ${_qnn_schema__outputs}
COMMAND
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
"${_qnn_schema__include_dir}/executorch/backends/qualcomm"
${_qnn_schema__srcs}
WORKING_DIRECTORY ${EXECUTORCH_SOURCE_DIR}
DEPENDS flatc
COMMENT "Generating qnn_schema headers"
VERBATIM
)
include_directories(
BEFORE ${_qnn_schema__include_dir}
${EXECUTORCH_SOURCE_DIR}/third-party/flatbuffers/include
)
#
# declare targets
#
add_library(executorch_backend INTERFACE)
add_library(qcir INTERFACE qcir_schema_output)
add_library(qcir_utils STATIC)
add_library(qnn_backend STATIC)
add_library(qnn_backend_cache STATIC)
add_library(qnn_context STATIC)
add_library(qnn_custom_protocol STATIC)
add_library(qnn_device STATIC)
add_library(qnn_executorch_backend SHARED)
add_library(qnn_executorch_header INTERFACE)
add_library(qnn_executorch_logging STATIC)
add_library(qnn_factory STATIC)
add_library(qnn_function_interface INTERFACE)
add_library(qnn_graph STATIC)
add_library(qnn_implementation STATIC)
add_library(qnn_logger STATIC)
add_library(qnn_manager STATIC)
add_library(qnn_mem_manager STATIC)
add_library(qnn_profiler STATIC)
add_library(qnn_schema INTERFACE ${_qnn_schema__outputs})
add_library(qnn_sys_function_interface INTERFACE)
add_library(qnn_sys_implementation STATIC)
add_library(shared_buffer STATIC)
add_library(wrappers STATIC)
add_library(utils STATIC)
#
# declare dependency
#
target_link_libraries(qcir_utils PRIVATE qcir)
target_link_libraries(wrappers PRIVATE qnn_executorch_logging)
target_link_libraries(
qnn_implementation PRIVATE qnn_function_interface qnn_executorch_logging ${CMAKE_DL_LIBS}
)
target_link_libraries(
qnn_sys_implementation PRIVATE qnn_sys_function_interface qnn_executorch_logging ${CMAKE_DL_LIBS}
)
target_link_libraries(qnn_executorch_logging PRIVATE qnn_schema)
target_link_libraries(qnn_profiler PRIVATE qnn_executorch_logging)
target_link_libraries(qnn_logger PRIVATE qnn_implementation ${android_log})
target_link_libraries(qnn_backend PRIVATE qnn_implementation qnn_logger)
target_link_libraries(qnn_custom_protocol PRIVATE qcir_utils)
target_link_libraries(
qnn_device PRIVATE qnn_executorch_logging qnn_implementation qnn_logger
)
target_link_libraries(
qnn_backend_cache PRIVATE qnn_sys_implementation qcir_utils
)
target_link_libraries(
qnn_context PRIVATE qnn_implementation qnn_logger qnn_backend qnn_device
qnn_backend_cache
)
target_link_libraries(
qnn_graph PRIVATE qnn_executorch_logging qnn_implementation qnn_context
qnn_profiler
)
target_link_libraries(
qnn_mem_manager PRIVATE qnn_executorch_logging qnn_implementation qnn_context
)
target_link_libraries(
qnn_factory PRIVATE qnn_schema qnn_backend qnn_device qnn_context qnn_graph
qnn_mem_manager qnn_custom_protocol
)
target_link_libraries(
qnn_manager PRIVATE qnn_factory wrappers qnn_schema utils shared_buffer
)
target_link_libraries(
qnn_executorch_backend PRIVATE qnn_executorch_header qnn_schema qnn_manager
executorch_core qcir_utils extension_tensor
)
set_target_properties(
qnn_executorch_backend PROPERTIES LINK_FLAGS "-Wl,-rpath='$ORIGIN'"
)
target_link_libraries(utils PRIVATE qnn_executorch_logging)
target_link_libraries(
shared_buffer PRIVATE qnn_executorch_logging ${CMAKE_DL_LIBS}
)
#
# add linker option
#
target_link_options_shared_lib(qnn_executorch_backend)
#
# add sources
#
add_subdirectory(
${QNN_EXECUTORCH_ROOT_DIR}/runtime ${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch
)
add_subdirectory(
${QNN_EXECUTORCH_ROOT_DIR}/runtime/backends
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/backends
)
add_subdirectory(
${QNN_EXECUTORCH_ROOT_DIR}/aot/wrappers
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/wrappers
)
add_subdirectory(
${QNN_EXECUTORCH_ROOT_DIR}/aot/ir
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/ir
)
install(TARGETS qnn_executorch_backend DESTINATION lib)
# QNN pybind
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
add_subdirectory(
${EXECUTORCH_SOURCE_DIR}/third-party/pybind11
${CMAKE_CURRENT_BINARY_DIR}/pybind11
)
add_library(PyQnnManagerAdaptor MODULE)
add_library(PyQnnWrapperAdaptor MODULE)
# PyQnnManager containing a pybind type triggers the warning because pybind11
# code internally forces hidden visibility.
set_target_properties(
PyQnnManagerAdaptor PROPERTIES CXX_VISIBILITY_PRESET hidden
)
set_target_properties(
PyQnnWrapperAdaptor PROPERTIES CXX_VISIBILITY_PRESET hidden
)
target_link_libraries(
PyQnnManagerAdaptor
PRIVATE pybind11::module
pybind11::lto
qnn_schema
qnn_manager
qnn_executorch_header
executorch
qcir_utils
extension_tensor
)
target_link_libraries(
PyQnnWrapperAdaptor PRIVATE pybind11::module pybind11::lto wrappers
qnn_executorch_logging qnn_executorch_header
)
pybind11_extension(PyQnnManagerAdaptor)
pybind11_extension(PyQnnWrapperAdaptor)
if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
# Strip unnecessary sections of the binary
pybind11_strip(PyQnnManagerAdaptor)
pybind11_strip(PyQnnWrapperAdaptor)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
# need to allow exceptions in pybind
set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
-fexceptions
)
target_compile_options(
PyQnnManagerAdaptor PUBLIC ${_pybind_compile_options}
)
target_compile_options(
PyQnnWrapperAdaptor PUBLIC ${_pybind_compile_options}
)
endif()
add_subdirectory(
${QNN_EXECUTORCH_ROOT_DIR}/aot/python
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/python
)
endif()