Skip to content

Commit

Permalink
Add third_party and update CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
jianfeifeng committed Mar 13, 2020
1 parent 890a32e commit a193d96
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.15)

file(GLOB BOLT_CONFIGURE_FILE $ENV{BOLT_ROOT}/bolt.cmake ${BOLT_ROOT}/bolt.cmake)
if (BOLT_CONFIGURE_FILE)
Expand All @@ -22,7 +22,7 @@ add_subdirectory(image)
add_subdirectory(inference)
add_subdirectory(tests)
add_custom_target(bolt_library ALL
COMMAND ./scripts/build_light_bolt.sh ${CMAKE_BINARY_DIR}
COMMAND ./scripts/build_light_bolt.sh ${CMAKE_BINARY_DIR} ${USE_MALI}
WORKING_DIRECTORY $ENV{BOLT_ROOT})

if (USE_MALI)
Expand Down
7 changes: 5 additions & 2 deletions scripts/build_light_bolt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BOLT_ROOT=${script_dir}/..
current_dir=${PWD}

build_dir=$1
use_mali=$2

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

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

if [ -f "${BOLT_ROOT}/gcl/tools/kernel_lib_compile/lib/libkernelbin.so" ];then
if [ -f "${BOLT_ROOT}/gcl/tools/kernel_lib_compile/lib/libkernelbin.so" ] && [ $use_mali == "ON" ];
then
aarch64-linux-android-strip ${BOLT_ROOT}/gcl/tools/kernel_lib_compile/lib/libkernelbin.so || exit 1
#cp ${BOLT_ROOT}/gcl/tools/kernel_lib_compile/lib/libkernelbin.so ${build_dir}
aarch64-linux-android21-clang++ -shared -o ${build_dir}/libBoltModel.so ${srcs} \
Expand Down
264 changes: 264 additions & 0 deletions third_party/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
#!/bin/bash

script_name=$0
compiler_arch="gnu"
build_threads="8"

print_help() {
cat <<EOF
Usage: ${script_name} [OPTION]...
Build third party library.
Mandatory arguments to long options are mandatory for short options too.
-h, --help display this help and exit.
-c, --compiler <llvm|gnu> use to set compiler(default: gnu).
-t, --threads use parallel build(default: 8).
EOF
exit 1;
}

TEMP=`getopt -o c:ht: --long compiler:help,threads: \
-n ${script_name} -- "$@"`
if [ $? != 0 ] ; then echo "[ERROR] terminating..." >&2 ; exit 1 ; fi
eval set -- "$TEMP"
while true ; do
case "$1" in
-c|--compiler)
compiler_arch=$2
echo "[INFO] build library for '${compiler_arch}'" ;
shift 2 ;;
-t|--threads)
build_threads=$2
echo "[INFO] '${build_threads}' threads parallel to build" ;
shift 2 ;;
-h|--help)
print_help ;
shift ;;
--) shift ;
break ;;
*) echo "[ERROR]" ; exit 1 ;;
esac
done

exeIsValid(){
if type $1 2>/dev/null;
then
return 1
else
return 0
fi
}

exeIsValid wget
if [ $? == 0 ] ; then
echo "[ERROR] please install wget tools and set shell environment PATH to find it"
exit 1
fi

exeIsValid git
if [ $? == 0 ] ; then
echo "[ERROR] please install git tools and set shell environment PATH to find it"
exit 1
fi

exeIsValid unzip
if [ $? == 0 ] ; then
echo "[ERROR] please install unzip tools and set shell environment PATH to find it"
exit 1
fi

exeIsValid tar
if [ $? == 0 ] ; then
echo "[ERROR] please install tar tools and set shell environment PATH to find it"
exit 1
fi

if [ "${compiler_arch}" == "llvm" ] ; then
exeIsValid aarch64-linux-android21-clang
if [ $? == 0 ] ; then
echo "[ERROR] please install android ndk aarch64-linux-android21-clang compiler and set shell environment PATH to find it"
exit 1
fi
exeIsValid aarch64-linux-android21-clang++
if [ $? == 0 ] ; then
echo "[ERROR] please install android ndk aarch64-linux-android21-clang++ compiler and set shell environment PATH to find it"
exit 1
fi
export CC=aarch64-linux-android21-clang
export CXX=aarch64-linux-android21-clang++
else
exeIsValid aarch64-linux-gnu-gcc
if [ $? == 0 ] ; then
echo "[ERROR] please install GNU gcc ARM compiler and set shell environment PATH to find it"
exit 1
fi
exeIsValid aarch64-linux-gnu-g++
if [ $? == 0 ] ; then
echo "[ERROR] please install GNU gcc ARM compiler and set shell environment PATH to find it"
exit 1
fi
export CC=aarch64-linux-gnu-gcc
export CXX=aarch64-linux-gnu-g++
fi

script_abs=$(readlink -f "$0")
script_dir=$(dirname $script_abs)
current_dir=${PWD}

if [ ! -d "${script_dir}/sources" ]; then
mkdir ${script_dir}/sources
fi

rm -rf ${script_dir}/${compiler_arch}
mkdir ${script_dir}/${compiler_arch}
env_file="${script_dir}/${compiler_arch}.sh"
PROTOC_ROOT=${script_dir}/${compiler_arch}/protoc
Protobuf_ROOT=${script_dir}/${compiler_arch}/protobuf
FlatBuffers_ROOT=${script_dir}/${compiler_arch}/flatbuffers
TFLite_ROOT=${script_dir}/${compiler_arch}/tflite
OpenCL_ROOT=${script_dir}/${compiler_arch}/opencl
JPEG_ROOT=${script_dir}/${compiler_arch}/jpeg


# download prebuilt protoc
echo "[INFO] install protoc in ${script_dir}..."
rm -rf ${PROTOC_ROOT}
mkdir ${PROTOC_ROOT}
cd ${PROTOC_ROOT}
if [ ! -f "${script_dir}/sources/protoc-3.1.0-linux-x86_64.zip" ]; then
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.1.0/protoc-3.1.0-linux-x86_64.zip || exit 1
cp protoc-3.1.0-linux-x86_64.zip ${script_dir}/sources/
else
cp ${script_dir}/sources/protoc-3.1.0-linux-x86_64.zip .
fi
unzip protoc-3.1.0-linux-x86_64.zip
rm protoc-3.1.0-linux-x86_64.zip
export PATH=${PROTOC_ROOT}/bin:$PATH


# download and build protobuf
echo "[INFO] install protobuf in ${script_dir}..."
rm -rf ${Protobuf_ROOT}
mkdir ${Protobuf_ROOT}
cd ${Protobuf_ROOT}
if [ ! -f "${script_dir}/sources/v3.1.0.tar.gz" ]; then
wget https://github.com/protocolbuffers/protobuf/archive/v3.1.0.tar.gz || exit 1
cp v3.1.0.tar.gz ${script_dir}/sources/
else
cp ${script_dir}/sources/v3.1.0.tar.gz .
fi
tar xzf v3.1.0.tar.gz
cd protobuf-3.1.0
if [ ! -f "./configure" ]; then
./autogen.sh
fi
./configure --host=arm-linux --with-protoc=${PROTOC_ROOT}/bin/protoc\
--prefix=${Protobuf_ROOT}
make -j${build_threads} || exit 1
make install -j${build_threads} || exit 1
cp ${PROTOC_ROOT}/bin/protoc ${Protobuf_ROOT}/bin
cd ..
rm -rf v3.1.0.tar.gz protobuf-3.1.0


# download flatbuffers header file
echo "[INFO] install flatbuffers in ${script_dir}..."
rm -rf ${FlatBuffers_ROOT}
mkdir ${FlatBuffers_ROOT}
cd ${FlatBuffers_ROOT}
if [ ! -d "${script_dir}/sources/flatbuffers" ]; then
git init
git remote add -f origin https://github.com/google/flatbuffers || exit 1
git config core.sparsecheckout true
echo "include" >> .git/info/sparse-checkout
git pull origin master || exit 1
rm -rf .git*
cp -r ../flatbuffers ${script_dir}/sources/
else
cp -r ${script_dir}/sources/flatbuffers/* .
fi


# download tensorflow-lite header file
echo "[INFO] install TFLite in ${script_dir}..."
rm -rf ${TFLite_ROOT}
mkdir ${TFLite_ROOT}
cd ${TFLite_ROOT}
if [ ! -d "${script_dir}/sources/tflite" ]; then
mkdir include
cd include
git init
git remote add -f origin https://github.com/tensorflow/tensorflow || exit 1
git config core.sparsecheckout true
echo "lite/schema/schema_generated.h" >> .git/info/sparse-checkout
git pull origin master || exit 1
rm -rf .git*
cp -r ../../tflite ${script_dir}/sources/
else
cp -r ${script_dir}/sources/tflite/* .
fi


# download and install OpenCL
echo "[INFO] install opencl in ${script_dir}..."
rm -rf ${OpenCL_ROOT}
mkdir ${OpenCL_ROOT}
cd ${OpenCL_ROOT}
if [ ! -d "${script_dir}/sources/opencl" ]; then
mkdir include
cd include
git init
git remote add -f origin https://github.com/KhronosGroup/OpenCL-Headers || exit 1
git config core.sparsecheckout true
echo "CL" >> .git/info/sparse-checkout
git pull origin master || exit 1
rm -rf .git*
cd ..

mkdir lib64
android_device=`adb devices | head -n 2 | tail -n 1 | awk '{print $1}'`
adb -s ${android_device} pull /vendor/lib64/libOpenCL.so lib64/
adb -s ${android_device} pull /vendor/lib64/egl/libGLES_mali.so lib64/
cp -r ../opencl ${script_dir}/sources/
else
cp -r ${script_dir}/sources/opencl/* .
fi


# download and build jpeg
echo "[INFO] install jpeg in ${script_dir}..."
rm -rf ${JPEG_ROOT}
mkdir ${JPEG_ROOT}
cd ${JPEG_ROOT}
if [ ! -f "${script_dir}/sources/jpegsrc.v9c.tar.gz" ]; then
wget http://www.ijg.org/files/jpegsrc.v9c.tar.gz || exit 1
cp jpegsrc.v9c.tar.gz ${script_dir}/sources/
else
cp ${script_dir}/sources/jpegsrc.v9c.tar.gz .
fi
tar xzf jpegsrc.v9c.tar.gz
cd jpeg-9c
if [ ! -f "./configure" ]; then
./autogen.sh
fi
./configure --host=arm-linux --prefix=${JPEG_ROOT}
make -j${build_threads} || exit 1
make install -j${build_threads} || exit 1
cd ..
rm -rf jpeg-9c jpegsrc.v9c.tar.gz


echo "[INFO] generate environment file to ${env_file}..."
echo "#!/bin/bash
export Protobuf_ROOT=${script_dir}/${compiler_arch}/protobuf
export FlatBuffers_ROOT=${script_dir}/${compiler_arch}/flatbuffers
export TFLite_ROOT=${script_dir}/${compiler_arch}/tflite
export OpenCL_ROOT=${script_dir}/${compiler_arch}/opencl
export JPEG_ROOT=${script_dir}/${compiler_arch}/jpeg
export PATH=\${Protobuf_ROOT}/bin:\$PATH
export LD_LIBRARY_PATH=\${Protobuf_ROOT}/lib:\${OpenCL_ROOT}/lib64:\${JPEG_ROOT}/lib:\$LD_LIBRARY_PATH
" > ${env_file}
chmod a+x ${env_file}
echo "[INFO] please source ${env_file} before use..."

cd ${current_dir}

0 comments on commit a193d96

Please sign in to comment.