From 0d467313147bcce6e666724451fe9273bf707412 Mon Sep 17 00:00:00 2001 From: yejianwu Date: Tue, 13 Feb 2018 11:21:11 +0800 Subject: [PATCH] update ANDROID_ABI to TARGET_ABI include 'host' stand for x86. update RUNTIME content, with options cpu, gpu, dsp only --- build_mace_run.sh | 5 +++-- build_production_code.sh | 10 +++++----- clear_env.sh | 5 +++-- config | 2 +- env.sh | 12 ++++-------- generate_model_code.sh | 2 +- generate_production_code.sh | 2 +- mace_tools.py | 32 ++++++++++++++++++-------------- merge_libs.sh | 2 +- tuning_run.sh | 2 +- validate_tools.sh | 2 +- 11 files changed, 39 insertions(+), 37 deletions(-) diff --git a/build_mace_run.sh b/build_mace_run.sh index 1b53a294..c635d800 100644 --- a/build_mace_run.sh +++ b/build_mace_run.sh @@ -20,7 +20,7 @@ if [ "$PRODUCTION_MODE" = 1 ]; then PRODUCTION_MODE_BUILD_FLAGS="--define production=true" fi -if [ x"$RUNTIME" = x"local" ]; then +if [ x"$TARGET_ABI" = x"host" ]; then bazel build --verbose_failures -c opt --strip always codegen:generated_models \ --copt="-std=c++11" \ --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \ @@ -44,11 +44,12 @@ else bazel build --verbose_failures -c opt --strip always examples:mace_run \ --crosstool_top=//external:android/crosstool \ --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ - --cpu=${ANDROID_ABI} \ + --cpu=${TARGET_ABI} \ --copt="-std=c++11" \ --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \ --copt="-Werror=return-type" \ --copt="-DMACE_MODEL_TAG=${MODEL_TAG}" \ + --define openmp=true \ $PRODUCTION_MODE_BUILD_FLAGS \ $HEXAGON_MODE_BUILD_FLAG || exit 1 fi diff --git a/build_production_code.sh b/build_production_code.sh index 68f32fff..884e3aae 100644 --- a/build_production_code.sh +++ b/build_production_code.sh @@ -7,7 +7,7 @@ Usage() { CURRENT_DIR=`dirname $0` source ${CURRENT_DIR}/env.sh -build_local_target() +build_host_target() { BAZEL_TARGET=$1 bazel build --verbose_failures -c opt --strip always $BAZEL_TARGET \ @@ -24,16 +24,16 @@ build_target() bazel build --verbose_failures -c opt --strip always $BAZEL_TARGET \ --crosstool_top=//external:android/crosstool \ --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ - --cpu=$ANDROID_ABI \ + --cpu=$TARGET_ABI \ --copt="-std=c++11" \ --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \ --copt="-Werror=return-type" \ --copt="-DMACE_OBFUSCATE_LITERALS" || exit 1 } -if [ x"$RUNTIME" = x"local" ]; then - build_local_target //codegen:generated_opencl_prod - build_local_target //codegen:generated_tuning_params +if [ x"$TARGET_ABI" = x"host" ]; then + build_host_target //codegen:generated_opencl_prod + build_host_target //codegen:generated_tuning_params else build_target //codegen:generated_opencl_prod build_target //codegen:generated_tuning_params diff --git a/clear_env.sh b/clear_env.sh index 40b30a4c..1c67f17a 100644 --- a/clear_env.sh +++ b/clear_env.sh @@ -1,7 +1,8 @@ CURRENT_DIR=`dirname $0` source ${CURRENT_DIR}/env.sh -if [ x"$RUNTIME" != x"local" ]; then +if [ x"$TARGET_ABI" != x"host" ]; then adb shell rm -rf $PHONE_DATA_DIR - rm -rf codegen/models codegen/opencl codegen/tuning fi + +rm -rf codegen/models codegen/opencl codegen/tuning diff --git a/config b/config index bf0382a8..8bef97ac 100644 --- a/config +++ b/config @@ -10,6 +10,6 @@ MODEL_TAG=mobile_net INPUT_SHAPE=1,64,64,3 OUTPUT_SHAPE=1,64,64,2 RUNTIME=gpu -ANDROID_ABI=armeabi-v7a ; Or 'arm64-v8a' +TARGET_ABI=armeabi-v7a ; Or 'arm64-v8a', 'host' etc. LIMIT_OPENCL_KERNEL_TIME=0 DSP_MODE=0 ; used only for dsp diff --git a/env.sh b/env.sh index 50163e5a..e18ef2b7 100644 --- a/env.sh +++ b/env.sh @@ -14,25 +14,21 @@ MODEL_CODEGEN_DIR=${CODEGEN_DIR}/models/${MODEL_TAG} CL_CODEGEN_DIR=${CODEGEN_DIR}/opencl TUNING_CODEGEN_DIR=${CODEGEN_DIR}/tuning VERSION_SOURCE_PATH=${CODEGEN_DIR}/version -GENERATED_MODEL_LIB_NAME="libgenerated_models.a" -MACE_RUNTIME=cpu if [ x"$RUNTIME" = x"dsp" ]; then DATA_TYPE="DT_UINT8" DEVICE_TYPE="HEXAGON" LIB_FOLDER_NAME="${LIB_FOLDER_NAME}_dsp" - MACE_RUNTIME=$RUNTIME elif [ x"$RUNTIME" = x"gpu" ]; then DATA_TYPE="DT_HALF" DEVICE_TYPE="OPENCL" - MACE_RUNTIME=$RUNTIME elif [ x"$RUNTIME" = x"cpu" ]; then DATA_TYPE="DT_FLOAT" DEVICE_TYPE="CPU" -elif [ x"$RUNTIME" = x"local" ];then - DATA_TYPE="DT_FLOAT" - DEVICE_TYPE="CPU" - GENERATED_MODEL_LIB_NAME="libgenerated_models.pic.a" fi +GENERATED_MODEL_LIB_NAME="libgenerated_models.a" +if [ x"$TARGET_ABI" = x"host" ]; then + GENERATED_MODEL_LIB_NAME="libgenerated_models.pic.a" +fi GENERATED_MODEL_LIB_PATH="bazel-bin/codegen/${GENERATED_MODEL_LIB_NAME}" diff --git a/generate_model_code.sh b/generate_model_code.sh index 501deea7..fc6292ce 100644 --- a/generate_model_code.sh +++ b/generate_model_code.sh @@ -14,7 +14,7 @@ bazel-bin/lib/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \ --input_node=${TF_INPUT_NODE} \ --output_node=${TF_OUTPUT_NODE} \ --data_type=${DATA_TYPE} \ - --runtime=${MACE_RUNTIME} \ + --runtime=${RUNTIME} \ --output_type=source \ --template=${LIBMACE_SOURCE_DIR}/lib/python/tools/model.template \ --model_tag=${MODEL_TAG} \ diff --git a/generate_production_code.sh b/generate_production_code.sh index 2d9caceb..f5a06288 100644 --- a/generate_production_code.sh +++ b/generate_production_code.sh @@ -19,7 +19,7 @@ if [ "$PULL_OR_NOT" = 1 ]; then CL_BIN_DIR=${CL_BIN_DIRS} rm -rf ${CL_BIN_DIR} mkdir -p ${CL_BIN_DIR} - if [ x"$RUNTIME" != x"local" ]; then + if [ x"$TARGET_ABI" != x"host" ]; then adb pull ${KERNEL_DIR}/. ${CL_BIN_DIR} adb pull ${PHONE_DATA_DIR}/mace_run.config ${CL_BIN_DIR} fi diff --git a/mace_tools.py b/mace_tools.py index 7c6c0f05..15aa5623 100644 --- a/mace_tools.py +++ b/mace_tools.py @@ -34,22 +34,26 @@ def run_command(command): def get_libs(configs): - libmace_name = "libmace" + global_target_abi = "" + global_runtime = "" + runtime_list = [] for config in configs: - if config["ANDROID_ABI"] == "armeabi-v7a": - libmace_name += "_v7" - break - elif config["ANDROID_ABI"] == "arm64-v8a": - libmace_name += "_v8" - break + if global_target_abi == "": + global_target_abi = config["TARGET_ABI"] + elif global_target_abi != config["TARGET_ABI"]: + raise Exception("Multiple TARGET_ABI found in config files!") + runtime_list.append(config["RUNTIME"]) + + if "dsp" in runtime_list: + global_runtime = "dsp" + elif "gpu" in runtime_list: + global_runtime = "gpu" + elif "cpu" in runtime_list: + global_runtime = "cpu" + else: + raise Exception("Not found available RUNTIME in config files!") - for config in configs: - if config["RUNTIME"] == "dsp": - libmace_name += "_dsp" - break - if config["RUNTIME"] == "local": - libmace_name += "_local" - break + libmace_name = "libmace-{}-{}".format(global_target_abi, global_runtime) command = "bash tools/download_and_link_lib.sh " + libmace_name run_command(command) diff --git a/merge_libs.sh b/merge_libs.sh index 59667f70..fb313516 100644 --- a/merge_libs.sh +++ b/merge_libs.sh @@ -38,7 +38,7 @@ $ANDROID_NDK_HOME/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin # Merge opencl bin and tuning result echo "create ${LIBMACE_BUILD_DIR}/libmace/lib/libmace_opencl.a" > ${LIBMACE_TEMP_DIR}/libmace_opencl.mri -if [ x"RUNTIME" = x"local" ]; then +if [ x"TARGET_ABI" = x"host" ]; then echo "addlib bazel-bin/codegen/libgenerated_opencl_prod.pic.a" >> ${LIBMACE_TEMP_DIR}/libmace_opencl.mri echo "addlib bazel-bin/codegen/libgenerated_tuning_params.pic.a" >> ${LIBMACE_TEMP_DIR}/libmace_opencl.mri else diff --git a/tuning_run.sh b/tuning_run.sh index 5a348f7e..649e60e5 100644 --- a/tuning_run.sh +++ b/tuning_run.sh @@ -17,7 +17,7 @@ ROUND=$2 TUNING_OR_NOT=$3 PRODUCTION_MODE=$4 -if [ x"$RUNTIME" = x"local" ]; then +if [ x"$TARGET_ABI" = x"host" ]; then MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL \ ${MODEL_OUTPUT_DIR}/mace_run \ --input_shape="${INPUT_SHAPE}"\ diff --git a/validate_tools.sh b/validate_tools.sh index a67eeaf6..75f93a80 100644 --- a/validate_tools.sh +++ b/validate_tools.sh @@ -26,7 +26,7 @@ else python tools/validate.py --model_file ${TF_MODEL_FILE_PATH} \ --input_file ${MODEL_OUTPUT_DIR}/${INPUT_FILE_NAME} \ --mace_out_file ${MODEL_OUTPUT_DIR}/${OUTPUT_FILE_NAME} \ - --mace_runtime ${MACE_RUNTIME} \ + --mace_runtime ${RUNTIME} \ --input_node ${TF_INPUT_NODE} \ --output_node ${TF_OUTPUT_NODE} \ --input_shape ${INPUT_SHAPE} \ -- GitLab