提交 72544211 编写于 作者: Y yejianwu

build libmace for target_socs

上级 09b1704d
#!/bin/bash
Usage() {
echo "Usage: bash tools/clear_env.sh target_soc"
}
if [ $# -lt 1 ]; then
Usage
exit 1
fi
CURRENT_DIR=`dirname $0` CURRENT_DIR=`dirname $0`
source ${CURRENT_DIR}/env.sh source ${CURRENT_DIR}/env.sh
TARGET_SOC=$1
DEVICE_ID=`echo_device_id_by_soc $TARGET_SOC`
if [ x"$TARGET_ABI" != x"host" ]; then if [ x"$TARGET_ABI" != x"host" ]; then
adb shell rm -rf $PHONE_DATA_DIR adb -s $DEVICE_ID shell rm -rf $PHONE_DATA_DIR || exit 1
fi fi
rm -rf mace/codegen/models rm -rf mace/codegen/models
......
...@@ -32,3 +32,14 @@ if [ x"$TARGET_ABI" = x"host" ]; then ...@@ -32,3 +32,14 @@ if [ x"$TARGET_ABI" = x"host" ]; then
GENERATED_MODEL_LIB_NAME="libgenerated_models.pic.a" GENERATED_MODEL_LIB_NAME="libgenerated_models.pic.a"
fi fi
GENERATED_MODEL_LIB_PATH="bazel-bin/mace/codegen/${GENERATED_MODEL_LIB_NAME}" GENERATED_MODEL_LIB_PATH="bazel-bin/mace/codegen/${GENERATED_MODEL_LIB_NAME}"
echo_device_id_by_soc()
{
TARGET_SOC=$1
for device in `adb devices | grep "^[A-Za-z0-9]\+[[:space:]]\+device$"| cut -f1`; do
device_soc=`adb -s ${device} shell getprop | grep ro.board.platform | cut -d [ -f3 | cut -d ] -f1`
if [ x"$TARGET_SOC" = x"$device_soc" ]; then
echo "$device"
fi
done
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Each yaml file describes a exported library (could be named [target_abi]/libmace-${filename}.a), # Each yaml file describes a exported library (could be named [target_abi]/libmace-${filename}.a),
# which can contains more than one models # which can contains more than one models
target_abis: [armeabi-v7a, arm64-v8a] target_abis: [armeabi-v7a, arm64-v8a]
target_socs: [MSM8953] # target_socs not enabled yet target_socs: [MSM8953]
embed_model_data: 1 embed_model_data: 1
vlog_level: 0 vlog_level: 0
models: models:
......
#!/bin/bash #!/bin/bash
Usage() { Usage() {
echo "Usage: bash tools/generate_production_code.sh cl_bin_dirs pull_or_not" echo "Usage: bash tools/generate_production_code.sh target_soc cl_bin_dirs pull_or_not"
} }
if [ $# -lt 2 ]; then if [ $# -lt 3 ]; then
Usage Usage
exit 1 exit 1
fi fi
...@@ -12,16 +12,19 @@ fi ...@@ -12,16 +12,19 @@ fi
CURRENT_DIR=`dirname $0` CURRENT_DIR=`dirname $0`
source ${CURRENT_DIR}/env.sh source ${CURRENT_DIR}/env.sh
CL_BIN_DIRS=$1 TARGET_SOC=$1
PULL_OR_NOT=$2 CL_BIN_DIRS=$2
PULL_OR_NOT=$3
DEVICE_ID=`echo_device_id_by_soc $TARGET_SOC`
if [ "$PULL_OR_NOT" = 1 ]; then if [ "$PULL_OR_NOT" = 1 ]; then
CL_BIN_DIR=${CL_BIN_DIRS} CL_BIN_DIR=${CL_BIN_DIRS}
rm -rf ${CL_BIN_DIR} rm -rf ${CL_BIN_DIR}
mkdir -p ${CL_BIN_DIR} mkdir -p ${CL_BIN_DIR}
if [ x"$TARGET_ABI" != x"host" ]; then if [ x"$TARGET_ABI" != x"host" ]; then
adb pull ${KERNEL_DIR}/. ${CL_BIN_DIR} > /dev/null adb -s $DEVICE_ID pull ${KERNEL_DIR}/. ${CL_BIN_DIR} > /dev/null || exit 1
adb pull ${PHONE_DATA_DIR}/mace_run.config ${CL_BIN_DIR} > /dev/null adb -s $DEVICE_ID pull ${PHONE_DATA_DIR}/mace_run.config ${CL_BIN_DIR} > /dev/null || exit 1
fi fi
fi fi
......
...@@ -57,15 +57,15 @@ def generate_opencl_and_version_code(): ...@@ -57,15 +57,15 @@ def generate_opencl_and_version_code():
run_command(command) run_command(command)
def clear_env(): def clear_env(target_soc):
command = "bash tools/clear_env.sh" command = "bash tools/clear_env.sh {}".format(target_soc)
run_command(command) run_command(command)
def generate_random_input(model_output_dir): def generate_random_input(target_soc, model_output_dir):
generate_data_or_not = True generate_data_or_not = True
command = "bash tools/validate_tools.sh {} {}".format( command = "bash tools/validate_tools.sh {} {} {}".format(
model_output_dir, int(generate_data_or_not)) target_soc, model_output_dir, int(generate_data_or_not))
run_command(command) run_command(command)
...@@ -80,10 +80,10 @@ def build_mace_run(production_mode, model_output_dir, hexagon_mode): ...@@ -80,10 +80,10 @@ def build_mace_run(production_mode, model_output_dir, hexagon_mode):
run_command(command) run_command(command)
def tuning_run(model_output_dir, running_round, tuning, production_mode, def tuning_run(target_soc, model_output_dir, running_round, tuning, production_mode,
restart_round, option_args=''): restart_round, option_args=''):
command = "bash tools/tuning_run.sh {} {} {} {} {} \"{}\"".format( command = "bash tools/tuning_run.sh {} {} {} {} {} {} \"{}\"".format(
model_output_dir, running_round, int(tuning), int(production_mode), target_soc, model_output_dir, running_round, int(tuning), int(production_mode),
restart_round, option_args) restart_round, option_args)
run_command(command) run_command(command)
...@@ -93,22 +93,22 @@ def benchmark_model(model_output_dir, option_args=''): ...@@ -93,22 +93,22 @@ def benchmark_model(model_output_dir, option_args=''):
run_command(command) run_command(command)
def run_model(model_output_dir, running_round, restart_round, option_args): def run_model(target_soc, model_output_dir, running_round, restart_round, option_args):
tuning_run(model_output_dir, running_round, False, False, restart_round, tuning_run(target_soc, model_output_dir, running_round, False, False, restart_round,
option_args) option_args)
def generate_production_code(model_output_dirs, pull_or_not): def generate_production_code(target_soc, model_output_dirs, pull_or_not):
cl_bin_dirs = [] cl_bin_dirs = []
for d in model_output_dirs: for d in model_output_dirs:
cl_bin_dirs.append(os.path.join(d, "opencl_bin")) cl_bin_dirs.append(os.path.join(d, "opencl_bin"))
cl_bin_dirs_str = ",".join(cl_bin_dirs) cl_bin_dirs_str = ",".join(cl_bin_dirs)
command = "bash tools/generate_production_code.sh {} {}".format( command = "bash tools/generate_production_code.sh {} {} {}".format(
cl_bin_dirs_str, int(pull_or_not)) target_soc, cl_bin_dirs_str, int(pull_or_not))
run_command(command) run_command(command)
def build_mace_run_prod(model_output_dir, tuning, global_runtime): def build_mace_run_prod(target_soc, model_output_dir, tuning, global_runtime):
if "dsp" == global_runtime: if "dsp" == global_runtime:
hexagon_mode = True hexagon_mode = True
else: else:
...@@ -117,6 +117,7 @@ def build_mace_run_prod(model_output_dir, tuning, global_runtime): ...@@ -117,6 +117,7 @@ def build_mace_run_prod(model_output_dir, tuning, global_runtime):
production_or_not = False production_or_not = False
build_mace_run(production_or_not, model_output_dir, hexagon_mode) build_mace_run(production_or_not, model_output_dir, hexagon_mode)
tuning_run( tuning_run(
target_soc,
model_output_dir, model_output_dir,
running_round=0, running_round=0,
tuning=tuning, tuning=tuning,
...@@ -125,7 +126,7 @@ def build_mace_run_prod(model_output_dir, tuning, global_runtime): ...@@ -125,7 +126,7 @@ def build_mace_run_prod(model_output_dir, tuning, global_runtime):
production_or_not = True production_or_not = True
pull_or_not = True pull_or_not = True
generate_production_code([model_output_dir], pull_or_not) generate_production_code(target_soc, [model_output_dir], pull_or_not)
build_mace_run(production_or_not, model_output_dir, hexagon_mode) build_mace_run(production_or_not, model_output_dir, hexagon_mode)
...@@ -147,13 +148,13 @@ def build_production_code(): ...@@ -147,13 +148,13 @@ def build_production_code():
run_command(command) run_command(command)
def merge_libs_and_tuning_results(output_dir, model_output_dirs): def merge_libs_and_tuning_results(target_soc, output_dir, model_output_dirs):
pull_or_not = False pull_or_not = False
generate_production_code(model_output_dirs, pull_or_not) generate_production_code(target_soc, model_output_dirs, pull_or_not)
build_production_code() build_production_code()
model_output_dirs_str = ",".join(model_output_dirs) model_output_dirs_str = ",".join(model_output_dirs)
command = "bash tools/merge_libs.sh {} {}".format(output_dir, command = "bash tools/merge_libs.sh {} {} {}".format(target_soc, output_dir,
model_output_dirs_str) model_output_dirs_str)
run_command(command) run_command(command)
...@@ -191,13 +192,6 @@ def parse_args(): ...@@ -191,13 +192,6 @@ def parse_args():
def main(unused_args): def main(unused_args):
configs = parse_model_configs() configs = parse_model_configs()
if FLAGS.mode == "build" or FLAGS.mode == "all":
# Remove previous output dirs
if not os.path.exists(FLAGS.output_dir):
os.makedirs(FLAGS.output_dir)
elif os.path.exists(os.path.join(FLAGS.output_dir, "libmace")):
shutil.rmtree(os.path.join(FLAGS.output_dir, "libmace"))
if FLAGS.mode == "validate": if FLAGS.mode == "validate":
FLAGS.round = 1 FLAGS.round = 1
FLAGS.restart_round = 1 FLAGS.restart_round = 1
...@@ -206,79 +200,88 @@ def main(unused_args): ...@@ -206,79 +200,88 @@ def main(unused_args):
os.environ["VLOG_LEVEL"] = str(configs["vlog_level"]) os.environ["VLOG_LEVEL"] = str(configs["vlog_level"])
os.environ["PROJECT_NAME"] = os.path.splitext(os.path.basename(FLAGS.config))[0] os.environ["PROJECT_NAME"] = os.path.splitext(os.path.basename(FLAGS.config))[0]
if FLAGS.mode == "build" or FLAGS.mode == "all":
# Remove previous output dirs
if not os.path.exists(FLAGS.output_dir):
os.makedirs(FLAGS.output_dir)
elif os.path.exists(os.path.join(FLAGS.output_dir, "libmace")):
shutil.rmtree(os.path.join(FLAGS.output_dir, os.environ["PROJECT_NAME"]))
os.makedirs(os.path.join(FLAGS.output_dir, os.environ["PROJECT_NAME"]))
generate_opencl_and_version_code() generate_opencl_and_version_code()
option_args = ' '.join([arg for arg in unused_args if arg.startswith('--')]) option_args = ' '.join([arg for arg in unused_args if arg.startswith('--')])
for target_abi in configs["target_abis"]: for target_abi in configs["target_abis"]:
global_runtime = get_global_runtime(configs) for target_soc in configs["target_socs"]:
# Transfer params by environment global_runtime = get_global_runtime(configs)
os.environ["TARGET_ABI"] = target_abi
model_output_dirs = []
for model_name in configs["models"]:
# Transfer params by environment # Transfer params by environment
os.environ["MODEL_TAG"] = model_name os.environ["TARGET_ABI"] = target_abi
print '=======================', model_name, '=======================' model_output_dirs = []
model_config = configs["models"][model_name] for model_name in configs["models"]:
for key in model_config: # Transfer params by environment
if key in ['input_nodes', 'output_nodes'] and isinstance(model_config[key], list): os.environ["MODEL_TAG"] = model_name
os.environ[key.upper()] = ",".join(model_config[key]) print '=======================', model_name, '======================='
elif key in ['input_shapes', 'output_shapes'] and isinstance(model_config[key], list): model_config = configs["models"][model_name]
os.environ[key.upper()] = ":".join(model_config[key]) for key in model_config:
else: if key in ['input_nodes', 'output_nodes'] and isinstance(model_config[key], list):
os.environ[key.upper()] = str(model_config[key]) os.environ[key.upper()] = ",".join(model_config[key])
elif key in ['input_shapes', 'output_shapes'] and isinstance(model_config[key], list):
md5 = hashlib.md5() os.environ[key.upper()] = ":".join(model_config[key])
md5.update(model_config["model_file_path"]) else:
model_path_digest = md5.hexdigest() os.environ[key.upper()] = str(model_config[key])
model_output_dir = "%s/%s/%s/%s" % (FLAGS.output_dir, model_name, model_path_digest, target_abi)
model_output_dirs.append(model_output_dir) md5 = hashlib.md5()
md5.update(model_config["model_file_path"])
if FLAGS.mode == "build" or FLAGS.mode == "all": model_path_digest = md5.hexdigest()
if os.path.exists(model_output_dir): model_output_dir = "%s/%s/%s/%s/%s" % (FLAGS.output_dir, model_name, model_path_digest, target_soc, target_abi)
shutil.rmtree(model_output_dir) model_output_dirs.append(model_output_dir)
os.makedirs(model_output_dir)
clear_env() if FLAGS.mode == "build" or FLAGS.mode == "all":
if os.path.exists(model_output_dir):
# Support http:// and https:// shutil.rmtree(model_output_dir)
if model_config["model_file_path"].startswith( os.makedirs(model_output_dir)
"http://") or model_config["model_file_path"].startswith("https://"): clear_env(target_soc)
os.environ["MODEL_FILE_PATH"] = model_output_dir + "/model.pb"
urllib.urlretrieve(model_config["model_file_path"], os.environ["MODEL_FILE_PATH"]) # Support http:// and https://
if model_config["model_file_path"].startswith(
if model_config["platform"] == "caffe" and (model_config["weight_file_path"].startswith( "http://") or model_config["model_file_path"].startswith("https://"):
"http://") or model_config["weight_file_path"].startswith("https://")): os.environ["MODEL_FILE_PATH"] = model_output_dir + "/model.pb"
os.environ["WEIGHT_FILE_PATH"] = model_output_dir + "/model.caffemodel" urllib.urlretrieve(model_config["model_file_path"], os.environ["MODEL_FILE_PATH"])
urllib.urlretrieve(model_config["weight_file_path"], os.environ["WEIGHT_FILE_PATH"])
if model_config["platform"] == "caffe" and (model_config["weight_file_path"].startswith(
if FLAGS.mode == "build" or FLAGS.mode == "run" or FLAGS.mode == "validate"\ "http://") or model_config["weight_file_path"].startswith("https://")):
or FLAGS.mode == "benchmark" or FLAGS.mode == "all": os.environ["WEIGHT_FILE_PATH"] = model_output_dir + "/model.caffemodel"
generate_random_input(model_output_dir) urllib.urlretrieve(model_config["weight_file_path"], os.environ["WEIGHT_FILE_PATH"])
if FLAGS.mode == "build" or FLAGS.mode == "all": if FLAGS.mode == "build" or FLAGS.mode == "run" or FLAGS.mode == "validate"\
generate_model_code() or FLAGS.mode == "benchmark" or FLAGS.mode == "all":
build_mace_run_prod(model_output_dir, FLAGS.tuning, global_runtime) generate_random_input(target_soc, model_output_dir)
if FLAGS.mode == "run" or FLAGS.mode == "validate" or FLAGS.mode == "all": if FLAGS.mode == "build" or FLAGS.mode == "all":
run_model(model_output_dir, FLAGS.round, FLAGS.restart_round, option_args) generate_model_code()
build_mace_run_prod(target_soc, model_output_dir, FLAGS.tuning, global_runtime)
if FLAGS.mode == "benchmark":
benchmark_model(model_output_dir, option_args) if FLAGS.mode == "run" or FLAGS.mode == "validate" or FLAGS.mode == "all":
run_model(target_soc, model_output_dir, FLAGS.round, FLAGS.restart_round)
if FLAGS.mode == "validate" or FLAGS.mode == "all":
validate_model(model_output_dir) if FLAGS.mode == "benchmark":
benchmark_model(model_output_dir)
if FLAGS.mode == "build" or FLAGS.mode == "merge" or FLAGS.mode == "all":
merge_libs_and_tuning_results(FLAGS.output_dir + "/" + target_abi, if FLAGS.mode == "validate" or FLAGS.mode == "all":
model_output_dirs) validate_model(model_output_dir)
if FLAGS.mode == "throughput_test": if FLAGS.mode == "build" or FLAGS.mode == "merge" or FLAGS.mode == "all":
merged_lib_file = FLAGS.output_dir + "/%s/libmace/lib/libmace_%s.a" % \ merge_libs_and_tuning_results(target_soc, FLAGS.output_dir + "/" + os.environ["PROJECT_NAME"],
(configs["target_abis"][0], os.environ["PROJECT_NAME"]) model_output_dirs)
generate_random_input(FLAGS.output_dir)
for model_name in configs["models"]: if FLAGS.mode == "throughput_test":
runtime = configs["models"][model_name]["runtime"] merged_lib_file = FLAGS.output_dir + "/%s/libmace/lib/libmace_%s.a" % \
os.environ["%s_MODEL_TAG" % runtime.upper()] = model_name (configs["target_abis"][0], os.environ["PROJECT_NAME"])
build_run_throughput_test(FLAGS.run_seconds, merged_lib_file, FLAGS.output_dir) 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)
if __name__ == "__main__": if __name__ == "__main__":
......
#!/bin/bash #!/bin/bash
Usage() { Usage() {
echo "Usage: bash tools/merge_libs.sh libmace_output_dir model_output_dirs" echo "Usage: bash tools/merge_libs.sh target_soc libmace_output_dir model_output_dirs"
} }
if [ $# -lt 2 ]; then if [ $# -lt 3 ]; then
Usage Usage
exit 1 exit 1
fi fi
...@@ -12,23 +12,33 @@ fi ...@@ -12,23 +12,33 @@ fi
CURRENT_DIR=`dirname $0` CURRENT_DIR=`dirname $0`
source ${CURRENT_DIR}/env.sh source ${CURRENT_DIR}/env.sh
LIBMACE_BUILD_DIR=$1 TARGET_SOC=$1
MODEL_OUTPUT_DIRS=$2 LIBMACE_BUILD_DIR=$2
MODEL_OUTPUT_DIRS=$3
MODEL_OUTPUT_DIRS_ARR=(${MODEL_OUTPUT_DIRS//,/ }) MODEL_OUTPUT_DIRS_ARR=(${MODEL_OUTPUT_DIRS//,/ })
MODEL_HEADER_DIR=${LIBMACE_BUILD_DIR}/libmace/include/mace/public MODEL_HEADER_DIR=${LIBMACE_BUILD_DIR}/include/mace/public
MODEL_DATA_DIR=${LIBMACE_BUILD_DIR}/libmace/data MODEL_DATA_DIR=${LIBMACE_BUILD_DIR}/data
rm -rf ${LIBMACE_BUILD_DIR}/libmace if [ ! -d "${MODEL_HEADER_DIR}" ]; then
mkdir -p ${LIBMACE_BUILD_DIR}/libmace/include/mace/public mkdir -p ${MODEL_HEADER_DIR}
mkdir -p ${LIBMACE_BUILD_DIR}/libmace/lib fi
mkdir -p ${MODEL_DATA_DIR} if [ ! -d "${LIBMACE_BUILD_DIR}/${TARGET_ABI}" ]; then
cp -rf ${MACE_SOURCE_DIR}/mace/public/*.h ${LIBMACE_BUILD_DIR}/libmace/include/mace/public/ mkdir -p ${LIBMACE_BUILD_DIR}/${TARGET_ABI}
cp ${MACE_SOURCE_DIR}/mace/core/runtime/hexagon/libhexagon_controller.so ${LIBMACE_BUILD_DIR}/libmace/lib fi
if [ ! -d "${LIBMACE_BUILD_DIR}/hexagon" ]; then
mkdir -p ${LIBMACE_BUILD_DIR}/hexagon
fi
if [ ! -d "${MODEL_DATA_DIR}" ]; then
mkdir -p ${MODEL_DATA_DIR}
fi
cp -rf ${MACE_SOURCE_DIR}/mace/public/*.h ${LIBMACE_BUILD_DIR}/include/mace/public/
cp ${MACE_SOURCE_DIR}/mace/core/runtime/hexagon/libhexagon_controller.so ${LIBMACE_BUILD_DIR}/hexagon/
LIBMACE_TEMP_DIR=`mktemp -d -t libmace.XXXX` LIBMACE_TEMP_DIR=`mktemp -d -t libmace.XXXX`
# Merge all libraries in to one # Merge all libraries in to one
echo "create ${LIBMACE_BUILD_DIR}/libmace/lib/libmace_${PROJECT_NAME}.a" > ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri echo "create ${LIBMACE_BUILD_DIR}/${TARGET_ABI}/libmace_${PROJECT_NAME}.${TARGET_SOC}.a" > ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
if [ x"$TARGET_ABI" = x"host" ]; then if [ x"$TARGET_ABI" = x"host" ]; then
echo "addlib bazel-bin/mace/codegen/libgenerated_opencl_prod.pic.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri echo "addlib bazel-bin/mace/codegen/libgenerated_opencl_prod.pic.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
......
#!/bin/bash #!/bin/bash
Usage() { Usage() {
echo "Usage: bash tools/tuning_run.sh model_output_dir round tuning production_mode" echo "Usage: bash tools/tuning_run.sh target_soc model_output_dir round tuning production_mode"
} }
if [ $# -lt 4 ]; then if [ $# -lt 7 ]; then
Usage Usage
exit 1 exit 1
fi fi
...@@ -12,15 +12,18 @@ fi ...@@ -12,15 +12,18 @@ fi
CURRENT_DIR=`dirname $0` CURRENT_DIR=`dirname $0`
source ${CURRENT_DIR}/env.sh source ${CURRENT_DIR}/env.sh
MODEL_OUTPUT_DIR=$1 TARGET_SOC=$1
ROUND=$2 MODEL_OUTPUT_DIR=$2
TUNING_OR_NOT=$3 ROUND=$3
PRODUCTION_MODE=$4 TUNING_OR_NOT=$4
RESTART_ROUND=$5 PRODUCTION_MODE=$5
OPTION_ARGS=$6 RESTART_ROUND=$6
OPTION_ARGS=$7
echo $OPTION_ARGS echo $OPTION_ARGS
DEVICE_ID=`echo_device_id_by_soc $TARGET_SOC`
if [ x"$TARGET_ABI" = x"host" ]; then if [ x"$TARGET_ABI" = x"host" ]; then
MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL \ MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL \
${MODEL_OUTPUT_DIR}/mace_run \ ${MODEL_OUTPUT_DIR}/mace_run \
...@@ -42,22 +45,22 @@ else ...@@ -42,22 +45,22 @@ else
tuning_flag=0 tuning_flag=0
fi fi
adb shell "mkdir -p ${PHONE_DATA_DIR}" || exit 1 adb -s $DEVICE_ID shell "mkdir -p ${PHONE_DATA_DIR}" || exit 1
if [ "$PRODUCTION_MODE" = 0 ]; then if [ "$PRODUCTION_MODE" = 0 ]; then
adb shell "mkdir -p ${KERNEL_DIR}" || exit 1 adb -s $DEVICE_ID shell "mkdir -p ${KERNEL_DIR}" || exit 1
fi fi
IFS=',' read -r -a INPUT_NAMES <<< "${INPUT_NODES}" IFS=',' read -r -a INPUT_NAMES <<< "${INPUT_NODES}"
for NAME in "${INPUT_NAMES[@]}";do for NAME in "${INPUT_NAMES[@]}";do
FORMATTED_NAME=$(sed s/[^[:alnum:]]/_/g <<< ${NAME}) FORMATTED_NAME=$(sed s/[^[:alnum:]]/_/g <<< ${NAME})
adb push ${MODEL_OUTPUT_DIR}/${INPUT_FILE_NAME}_${FORMATTED_NAME} ${PHONE_DATA_DIR} > /dev/null || exit 1 adb -s $DEVICE_ID push ${MODEL_OUTPUT_DIR}/${INPUT_FILE_NAME}_${FORMATTED_NAME} ${PHONE_DATA_DIR} > /dev/null || exit 1
done done
adb </dev/null push ${MODEL_OUTPUT_DIR}/mace_run ${PHONE_DATA_DIR} > /dev/null || exit 1 adb -s $DEVICE_ID </dev/null push ${MODEL_OUTPUT_DIR}/mace_run ${PHONE_DATA_DIR} > /dev/null || exit 1
if [ "$EMBED_MODEL_DATA" = 0 ]; then if [ "$EMBED_MODEL_DATA" = 0 ]; then
adb push ${MODEL_OUTPUT_DIR}/${MODEL_TAG}.data ${PHONE_DATA_DIR} > /dev/null || exit 1 adb -s $DEVICE_ID push ${MODEL_OUTPUT_DIR}/${MODEL_TAG}.data ${PHONE_DATA_DIR} > /dev/null || exit 1
fi fi
adb push mace/core/runtime/hexagon/libhexagon_controller.so ${PHONE_DATA_DIR} > /dev/null || exit 1 adb -s $DEVICE_ID push mace/core/runtime/hexagon/libhexagon_controller.so ${PHONE_DATA_DIR} > /dev/null || exit 1
ADB_CMD_STR="LD_LIBRARY_PATH=${PHONE_DATA_DIR} \ ADB_CMD_STR="LD_LIBRARY_PATH=${PHONE_DATA_DIR} \
MACE_TUNING=${tuning_flag} \ MACE_TUNING=${tuning_flag} \
...@@ -78,11 +81,11 @@ else ...@@ -78,11 +81,11 @@ else
--restart_round=$RESTART_ROUND \ --restart_round=$RESTART_ROUND \
$OPTION_ARGS; echo \\$?" $OPTION_ARGS; echo \\$?"
echo $ADB_CMD_STR echo $ADB_CMD_STR
mace_adb_output=`adb </dev/null shell "$ADB_CMD_STR"` || exit 1 mace_adb_output=`adb -s $DEVICE_ID </dev/null shell "$ADB_CMD_STR"` || exit 1
echo "$mace_adb_output" | head -n -1 echo "$mace_adb_output" | head -n -1
mace_adb_return_code=`echo "$mace_adb_output" | tail -1` mace_adb_return_code=`echo "$mace_adb_output" | tail -1`
if [ $mace_adb_return_code -ne 0 ]; then if [ ${mace_adb_return_code%?} -ne 0 ]; then
exit 1 exit 1
fi fi
fi fi
#!/bin/bash #!/bin/bash
Usage() { Usage() {
echo "Usage: bash tools/validate_tools.sh model_output_dir generate_data_or_not" echo "Usage: bash tools/validate_tools.sh target_soc model_output_dir generate_data_or_not"
} }
if [ $# -lt 2 ]; then if [ $# -lt 3 ]; then
Usage Usage
exit 1 exit 1
fi fi
...@@ -12,8 +12,11 @@ fi ...@@ -12,8 +12,11 @@ fi
CURRENT_DIR=`dirname $0` CURRENT_DIR=`dirname $0`
source ${CURRENT_DIR}/env.sh source ${CURRENT_DIR}/env.sh
MODEL_OUTPUT_DIR=$1 TARGET_SOC=$1
GENERATE_DATA_OR_NOT=$2 MODEL_OUTPUT_DIR=$2
GENERATE_DATA_OR_NOT=$3
DEVICE_ID=`echo_device_id_by_soc $TARGET_SOC`
IFS=',' read -r -a INPUT_NAMES <<< "${INPUT_NODES}" IFS=',' read -r -a INPUT_NAMES <<< "${INPUT_NODES}"
IFS=',' read -r -a OUTPUT_NAMES <<< "${OUTPUT_NODES}" IFS=',' read -r -a OUTPUT_NAMES <<< "${OUTPUT_NODES}"
...@@ -35,7 +38,7 @@ if [ "$PLATFORM" == "tensorflow" ];then ...@@ -35,7 +38,7 @@ if [ "$PLATFORM" == "tensorflow" ];then
for NAME in "${OUTPUT_NAMES[@]}";do for NAME in "${OUTPUT_NAMES[@]}";do
FORMATTED_NAME=$(sed s/[^[:alnum:]]/_/g <<< ${NAME}) FORMATTED_NAME=$(sed s/[^[:alnum:]]/_/g <<< ${NAME})
rm -rf ${MODEL_OUTPUT_DIR}/${OUTPUT_FILE_NAME}_${FORMATTED_NAME} rm -rf ${MODEL_OUTPUT_DIR}/${OUTPUT_FILE_NAME}_${FORMATTED_NAME}
adb pull ${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME}_${FORMATTED_NAME} ${MODEL_OUTPUT_DIR} > /dev/null adb -s $DEVICE_ID pull ${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME}_${FORMATTED_NAME} ${MODEL_OUTPUT_DIR} > /dev/null || exit 1
done done
fi fi
python -u tools/validate.py --platform=tensorflow \ python -u tools/validate.py --platform=tensorflow \
...@@ -77,7 +80,7 @@ elif [ "$PLATFORM" == "caffe" ];then ...@@ -77,7 +80,7 @@ elif [ "$PLATFORM" == "caffe" ];then
for NAME in "${OUTPUT_NAMES[@]}";do for NAME in "${OUTPUT_NAMES[@]}";do
FORMATTED_NAME=$(sed s/[^[:alnum:]]/_/g <<< ${NAME}) FORMATTED_NAME=$(sed s/[^[:alnum:]]/_/g <<< ${NAME})
rm -rf ${MODEL_OUTPUT_DIR}/${OUTPUT_FILE_NAME}_${FORMATTED_NAME} rm -rf ${MODEL_OUTPUT_DIR}/${OUTPUT_FILE_NAME}_${FORMATTED_NAME}
adb pull ${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME}_${FORMATTED_NAME} ${MODEL_OUTPUT_DIR} > /dev/null adb -s $DEVICE_ID pull ${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME}_${FORMATTED_NAME} ${MODEL_OUTPUT_DIR} > /dev/null || exit 1
done done
fi fi
for NAME in "${OUTPUT_NAMES[@]}";do for NAME in "${OUTPUT_NAMES[@]}";do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册