-
Notifications
You must be signed in to change notification settings - Fork 561
/
build.sh
executable file
·247 lines (220 loc) · 7.83 KB
/
build.sh
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
#!/bin/bash
set -e
# Deepdetect architecture and build profiles
deepdetect_arch=(cpu gpu)
deepdetect_cpu_build_profiles=(default tf armv7)
deepdetect_gpu_build_profiles=(default tf caffe2 tensorrt)
# NOTE(beniz): list of all supported card by CUDA 11.1
# https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
if [ ! "$DEEPDETECT_CUDA_ARCH_FLAGS" ]; then
for card in 50 52 60 61 62 70 72 75 80 86; do
DEEPDETECT_CUDA_ARCH_FLAGS="$DEEPDETECT_CUDA_ARCH_FLAGS -gencode arch=compute_${card},code=sm_${card}"
done
# trim spaces
DEEPDETECT_CUDA_ARCH_FLAGS="$(echo ${DEEPDETECT_CUDA_ARCH_FLAGS} | xargs)"
fi
DEEPDETECT_CUDA_ARCH="5.0;5.2;6.0;6.1;6.2;7.0;7.2;7.5;8.0;8.6"
DEEPDETECT_RELEASE=${DEEPDETECT_RELEASE:-OFF}
# Help menu with arguments descriptions
help_menu() {
IFS=,
echo "Deepdetect build script"
echo ""
echo "Env variables usage: DEEPDETECT_ARCH=${deepdetect_arch[*]} DEEPDETECT_BUILD=${deepdetect_cpu_build_profiles[*]},[...] $0 "
echo ""
echo "or"
echo ""
echo "Params usage: $0 [options...]" >&2
echo
echo " -a, --deepdetect-arch Choose Deepdetect architecture : ${deepdetect_arch[*]}"
echo " -b, --deepdetect-build Choose Deepdetect build profile : CPU (${deepdetect_cpu_build_profiles[*]}) / GPU (${deepdetect_gpu_build_profiles[*]})"
echo " -c, --deepdetect-cuda-arch Choose Deepdetect cuda arch (default: ${deepdetect_cuda_arch})"
echo
exit 1
}
# Parse arguments
while (("$#")); do
case "$1" in
-a | --deepdetect-arch)
DEEPDETECT_ARCH=$2
shift 2
;;
-b | --deepdetect-build)
DEEPDETECT_BUILD=$2
shift 2
;;
-c | --deepdetect-cuda-arch)
DEEPDETECT_CUDA_ARCH=$2
shift 2
;;
-h | --help)
help_menu
break
;;
esac
done
# Check arguments for incompatibility
if [[ -v DEEPDETECT_OPENCV4_BUILD_PATH ]] && [[ -v BUILD_OPENCV ]]; then
echo "Please choose between setting DEEPDETECT_OPENCV4_BUILD_PATH or BUILD_OPENCV"
echo "Use DEEPDETECT_OPENCV4_BUILD_PATH if you wish to use a custom opencv build"
echo "Use BUILD_OPENCV if you wish for opencv to be built for you"
exit
fi
# Deepdetect platform selector
select_platform() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Select Deepdetect build platform"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
for index in ${!deepdetect_arch[*]}; do
echo " $index. ${deepdetect_arch[$index]^^}"
done
echo ""
local choice
read -p "Enter choice : " choice
DEEPDETECT_ARCH=${deepdetect_arch[$choice]}
}
# Deepdetect select CPU build profile
select_cpu_build_profile() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Select Deepdetect build profile"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
for index in ${!deepdetect_cpu_build_profiles[*]}; do
echo " $index. ${deepdetect_cpu_build_profiles[$index]}"
done
echo ""
local choice
read -p "Enter choice : " choice
DEEPDETECT_BUILD=${deepdetect_cpu_build_profiles[$choice]}
}
# Deepdetect select GPU build profile
select_gpu_build_profile() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo " Select Deepdetect build profile"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
for index in ${!deepdetect_gpu_build_profiles[*]}; do
echo " $index. ${deepdetect_gpu_build_profiles[$index]}"
done
echo ""
local choice
read -p "Enter choice : " choice
DEEPDETECT_BUILD=${deepdetect_gpu_build_profiles[$choice]}
}
# Use menu...
show_interactive_platform_selector() {
# Main menu handler loop
select_platform
if [ ${DEEPDETECT_ARCH} == "cpu" ]; then
select_cpu_build_profile
fi
if [ ${DEEPDETECT_ARCH} == "gpu" ]; then
select_gpu_build_profile
fi
}
if [[ ${BUILD_OPENCV} == "ON" ]]; then
echo "Opencv will be built from source"
# Build OpenCV 4 with CUDA
DEEPDETECT_OPENCV4_BUILD_PATH="$(git rev-parse --show-toplevel)/build/opencv/opencv-4.7.0/build"
if [ ! -d opencv ]; then
echo "Downloading opencv"
mkdir opencv && cd opencv && wget -O opencv.zip https://github.com/opencv/opencv/archive/refs/tags/4.7.0.zip && wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.7.0.zip && unzip opencv.zip && unzip opencv_contrib.zip
cd "opencv-4.7.0" && mkdir build && cd build
else
cd $DEEPDETECT_OPENCV4_BUILD_PATH
fi
cmake -D CMAKE_BUILD_TYPE=DEBUG \
-D CMAKE_INSTALL_PREFIX=/tmp/ \
-D CMAKE_LIBRARY_PATH=/usr/local/cuda/lib64/stubs \
-D CMAKE_CXX_FLAGS="-Wl,--allow-shlib-undefined" \
-D WITH_TBB=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_CUDA=ON \
-D BUILD_opencv_cudacodec=ON \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=OFF \
-D CUDA_ARCH_BIN="6.1 7.5 8.6" \
-D WITH_V4L=ON \
-D WITH_QT=OFF \
-D WITH_OPENGL=ON \
-D WITH_GSTREAMER=ON \
-D WITH_NVCUVID=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_PC_FILE_NAME=opencv.pc \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.7.0/modules \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_opencv_cudev=ON \
-D BUILD_opencv_core=ON \
-D BUILD_opencv_imgproc=ON \
-D BUILD_opencv_imgcodecs=ON \
-D BUILD_opencv_videoio=ON \
-D BUILD_opencv_highgui=ON ..
make -j20
make install
cd ../../..
else
echo "Using custom opencv"
fi
# Build functions
cpu_build() {
case ${DEEPDETECT_BUILD} in
"tf")
cmake .. -DUSE_TF=ON -DUSE_TF_CPU_ONLY=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=OFF -DUSE_CPU_ONLY=ON -DRELEASE=${DEEPDETECT_RELEASE} -DOpenCV_DIR=${DEEPDETECT_OPENCV4_BUILD_PATH}
make -j6
;;
"armv7")
cmake .. -DUSE_NCNN=ON -DRPI3=ON -DUSE_HDF5=OFF -DUSE_TORCH=OFF -DRELEASE=${DEEPDETECT_RELEASE} -DOpenCV_DIR=${DEEPDETECT_OPENCV4_BUILD_PATH}
make -j6
;;
*)
cmake .. -DUSE_XGBOOST=ON -DUSE_CAFFE=ON -DUSE_CPU_ONLY=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=ON -DRELEASE=${DEEPDETECT_RELEASE} -DOpenCV_DIR=${DEEPDETECT_OPENCV4_BUILD_PATH}
make -j6
;;
esac
}
gpu_build() {
local extra_flags=
local default_flags="-DUSE_FAISS=OFF -DUSE_CUDNN=ON -DUSE_XGBOOST=OFF -DUSE_SIMSEARCH=OFF -DUSE_TSNE=OFF -DUSE_TORCH=ON -DUSE_OPENCV_VERSION=4 -DOpenCV_DIR=${DEEPDETECT_OPENCV4_BUILD_PATH}"
case ${DEEPDETECT_BUILD} in
"tf") extra_flags="$default_flags -DUSE_TF=ON" ;;
"caffe2") extra_flags="$default_flags -DUSE_CAFFE2=ON" ;;
"tensorrt") extra_flags="-DUSE_TENSORRT=ON -DUSE_TORCH=OFF -DUSE_CUDA_CV=ON -DUSE_OPENCV_VERSION=4 -DOpenCV_DIR=${DEEPDETECT_OPENCV4_BUILD_PATH}";;
*) extra_flags="$default_flags";;
esac
echo $extra_flags
cmake .. $extra_flags -DCUDA_ARCH_FLAGS="${DEEPDETECT_CUDA_ARCH_FLAGS}" -DCUDA_ARCH="${DEEPDETECT_CUDA_ARCH}" -DRELEASE="${DEEPDETECT_RELEASE}" -DOpenCV_DIR="${DEEPDETECT_OPENCV4_BUILD_PATH}"
make -j6
}
# If no arguments provided, display usage information
if [ -z "$DEEPDETECT_ARCH" ] && [ $# -eq 0 ]; then
show_interactive_platform_selector
fi
# Select build profile
if [[ ${DEEPDETECT_ARCH} == "cpu" ]]; then
echo ""
echo "Deepdetect build params :"
echo " DEEPDETECT_ARCH : ${DEEPDETECT_ARCH}"
echo " DEEPDETECT_BUILD : ${DEEPDETECT_BUILD}"
echo ""
cpu_build
elif [[ ${DEEPDETECT_ARCH} == "gpu" ]]; then
echo ""
echo "Deepdetect build params :"
echo " DEEPDETECT_ARCH : ${DEEPDETECT_ARCH}"
echo " DEEPDETECT_BUILD : ${DEEPDETECT_BUILD}"
echo " DEEPDETECT_CUDA_ARCH : ${DEEPDETECT_CUDA_ARCH}"
echo " DEEPDETECT_CUDA_ARCH_FLAGS : ${DEEPDETECT_CUDA_ARCH_FLAGS}"
echo " DEEPDETECT_OPENCV4_BUILD_PATH : ${DEEPDETECT_OPENCV4_BUILD_PATH}"
echo ""
gpu_build
else
echo "Missing DEEPDETECT_ARCH variable to select build profile: cpu or gpu"
fi