forked from neo-ai/neo-ai-dlr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
468 lines (433 loc) · 19.6 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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
cmake_minimum_required (VERSION 3.6)
include(cmake/Utils.cmake)
include(3rdparty/tvm/cmake/util/FindCUDA.cmake)
# Option for Android on Arm --- has to come before project() function
option(ANDROID_BUILD "Build for Android target" OFF)
option(AAR_BUILD "Build Android Archive (AAR)" OFF)
if(ANDROID_BUILD)
set(ANDROID_SYSROOT "${NDK_ROOT}/sysroot")
if(NOT ANDROID_PLATFORM AND NOT ANDROID_NATIVE_API_LEVEL)
set(ANDROID_PLATFORM "android-21")
message(STATUS "ANDROID_PLATFORM not set. Defaulting to android-21")
endif()
endif(ANDROID_BUILD)
project(dlr)
# The following lines should be after project()
set_default_configuration_release()
msvc_use_static_runtime()
message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
set(CMAKE_LOCAL "${PROJECT_SOURCE_DIR}/cmake")
# CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES stuff should go after project() function
if(ANDROID_BUILD)
# Disable debugging info for Release build by setting -g level to 0. It will reduce libdlr.so size by a factor of 3.
# NDK Issue https://github.com/android/ndk/issues/243
if (CMAKE_BUILD_TYPE STREQUAL "Release")
string(REPLACE "-g " "-g0 " CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REPLACE "-g " "-g0 " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-g " "-g0 " CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS})
endif()
# Add ARCH specific header folder to CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
if (ANDROID_ABI STREQUAL "x86_64")
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${ANDROID_SYSROOT}/usr/include/x86_64-linux-android)
elseif (ANDROID_ABI STREQUAL "x86")
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${ANDROID_SYSROOT}/usr/include/i686-linux-android)
elseif (ANDROID_ABI STREQUAL "arm64-v8a")
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${ANDROID_SYSROOT}/usr/include/aarch64-linux-android)
else() # Default to armv7a which matches NDK toolchain.cmake behavior
list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
endif()
message(STATUS "CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES: ${CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES}")
message(STATUS "Android CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
message(STATUS "Android CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})
message(STATUS "Android CMAKE_ASM_FLAGS: " ${CMAKE_ASM_FLAGS})
endif(ANDROID_BUILD)
# Options
option(USE_OPENCL "Build with OpenCL" OFF)
option(USE_CUDA "Build with CUDA" OFF)
option(USE_CUDNN "Build with CUDNN" OFF)
option(USE_TENSORRT "Build with Tensor RT" OFF)
# Use RPATH on Mac OS X as flexible mechanism for locating dependencies
# See https://blog.kitware.com/upcoming-in-cmake-2-8-12-osx-rpath-support/
set(CMAKE_MACOSX_RPATH TRUE)
set(python-build "bp3-python setup.py build")
# Set BUILD_SHARED_LIBS as option. By default, build shared libraries;
# User can set this to OFF to build static libraries instead.
option(BUILD_SHARED_LIBS "Build shared library" ON)
option(TEST_COVERAGE "C++ test coverage" OFF)
# Compiler flags
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funroll-loops")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
if(TEST_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
endif()
set(DLR_LINKER_LIBS "")
set(TVM_SRC "${PROJECT_SOURCE_DIR}/3rdparty/tvm")
set(TREELITE_SRC "${PROJECT_SOURCE_DIR}/3rdparty/treelite")
set(DMLC_CORE_SRC "${TVM_SRC}/3rdparty/dmlc-core")
set(DLPACK_SRC "${TVM_SRC}/3rdparty/dlpack")
set(FMT_SRC "${TREELITE_SRC}/3rdparty/fmt")
include_directories("${TVM_SRC}/include")
include_directories("${TVM_SRC}/src/runtime")
include_directories("${DLPACK_SRC}/include")
include_directories("${DMLC_CORE_SRC}/include")
include_directories("${FMT_SRC}/include")
include_directories("${TREELITE_SRC}/include")
include_directories("${TREELITE_SRC}/runtime/native/include")
include_directories("${PROJECT_SOURCE_DIR}/include")
# Add only top level *.cc files (non-RECURSE)
FILE(GLOB DLR_SRC
"src/*.cc"
${TVM_SRC}/src/runtime/dso_library.cc
${TVM_SRC}/src/runtime/cpu_device_api.cc
${TVM_SRC}/src/runtime/contrib/sort/sort.cc
)
if(USE_OPENCL)
message("USING OpenCL")
if(USE_OPENCL STREQUAL "ON")
find_package(OpenCL QUIET)
if(NOT OpenCL_FOUND)
message(FATAL_ERROR "OpenCL not found, please specify OpenCL location with -DUSE_OPENCL=/path/to/OpenCL")
endif(NOT OpenCL_FOUND)
else(USE_OPENCL STREQUAL "ON")
set(OpenCL_TOOLKIT_ROOT_DIR ${USE_OPENCL})
message(STATUS "Custom OPENCL_PATH=" ${OpenCL_TOOLKIT_ROOT_DIR})
set(OpenCL_INCLUDE_DIRS ${OpenCL_TOOLKIT_ROOT_DIR}/include)
set(OpenCL_LIBRARIES ${USE_OPENCL}/lib/libOpenCL.so)
endif(USE_OPENCL STREQUAL "ON")
include_directories(${OpenCL_INCLUDE_DIRS})
list(APPEND DLR_LINKER_LIBS ${OpenCL_LIBRARIES})
file(GLOB RUNTIME_OPENCL_SRCS ${TVM_SRC}/src/runtime/opencl/*.cc)
list(APPEND DLR_SRC ${RUNTIME_OPENCL_SRCS})
set(USE_OPENCL OFF)
endif(USE_OPENCL)
if(USE_CUDA)
message("USING CUDA")
find_cuda(${USE_CUDA})
if(NOT CUDA_FOUND)
message(FATAL_ERROR "CUDA not found, please specify CUDA location with -DUSE_CUDA=/path/to/cuda/")
endif(NOT CUDA_FOUND)
if (NOT USE_CUDA STREQUAL "ON")
set(CUDA_TOOLKIT_ROOT_DIR ${USE_CUDA})
endif(NOT USE_CUDA STREQUAL "ON")
message(STATUS "Custom CUDA_PATH=" ${CUDA_TOOLKIT_ROOT_DIR})
set(CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_ROOT_DIR}/include)
include_directories(${CUDA_INCLUDE_DIRS})
find_library(_CUDA_CUDA_LIBRARY cuda
PATHS ${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib lib64 lib64/stubs)
message(STATUS "CUDA_CUDA_LIBRARY: " ${_CUDA_CUDA_LIBRARY})
if(_CUDA_CUDA_LIBRARY)
set(CUDA_CUDA_LIBRARY ${_CUDA_CUDA_LIBRARY})
endif()
find_library(CUDA_CUDART_LIBRARY cudart
PATHS ${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib lib64)
message(STATUS "CUDA_CUDART_LIBRARY: " ${CUDA_CUDART_LIBRARY})
list(APPEND DLR_LINKER_LIBS ${CUDA_CUDART_LIBRARY})
list(APPEND DLR_LINKER_LIBS ${CUDA_CUDA_LIBRARY})
list(APPEND DLR_LINKER_LIBS ${CUDA_NVRTC_LIBRARY})
file(GLOB RUNTIME_CUDA_SRCS ${TVM_SRC}/src/runtime/cuda/*.cc)
list(APPEND DLR_SRC ${RUNTIME_CUDA_SRCS})
set(USE_CUDA OFF)
endif()
if(USE_CUDNN)
message("USING CUDNN")
set(USE_CUDNN ${USE_CUDA})
set(CUDNN_TOOLKIT_ROOT_DIR ${USE_CUDNN})
message(STATUS "Custom CUDNN_PATH=" ${CUDNN_TOOLKIT_ROOT_DIR})
find_library(CUDA_CUDNN_LIBRARY cudnn
PATH ${CUDNN_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES lib lib64)
if (CUDA_CUDNN_LIBRARY MATCHES "NOTFOUND")
set(CUDA_CUDNN_LIBRARY ${USE_CUDNN}/lib64/libcudnn.so)
endif()
message(STATUS "CUDA_CUDNN_LIBRARY: " ${CUDA_CUDNN_LIBRARY})
list(APPEND DLR_LINKER_LIBS ${CUDA_CUDNN_LIBRARY})
file(GLOB CONTRIB_CUDNN_SRCS ${TVM_SRC}/src/contrib/cudnn/*.cc)
list(APPEND RUNTIME_SRCS ${CONTRIB_CUDNN_SRCS})
set(USE_CUDNN_OFF)
endif()
if(USE_TENSORRT)
message("USING TENSORRT")
if(IS_DIRECTORY ${USE_TENSORRT})
set(TENSORRT_ROOT_DIR ${USE_TENSORRT})
message(STATUS "Custom TensorRT path: " ${TENSORRT_ROOT_DIR})
endif()
find_path(TENSORRT_INCLUDE_DIR NvInfer.h HINTS ${TENSORRT_ROOT_DIR} PATH_SUFFIXES include)
find_library(TENSORRT_LIB_DIR nvinfer HINTS ${TENSORRT_ROOT_DIR} PATH_SUFFIXES lib)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TENSORRT DEFAULT_MSG TENSORRT_INCLUDE_DIR TENSORRT_LIB_DIR)
if(NOT TENSORRT_FOUND)
message(ERROR "Could not find TensorRT.")
endif()
message(STATUS "TENSORRT_LIB_DIR: " ${TENSORRT_LIB_DIR})
include_directories(${TENSORRT_INCLUDE_DIR})
list(APPEND DLR_LINKER_LIBS ${TENSORRT_LIB_DIR})
# NNVM TRT Integration
file(GLOB TENSORRT_SRCS ${TVM_SRC}/src/contrib/subgraph/*.cc)
list(APPEND DLR_SRC ${TENSORRT_SRCS})
add_definitions(-DTVM_GRAPH_RUNTIME_TENSORRT)
# TRT Relay sources
file(GLOB TENSORRT_RELAY_SRCS ${TVM_SRC}/src/runtime/contrib/tensorrt/*.cc)
list(APPEND DLR_SRC ${TENSORRT_RELAY_SRCS})
# Additional TVM compiler sources
include_directories("${TVM_SRC}/3rdparty/rang/include")
include_directories("${TVM_SRC}/3rdparty/compiler-rt")
include_directories("${TVM_SRC}/topi/include")
list(APPEND DLR_SRC
# Ops
${TVM_SRC}/src/relay/op/nn/nn.cc
${TVM_SRC}/src/relay/op/nn/pooling.cc
${TVM_SRC}/src/relay/op/nn/convolution.cc
${TVM_SRC}/src/relay/op/nn/pad.cc
${TVM_SRC}/src/relay/op/tensor/binary.cc
${TVM_SRC}/src/relay/op/tensor/unary.cc
${TVM_SRC}/src/relay/op/tensor/transform.cc
${TVM_SRC}/src/relay/op/tensor/reduce.cc
${TVM_SRC}/src/relay/op/image/resize.cc
${TVM_SRC}/src/relay/ir/expr_functor.cc
${TVM_SRC}/src/relay/ir/pattern_functor.cc
${TVM_SRC}/src/relay/pass/util.cc
${TVM_SRC}/src/relay/ir/type_functor.cc
${TVM_SRC}/src/relay/ir/type.cc
${TVM_SRC}/src/lang/ir.cc
${TVM_SRC}/src/lang/expr.cc
${TVM_SRC}/src/relay/ir/expr.cc
${TVM_SRC}/src/relay/ir/adt.cc
${TVM_SRC}/src/relay/ir/module.cc
${TVM_SRC}/src/relay/pass/pass_manager.cc
${TVM_SRC}/src/lang/attrs.cc
${TVM_SRC}/src/lang/tensor.cc
${TVM_SRC}/src/relay/pass/eta_expand.cc
${TVM_SRC}/src/relay/pass/kind_check.cc
${TVM_SRC}/src/lang/expr_operator.cc
${TVM_SRC}/src/arithmetic/int_set.cc
${TVM_SRC}/src/arithmetic/analyzer.cc
${TVM_SRC}/src/arithmetic/modular_set.cc
${TVM_SRC}/src/arithmetic/const_int_bound.cc
${TVM_SRC}/src/arithmetic/canonical_simplify.cc
${TVM_SRC}/src/arithmetic/rewrite_simplify.cc
${TVM_SRC}/src/arithmetic/ir_mutator_with_analyzer.cc
${TVM_SRC}/src/pass/ir_mutator.cc
${TVM_SRC}/src/pass/ir_deep_compare.cc
${TVM_SRC}/src/pass/simple_passes.cc
${TVM_SRC}/src/pass/ir_visitor.cc
${TVM_SRC}/src/relay/ir/pretty_printer.cc
${TVM_SRC}/src/relay/ir/doc.cc
${TVM_SRC}/src/relay/pass/dependency_graph.cc
${TVM_SRC}/src/node/reflection.cc
${TVM_SRC}/src/arithmetic/stmt_simplify.cc
${TVM_SRC}/src/relay/pass/type_infer.cc
${TVM_SRC}/src/relay/pass/type_solver.cc
${TVM_SRC}/src/lang/api_registry.cc
${TVM_SRC}/src/relay/pass/match_exhaustion.cc
${TVM_SRC}/src/node/serialization.cc
${TVM_SRC}/src/relay/ir/alpha_equal.cc
${TVM_SRC}/src/relay/ir/error.cc
${TVM_SRC}/src/relay/pass/de_duplicate.cc
${TVM_SRC}/src/relay/pass/well_formed.cc
${TVM_SRC}/src/relay/ir/op.cc
${TVM_SRC}/src/relay/op/type_relations.cc
${TVM_SRC}/src/op/compute_op.cc
${TVM_SRC}/src/schedule/message_passing.cc
${TVM_SRC}/src/op/op_util.cc
${TVM_SRC}/src/pass/ir_util.cc
${TVM_SRC}/src/op/cross_thread_reduction.cc
${TVM_SRC}/src/lang/data_layout.cc
${TVM_SRC}/src/op/tensorize.cc
${TVM_SRC}/src/pass/arg_binder.cc
${TVM_SRC}/src/relay/ir/base.cc
${TVM_SRC}/src/relay/backend/contrib/tensorrt/common_utils.cc
)
set(USE_TENSORRT OFF)
endif()
if(WITH_TENSORFLOW_LITE_LIB)
if(NOT WITH_TENSORFLOW_LITE_LIB MATCHES ".*libtensorflow-lite\.a$")
message(FATAL_ERROR "WITH_TENSORFLOW_LITE_LIB should point to static library libtensorflow-lite.a")
endif()
message("Adding libtensorflow-lite.a to DLR shared library")
# Download Tensorflow and FlatBuffers source code
set(TENSORFLOW_VER "1.15.2")
set(TENSORFLOW_SHA1 "b9e71bf287a186ceb9d859588671d890c45e51a7")
set(FLATBUFFERS_VER "1.11.0")
set(FLATBUFFERS_SHA1 "2b2633902c57c6980b3a41b44d8ad933f214d71d")
set(TENSORFLOW_URL "https://github.com/tensorflow/tensorflow/archive/v${TENSORFLOW_VER}.tar.gz")
set(TENSORFLOW_TGZ "/tmp/tensorflow-${TENSORFLOW_VER}.tar.gz")
set(TENSORFLOW_SRC "${PROJECT_SOURCE_DIR}/3rdparty/tensorflow-${TENSORFLOW_VER}")
set(FLATBUFFERS_URL "https://github.com/google/flatbuffers/archive/v${FLATBUFFERS_VER}.tar.gz")
set(FLATBUFFERS_TGZ "/tmp/flatbuffers-${FLATBUFFERS_VER}.tar.gz")
set(FLATBUFFERS_SRC "${PROJECT_SOURCE_DIR}/3rdparty/flatbuffers-${FLATBUFFERS_VER}")
download_file(${TENSORFLOW_URL} ${TENSORFLOW_TGZ} SHA1 ${TENSORFLOW_SHA1})
download_file(${FLATBUFFERS_URL} ${FLATBUFFERS_TGZ} SHA1 ${FLATBUFFERS_SHA1})
# Extract Tensorflow and FlatBuffers source code
message(STATUS "Extracting " ${TENSORFLOW_TGZ} " ...")
execute_process(
COMMAND rm -rf ${PROJECT_SOURCE_DIR}/3rdparty/tensorflow*
COMMAND tar -C ${PROJECT_SOURCE_DIR}/3rdparty -zxf ${TENSORFLOW_TGZ}
RESULT_VARIABLE tf_ret
)
if(NOT tf_ret EQUAL "0")
message(FATAL_ERROR "Failed to extract " ${TENSORFLOW_TGZ})
endif()
message(STATUS "Extracting " ${FLATBUFFERS_TGZ} " ...")
execute_process(
COMMAND rm -rf ${PROJECT_SOURCE_DIR}/3rdparty/flatbuffers*
COMMAND tar -C ${PROJECT_SOURCE_DIR}/3rdparty -zxf ${FLATBUFFERS_TGZ}
RESULT_VARIABLE fb_ret
)
if(NOT fb_ret EQUAL "0")
message(FATAL_ERROR "Failed to extract " ${FLATBUFFERS_TGZ})
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DDLR_TFLITE")
include_directories("${TENSORFLOW_SRC}")
include_directories("${FLATBUFFERS_SRC}/include")
list(APPEND DLR_SRC "src/dlr_tflite/dlr_tflite.cc")
if(ANDROID_BUILD) # Android build needs additional library liblog
list(APPEND DLR_LINKER_LIBS -Wl,--whole-archive ${WITH_TENSORFLOW_LITE_LIB} -Wl,--no-whole-archive -llog)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Mac OS linker is different from Linux.
# Use -force_load instead of --whole-archive
list(APPEND DLR_LINKER_LIBS -Wl,-force_load,${WITH_TENSORFLOW_LITE_LIB})
else() # Regulal Linux Build
list(APPEND DLR_LINKER_LIBS -Wl,--whole-archive ${WITH_TENSORFLOW_LITE_LIB} -Wl,--no-whole-archive -ldl)
endif()
endif()
if(WITH_TENSORFLOW_LIB)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDLR_TENSORFLOW")
include_directories("${WITH_TENSORFLOW_LIB}/include")
list(APPEND DLR_SRC "src/dlr_tensorflow/dlr_tensorflow.cc")
list(APPEND DLR_LINKER_LIBS -L${WITH_TENSORFLOW_LIB}/lib -ltensorflow_framework -ltensorflow)
endif()
if(WITH_HEXAGON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDLR_HEXAGON")
list(APPEND DLR_SRC "src/dlr_hexagon/dlr_hexagon.cc")
endif()
if(AAR_BUILD)
list(APPEND DLR_SRC "src/jni/dlr_jni.cc")
endif()
set(MAIN_EXEC "")
FILE(GLOB MAIN_SRC src/*.cc)
add_subdirectory(${TVM_SRC} EXCLUDE_FROM_ALL)
add_subdirectory(${TREELITE_SRC} EXCLUDE_FROM_ALL)
add_library(objdlr OBJECT ${DLR_SRC})
#shared_library
find_package(Threads)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
add_library(dlr SHARED $<TARGET_OBJECTS:objdlr>)
set_output_directory(dlr ${CMAKE_BINARY_DIR}/lib)
set_target_properties(dlr PROPERTIES LINKER_LANGUAGE CXX)
message(STATUS "DLR_LINKER_LIBS: " ${DLR_LINKER_LIBS})
if(ANDROID_BUILD)
target_link_libraries(dlr treelite_runtime_static tvm_runtime_static ${DLR_LINKER_LIBS})
else(ANDROID_BUILD)
target_link_libraries(dlr treelite_runtime_static tvm_runtime_static ${DLR_LINKER_LIBS} -lpthread)
endif()
add_library(dlr_static STATIC $<TARGET_OBJECTS:objdlr>)
set_output_directory(dlr_static ${CMAKE_BINARY_DIR}/lib)
set(OPREFIX object_)
add_custom_target(combined_lib
COMMAND mkdir -p ${OPREFIX}tvm_runtime || true && cd ${OPREFIX}tvm_runtime && ar -x ${TVM_RUNTIME}
COMMAND mkdir -p ${OPREFIX}treelite_runtime || true && cd ${OPREFIX}treelite_runtime && ar -x ${TREELITE_RUNTIME}
COMMAND g++ ${OPREFIX}*/*.o -shared -o ${CMAKE_CURRENT_SOURCE_DIR}/libcombined.so
COMMAND rm -rf ${OPREFIX}*
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# Demos
set(DEMO_EXECS "")
file(GLOB DEMO_SRCS demo/cpp/*.cc)
foreach(__srcpath ${DEMO_SRCS})
get_filename_component(__srcname ${__srcpath} NAME)
string(REPLACE ".cc" "" __execname ${__srcname})
list(APPEND DEMO_EXECS ${__execname})
add_executable(${__execname} ${__srcpath} $<TARGET_OBJECTS:objdlr>)
if (ANDROID_BUILD)
target_link_libraries(${__execname} PRIVATE treelite_runtime_static tvm_runtime_static ${DLR_LINKER_LIBS} -fuse-ld=gold)
else (ANDROID_BUILD)
target_link_libraries(${__execname} PRIVATE treelite_runtime_static tvm_runtime_static ${DLR_LINKER_LIBS} -lpthread)
endif ()
set_output_directory(${__execname} ${CMAKE_BINARY_DIR}/bin)
set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_ALL 1)
set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
endforeach()
add_custom_target(demo DEPENDS ${DEMO_EXECS})
# Tests
if(NOT(AAR_BUILD))
include(cmake/googletest.cmake)
fetch_googletest(
${PROJECT_SOURCE_DIR}/cmake
${PROJECT_BINARY_DIR}/googletest
)
enable_testing()
file(GLOB TEST_SRCS tests/cpp/*.cc)
if(WITH_TENSORFLOW_LITE_LIB)
file(GLOB TFLITE_TEST_SRCS tests/cpp/dlr_tflite/*.cc)
list(APPEND TEST_SRCS ${TFLITE_TEST_SRCS})
endif()
if(WITH_TENSORFLOW_LIB)
file(GLOB TENSORFLOW_TEST_SRCS tests/cpp/dlr_tensorflow/*.cc)
list(APPEND TEST_SRCS ${TENSORFLOW_TEST_SRCS})
endif()
if(WITH_HEXAGON)
file(GLOB HEXAGON_TEST_SRCS tests/cpp/dlr_hexagon/*.cc)
list(APPEND TEST_SRCS ${HEXAGON_TEST_SRCS})
endif()
foreach(__srcpath ${TEST_SRCS})
get_filename_component(__srcname ${__srcpath} NAME)
string(REPLACE ".cc" "" __execname ${__srcname})
add_executable(${__execname} ${__srcpath})
target_link_libraries(${__execname} dlr gtest_main)
set_output_directory(${__execname} ${CMAKE_BINARY_DIR})
add_test(NAME ${__execname} COMMAND ${__execname})
message(STATUS "Added Test: " ${__execname})
endforeach()
if(WITH_TENSORFLOW_LITE_LIB)
# Download Test TFLite model
file(MAKE_DIRECTORY mobilenet_v2_0.75_224)
download_file(
https://neo-ai-dlr-test-artifacts.s3-us-west-2.amazonaws.com/tflite-models/mobilenet_v2_0.75_224.tflite
./mobilenet_v2_0.75_224/mobilenet_v2_0.75_224.tflite
SHA1
c653a09facaf2dfb5e3910030b3f74ad04259e30
)
endif() # WITH_TENSORFLOW_LITE_LIB
if(WITH_TENSORFLOW_LIB)
# Download Test Tensorflow model
file(MAKE_DIRECTORY mobilenet_v1_1.0_224)
download_file(
https://neo-ai-dlr-test-artifacts.s3-us-west-2.amazonaws.com/tf-models/mobilenet_v1_1.0_224_frozen.pb
./mobilenet_v1_1.0_224/mobilenet_v1_1.0_224_frozen.pb
SHA1
4df8525bcf2ec96296098ba7fec0fff1abe32fce
)
endif() # WITH_TENSORFLOW_LIB
if(WITH_HEXAGON)
# Download Test Hexagon model for Android 64 aarch64
file(MAKE_DIRECTORY dlr_hexagon_model)
download_file(
https://neo-ai-dlr-test-artifacts.s3-us-west-2.amazonaws.com/hexagon-models/android_ReleaseG_aarch64/mobilenet_v1_0.75_224_quant_hexagon_model.so
./dlr_hexagon_model/mobilenet_v1_0.75_224_quant_hexagon_model.so
SHA1
989d6f1613e948e432a31d5b5741bff7f9a9bacb
)
# Download Hexagon NNLib for Hexagon V65
download_file(
https://neo-ai-dlr-test-artifacts.s3-us-west-2.amazonaws.com/hexagon-models/hexagon_ReleaseG_dynamic_toolv83_v65/libhexagon_nn_skel.so
./dlr_hexagon_model/libhexagon_nn_skel.so
SHA1
6746c34f54aad3df24d9fc5f632ebd9dfc64ed69
)
endif() # WITH_HEXAGON
if(WITH_TENSORFLOW_LITE_LIB OR WITH_TENSORFLOW_LIB OR WITH_HEXAGON)
download_file(
https://neo-ai-dlr-test-artifacts.s3-us-west-2.amazonaws.com/tflite-models/cat224-3.txt
./cat224-3.txt
SHA1
e35e82f3371bed37caa7ecece417f50876414077
)
endif() # WITH_TENSORFLOW_LITE_LIB OR WITH_TENSORFLOW_LIB OR WITH_HEXAGON
endif()
# Group sources
#auto_source_group("${SOURCES}")