Skip to content

Commit

Permalink
[CONVERTER2TNN][UPD] 1. default do not clean build directory; (#694)
Browse files Browse the repository at this point in the history
Co-authored-by: tiankai <tiankai@tencent.com>
  • Loading branch information
2 people authored and shaundai-tencent committed Jan 5, 2021
1 parent be65fd9 commit e6c176c
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 58 deletions.
119 changes: 81 additions & 38 deletions tools/convert2tnn/build.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,84 @@
if [ ! -d "bin" ]; then
mkdir bin
fi

if [ ! -d "temp" ]; then
mkdir temp
fi

function build_model_check() {
cd $2

cmake ../../.. \
-DCMAKE_BUILD_TYPE=Release \
-DTNN_CPU_ENABLE:BOOL="ON" \
-DTNN_MODEL_CHECK_ENABLE:BOOL="ON" \
-DTNN_CONVERTER_ENABLE:BOOL="ON" \
-DTNN_BUILD_SHARED="OFF"

make -j4
cp tools/converter/TnnConverter ../bin/

if [ -f "model_check" ]; then
mv model_check ../$1

cd ..

rm -rf $2

cd ../onnx2tnn/onnx-converter
./build.sh

echo "Compiled successfully !"
else
cd ..
rm -rf $1 $2
echo "Compiled failed !!!"
fi
#!/usr/bin/env bash

CURRENT_DIR=$(pwd)
CLEAN=""
BUILD_DIR=build
BIN_DIR=bin

function usage() {
echo "usage: ./build.sh [-c]"
echo "options:"
echo " -c Clean up build folders."
}

function clean_build() {
echo $1 | grep "${BUILD_DIR}\b" >/dev/null
if [[ "$?" != "0" ]]; then
die "Warnning: $1 seems not to be a BUILD folder."
fi
rm -rf $1
mkdir -p $1
}

function build_model_check_and_tnn_converter() {

if [ "-c" == "${CLEAN}" ]; then
clean_build ${BUILD_DIR}
fi
pwd
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}

cmake ../../.. \
-DCMAKE_BUILD_TYPE=DEBUG \
-DTNN_CPU_ENABLE:BOOL="ON" \
-DTNN_MODEL_CHECK_ENABLE:BOOL="ON" \
-DTNN_CONVERTER_ENABLE:BOOL="ON" \
-DTNN_BUILD_SHARED="OFF" \
-DDEBUG="ON"

make -j4

if [ -f "model_check" ]; then
cp model_check ../${BIN_DIR}
echo "Compiled model_check successfully !"
else

echo "Compiled model_check failed !!!"
fi

if [ -f "tools/converter/TnnConverter" ]; then
cp tools/converter/TnnConverter ../${BIN_DIR}
echo "Compiled model_check successfully !"
else
echo "Compiled TNNConverter failed !!!"
fi
}

build_model_check bin temp
function build_onnx2tnn() {
cd ${CURRENT_DIR}
cd ../onnx2tnn/onnx-converter/

if [ "-c" == "${CLEAN}" ]; then
./build.sh -c
else
./build.sh
fi
}

while [ "$1" != "" ]; do
case $1 in
-c)
shift
CLEAN="-c"
;;
*)
usage
exit 1
;;
esac
done

build_model_check_and_tnn_converter

build_onnx2tnn
3 changes: 1 addition & 2 deletions tools/convert2tnn/utils/align_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def run_tnn_model_check(proto_path, model_path, input_path, reference_output_pat
if ret == 0:
print_align_message(is_tflite)
else:
print_not_align_message(None, is_tflie)

print_not_align_message(None, is_tflite)
return


Expand Down
66 changes: 48 additions & 18 deletions tools/onnx2tnn/onnx-converter/build.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,59 @@
export CMAKE=/path/to/cmake
export CPP_COMPILER=/path/to/g++
export C_COMPILER=/path/to/gcc
export PYTHON=/path/to/python3
##!/usr/bin/env bash

# here is an example, make sure libpython3 is in LD_LIBRARY_PATH
export CMAKE=cmake
export CPP_COMPILER=g++
export C_COMPILER=gcc
export PYTHON=`which python3`

set -xe
CLEAN=""
BUILD_DIR=build

if [ -d "build" ]; then
rm -rf build/
fi
#set -xe

$PYTHON script/detect_dependency.py
function usage() {
echo "usage: ./build.sh [-c]"
echo "options:"
echo " -c Clean up build folders."
}

mkdir -p build
cd build && $CMAKE .. \
-DCMAKE_CXX_COMPILER=$CPP_COMPILER \
-DCMAKE_C_COMPILER=$C_COMPILER \
-DPYTHON_EXECUTABLE=$PYTHON \
&& make -j4 && cd ..
function clean_build() {
echo $1 | grep "${BUILD_DIR}\b" > /dev/null
if [[ "$?" != "0" ]]; then
die "Warnning: $1 seems not to be a BUILD folder."
fi
rm -rf $1
mkdir -p $1
}

cp build/*.so .
function build() {

rm -rf build/
$PYTHON script/detect_dependency.py
if [ "-c" == "${CLEAN}" ]; then
clean_build ${BUILD_DIR}
fi
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}

${CMAKE} .. -DCMAKE_CXX_COMPILER=$CPP_COMPILER \
-DCMAKE_C_COMPILER=$C_COMPILER \
-DPYTHON_EXECUTABLE=$PYTHON \

make -j4
cp *.so ../
cd ../
}


while [ "$1" != "" ]; do
case $1 in
-c)
shift
CLEAN="-c"
;;
*)
usage
exit 1
esac
done

build

0 comments on commit e6c176c

Please sign in to comment.