forked from hpi-xnor/BMXNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
388 lines (338 loc) · 14.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
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
cmake_minimum_required(VERSION 2.8.7)
project(mxnet C CXX)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
endif()
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules;${CMAKE_MODULE_PATH}")
include(cmake/Utils.cmake)
mxnet_option(USE_OPENCV "Build with OpenCV support" ON)
mxnet_option(USE_OPENMP "Build with Openmp support" ON)
mxnet_option(USE_CUDNN "Build with cudnn support" ON) # one could set CUDNN_ROOT for search path
mxnet_option(USE_CUDA "Build with CUDA support" ON)
mxnet_option(USE_PROFILER "Build with Profiler support" OFF)
mxnet_option(USE_DIST_KVSTORE "Build with DIST_KVSTORE support" OFF)
mxnet_option(USE_PLUGINS_WARPCTC "Use WARPCTC Plugins" OFF)
mxnet_option(USE_PLUGIN_CAFFE "Use Caffe Plugin" OFF)
mxnet_option(USE_MXNET_LIB_NAMING "Use MXNet library naming conventions." ON)
SET(EXTRA_OPERATORS "" CACHE PATH "EXTRA OPERATORS PATH")
if(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DDMLC_USE_CXX11)
add_definitions(-DMSHADOW_IN_CXX11)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DMXNET_EXPORTS)
add_definitions(-DNNVM_EXPORTS)
add_definitions(-DDMLC_STRICT_CXX11)
set(CMAKE_C_FLAGS "/MP")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} /bigobj")
else(MSVC)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11)
check_cxx_compiler_flag("-msse2" SUPPORT_MSSE2)
set(CMAKE_C_FLAGS "-Wall -Wno-unknown-pragmas -fPIC")
if(NDEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
else(NDEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb3")
endif(NDEBUG)
set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
if(SUPPORT_CXX11)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if(SUPPORT_MSSE2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
endif()
endif(MSVC)
if(EXISTS ${PROJECT_SOURCE_DIR}/mshadow/cmake)
include(mshadow/cmake/mshadow.cmake)
include(mshadow/cmake/Utils.cmake)
include(mshadow/cmake/Cuda.cmake)
else()
include(mshadowUtils)
include(Cuda)
include(mshadow)
endif()
foreach(var ${C_CXX_INCLUDE_DIRECTORIES})
include_directories(${var})
endforeach()
set(mxnet_LINKER_LIBS "")
set(mxnet_LINKER_LIBS_DEBUG "")
set(mxnet_LINKER_LIBS_RELEASE "")
list(APPEND mxnet_LINKER_LIBS ${mshadow_LINKER_LIBS})
include_directories("include")
include_directories("mshadow")
include_directories("nnvm/include")
include_directories("dmlc-core/include")
if(USE_OPENCV)
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
if(NOT OpenCV_FOUND) # if not OpenCV 3.x, then imgcodecs are not found
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
endif()
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
list(APPEND mxnet_LINKER_LIBS ${OpenCV_LIBS})
message(STATUS "OpenCV found (${OpenCV_CONFIG_PATH})")
add_definitions(-DMXNET_USE_OPENCV=1)
else(USE_OPENCV)
message(STATUS "OpenCV Disabled")
add_definitions(-DMXNET_USE_OPENCV=0)
endif()
if(USE_OPENMP)
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}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
endif()
# cudnn detection
if(USE_CUDNN AND USE_CUDA)
detect_cuDNN()
if(HAVE_CUDNN)
add_definitions(-DUSE_CUDNN)
include_directories(SYSTEM ${CUDNN_INCLUDE})
list(APPEND mxnet_LINKER_LIBS ${CUDNN_LIBRARY})
add_definitions(-DMSHADOW_USE_CUDNN=1)
endif()
endif()
if(EXISTS ${PROJECT_SOURCE_DIR}/dmlc-core/cmake)
add_subdirectory("dmlc-core")
endif()
if(USE_DIST_KVSTORE)
if(EXISTS ${PROJECT_SOURCE_DIR}/ps-lite/CMakeLists.txt)
add_subdirectory("ps-lite")
endif()
endif()
mxnet_source_group("Include\\common" GLOB "src/common/*.h")
mxnet_source_group("Include\\c_api" GLOB "src/c_api/*.h")
mxnet_source_group("Include\\engine" GLOB "src/engine/*.h")
mxnet_source_group("Include\\io" GLOB "src/io/*.h")
mxnet_source_group("Include\\kvstore" GLOB "src/kvstore/*.h")
mxnet_source_group("Include\\ndarray" GLOB "src/ndarray/*.h")
mxnet_source_group("Include\\operator" GLOB "src/operator/*.h")
mxnet_source_group("Include\\optimizer" GLOB "src/optimizer/*.h")
mxnet_source_group("Include\\resource.cc" GLOB "src/resource.cc/*.h")
mxnet_source_group("Include\\storage" GLOB "src/storage/*.h")
mxnet_source_group("Include\\symbol" GLOB "src/symbol/*.h")
mxnet_source_group("Include\\executor" GLOB "src/executor/*.h")
mxnet_source_group("Cuda\\common" GLOB "src/common/*.cu")
mxnet_source_group("Cuda\\c_api" GLOB "src/c_api/*.cu")
mxnet_source_group("Cuda\\engine" GLOB "src/engine/*.cu")
mxnet_source_group("Cuda\\io" GLOB "src/io/*.cu")
mxnet_source_group("Cuda\\kvstore" GLOB "src/kvstore/*.cu")
mxnet_source_group("Cuda\\ndarray" GLOB "src/ndarray/*.cu")
mxnet_source_group("Cuda\\operator" GLOB "src/operator/*.cu")
mxnet_source_group("Cuda\\operator\\tensor" GLOB "src/operator/tensor/*.cu")
mxnet_source_group("Cuda\\optimizer" GLOB "src/optimizer/*.cu")
mxnet_source_group("Cuda\\resource.cc" GLOB "src/resource.cc/*.cu")
mxnet_source_group("Cuda\\storage" GLOB "src/storage/*.cu")
mxnet_source_group("Cuda\\symbol" GLOB "src/symbol/*.cu")
mxnet_source_group("Source" GLOB "src/*.cc")
mxnet_source_group("Source\\common" GLOB "src/common/*.cc")
mxnet_source_group("Source\\c_api" GLOB "src/c_api/*.cc")
mxnet_source_group("Source\\engine" GLOB "src/engine/*.cc")
mxnet_source_group("Source\\io" GLOB "src/io/*.cc")
mxnet_source_group("Source\\kvstore" GLOB "src/kvstore/*.cc")
mxnet_source_group("Source\\ndarray" GLOB "src/ndarray/*.cc")
mxnet_source_group("Source\\operator" GLOB "src/operator/*.cc")
mxnet_source_group("Source\\operator\\tensor" GLOB "src/operator/tensor/*.cc")
mxnet_source_group("Source\\optimizer" GLOB "src/optimizer/*.cc")
mxnet_source_group("Source\\resource.cc" GLOB "src/resource.cc/*.cc")
mxnet_source_group("Source\\storage" GLOB "src/storage/*.cc")
mxnet_source_group("Source\\symbol" GLOB "src/symbol/*.cc")
mxnet_source_group("Source\\executor" GLOB "src/executor/*.cc")
mxnet_source_group("Source\\nnvm" GLOB "src/nnvm/*.cc")
FILE(GLOB_RECURSE SOURCE "src/*.cc" "src/*.h")
FILE(GLOB_RECURSE CUDA "src/*.cu")
# add nnvm to source
mxnet_source_group("NNVM\\Include\\c_api" GLOB "nnvm/src/c_api/*.h")
mxnet_source_group("NNVM\\Include\\core" GLOB "nnvm/src/core/*.h")
mxnet_source_group("NNVM\\Include\\pass" GLOB "nnvm/src/pass/*.h")
mxnet_source_group("NNVM\\Include\\nnvm" GLOB "nnvm/include/nnvm/*.h")
mxnet_source_group("NNVM\\Include\\dmlc" GLOB "nnvm/include/dmlc/*.h")
mxnet_source_group("NNVM\\Source" GLOB "nnvm/src/*.cc")
mxnet_source_group("NNVM\\Source\\c_api" GLOB "nnvm/src/c_api/*.cc")
mxnet_source_group("NNVM\\Source\\core" GLOB "nnvm/src/core/*.cc")
mxnet_source_group("NNVM\\Source\\pass" GLOB "nnvm/src/pass/*.cc")
FILE(GLOB_RECURSE NNVMSOURCE "nnvm/src/*.cc" "nnvm/src/*.h" "nnvm/include/*.h")
list(APPEND SOURCE ${NNVMSOURCE})
# add mshadow file
mxnet_source_group("mshadow\\Include" GLOB "mshadow/mshadow/*.h")
mxnet_source_group("mshadow\\Include\\cuda" GLOB "mshadow/mshadow/cuda/*.h")
mxnet_source_group("mshadow\\Include\\extension" GLOB "mshadow/mshadow/extension/*.h")
mxnet_source_group("mshadow\\Include\\packet" GLOB "mshadow/mshadow/packet/*.h")
FILE(GLOB_RECURSE MSHADOWSOURCE "mshadow/mshadow/*.h")
list(APPEND SOURCE ${MSHADOWSOURCE})
# add smd_hpi
##========== add smd_hpi to source ============##
mxnet_source_group("SMD_HPI\\Include" GLOB "smd_hpi/src/*.h")
mxnet_source_group("SMD_HPI\\Source" GLOB "smd_hpi/src/*.cc")
mxnet_source_group("SMD_HPI\\Cuda" GLOB "smd_hpi/src/*.cu")
FILE(GLOB_RECURSE SMD_HPI_SOURCE "smd_hpi/src/*.cc" "smd_hpi/src/*.h")
FILE(GLOB_RECURSE SMD_HPI_CUDA "smd_hpi/src/*.cu")
list(APPEND SOURCE ${SMD_HPI_SOURCE})
list(APPEND CUDA ${SMD_HPI_CUDA})
# add build_in popcnt
INCLUDE(FindSSE)
FindSSE()
IF(SSE4_2_FOUND)
message(STATUS "enabling popcnt...")
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mpopcnt -funroll-loops")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mpopcnt -funroll-loops")
else()
message(STATUS "will NOT enable popcnt...")
ENDIF(SSE4_2_FOUND)
# set type of Binary_Word
set(BINARY_WORD_TYPE "uint64" CACHE STRING "Selected BINARY_WORD_TYPE")
set_property(CACHE BINARY_WORD_TYPE PROPERTY STRINGS "uint32;uint64")
if(BINARY_WORD_TYPE STREQUAL "uint32")
message(STATUS "using uint32_t as container for binarized values")
add_definitions(-DBINARY_WORD_32=1)
add_definitions(-DBINARY_WORD_64=0)
elseif(BINARY_WORD_TYPE STREQUAL "uint64")
message(STATUS "using uint64_t as container for binarized values")
add_definitions(-DBINARY_WORD_32=0)
add_definitions(-DBINARY_WORD_64=1)
endif()
##=============================================##
add_subdirectory(smd_hpi)
if(USE_PLUGINS_WARPCTC)
set(WARPCTC_INCLUDE "" CACHE PATH "WARPCTC include")
set(WARPCTC_LIB_DEBUG "" CACHE FILEPATH "WARPCTC lib")
set(WARPCTC_LIB_RELEASE "" CACHE FILEPATH "WARPCTC lib")
set(mxnet_LINKER_LIBS_RELEASE ${WARPCTC_LIB_RELEASE})
set(mxnet_LINKER_LIBS_DEBUG ${WARPCTC_LIB_DEBUG})
include_directories(SYSTEM ${WARPCTC_INCLUDE})
list(APPEND mxnet_LINKER_LIBS ${WARPCTC_LIB})
mxnet_source_group("Include\\plugin\\warpctc" GLOB "plugin/warpctc/*.h")
mxnet_source_group("Source\\plugin\\warpctc" GLOB "plugin/warpctc/*.cc")
mxnet_source_group("Cuda\\plugin\\warpctc" GLOB "plugin/warpctc/*.cu")
FILE(GLOB_RECURSE PLUGINS_SOURCE "plugin/warpctc/*.cc" "plugin/warpctc/*.h")
FILE(GLOB_RECURSE PLUGINS_CUSRC "plugin/warpctc/*.cu")
list(APPEND SOURCE ${PLUGINS_SOURCE})
list(APPEND CUDA ${PLUGINS_CUSRC})
endif()
if(USE_PLUGIN_CAFFE)
if(NOT DEFINED CAFFE_PATH)
if(EXISTS ${PROJECT_SOURCE_DIR}/caffe)
# Need newer FindCUDA.cmake that correctly handles -std=c++11
cmake_minimum_required(VERSION 3.3)
set(CAFFE_PATH ${PROJECT_SOURCE_DIR}/caffe)
endif()
endif()
list(APPEND CMAKE_MODULE_PATH ${CAFFE_PATH}/cmake)
include_directories(${CAFFE_PATH}/include)
include_directories(${CAFFE_PATH}/build/src)
include_directories(${CMAKE_BINARY_DIR}/caffe/include)
link_directories(${CAFFE_PATH}/build/lib)
if(NOT DEFINED CAFFE_PATH)
message(FATAL_ERROR "Please set CAFFE_PATH to point to the caffe source installation")
endif()
mxnet_source_group("Include\\plugin\\caffe" GLOB "plugin/caffe/*.h")
mxnet_source_group("Source\\plugin\\caffe" GLOB "plugin/caffe/*.cc")
mxnet_source_group("Cuda\\plugin\\caffe" GLOB "plugin/caffe/*.cu")
FILE(GLOB_RECURSE PLUGINS_SOURCE "plugin/caffe/*.cc" "plugin/caffe/*.h")
FILE(GLOB_RECURSE PLUGINS_CUSRC "plugin/caffe/*.cu")
list(APPEND SOURCE ${PLUGINS_SOURCE})
list(APPEND CUDA ${PLUGINS_CUSRC})
include_directories(${CMAKE_BINARY_DIR}/include)
list(APPEND mxnet_LINKER_LIBS
protobuf boost_system boost_thread boost_filesystem
gflags glog caffe
${Caffe_LINKER_LIBS}
)
endif()
if (NOT (EXTRA_OPERATORS STREQUAL ""))
mxnet_source_group("Extra" GLOB_RECURSE "${EXTRA_OPERATORS}/*.cc")
mxnet_source_group("Extra\\Cuda" GLOB_RECURSE "${EXTRA_OPERATORS}/*.cu")
FILE(GLOB_RECURSE EXTRA_SRC "${EXTRA_OPERATORS}/*.cc")
FILE(GLOB_RECURSE EXTRA_CUSRC "${EXTRA_OPERATORS}/*.cu")
list(APPEND SOURCE ${EXTRA_SRC})
list(APPEND CUDA ${EXTRA_CUSRC})
endif()
if(MSVC)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif()
if(USE_CUDA)
list(APPEND CUDA_INCLUDE_DIRS ${INCLUDE_DIRECTORIES})
# define preprocessor macro so that we will not include the generated forcelink header
mshadow_cuda_compile(cuda_objs ${CUDA})
if(MSVC)
FIND_LIBRARY(CUDA_nvrtc_LIBRARY nvrtc "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64" "${CUDA_TOOLKIT_ROOT_DIR}/lib/win32")
list(APPEND mxnet_LINKER_LIBS ${CUDA_nvrtc_LIBRARY})
set(CUDA_cuda_LIBRARY "${CUDA_nvrtc_LIBRARY}/../cuda.lib")
list(APPEND mxnet_LINKER_LIBS ${CUDA_cuda_LIBRARY})
else(MSVC)
list(APPEND mxnet_LINKER_LIBS nvrtc cuda)
link_directories("${CUDA_TOOLKIT_ROOT_DIR}/lib64")
endif()
list(APPEND SOURCE ${cuda_objs} ${CUDA})
add_definitions(-DMXNET_USE_CUDA=1)
add_definitions(-DMXNET_USE_NVRTC=1)
if(CUDA_LIBRARY_PATH)
link_directories(${CUDA_LIBRARY_PATH}/stubs)
endif()
endif()
# unsupported: if caffe is a subdirectory of mxnet, load its CMakeLists.txt as well
if(USE_PLUGIN_CAFFE)
if(EXISTS ${PROJECT_SOURCE_DIR}/caffe)
add_subdirectory(caffe)
endif()
endif()
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/nnvm/CMakeLists.txt")
list(APPEND mxnet_LINKER_LIBS nnvm)
endif()
if(NOT MSVC)
# Only add c++11 flags and definitions after cuda compiling
add_definitions(-DDMLC_USE_CXX11)
add_definitions(-DMSHADOW_IN_CXX11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()
add_library(mxnet SHARED ${SOURCE})
target_link_libraries(mxnet ${mxnet_LINKER_LIBS})
if(USE_PLUGINS_WARPCTC)
target_link_libraries(mxnet debug ${mxnet_LINKER_LIBS_DEBUG})
target_link_libraries(mxnet optimized ${mxnet_LINKER_LIBS_RELEASE})
endif()
target_link_libraries(mxnet dmlccore)
if(MSVC AND USE_MXNET_LIB_NAMING)
set_target_properties(mxnet PROPERTIES OUTPUT_NAME "libmxnet")
endif()
if(USE_DIST_KVSTORE)
add_definitions(-DMXNET_USE_DIST_KVSTORE)
target_link_libraries(mxnet pslite)
target_link_libraries(mxnet ${pslite_LINKER_LIBS})
include_directories(SYSTEM ${pslite_INCLUDE_DIR})
endif()
if(USE_PROFILER)
add_definitions(-DMXNET_USE_PROFILER)
endif()
if(INSTALL_PYTHON_VERSIONS)
foreach(version ${INSTALL_PYTHON_VERSIONS})
set(outdir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/python${version}/site-packages/mxnet)
add_custom_command(TARGET mxnet POST_BUILD
COMMAND mkdir -p ${outdir}
COMMAND cp -rul ${CMAKE_CURRENT_SOURCE_DIR}/python/mxnet/* ${outdir}
)
endforeach()
endif()
# ---[ Linter target
if(MSVC)
find_package(PythonInterp)
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "Path to the python executable")
endif()
set(LINT_DIRS include src scripts python)
add_custom_target(mxnet_lint COMMAND ${CMAKE_COMMAND} -DMSVC=${MSVC} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DLINT_DIRS=${LINT_DIRS} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} -DPROJECT_NAME=mxnet -P ${PROJECT_SOURCE_DIR}/dmlc-core/cmake/lint.cmake)
add_subdirectory(tests/cpp)
add_subdirectory(example/image-classification/predict-cpp)
add_subdirectory(smd_hpi/tools/model-converter) # added by smd_hpi