Skip to content

Commit a193d96

Browse files
committed
Add third_party and update CMakeLists.txt
1 parent 890a32e commit a193d96

File tree

3 files changed

+271
-4
lines changed

3 files changed

+271
-4
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.2)
1+
cmake_minimum_required(VERSION 3.15)
22

33
file(GLOB BOLT_CONFIGURE_FILE $ENV{BOLT_ROOT}/bolt.cmake ${BOLT_ROOT}/bolt.cmake)
44
if (BOLT_CONFIGURE_FILE)
@@ -22,7 +22,7 @@ add_subdirectory(image)
2222
add_subdirectory(inference)
2323
add_subdirectory(tests)
2424
add_custom_target(bolt_library ALL
25-
COMMAND ./scripts/build_light_bolt.sh ${CMAKE_BINARY_DIR}
25+
COMMAND ./scripts/build_light_bolt.sh ${CMAKE_BINARY_DIR} ${USE_MALI}
2626
WORKING_DIRECTORY $ENV{BOLT_ROOT})
2727

2828
if (USE_MALI)

scripts/build_light_bolt.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ BOLT_ROOT=${script_dir}/..
77
current_dir=${PWD}
88

99
build_dir=$1
10+
use_mali=$2
1011

1112
srcs=""
1213
searchFiles() {
@@ -33,13 +34,15 @@ searchFiles ${build_dir}
3334
srcs="${srcs} ${build_dir}/model-tools/src/CMakeFiles/model-tools.dir/model_serialize_deserialize.cpp.o \
3435
${build_dir}/model-tools/src/CMakeFiles/model-tools.dir/model_tools.cpp.o"
3536

36-
if [ -f "${BOLT_ROOT}/third_party/llvm/opencl/lib64/libOpenCL.so" ];then
37+
if [ -f "${BOLT_ROOT}/third_party/llvm/opencl/lib64/libOpenCL.so" ] && [ $use_mali == "ON" ];
38+
then
3739
cp ${BOLT_ROOT}/third_party/llvm/opencl/lib64/libOpenCL.so ${build_dir}
3840
aarch64-linux-android-strip ${build_dir}/libOpenCL.so || exit 1
3941
#aarch64-linux-android-readelf -dW ${build_dir}/libOpenCL.so
4042
fi
4143

42-
if [ -f "${BOLT_ROOT}/gcl/tools/kernel_lib_compile/lib/libkernelbin.so" ];then
44+
if [ -f "${BOLT_ROOT}/gcl/tools/kernel_lib_compile/lib/libkernelbin.so" ] && [ $use_mali == "ON" ];
45+
then
4346
aarch64-linux-android-strip ${BOLT_ROOT}/gcl/tools/kernel_lib_compile/lib/libkernelbin.so || exit 1
4447
#cp ${BOLT_ROOT}/gcl/tools/kernel_lib_compile/lib/libkernelbin.so ${build_dir}
4548
aarch64-linux-android21-clang++ -shared -o ${build_dir}/libBoltModel.so ${srcs} \

third_party/install.sh

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
#!/bin/bash
2+
3+
script_name=$0
4+
compiler_arch="gnu"
5+
build_threads="8"
6+
7+
print_help() {
8+
cat <<EOF
9+
Usage: ${script_name} [OPTION]...
10+
Build third party library.
11+
12+
Mandatory arguments to long options are mandatory for short options too.
13+
-h, --help display this help and exit.
14+
-c, --compiler <llvm|gnu> use to set compiler(default: gnu).
15+
-t, --threads use parallel build(default: 8).
16+
EOF
17+
exit 1;
18+
}
19+
20+
TEMP=`getopt -o c:ht: --long compiler:help,threads: \
21+
-n ${script_name} -- "$@"`
22+
if [ $? != 0 ] ; then echo "[ERROR] terminating..." >&2 ; exit 1 ; fi
23+
eval set -- "$TEMP"
24+
while true ; do
25+
case "$1" in
26+
-c|--compiler)
27+
compiler_arch=$2
28+
echo "[INFO] build library for '${compiler_arch}'" ;
29+
shift 2 ;;
30+
-t|--threads)
31+
build_threads=$2
32+
echo "[INFO] '${build_threads}' threads parallel to build" ;
33+
shift 2 ;;
34+
-h|--help)
35+
print_help ;
36+
shift ;;
37+
--) shift ;
38+
break ;;
39+
*) echo "[ERROR]" ; exit 1 ;;
40+
esac
41+
done
42+
43+
exeIsValid(){
44+
if type $1 2>/dev/null;
45+
then
46+
return 1
47+
else
48+
return 0
49+
fi
50+
}
51+
52+
exeIsValid wget
53+
if [ $? == 0 ] ; then
54+
echo "[ERROR] please install wget tools and set shell environment PATH to find it"
55+
exit 1
56+
fi
57+
58+
exeIsValid git
59+
if [ $? == 0 ] ; then
60+
echo "[ERROR] please install git tools and set shell environment PATH to find it"
61+
exit 1
62+
fi
63+
64+
exeIsValid unzip
65+
if [ $? == 0 ] ; then
66+
echo "[ERROR] please install unzip tools and set shell environment PATH to find it"
67+
exit 1
68+
fi
69+
70+
exeIsValid tar
71+
if [ $? == 0 ] ; then
72+
echo "[ERROR] please install tar tools and set shell environment PATH to find it"
73+
exit 1
74+
fi
75+
76+
if [ "${compiler_arch}" == "llvm" ] ; then
77+
exeIsValid aarch64-linux-android21-clang
78+
if [ $? == 0 ] ; then
79+
echo "[ERROR] please install android ndk aarch64-linux-android21-clang compiler and set shell environment PATH to find it"
80+
exit 1
81+
fi
82+
exeIsValid aarch64-linux-android21-clang++
83+
if [ $? == 0 ] ; then
84+
echo "[ERROR] please install android ndk aarch64-linux-android21-clang++ compiler and set shell environment PATH to find it"
85+
exit 1
86+
fi
87+
export CC=aarch64-linux-android21-clang
88+
export CXX=aarch64-linux-android21-clang++
89+
else
90+
exeIsValid aarch64-linux-gnu-gcc
91+
if [ $? == 0 ] ; then
92+
echo "[ERROR] please install GNU gcc ARM compiler and set shell environment PATH to find it"
93+
exit 1
94+
fi
95+
exeIsValid aarch64-linux-gnu-g++
96+
if [ $? == 0 ] ; then
97+
echo "[ERROR] please install GNU gcc ARM compiler and set shell environment PATH to find it"
98+
exit 1
99+
fi
100+
export CC=aarch64-linux-gnu-gcc
101+
export CXX=aarch64-linux-gnu-g++
102+
fi
103+
104+
script_abs=$(readlink -f "$0")
105+
script_dir=$(dirname $script_abs)
106+
current_dir=${PWD}
107+
108+
if [ ! -d "${script_dir}/sources" ]; then
109+
mkdir ${script_dir}/sources
110+
fi
111+
112+
rm -rf ${script_dir}/${compiler_arch}
113+
mkdir ${script_dir}/${compiler_arch}
114+
env_file="${script_dir}/${compiler_arch}.sh"
115+
PROTOC_ROOT=${script_dir}/${compiler_arch}/protoc
116+
Protobuf_ROOT=${script_dir}/${compiler_arch}/protobuf
117+
FlatBuffers_ROOT=${script_dir}/${compiler_arch}/flatbuffers
118+
TFLite_ROOT=${script_dir}/${compiler_arch}/tflite
119+
OpenCL_ROOT=${script_dir}/${compiler_arch}/opencl
120+
JPEG_ROOT=${script_dir}/${compiler_arch}/jpeg
121+
122+
123+
# download prebuilt protoc
124+
echo "[INFO] install protoc in ${script_dir}..."
125+
rm -rf ${PROTOC_ROOT}
126+
mkdir ${PROTOC_ROOT}
127+
cd ${PROTOC_ROOT}
128+
if [ ! -f "${script_dir}/sources/protoc-3.1.0-linux-x86_64.zip" ]; then
129+
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.1.0/protoc-3.1.0-linux-x86_64.zip || exit 1
130+
cp protoc-3.1.0-linux-x86_64.zip ${script_dir}/sources/
131+
else
132+
cp ${script_dir}/sources/protoc-3.1.0-linux-x86_64.zip .
133+
fi
134+
unzip protoc-3.1.0-linux-x86_64.zip
135+
rm protoc-3.1.0-linux-x86_64.zip
136+
export PATH=${PROTOC_ROOT}/bin:$PATH
137+
138+
139+
# download and build protobuf
140+
echo "[INFO] install protobuf in ${script_dir}..."
141+
rm -rf ${Protobuf_ROOT}
142+
mkdir ${Protobuf_ROOT}
143+
cd ${Protobuf_ROOT}
144+
if [ ! -f "${script_dir}/sources/v3.1.0.tar.gz" ]; then
145+
wget https://github.com/protocolbuffers/protobuf/archive/v3.1.0.tar.gz || exit 1
146+
cp v3.1.0.tar.gz ${script_dir}/sources/
147+
else
148+
cp ${script_dir}/sources/v3.1.0.tar.gz .
149+
fi
150+
tar xzf v3.1.0.tar.gz
151+
cd protobuf-3.1.0
152+
if [ ! -f "./configure" ]; then
153+
./autogen.sh
154+
fi
155+
./configure --host=arm-linux --with-protoc=${PROTOC_ROOT}/bin/protoc\
156+
--prefix=${Protobuf_ROOT}
157+
make -j${build_threads} || exit 1
158+
make install -j${build_threads} || exit 1
159+
cp ${PROTOC_ROOT}/bin/protoc ${Protobuf_ROOT}/bin
160+
cd ..
161+
rm -rf v3.1.0.tar.gz protobuf-3.1.0
162+
163+
164+
# download flatbuffers header file
165+
echo "[INFO] install flatbuffers in ${script_dir}..."
166+
rm -rf ${FlatBuffers_ROOT}
167+
mkdir ${FlatBuffers_ROOT}
168+
cd ${FlatBuffers_ROOT}
169+
if [ ! -d "${script_dir}/sources/flatbuffers" ]; then
170+
git init
171+
git remote add -f origin https://github.com/google/flatbuffers || exit 1
172+
git config core.sparsecheckout true
173+
echo "include" >> .git/info/sparse-checkout
174+
git pull origin master || exit 1
175+
rm -rf .git*
176+
cp -r ../flatbuffers ${script_dir}/sources/
177+
else
178+
cp -r ${script_dir}/sources/flatbuffers/* .
179+
fi
180+
181+
182+
# download tensorflow-lite header file
183+
echo "[INFO] install TFLite in ${script_dir}..."
184+
rm -rf ${TFLite_ROOT}
185+
mkdir ${TFLite_ROOT}
186+
cd ${TFLite_ROOT}
187+
if [ ! -d "${script_dir}/sources/tflite" ]; then
188+
mkdir include
189+
cd include
190+
git init
191+
git remote add -f origin https://github.com/tensorflow/tensorflow || exit 1
192+
git config core.sparsecheckout true
193+
echo "lite/schema/schema_generated.h" >> .git/info/sparse-checkout
194+
git pull origin master || exit 1
195+
rm -rf .git*
196+
cp -r ../../tflite ${script_dir}/sources/
197+
else
198+
cp -r ${script_dir}/sources/tflite/* .
199+
fi
200+
201+
202+
# download and install OpenCL
203+
echo "[INFO] install opencl in ${script_dir}..."
204+
rm -rf ${OpenCL_ROOT}
205+
mkdir ${OpenCL_ROOT}
206+
cd ${OpenCL_ROOT}
207+
if [ ! -d "${script_dir}/sources/opencl" ]; then
208+
mkdir include
209+
cd include
210+
git init
211+
git remote add -f origin https://github.com/KhronosGroup/OpenCL-Headers || exit 1
212+
git config core.sparsecheckout true
213+
echo "CL" >> .git/info/sparse-checkout
214+
git pull origin master || exit 1
215+
rm -rf .git*
216+
cd ..
217+
218+
mkdir lib64
219+
android_device=`adb devices | head -n 2 | tail -n 1 | awk '{print $1}'`
220+
adb -s ${android_device} pull /vendor/lib64/libOpenCL.so lib64/
221+
adb -s ${android_device} pull /vendor/lib64/egl/libGLES_mali.so lib64/
222+
cp -r ../opencl ${script_dir}/sources/
223+
else
224+
cp -r ${script_dir}/sources/opencl/* .
225+
fi
226+
227+
228+
# download and build jpeg
229+
echo "[INFO] install jpeg in ${script_dir}..."
230+
rm -rf ${JPEG_ROOT}
231+
mkdir ${JPEG_ROOT}
232+
cd ${JPEG_ROOT}
233+
if [ ! -f "${script_dir}/sources/jpegsrc.v9c.tar.gz" ]; then
234+
wget http://www.ijg.org/files/jpegsrc.v9c.tar.gz || exit 1
235+
cp jpegsrc.v9c.tar.gz ${script_dir}/sources/
236+
else
237+
cp ${script_dir}/sources/jpegsrc.v9c.tar.gz .
238+
fi
239+
tar xzf jpegsrc.v9c.tar.gz
240+
cd jpeg-9c
241+
if [ ! -f "./configure" ]; then
242+
./autogen.sh
243+
fi
244+
./configure --host=arm-linux --prefix=${JPEG_ROOT}
245+
make -j${build_threads} || exit 1
246+
make install -j${build_threads} || exit 1
247+
cd ..
248+
rm -rf jpeg-9c jpegsrc.v9c.tar.gz
249+
250+
251+
echo "[INFO] generate environment file to ${env_file}..."
252+
echo "#!/bin/bash
253+
export Protobuf_ROOT=${script_dir}/${compiler_arch}/protobuf
254+
export FlatBuffers_ROOT=${script_dir}/${compiler_arch}/flatbuffers
255+
export TFLite_ROOT=${script_dir}/${compiler_arch}/tflite
256+
export OpenCL_ROOT=${script_dir}/${compiler_arch}/opencl
257+
export JPEG_ROOT=${script_dir}/${compiler_arch}/jpeg
258+
export PATH=\${Protobuf_ROOT}/bin:\$PATH
259+
export LD_LIBRARY_PATH=\${Protobuf_ROOT}/lib:\${OpenCL_ROOT}/lib64:\${JPEG_ROOT}/lib:\$LD_LIBRARY_PATH
260+
" > ${env_file}
261+
chmod a+x ${env_file}
262+
echo "[INFO] please source ${env_file} before use..."
263+
264+
cd ${current_dir}

0 commit comments

Comments
 (0)