forked from kendryte/nncase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
277 lines (238 loc) · 8.71 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
cmake_minimum_required(VERSION 3.15)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules)
if(NOT DEFINED NNCASE_VERSION)
set(NNCASE_VERSION "2.0.0")
endif()
if(DEFINED ENV{NNCASE_VERSION_SUFFIX})
set(NNCASE_VERSION_SUFFIX $ENV{NNCASE_VERSION_SUFFIX})
endif()
if(NOT DEFINED NNCASE_VERSION_SUFFIX)
find_package (Git)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --always --dirty --tag
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE)
if ("v${NNCASE_VERSION}" STREQUAL "${GIT_TAG}")
set(NNCASE_VERSION_SUFFIX "")
else()
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --always --dirty
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DESC
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(NNCASE_VERSION_SUFFIX "-${GIT_DESC}")
endif()
endif()
if (NOT PACKAGE_VERSION)
set(PACKAGE_VERSION
"${NNCASE_VERSION}${NNCASE_VERSION_SUFFIX}")
endif()
project(nncase
VERSION ${NNCASE_VERSION}
LANGUAGES C CXX ASM)
option(ENABLE_OPENMP "OpenMP support" ON)
option(ENABLE_HALIDE "halide kernels support" ON)
option(DOTNET_INIT_FOR_CONFIG "Initialize dotnet from runtimeconfig" OFF)
option(BUILD_PYTHON_BINDING "Build python binding" ON)
option(BUILD_CSHARP_BINDING "Build csharp binding" ON)
option(BUILD_BENCHMARK "Build benchmark programs" ON)
option(BUILD_TESTING "Build test programs" OFF)
option(ENABLE_OP_PROFILE "Profile ops cast time" OFF)
option(ENABLE_DUMP_MANAGER "Enable dump manager" OFF)
option(ENABLE_RVV "Some kernel impl by rvv" OFF)
option(ENABLE_DUMP_MEM "Dump mem usage" OFF)
if (ENABLE_OP_PROFILE)
add_definitions(-DENABLE_OP_PROFILE)
endif()
if(ENABLE_DUMP_MEM)
add_definitions(-DDUMP_MEM)
endif()
if(NOT CMAKE_TOOLCHAIN_FILE)
include(toolchains/native.toolchain.cmake)
endif()
if (BUILDING_RUNTIME)
option(ENABLE_VULKAN_RUNTIME "Enable Vulkan runtime" OFF)
option(ENABLE_K210_RUNTIME "Enable k210 runtime" OFF)
option(DEFAULT_BUILTIN_RUNTIMES "Use default builtin runtimes" ON)
option(DEFAULT_SHARED_RUNTIME_TENSOR_PLATFORM_IMPL "Use default shared memory platform impl" ON)
endif()
include(cmake/configure-conan.cmake)
include(cmake/conan.cmake)
if(NOT CONAN_EXPORTED)
conan_check()
conan_add_remote(NAME sunnycase URL https://conan.sunnycase.moe INDEX 0)
endif()
if(CONAN_EXPORTED) # in conan local cache
message(STATUS "Standard Conan Installation")
else() # in user space
message(STATUS "Auto Cmake Conan Installation")
include(${CMAKE_SOURCE_DIR}/cmake/conan.cmake)
conan_cmake_run(CONANFILE conanfile.py
BASIC_SETUP
OPTIONS ${CONAN_OPTS}
SETTINGS ${CONAN_SETTINGS}
BUILD missing)
endif()
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
include(cmake/dependencies.cmake)
if (BUILDING_RUNTIME)
set(NNCASE_MAIN_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/Native/include)
set(NNCASE_MAIN_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/Native/include)
set(NNCASE_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/Native/include)
set(THIRD_PARTY ${CMAKE_CURRENT_LIST_DIR}/third_party)
set_property(GLOBAL PROPERTY POSITION_INDEPENDENT_CODE ON)
if (MSVC)
add_definitions(/D_CRT_SECURE_NO_WARNINGS /DNOMINMAX)
add_compile_options(/wd4267 /wd4251 /wd4244 /FC /utf-8 /W3 /WX /wd4297 -Wno-unused-function -Wno-unused-command-line-argument)
else()
add_compile_options(-Wall -Wextra -pedantic -Werror -Wno-multichar -Wno-missing-field-initializers -Wno-unused-function -Wno-type-limits)
if (APPLE)
add_compile_options(-Wno-four-char-constants -Wno-sometimes-uninitialized)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wno-uninitialized -Wno-unused-private-field)
else()
add_compile_options(-Wno-maybe-uninitialized -Wno-attributes)
if (CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 9)
add_compile_options(-Wno-unused-private-field)
endif()
endif()
endif()
include_directories(${NNCASE_MAIN_INCLUDE_DIR})
include_directories(${NNCASE_INCLUDE_DIR})
add_subdirectory(src/Native/include/nncase)
# add_subdirectory(src/Native/src/kernels)
# add_subdirectory(src/Native/src/runtime)
add_subdirectory(src/Native/src)
# add_subdirectory(src/Native/src/functional)
if(BUILD_BENCHMARK)
# add_subdirectory(benchmark)
endif()
# Python binding
if(BUILD_PYTHON_BINDING)
# add_subdirectory(python/nncaseruntime/native)
endif()
install(DIRECTORY ${NNCASE_INCLUDE_DIR}/nncase
DESTINATION include
COMPONENT nncase-headers
FILES_MATCHING
PATTERN "*.def"
PATTERN "*.h"
PATTERN "*version.h"
PATTERN "CMakeFiles" EXCLUDE
)
install(DIRECTORY src/Native/include/nncase/
DESTINATION include/nncase
COMPONENT nncase-headers
FILES_MATCHING
PATTERN "*.def"
PATTERN "*.h"
PATTERN "*version.h"
PATTERN "CMakeFiles" EXCLUDE
)
install(DIRECTORY src/Native/include/nncase/kernels
DESTINATION include/nncase
COMPONENT nncase-headers
FILES_MATCHING
PATTERN "*.def"
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN "*.td"
PATTERN "*.inc"
PATTERN "LICENSE.TXT"
)
install(DIRECTORY src/Native/include/nncase/runtime
DESTINATION include/nncase
COMPONENT nncase-headers
FILES_MATCHING
PATTERN "*.def"
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN "*.td"
PATTERN "*.inc"
PATTERN "LICENSE.TXT"
)
else()
set(CMAKE_SKIP_RPATH OFF)
set(NNCASE_MAIN_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/Native/include)
set(NNCASE_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/Native/include)
set(THIRD_PARTY ${CMAKE_CURRENT_LIST_DIR}/third_party)
set_property(GLOBAL PROPERTY POSITION_INDEPENDENT_CODE ON)
if (APPLE)
set(CMAKE_MACOSX_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "@loader_path")
set(CMAKE_INSTALL_NAME_DIR "@rpath")
else ()
set(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()
if (MSVC)
add_definitions(/D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS /D_CRT_SECURE_NO_WARNINGS /DNOMINMAX)
add_compile_options(/wd4267 /wd4251 /wd4244 /FC /utf-8 /W3 /WX -Wno-unused-function -Wno-unused-command-line-argument)
set(PYBIND11_CPP_STANDARD "/std:c++latest")
else()
add_compile_options(-fvisibility=hidden)
add_compile_options(-Wall -Wextra -pedantic -Werror -Wno-multichar -Wno-missing-field-initializers -Wno-unused-function -Wno-type-limits -Wno-unused-local-typedefs -Wno-sign-compare)
if (APPLE)
add_compile_options(-Wno-four-char-constants -Wno-sometimes-uninitialized -Wno-deprecated)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wno-uninitialized -Wno-gnu-zero-variadic-macro-arguments)
else ()
add_compile_options(-Wno-maybe-uninitialized -Wno-deprecated-copy)
add_link_options(-Wl,--exclude-libs,ALL)
endif()
endif()
include_directories(${NNCASE_MAIN_INCLUDE_DIR})
include_directories(${NNCASE_INCLUDE_DIR})
add_subdirectory(src/Native/include/nncase)
add_subdirectory(src/Native/src)
# Python binding
if(BUILD_PYTHON_BINDING)
add_subdirectory(python/nncase/native)
endif()
# Csharp binding
if(BUILD_CSHARP_BINDING)
#add_subdirectory(csharp)
endif()
# Thrid party
# add_subdirectory(third_party/onnx)
install(DIRECTORY src/Native/include/nncase
DESTINATION include
COMPONENT nncase-headers
FILES_MATCHING
PATTERN "*.def"
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN "*.td"
PATTERN "*.inc"
PATTERN "LICENSE.TXT"
PATTERN "*.h"
)
install(DIRECTORY ${NNCASE_INCLUDE_DIR}/nncase
DESTINATION include
COMPONENT nncase-headers
FILES_MATCHING
PATTERN "*.def"
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN "*.td"
PATTERN "*.inc"
PATTERN "CMakeFiles" EXCLUDE
PATTERN "config.h" EXCLUDE
PATTERN "*.h"
)
install(DIRECTORY python/nncase
DESTINATION python
COMPONENT nncase-python
FILES_MATCHING
PATTERN "*.py"
)
# Targets
#add_subdirectory(targets/cpu)
#add_subdirectory(targets/k210)
#add_subdirectory(targets/vulkan)
endif()
if(BUILD_TESTING)
add_subdirectory(tests/kernels)
endif()
# Modules
#add_subdirectory(modules/vulkan)