提交 829b452f 编写于 作者: Y Yuan Shuai 提交者: GitHub

[LITE][BENCHMARK] enhance android arm cpu benchmark (#1939)

* enhance benchmark
* update code format. test=develop
上级 cfd5abe5
#!/bin/bash
set -e
# Check input
if [ $# -lt 3 ];
then
echo "Input error"
echo "USAGE:"
echo " sh benchmark.sh benchmark_bin_path benchmark_models_path result_filename"
echo " sh benchmark.sh benchmark_bin_path benchmark_models_path result_filename is_run_model_optimize"
echo "Usage:"
echo " sh benchmark.sh <benchmark_bin_path> <benchmark_models_path> <result_filename>"
echo " sh benchmark.sh <benchmark_bin_path> <benchmark_models_path> <result_filename> <is_run_model_optimize: [true|false]>"
exit
fi
# Set benchmark params
ANDROID_DIR=/data/local/tmp
WARMUP=10
REPEATS=30
BENCHMARK_BIN=$1
MODELS_DIR=$2
RESULT_FILENAME=$3
WARMUP=10
REPEATS=30
IS_RUN_MODEL_OPTIMIZE=false
NUM_THREADS_LIST=(1 2 4)
MODELS_LIST=$(ls $MODELS_DIR)
# Check input
if [ $# -gt 3 ];
then
IS_RUN_MODEL_OPTIMIZE=$4
fi
# Adb push benchmark_bin, models
adb push $BENCHMARK_BIN $ANDROID_DIR/benchmark_bin
adb shell chmod 777 $ANDROID_DIR/benchmark_bin
adb shell chmod +x $ANDROID_DIR/benchmark_bin
adb push $MODELS_DIR $ANDROID_DIR
adb shell "echo PaddleLite Benchmark > $ANDROID_DIR/$RESULT_FILENAME"
for threads in 1 2 4
do
adb shell "echo Threads=$threads Warmup=$WARMUP Repeats=$REPEATS >> $ANDROID_DIR/$RESULT_FILENAME"
for model_name in `ls $MODELS_DIR`
do
echo "Model=$model_name Threads=$threads"
adb shell "$ANDROID_DIR/benchmark_bin --model_dir=$ANDROID_DIR/${MODELS_DIR##*/}/$model_name --warmup=$WARMUP --repeats=$REPEATS --threads=$threads --result_filename=$ANDROID_DIR/$RESULT_FILENAME --run_model_optimize=$IS_RUN_MODEL_OPTIMIZE"
done
adb shell "echo >> $ANDROID_DIR/$RESULT_FILENAME"
# Run benchmark
adb shell "echo 'PaddleLite Benchmark' > $ANDROID_DIR/$RESULT_FILENAME"
for threads in ${NUM_THREADS_LIST[@]}; do
adb shell "echo Threads=$threads Warmup=$WARMUP Repeats=$REPEATS >> $ANDROID_DIR/$RESULT_FILENAME"
for model_name in ${MODELS_LIST[@]}; do
echo "Model=$model_name Threads=$threads"
adb shell "$ANDROID_DIR/benchmark_bin \
--model_dir=$ANDROID_DIR/${MODELS_DIR}/$model_name \
--warmup=$WARMUP \
--repeats=$REPEATS \
--threads=$threads \
--result_filename=$ANDROID_DIR/$RESULT_FILENAME \
--run_model_optimize=$IS_RUN_MODEL_OPTIMIZE"
done
adb shell "echo >> $ANDROID_DIR/$RESULT_FILENAME"
done
# Adb pull benchmark result, show result
adb pull $ANDROID_DIR/$RESULT_FILENAME .
echo "\n--------------------------------------"
cat $RESULT_FILENAME
......
#!/bin/bash
set -e
function download_files_with_url_prefix {
local url_prefix=$1
local download_file_list=$2
local tar_file_pattern="tar.gz"
for file_name in ${download_file_list[*]}; do
echo "[INFO] Downloading ${file_name} ..."
wget -c ${url_prefix}/${file_name}
chmod +x ./${file_name}
# check tar.gz file
if [[ ${file_name} =~ ${tar_file_pattern} ]]
then
echo "[INFO] Extracting ${file_name} ..."
tar -zxvf ${file_name}
fi
done
}
# 1.Download tar packages: models, benchmark_bin
readonly DOWNLOAD_TAR_PREFIX="https://paddle-inference-dist.bj.bcebos.com/PaddleLite/"
readonly DOWNLOAD_TAR_LIST=("benchmark_bin_android_armv8_cpu.tar.gz" \
"benchmark_bin_android_armv7_cpu.tar.gz" \
"benchmark_models.tar.gz")
download_files_with_url_prefix ${DOWNLOAD_TAR_PREFIX} "${DOWNLOAD_TAR_LIST[*]}"
# 2.Download script: benchmark
readonly DOWNLOAD_SCRIPT_PREFIX="https://raw.githubusercontent.com/PaddlePaddle/Paddle-Lite/develop/lite/tools/"
readonly DOWNLOAD_SCRIPT_LIST=("benchmark.sh")
download_files_with_url_prefix ${DOWNLOAD_SCRIPT_PREFIX} "${DOWNLOAD_SCRIPT_LIST[*]}"
# 3.Run benchmark
echo "[INFO] Run benchmark for android armv7 cpu"
bash benchmark.sh \
./benchmark_bin_android_armv7_cpu \
./benchmark_models \
result_android_armv7_cpu.txt
echo "[INFO] Run benchmark for android armv8 cpu"
bash benchmark.sh \
./benchmark_bin_android_armv8_cpu \
./benchmark_models \
result_android_armv8_cpu.txt
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册