forked from Tencent/TNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
363 lines (311 loc) · 11.7 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
cmake_minimum_required(VERSION 3.1)
project(TNN)
ENABLE_LANGUAGE(ASM)
set(TNN_MAJOR_VERSION 0)
set(TNN_MINOR_VERSION 1)
set(TNN_PATCH_VERSION 0)
set(TNN_BUILD_VERSION 0)
set(TNN_VERSION "${TNN_MAJOR_VERSION}.${TNN_MINOR_VERSION}.${TNN_PATCH_VERSION}.${TNN_BUILD_VERSION}")
option(TNN_CPU_ENABLE "Enable Cpu" OFF)
option(TNN_X86_ENABLE "Enable X86" OFF)
option(TNN_ARM_ENABLE "Enable Arm" OFF)
option(TNN_ARM82_ENABLE "Enable Arm82" OFF)
option(TNN_METAL_ENABLE "Enable Metal" OFF)
option(TNN_OPENCL_ENABLE "Enable OpenCL" OFF)
option(TNN_CUDA_ENABLE "Enable CUDA" OFF)
option(TNN_DSP_ENABLE "Enable DSP" OFF)
option(TNN_ATLAS_ENABLE "Enable Atlas" OFF)
option(TNN_TENSORRT_ENABLE "Enable TensorRT" OFF)
option(TNN_OPENVINO_ENABLE "Enable OPENVINO" OFF)
option(TNN_NPU_ENABLE "Enable NPU" OFF)
option(TNN_HUAWEI_NPU_ENABLE "Enable NPU" OFF)
option(TNN_RK_NPU_ENABLE "Enable RKNPU" OFF)
option(TNN_SYMBOL_HIDE "Enable Hide Symbol Visibility" ON)
option(TNN_OPENMP_ENABLE "Enable OpenMP" OFF)
option(TNN_BUILD_SHARED "Build Shared Library" ON)
option(TNN_OPENVINO_BUILD_SHARED "Build Shared Openvino Library" OFF)
option(TNN_TEST_ENABLE "Enable Test" OFF)
option(TNN_UNIT_TEST_ENABLE "Enable Test" OFF)
option(TNN_PROFILER_ENABLE "Enable Test" OFF)
option(TNN_QUANTIZATION_ENABLE "Enable Test" OFF)
option(TNN_MODEL_CHECK_ENABLE "Enable Test" OFF)
option(TNN_BENCHMARK_MODE "Enable Benchmark" OFF)
option(TNN_UNIT_TEST_BENCHMARK "Enable Benchmark Layer" OFF)
option(TNN_CONVERTER_ENABLE "Enable Model Converter" OFF)
option(TNN_TNN2MEM_ENABLE "Enable tnn2mem" OFF)
option(TNN_BUILD_BENCHMARK_TEST_LIB_ENABLE "Enable Build Benchmark Test Lib" OFF)
message(${CMAKE_SOURCE_DIR})
message(${CMAKE_CURRENT_SOURCE_DIR})
include(cmake/macros.cmake)
if (SYSTEM.Windows)
add_definitions(-DBUILDING_DLL)
endif()
if(TNN_PROFILER_ENABLE)
add_definitions(-DTNN_PROFILE)
set(TNN_SYMBOL_HIDE OFF)
endif()
if(TNN_BENCHMARK_MODE)
add_definitions(-DGENERATE_RESOURCE)
endif()
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4003 /wd4819 /wd4244 /wd4018")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4003 /wd4819 /wd4244 /wd4018")
endif()
# ignore loop-vectorize warning
if(SYSTEM.Windows)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-pass-failed")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pass-failed")
endif()
# ignore deprecated warning
if(SYSTEM.Windows)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations -Wno-ignored-attributes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-ignored-attributes")
endif()
if(DEBUG)
set(TNN_SYMBOL_HIDE OFF)
add_definitions(-DDEBUG)
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "set build type to debug" FORCE)
endif()
else()
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "set build type to release" FORCE)
endif()
if(BUILD_FOR_ANDROID_COMMAND)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s -Wl,--gc-sections")
endif()
endif()
if(TNN_TEST_ENABLE)
option(TNN_METAL_FLOAT32 "Enable Metal Float32" ON)
else()
set(TNN_UNIT_TEST_ENABLE OFF)
endif()
if(TNN_UNIT_TEST_ENABLE)
enable_testing()
set(TNN_CPU_ENABLE ON)
set(TNN_SYMBOL_HIDE OFF)
add_definitions(-DGENERATE_RESOURCE)
endif()
if(TNN_CONVERTER_ENABLE)
set(TNN_SYMBOL_HIDE OFF)
add_definitions(-DTNN_CONVERTER_RUNTIME)
endif()
if(TNN_QUANTIZATION_ENABLE OR TNN_MODEL_CHECK_ENABLE)
set(TNN_SYMBOL_HIDE OFF)
add_definitions(-DFORWARD_CALLBACK_ENABLE)
endif()
if(TNN_MODEL_CHECK_ENABLE)
option(TNN_METAL_FLOAT32 "Enable Metal Float32" ON)
endif()
if(TNN_ARM82_ENABLE)
add_definitions(-DTNN_ARM82=1)
endif()
# only used to simulate arm82 computation in the unit test
option(TNN_ARM82_SIMU "Enable arm82 simulation" OFF)
if(TNN_ARM82_SIMU)
add_definitions(-DTNN_ARM82_SIMU)
endif()
if(TNN_METAL_FLOAT32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTNN_METAL_FULL_PRECISION=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTNN_METAL_FULL_PRECISION=1")
if(TNN_PROFILER_ENABLE OR TNN_MODEL_CHECK_ENABLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTNN_METAL_BENCHMARK=1 -DTNN_METAL_DEBUG=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTNN_METAL_BENCHMARK=1 -DTNN_METAL_DEBUG=1")
endif()
endif()
if(TNN_OPENMP_ENABLE)
FIND_PACKAGE(OpenMP REQUIRED)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
else()
error("OpenMP Not Found.")
endif()
endif()
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(TNN_METAL_ENABLE)
add_compile_options(-x objective-c++)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fobjc-arc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc")
endif()
if(TNN_TNN2MEM_ENABLE)
add_subdirectory(tools/tnn2mem)
endif()
message(STATUS ">>>>>>>>>>>>>")
message(STATUS "TNN BUILD INFO:")
message(STATUS "\tSystem: ${CMAKE_SYSTEM_NAME}")
message(STATUS "\tProcessor: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "\tCpu:\t${TNN_CPU_ENABLE}")
message(STATUS "\tX86:\t${TNN_X86_ENABLE}")
message(STATUS "\tArm:\t${TNN_ARM_ENABLE}")
message(STATUS "\tArm82:\t${TNN_ARM82_ENABLE}")
message(STATUS "\tMetal:\t${TNN_METAL_ENABLE}")
message(STATUS "\tOpenCL:\t${TNN_OPENCL_ENABLE}")
message(STATUS "\tCUDA:\t${TNN_CUDA_ENABLE}")
message(STATUS "\tDSP:\t${TNN_DSP_ENABLE}")
message(STATUS "\tAtlas:\t${TNN_ATLAS_ENABLE}")
message(STATUS "\tTensorRT:\t${TNN_TENSORRT_ENABLE}")
message(STATUS "\tHuaweiNPU:\t${TNN_HUAWEI_NPU_ENABLE}")
message(STATUS "\tRKNPU:\t${TNN_RK_NPU_ENABLE}")
message(STATUS "\tOpenVINO:\t${TNN_OPENVINO_ENABLE}")
message(STATUS "\tOpenMP:\t${TNN_OPENMP_ENABLE}")
message(STATUS "\tTEST:\t${TNN_TEST_ENABLE}")
message(STATUS "\t--Unit Test:\t${TNN_UNIT_TEST_ENABLE}")
message(STATUS "\tQantization:\t${TNN_QUANTIZATION_ENABLE}")
message(STATUS "\tModelCheck:\t${TNN_MODEL_CHECK_ENABLE}")
message(STATUS "\tDEBUG:\t${DEBUG}")
message(STATUS "\tPROFILE:\t${TNN_PROFILER_ENABLE}")
message(STATUS "\tBENCHMARK:\t${TNN_BENCHMARK_MODE}")
message(STATUS "\tBENCHMARK Layer:\t${TNN_UNIT_TEST_BENCHMARK}")
message(STATUS "\tModel Converter:\t${TNN_CONVERTER_ENABLE}")
message(STATUS "\tTNN2MEM:\t${TNN_TNN2MEM_ENABLE}")
message(STATUS "\tBENCHMARK Test Lib:\t${TNN_BUILD_BENCHMARK_TEST_LIB_ENABLE}")
include_directories(include)
include_directories(source)
file(GLOB_RECURSE SRC "source/tnn/core/*.h"
"source/tnn/core/*.cc"
"source/tnn/layer/*.h"
"source/tnn/layer/*.cc"
"source/tnn/utils/*.h"
"source/tnn/utils/*.cc"
"source/tnn/interpreter/*.h"
"source/tnn/interpreter/*.cc"
"source/tnn/optimizer/*.h"
"source/tnn/optimizer/*.cc"
"source/tnn/extern_wrapper/*.h"
"source/tnn/extern_wrapper/*.cc"
"source/tnn/memory_manager/*.h"
"source/tnn/memory_manager/*.cc")
if(TNN_SYMBOL_HIDE AND UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
endif()
if(TNN_X86_ENABLE)
add_subdirectory(source/tnn/device/x86)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNX86>")
endif()
if(TNN_CPU_ENABLE)
add_subdirectory(source/tnn/device/cpu)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNCpu>")
endif()
if(TNN_ARM_ENABLE)
add_subdirectory(source/tnn/device/arm)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNArm>")
if(TNN_ARM82_ENABLE)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNArm82>")
endif()
endif()
if(TNN_OPENVINO_ENABLE)
add_subdirectory(source/tnn/network/openvino)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNOpenVINO>")
endif()
if(TNN_OPENCL_ENABLE)
include(FindPythonInterp REQUIRED)
if (NOT PYTHON_EXECUTABLE)
message (FATAL_ERROR "No Python installation found! It is required by OpenCL codegen.")
endif ()
if(SHARING_MEM_WITH_OPENGL)
add_definitions(-DSHARING_MEM_WITH_OPENGL)
add_definitions(-DCL_HPP_TARGET_OPENCL_VERSION=120)
endif()
add_subdirectory(source/tnn/device/opencl)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNOpenCL>")
endif()
if(TNN_METAL_ENABLE)
add_subdirectory(source/tnn/device/metal)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNMetal>")
endif()
if(TNN_CUDA_ENABLE)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
add_subdirectory(source/tnn/device/cuda)
if(TNN_TENSORRT_ENABLE)
add_subdirectory(source/tnn/network/tensorrt)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNTensorRT>")
endif()
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNCuda>")
endif()
if(TNN_HUAWEI_NPU_ENABLE)
if(ANDROID_ABI STREQUAL "armeabi-v7a")
link_directories(
third_party/huawei_npu/hiai_ddk_latest/armeabi-v7a/
)
else()
link_directories(
third_party/huawei_npu/hiai_ddk_latest/arm64-v8a/
)
endif()
add_subdirectory(source/tnn/device/huawei_npu)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNNPU>")
endif()
if(TNN_RK_NPU_ENABLE)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
link_directories(
./third_party/rknpu/rknpu_ddk/lib64/
)
else()
link_directories(
./third_party/rknpu/rknpu_ddk/lib/
)
endif()
add_subdirectory(source/tnn/device/rknpu)
set(TARGET_OBJECTS ${TARGET_OBJECTS} "$<TARGET_OBJECTS:TNNRKNPU>")
endif()
if(TNN_BUILD_SHARED)
add_library(TNN SHARED ${SRC} ${TARGET_OBJECTS})
set_target_properties(TNN PROPERTIES VERSION ${TNN_VERSION} SOVERSION ${TNN_MAJOR_VERSION})
if(SHARING_MEM_WITH_OPENGL)
target_link_libraries(TNN -lEGL -lGLESv2)
endif()
else()
add_library(TNN STATIC ${SRC} ${TARGET_OBJECTS})
set_target_properties(TNN PROPERTIES VERSION ${TNN_VERSION})
if(SHARING_MEM_WITH_OPENGL)
target_link_libraries(TNN -lEGL -lGLESv2)
endif()
endif()
if(TNN_QUANTIZATION_ENABLE)
add_subdirectory(tools/quantization)
endif()
if(SYSTEM.Linux)
include(platforms/linux/CMakeLists.txt)
elseif(SYSTEM.Android)
include(platforms/android/CMakeLists.txt)
elseif(SYSTEM.iOS)
include(platforms/ios/CMakeLists.txt)
elseif(SYSTEM.Darwin)
include(platforms/mac/CMakeLists.txt)
elseif(SYSTEM.Windows)
include(platforms/windows/CMakeLists.txt)
endif()
if(TNN_MODEL_CHECK_ENABLE)
add_subdirectory(tools/model_check)
endif()
if (TNN_TEST_ENABLE OR TNN_CONVERTER_ENABLE)
add_subdirectory(third_party/gflags)
get_target_property(GFLAGS_INCLUDE_DIRS gflags INTERFACE_INCLUDE_DIRECTORIES)
include_directories(BEFORE "${GFLAGS_INCLUDE_DIRS}")
endif ()
if(TNN_TEST_ENABLE)
add_subdirectory(test)
endif()
if(TNN_CONVERTER_ENABLE)
add_subdirectory(third_party/flatbuffers)
add_subdirectory(tools/converter)
endif()
if(TNN_COVERAGE)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -coverage -lgcov")
endif()
endif()