From f3f3a58f5c663b38dfa962fc284a8a00cec594c5 Mon Sep 17 00:00:00 2001 From: yejianwu Date: Fri, 16 Mar 2018 11:42:40 +0800 Subject: [PATCH] support multi soc in throughput_test and benchmark --- tools/benchmark.sh | 19 +++++----- tools/build_run_throughput_test.sh | 56 ++++++++++++++++-------------- tools/generate_production_code.sh | 4 +-- tools/mace_tools.py | 27 +++++++------- 4 files changed, 56 insertions(+), 50 deletions(-) diff --git a/tools/benchmark.sh b/tools/benchmark.sh index a37627c4..e050f5b4 100644 --- a/tools/benchmark.sh +++ b/tools/benchmark.sh @@ -1,7 +1,7 @@ #!/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 || 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 diff --git a/tools/mace_tools.py b/tools/mace_tools.py index 4c61ae70..1858b411 100644 --- a/tools/mace_tools.py +++ b/tools/mace_tools.py @@ -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_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__": -- GitLab