forked from airockchip/rknn_model_zoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-linux.sh
210 lines (190 loc) · 5.17 KB
/
build-linux.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
#!/bin/bash
set -e
echo "$0 $@"
while getopts ":t:a:d:b:m:r" opt; do
case $opt in
t)
TARGET_SOC=$OPTARG
;;
a)
TARGET_ARCH=$OPTARG
;;
b)
BUILD_TYPE=$OPTARG
;;
m)
ENABLE_ASAN=ON
export ENABLE_ASAN=TRUE
;;
d)
BUILD_DEMO_NAME=$OPTARG
;;
r)
DISABLE_RGA=ON
;;
:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
?)
echo "Invalid option: -$OPTARG index:$OPTIND"
;;
esac
done
if [ -z ${TARGET_SOC} ] || [ -z ${BUILD_DEMO_NAME} ]; then
echo "$0 -t <target> -a <arch> -d <build_demo_name> [-b <build_type>] [-m]"
echo ""
echo " -t : target (rk356x/rk3588/rk3576/rv1106/rk1808/rv1126)"
echo " -a : arch (aarch64/armhf)"
echo " -d : demo name"
echo " -b : build_type(Debug/Release)"
echo " -m : enable address sanitizer, build_type need set to Debug"
echo " -r : disable rga, use cpu resize image"
echo "such as: $0 -t rk3588 -a aarch64 -d mobilenet"
echo "Note: 'rk356x' represents rk3562/rk3566/rk3568, 'rv1106' represents rv1103/rv1106, 'rv1126' represents rv1109/rv1126"
echo "Note: 'disable rga option is invalid for rv1103/rv1103b/rv1106"
echo ""
exit -1
fi
if [[ -z ${GCC_COMPILER} ]];then
if [[ ${TARGET_SOC} = "rv1106" || ${TARGET_SOC} = "rv1103" ]];then
echo "Please set GCC_COMPILER for $TARGET_SOC"
echo "such as export GCC_COMPILER=~/opt/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf"
exit
elif [[ ${TARGET_SOC} = "rv1109" || ${TARGET_SOC} = "rv1126" ]];then
GCC_COMPILER=arm-linux-gnueabihf
else
GCC_COMPILER=aarch64-linux-gnu
fi
fi
echo "$GCC_COMPILER"
export CC=${GCC_COMPILER}-gcc
export CXX=${GCC_COMPILER}-g++
if command -v ${CC} >/dev/null 2>&1; then
:
else
echo "${CC} is not available"
echo "Please set GCC_COMPILER for $TARGET_SOC"
echo "such as export GCC_COMPILER=~/opt/arm-rockchip830-linux-uclibcgnueabihf/bin/arm-rockchip830-linux-uclibcgnueabihf"
exit
fi
# Debug / Release
if [[ -z ${BUILD_TYPE} ]];then
BUILD_TYPE=Release
fi
# Build with Address Sanitizer for memory check, BUILD_TYPE need set to Debug
if [[ -z ${ENABLE_ASAN} ]];then
ENABLE_ASAN=OFF
fi
if [[ -z ${DISABLE_RGA} ]];then
DISABLE_RGA=OFF
fi
for demo_path in `find examples -name ${BUILD_DEMO_NAME}`
do
if [ -d "$demo_path/cpp" ]
then
BUILD_DEMO_PATH="$demo_path/cpp"
break;
fi
done
if [[ -z "${BUILD_DEMO_PATH}" ]]
then
echo "Cannot find demo: ${BUILD_DEMO_NAME}, only support:"
for demo_path in `find examples -name cpp`
do
if [ -d "$demo_path" ]
then
dname=`dirname "$demo_path"`
name=`basename $dname`
echo "$name"
fi
done
echo "rv1106_rv1103 only support: mobilenet and yolov5/6/7/8/x"
exit
fi
case ${TARGET_SOC} in
rk356x)
;;
rk3588)
;;
rv1106)
;;
rv1103)
TARGET_SOC="rv1106"
;;
rk3566)
TARGET_SOC="rk356x"
;;
rk3568)
TARGET_SOC="rk356x"
;;
rk3562)
TARGET_SOC="rk356x"
;;
rk3576)
TARGET_SOC="rk3576"
;;
rk1808):
TARGET_SOC="rk1808"
;;
rv1109)
;;
rv1126)
TARGET_SOC="rv1126"
;;
*)
echo "Invalid target: ${TARGET_SOC}"
echo "Valid target: rk3562,rk3566,rk3568,rk3588,rk3576,rv1106,rv1103,rk1808,rv1109,rv1126"
exit -1
;;
esac
TARGET_SDK="rknn_${BUILD_DEMO_NAME}_demo"
TARGET_PLATFORM=${TARGET_SOC}_linux
if [[ -n ${TARGET_ARCH} ]];then
TARGET_PLATFORM=${TARGET_PLATFORM}_${TARGET_ARCH}
fi
ROOT_PWD=$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )
INSTALL_DIR=${ROOT_PWD}/install/${TARGET_PLATFORM}/${TARGET_SDK}
BUILD_DIR=${ROOT_PWD}/build/build_${TARGET_SDK}_${TARGET_PLATFORM}_${BUILD_TYPE}
echo "==================================="
echo "BUILD_DEMO_NAME=${BUILD_DEMO_NAME}"
echo "BUILD_DEMO_PATH=${BUILD_DEMO_PATH}"
echo "TARGET_SOC=${TARGET_SOC}"
echo "TARGET_ARCH=${TARGET_ARCH}"
echo "BUILD_TYPE=${BUILD_TYPE}"
echo "ENABLE_ASAN=${ENABLE_ASAN}"
echo "DISABLE_RGA=${DISABLE_RGA}"
echo "INSTALL_DIR=${INSTALL_DIR}"
echo "BUILD_DIR=${BUILD_DIR}"
echo "CC=${CC}"
echo "CXX=${CXX}"
echo "==================================="
if [[ ! -d "${BUILD_DIR}" ]]; then
mkdir -p ${BUILD_DIR}
fi
if [[ -d "${INSTALL_DIR}" ]]; then
rm -rf ${INSTALL_DIR}
fi
cd ${BUILD_DIR}
cmake ../../${BUILD_DEMO_PATH} \
-DTARGET_SOC=${TARGET_SOC} \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=${TARGET_ARCH} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DENABLE_ASAN=${ENABLE_ASAN} \
-DDISABLE_RGA=${DISABLE_RGA} \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
make -j4
make install
# Check if there is a rknn model in the install directory
suffix=".rknn"
shopt -s nullglob
if [ -d "$INSTALL_DIR" ]; then
files=("$INSTALL_DIR/model/"/*"$suffix")
shopt -u nullglob
if [ ${#files[@]} -le 0 ]; then
echo -e "\e[91mThe RKNN model can not be found in \"$INSTALL_DIR/model\", please check!\e[0m"
fi
else
echo -e "\e[91mInstall directory \"$INSTALL_DIR\" does not exist, please check!\e[0m"
fi