提交 f3f3a58f 编写于 作者: Y yejianwu

support multi soc in throughput_test and benchmark

上级 f7fe515b
#!/bin/bash
Usage() {
echo "Usage: bash tools/benchmark.sh model_output_dir"
echo "Usage: bash tools/benchmark.sh target_soc model_output_dir option_args"
}
if [ $# -lt 1 ]; then
......@@ -12,11 +12,14 @@ fi
CURRENT_DIR=`dirname $0`
source ${CURRENT_DIR}/env.sh
MODEL_OUTPUT_DIR=$1
OPTION_ARGS=$2
TARGET_SOC=$1
MODEL_OUTPUT_DIR=$2
OPTION_ARGS=$3
echo $OPTION_ARGS
DEVICE_ID=`echo_device_id_by_soc $TARGET_SOC`
if [ -f "$MODEL_OUTPUT_DIR/benchmark_model" ]; then
rm -rf $MODEL_OUTPUT_DIR/benchmark_model
fi
......@@ -63,18 +66,18 @@ else
cp bazel-bin/mace/benchmark/benchmark_model $MODEL_OUTPUT_DIR
adb shell "mkdir -p ${PHONE_DATA_DIR}" || exit 1
adb -s $DEVICE_ID shell "mkdir -p ${PHONE_DATA_DIR}" || exit 1
IFS=',' read -r -a INPUT_NAMES <<< "${INPUT_NODES}"
for NAME in "${INPUT_NAMES[@]}";do
FORMATTED_NAME=$(sed s/[^[:alnum:]]/_/g <<< ${NAME})
adb push ${MODEL_OUTPUT_DIR}/${INPUT_FILE_NAME}_${FORMATTED_NAME} ${PHONE_DATA_DIR} || exit 1
adb -s $DEVICE_ID push ${MODEL_OUTPUT_DIR}/${INPUT_FILE_NAME}_${FORMATTED_NAME} ${PHONE_DATA_DIR} || exit 1
done
adb push ${MODEL_OUTPUT_DIR}/benchmark_model ${PHONE_DATA_DIR} || exit 1
adb -s $DEVICE_ID push ${MODEL_OUTPUT_DIR}/benchmark_model ${PHONE_DATA_DIR} || exit 1
if [ "$EMBED_MODEL_DATA" = 0 ]; then
adb push ${MODEL_OUTPUT_DIR}/${MODEL_TAG}.data ${PHONE_DATA_DIR} || exit 1
adb -s $DEVICE_ID push ${MODEL_OUTPUT_DIR}/${MODEL_TAG}.data ${PHONE_DATA_DIR} || exit 1
fi
adb </dev/null shell \
adb -s $DEVICE_ID </dev/null shell \
LD_LIBRARY_PATH=${PHONE_DATA_DIR} \
MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL \
MACE_RUN_PARAMETER_PATH=${PHONE_DATA_DIR}/mace_run.config \
......
#!/bin/bash
Usage() {
echo "Usage: bash tools/build_run_throughput_test.sh run_seconds merged_lib_file model_input_dir"
echo "Usage: bash tools/build_run_throughput_test.sh target_soc run_seconds merged_lib_file model_input_dir"
}
if [ $# -lt 1 ]; then
if [ $# -lt 4 ]; then
Usage
exit 1
fi
RUN_SECONDS=$1
MERGED_LIB_FILE=$2
MODEL_INPUT_DIR=$3
CURRENT_DIR=`dirname $0`
source ${CURRENT_DIR}/env.sh
TARGET_SOC=$1
RUN_SECONDS=$2
MERGED_LIB_FILE=$3
MODEL_INPUT_DIR=$4
DEVICE_ID=`echo_device_id_by_soc $TARGET_SOC`
if [ "$CPU_MODEL_TAG" != '' ]; then
CPU_MODEL_TAG_BUILD_FLAGS="--copt=-DMACE_CPU_MODEL_TAG=${CPU_MODEL_TAG}"
......@@ -46,28 +48,28 @@ bazel build --verbose_failures -c opt --strip always //mace/benchmark:model_thro
rm mace/benchmark/libmace_merged.a
adb shell "mkdir -p ${PHONE_DATA_DIR}" || exit 1
adb -s $DEVICE_ID shell "mkdir -p ${PHONE_DATA_DIR}" || exit 1
adb push ${MODEL_INPUT_DIR}/${INPUT_FILE_NAME}_${INPUT_NODES} ${PHONE_DATA_DIR} || exit 1
adb push bazel-bin/mace/benchmark/model_throughput_test ${PHONE_DATA_DIR} || exit 1
adb -s $DEVICE_ID push ${MODEL_INPUT_DIR}/${INPUT_FILE_NAME}_${INPUT_NODES} ${PHONE_DATA_DIR} || exit 1
adb -s $DEVICE_ID push bazel-bin/mace/benchmark/model_throughput_test ${PHONE_DATA_DIR} || exit 1
if [ "$EMBED_MODEL_DATA" = 0 ]; then
adb push codegen/models/${CPU_MODEL_TAG}/${CPU_MODEL_TAG}.data ${PHONE_DATA_DIR} || exit 1
adb push codegen/models/${GPU_MODEL_TAG}/${GPU_MODEL_TAG}.data ${PHONE_DATA_DIR} || exit 1
adb push codegen/models/${DSP_MODEL_TAG}/${DSP_MODEL_TAG}.data ${PHONE_DATA_DIR} || exit 1
adb -s $DEVICE_ID push codegen/models/${CPU_MODEL_TAG}/${CPU_MODEL_TAG}.data ${PHONE_DATA_DIR} || exit 1
adb -s $DEVICE_ID push codegen/models/${GPU_MODEL_TAG}/${GPU_MODEL_TAG}.data ${PHONE_DATA_DIR} || exit 1
adb -s $DEVICE_ID push codegen/models/${DSP_MODEL_TAG}/${DSP_MODEL_TAG}.data ${PHONE_DATA_DIR} || exit 1
fi
adb push mace/core/runtime/hexagon/libhexagon_controller.so ${PHONE_DATA_DIR} || exit 1
adb -s $DEVICE_ID push mace/core/runtime/hexagon/libhexagon_controller.so ${PHONE_DATA_DIR} || exit 1
adb </dev/null shell \
LD_LIBRARY_PATH=${PHONE_DATA_DIR} \
MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL \
MACE_RUN_PARAMETER_PATH=${PHONE_DATA_DIR}/mace_run.config \
MACE_KERNEL_PATH=$KERNEL_DIR \
MACE_LIMIT_OPENCL_KERNEL_TIME=${LIMIT_OPENCL_KERNEL_TIME} \
${PHONE_DATA_DIR}/model_throughput_test \
--input_shape="${INPUT_SHAPES}" \
--output_shape="${OUTPUT_SHAPES}" \
--input_file=${PHONE_DATA_DIR}/${INPUT_FILE_NAME}_${INPUT_NODES} \
--cpu_model_data_file=${PHONE_DATA_DIR}/${CPU_MODEL_TAG}.data \
--gpu_model_data_file=${PHONE_DATA_DIR}/${GPU_MODEL_TAG}.data \
--dsp_model_data_file=${PHONE_DATA_DIR}/${DSP_MODEL_TAG}.data \
--run_seconds=$RUN_SECONDS || exit 1
\ No newline at end of file
adb -s $DEVICE_ID </dev/null shell \
LD_LIBRARY_PATH=${PHONE_DATA_DIR} \
MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL \
MACE_RUN_PARAMETER_PATH=${PHONE_DATA_DIR}/mace_run.config \
MACE_KERNEL_PATH=$KERNEL_DIR \
MACE_LIMIT_OPENCL_KERNEL_TIME=${LIMIT_OPENCL_KERNEL_TIME} \
${PHONE_DATA_DIR}/model_throughput_test \
--input_shape="${INPUT_SHAPES}" \
--output_shape="${OUTPUT_SHAPES}" \
--input_file=${PHONE_DATA_DIR}/${INPUT_FILE_NAME}_${INPUT_NODES} \
--cpu_model_data_file=${PHONE_DATA_DIR}/${CPU_MODEL_TAG}.data \
--gpu_model_data_file=${PHONE_DATA_DIR}/${GPU_MODEL_TAG}.data \
--dsp_model_data_file=${PHONE_DATA_DIR}/${DSP_MODEL_TAG}.data \
--run_seconds=$RUN_SECONDS || exit 1
......@@ -23,8 +23,8 @@ if [ "$PULL_OR_NOT" = 1 ]; then
rm -rf ${CL_BIN_DIR}
mkdir -p ${CL_BIN_DIR}
if [ x"$TARGET_ABI" != x"host" ]; then
adb -s $DEVICE_ID pull ${KERNEL_DIR}/. ${CL_BIN_DIR} > /dev/null || exit 1
adb -s $DEVICE_ID pull ${PHONE_DATA_DIR}/mace_run.config ${CL_BIN_DIR} > /dev/null || exit 1
adb -s $DEVICE_ID pull ${KERNEL_DIR}/. ${CL_BIN_DIR} > /dev/null
adb -s $DEVICE_ID pull ${PHONE_DATA_DIR}/mace_run.config ${CL_BIN_DIR} > /dev/null
fi
fi
......
......@@ -94,9 +94,9 @@ def tuning_run(target_soc,
run_command(command)
def benchmark_model(model_output_dir, option_args=''):
command = "bash tools/benchmark.sh {} \"{}\"".format(model_output_dir,
option_args)
def benchmark_model(target_soc, model_output_dir, option_args=''):
command = "bash tools/benchmark.sh {} {} \"{}\"".format(
target_soc, model_output_dir, option_args)
run_command(command)
......@@ -138,9 +138,10 @@ def build_mace_run_prod(target_soc, model_output_dir, tuning, global_runtime):
build_mace_run(production_or_not, model_output_dir, hexagon_mode)
def build_run_throughput_test(run_seconds, merged_lib_file, model_input_dir):
command = "bash tools/build_run_throughput_test.sh {} {} {}".format(
run_seconds, merged_lib_file, model_input_dir)
def build_run_throughput_test(target_soc, run_seconds, merged_lib_file,
model_input_dir):
command = "bash tools/build_run_throughput_test.sh {} {} {} {}".format(
target_soc, run_seconds, merged_lib_file, model_input_dir)
run_command(command)
......@@ -226,8 +227,8 @@ def main(unused_args):
generate_opencl_and_version_code()
option_args = ' '.join([arg for arg in unused_args if arg.startswith('--')])
for target_abi in configs["target_abis"]:
for target_soc in configs["target_socs"]:
for target_abi in configs["target_abis"]:
global_runtime = get_global_runtime(configs)
# Transfer params by environment
os.environ["TARGET_ABI"] = target_abi
......@@ -291,7 +292,7 @@ def main(unused_args):
FLAGS.restart_round, option_args)
if FLAGS.mode == "benchmark":
benchmark_model(model_output_dir, option_args)
benchmark_model(target_soc, model_output_dir, option_args)
if FLAGS.mode == "validate" or FLAGS.mode == "all":
validate_model(target_soc, model_output_dir)
......@@ -302,14 +303,14 @@ def main(unused_args):
model_output_dirs)
if FLAGS.mode == "throughput_test":
merged_lib_file = FLAGS.output_dir + "/%s/libmace/lib/libmace_%s.a" % \
(configs["target_abis"][0], os.environ["PROJECT_NAME"])
merged_lib_file = FLAGS.output_dir + "/%s/%s/libmace_%s.%s.a" % \
(os.environ["PROJECT_NAME"], target_abi, os.environ["PROJECT_NAME"], target_soc)
generate_random_input(target_soc, FLAGS.output_dir)
for model_name in configs["models"]:
runtime = configs["models"][model_name]["runtime"]
os.environ["%s_MODEL_TAG" % runtime.upper()] = model_name
build_run_throughput_test(FLAGS.run_seconds, merged_lib_file,
FLAGS.output_dir)
build_run_throughput_test(target_soc, FLAGS.run_seconds,
merged_lib_file, FLAGS.output_dir)
if __name__ == "__main__":
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册