forked from jolibrain/deepdetect
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·180 lines (158 loc) · 5.15 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
#!/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 torch tf caffe2 tensorrt)
# NOTE(sileht): list of all supported card by CUDA 10.2
# https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
if [ ! "$DEEPDETECT_CUDA_ARCH" ]; then
for card in 50 52 60 61 62 70 72 75; do
DEEPDETECT_CUDA_ARCH="$DEEPDETECT_CUDA_ARCH -gencode arch=compute_${card},code=sm_${card}"
done
# trim spaces
DEEPDETECT_CUDA_ARCH="$(echo ${DEEPDETECT_CUDA_ARCH} | xargs)"
fi
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
# 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
}
# 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}
make
;;
"armv7")
cmake .. -DUSE_NCNN=ON -DRPI3=ON -DUSE_HDF5=OFF -DUSE_CAFFE=OFF -DRELEASE=${DEEPDETECT_RELEASE}
make
;;
*)
cmake .. -DUSE_XGBOOST=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DUSE_NCNN=ON -DUSE_CPU_ONLY=ON -DRELEASE=${DEEPDETECT_RELEASE}
make
;;
esac
}
gpu_build() {
local extra_flags=
case ${DEEPDETECT_BUILD} in
"tf") extra_flags="-DUSE_TF=ON" ;;
"caffe2") extra_flags="-DUSE_CAFFE2=ON" ;;
"torch") extra_flags="-DUSE_TORCH=ON" ;;
"tensorrt") extra_flags="-DUSE_TENSORRT_OSS=ON" ;;
esac
cmake .. $extra_flags -DUSE_FAISS=ON -DUSE_CUDNN=ON -DUSE_XGBOOST=ON -DUSE_SIMSEARCH=ON -DUSE_TSNE=ON -DCUDA_ARCH="${DEEPDETECT_CUDA_ARCH} -DRELEASE=${DEEPDETECT_RELEASE}"
make
}
# 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 ""
gpu_build
else
echo "Missing DEEPDETECT_ARCH variable to select build profile: cpu or gpu"
fi