forked from jolibrain/deepdetect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
288 lines (258 loc) · 12.9 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
cmake_minimum_required(VERSION 2.8.8)
project(deepdetect)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(ProcessorCount)
ProcessorCount(N)
include(ExternalProject)
set (deepdetect_VERSION_MAJOR 0)
set (deepdetect_VERSION_MINOR 1)
# options
OPTION(BUILD_TESTS "Should the tests be built")
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%H
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set (CMAKE_CXX_FLAGS "-g -Wall -Wextra -fopenmp -fPIC -std=c++11 -O2 -DUSE_OPENCV -DUSE_LMDB")
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/dd_config.h.in"
"${PROJECT_BINARY_DIR}/dd_config.h"
)
configure_file(
"${PROJECT_SOURCE_DIR}/src/githash.h.in"
"${PROJECT_BINARY_DIR}/githash.h"
)
# dependency on Eigen for confusion matrix fast computation
if (USE_TF)
else()
find_package(PkgConfig)
pkg_search_module(Eigen3 REQUIRED eigen3)
endif()
set(eigen_archive_hash "50812b426b7c")
#include_directories("$ENV{HOME}/include")
set(EIGEN3_INCLUDE_DIR ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/dbuild/external/eigen_archive/eigen-eigen-${eigen_archive_hash} ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/dbuild/external/eigen_archive /usr/include/eigen3)
include_directories("${EIGEN3_INCLUDE_DIR}")
# dependency on Boost
find_package(Boost 1.54 REQUIRED COMPONENTS filesystem thread system iostreams)
# optional packages
if (USE_CPU_ONLY)
else()
include(cmake/Cuda.cmake) # cuda + cudnn
endif()
if (USE_TF)
# protobuf with tf
set(PROTOBUF_INCLUDE_DIR ${CMAKE_BINARY_DIR}/protobuf/include/)
set(PROTOBUF_LIB_DIR ${CMAKE_BINARY_DIR}/protobuf/lib/)
include_directories("${PROTOBUF_INCLUDE_DIR}")
# Tensorflow
message(STATUS "Fetching Tensorflow")
add_definitions(-DUSE_TF)
if (CUDA_FOUND AND NOT USE_TF_CPU_ONLY)
ExternalProject_Add(
tensorflow
PREFIX tensorflow
INSTALL_DIR ${CMAKE_BINARY_DIR}
DOWNLOAD_COMMAND git clone --recurse-submodules https://github.com/tensorflow/tensorflow
CONFIGURE_COMMAND mkdir -p ${CMAKE_BINARY_DIR}/protobuf && git checkout v1.0.1 && mkdir -p dbuild && ${CMAKE_BINARY_DIR}/patches/test_patch.sh ${CMAKE_BINARY_DIR}/patches/tf/libtf_link.patch && ${CMAKE_BINARY_DIR}/patches/test_patch.sh ${CMAKE_BINARY_DIR}/patches/tf/test_only_BUILD.patch && sed "s/bazel /bazel --output_base=dbuild /" < configure > configure.new && mv configure configure.bak && mv configure.new configure && chmod +x configure && ./configure && bazel --output_base dbuild/ build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package //tensorflow:libtensorflow.so //tensorflow/examples/label_image //tensorflow/python/tools:freeze_graph && ln -s ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/bazel-out/local-opt ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/bazel-out/local_linux-opt && bazel shutdown && cd dbuild/external/protobuf && ./autogen.sh && ./configure --prefix=${CMAKE_BINARY_DIR}/protobuf && make -j${N} && make install
INSTALL_COMMAND ""
BUILD_COMMAND ""
BUILD_IN_SOURCE 1
)
else()
add_definitions(-DUSE_TF_CPU_ONLY)
ExternalProject_Add(
tensorflow
PREFIX tensorflow
INSTALL_DIR ${CMAKE_BINARY_DIR}
DOWNLOAD_COMMAND git clone --recurse-submodules https://github.com/tensorflow/tensorflow
CONFIGURE_COMMAND mkdir -p ${CMAKE_BINARY_DIR}/protobuf && git checkout v1.0.1 && mkdir -p dbuild && ${CMAKE_BINARY_DIR}/patches/test_patch.sh ${CMAKE_BINARY_DIR}/patches/tf/libtf_link.patch && ${CMAKE_BINARY_DIR}/patches/test_patch.sh ${CMAKE_BINARY_DIR}/patches/tf/test_only_BUILD.patch && sed "s/bazel /bazel --output_base=dbuild /" < configure > configure.new && mv configure configure.bak && mv configure.new configure && chmod +x configure && ./configure && bazel --output_base dbuild/ build -c opt //tensorflow:libtensorflow.so //tensorflow/examples/label_image //tensorflow/python/tools:freeze_graph && ln -s ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/bazel-out/local-opt ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/bazel-out/local_linux-opt && bazel shutdown && cd dbuild/external/protobuf && ./autogen.sh && ./configure --prefix=${CMAKE_BINARY_DIR}/protobuf && make -j${N} && make install
INSTALL_COMMAND ""
BUILD_COMMAND ""
BUILD_IN_SOURCE 1
)
endif()
set(TF_INC_DIR ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/ ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/dbuild/tensorflow/ ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/dbuild/execroot/tensorflow/bazel-out/host/genfiles/ ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/dbuild/execroot/tensorflow/bazel-out/local_linux-opt/genfiles)
set(TF_LIB_DIR ${CMAKE_BINARY_DIR}/tensorflow/src/tensorflow/dbuild/execroot/tensorflow/bazel-out/local_linux-opt/bin/tensorflow/)
include_directories("${TF_INC_DIR}")
endif() # USE_TF
# OpenCV
find_package(OpenCV REQUIRED)
set(OPENCV_VERSION ${OpenCV_VERSION_MAJOR})
include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "OpenCV ${OPENCV_VERSION} (${OpenCV_VERSION}) found (${OpenCV_CONFIG_PATH})")
# customized Caffe as external project
if (CAFFE_INC_DIR AND CAFFE_LIB_DIR)
# do nothing
else()
message(STATUS "Configuring customized caffe")
if (CUDA_FOUND AND NOT USE_CAFFE_CPU_ONLY)
if (CUDA_ARCH)
else()
if (NOT ${CUDA_VERSION} MATCHES "8.0")
set(CUDA_ARCH "-gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52")
else()
set(CUDA_ARCH "-gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_61,code=compute_61")
endif()
endif()
if (HAVE_CUDNN AND USE_CUDNN)
if (USE_TF)
ExternalProject_Add(
caffe_dd
PREFIX caffe_dd
INSTALL_DIR ${CMAKE_BINARY_DIR}
URL https://github.com/beniz/caffe/archive/master.tar.gz
CONFIGURE_COMMAND ln -sf Makefile.config.gpu.cudnn Makefile.config && echo "OPENCV_VERSION:=${OPENCV_VERSION}" >> Makefile.config && ${CMAKE_COMMAND} -E env PATH=${CMAKE_BINARY_DIR}/protobuf/bin:$ENV{PATH} make CUDA_ARCH=${CUDA_ARCH} -j${N}
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
else() # USE_TF
ExternalProject_Add(
caffe_dd
PREFIX caffe_dd
INSTALL_DIR ${CMAKE_BINARY_DIR}
URL https://github.com/beniz/caffe/archive/master.tar.gz
CONFIGURE_COMMAND ln -sf Makefile.config.gpu.cudnn Makefile.config && echo "OPENCV_VERSION:=${OPENCV_VERSION}" >> Makefile.config && make CUDA_ARCH=${CUDA_ARCH} -j${N}
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
endif()
else() # HAVE_CUDNN
if (USE_TF)
ExternalProject_Add(
caffe_dd
PREFIX caffe_dd
INSTALL_DIR ${CMAKE_BINARY_DIR}
URL https://github.com/beniz/caffe/archive/master.tar.gz
CONFIGURE_COMMAND ln -sf Makefile.config.gpu Makefile.config && echo "OPENCV_VERSION:=${OPENCV_VERSION}" >> Makefile.config && ${CMAKE_COMMAND} -E env PATH=${CMAKE_BINARY_DIR}/protobuf/bin:$ENV{PATH} make CUDA_ARCH=${CUDA_ARCH} -j${N}
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
else() # USE_TF
ExternalProject_Add(
caffe_dd
PREFIX caffe_dd
INSTALL_DIR ${CMAKE_BINARY_DIR}
URL https://github.com/beniz/caffe/archive/master.tar.gz
CONFIGURE_COMMAND ln -sf Makefile.config.gpu Makefile.config && echo "OPENCV_VERSION:=${OPENCV_VERSION}" >> Makefile.config && make CUDA_ARCH=${CUDA_ARCH} -j${N}
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
endif()
endif() # HAVE_CUDNN
else() # CUDA_FOUND
add_definitions(-DUSE_CAFFE_CPU_ONLY)
if (USE_TF)
ExternalProject_Add(
caffe_dd
PREFIX caffe_dd
INSTALL_DIR ${CMAKE_BINARY_DIR}
URL https://github.com/beniz/caffe/archive/master.tar.gz
CONFIGURE_COMMAND ln -sf Makefile.config.cpu Makefile.config && echo "OPENCV_VERSION:=${OPENCV_VERSION}" >> Makefile.config && ${CMAKE_COMMAND} -E env PATH=${CMAKE_BINARY_DIR}/protobuf/bin:$ENV{PATH} make -j${N}
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
else() # USE_TF
ExternalProject_Add(
caffe_dd
PREFIX caffe_dd
INSTALL_DIR ${CMAKE_BINARY_DIR}
URL https://github.com/beniz/caffe/archive/master.tar.gz
CONFIGURE_COMMAND ln -sf Makefile.config.cpu Makefile.config && echo "OPENCV_VERSION:=${OPENCV_VERSION}" >> Makefile.config && make -j${N}
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
endif()
endif()
if (CUDA_FOUND)
set(CAFFE_INC_DIR ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/include ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src ${CUDA_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIR})
set(CAFFE_LIB_DIR ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/lib ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src /usr/lib/x86_64-linux-gnu/hdf5/serial ${PROTOBUF_LIB_DIR} ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDA_curand_LIBRARY})
else()
set(CAFFE_INC_DIR ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/include ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src /usr/include/hdf5/serial ${PROTOBUF_INCLUDE_DIR})
set(CAFFE_LIB_DIR $ENV{HOME}/lib ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/lib ${CMAKE_BINARY_DIR}/caffe_dd/src/caffe_dd/build/src /usr/lib/x86_64-linux-gnu/hdf5/serial ${PROTOBUF_LIB_DIR})
endif()
endif()
if (USE_TF)
add_dependencies(caffe_dd tensorflow)
endif()
# XGBoost
if (USE_XGBOOST)
message(STATUS "Configuring XGBoost")
add_definitions(-DUSE_XGBOOST)
if (CUDA_FOUND AND USE_XGBOOST_GPU)
add_definitions(-DUSE_XGBOOST_GPU)
set(XGB_NVCC_FLAGS,"--expt-extended-lambda;-gencode arch=compute_35,code=compute_35")
ExternalProject_Add(
xgboost
PREFIX xgboost
INSTALL_DIR ${CMAKE_BINARY_DIR}
DOWNLOAD_COMMAND git clone --recursive https://github.com/dmlc/xgboost.git
UPDATE_COMMAND git submodule foreach git pull origin master
CONFIGURE_COMMAND wget https://github.com/NVlabs/cub/archive/1.6.4.zip && unzip 1.6.4.zip && rm 1.6.4.zip && ${CMAKE_BINARY_DIR}/patches/test_patch.sh ${CMAKE_BINARY_DIR}/patches/xgb/xgb_cmakelist_fix.patch && mkdir build && cd build &&
cmake .. -DPLUGIN_UPDATER_GPU=ON -DCUB_DIRECTORY=${CMAKE_BINARY_DIR}/xgboost/src/xgboost/cub-1.6.4/ -DCUDA_NVCC_FLAGS=-Xcompiler\ -fPIC\ --expt-extended-lambda\ -gencode\ arch=compute_30,code=compute_30\ -gencode\ arch=compute_35,code=compute_35\ -gencode\ arch=compute_50,code=compute_50\ -gencode\ arch=compute_52,code=compute_52\ -gencode\ arch=compute_61,code=compute_61 && make && make
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
else()
ExternalProject_Add(
xgboost
PREFIX xgboost
INSTALL_DIR ${CMAKE_BINARY_DIR}
DOWNLOAD_COMMAND git clone --recursive https://github.com/dmlc/xgboost.git
UPDATE_COMMAND git submodule foreach git pull origin master
CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/patches/test_patch.sh ${CMAKE_BINARY_DIR}/patches/xgb/xgb_cmakelist_fix.patch && mkdir build && cd build && cmake .. && make
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
endif()
set(XGBOOST_INC_DIR ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/include ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/src ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/rabit/include ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/dmlc-core/include ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/dmlc-core/src/)
set(XGBOOST_LIB_DIR ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/lib ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/build/ ${CMAKE_BINARY_DIR}/xgboost/src/xgboost/build/dmlc-core)
endif()
if (USE_TSNE)
message(STATUS "Configuring T-SNE")
add_definitions(-DUSE_TSNE)
ExternalProject_Add(
Multicore-TSNE
PREFIX Multicore-TSNE
INSTALL_DIR ${CMAKE_BINARY_DIR}
DOWNLOAD_COMMAND git clone https://github.com/beniz/Multicore-TSNE.git
CONFIGURE_COMMAND cd multicore_tsne && mkdir build && cd build && cmake ..
BUILD_COMMAND cd multicore_tsne/build/ && make
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)
set(TSNE_INC_DIR ${CMAKE_BINARY_DIR}/Multicore-TSNE/src/Multicore-TSNE/multicore_tsne)
set(TSNE_LIB_DIR ${CMAKE_BINARY_DIR}/Multicore-TSNE/src/Multicore-TSNE/multicore_tsne/build)
endif()
# add the binary tree to the search path for include files
# so that we will find dd_config.h
include_directories("${PROJECT_BINARY_DIR}")
include_directories(${CAFFE_INC_DIR} ${XGBOOST_INC_DIR} ${TSNE_INC_DIR})
# main library, main & tests
include_directories ("${PROJECT_SOURCE_DIR}/src")
add_subdirectory (src)
add_subdirectory(main)
# templates
file(COPY "templates" DESTINATION ".")
# examples
file(COPY "examples" DESTINATION ".")
# patches
file(COPY "patches" DESTINATION ".")
# unit testing
if (BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# status
MESSAGE(STATUS "Build Tests : ${BUILD_TESTS}")