From 2203cdd073b744a72f810c9ac22e5fa96235efb4 Mon Sep 17 00:00:00 2001 From: wuchenghui Date: Wed, 10 Jan 2018 21:26:16 +0800 Subject: [PATCH] fix validate_gcn_dsp.sh --- mace/python/tools/binary_codegen.py | 11 +++++++++-- tools/gcn.config | 3 ++- tools/validate.py | 2 +- tools/validate_gcn_dsp.sh | 25 ++++++++++++++++++++----- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/mace/python/tools/binary_codegen.py b/mace/python/tools/binary_codegen.py index ed516f8c..9a593fe3 100644 --- a/mace/python/tools/binary_codegen.py +++ b/mace/python/tools/binary_codegen.py @@ -14,11 +14,18 @@ FLAGS = None def generate_cpp_source(): + data_map = {} + if not os.path.exists(FLAGS.binary_file): + env = jinja2.Environment(loader=jinja2.FileSystemLoader(sys.path[0])) + return env.get_template('str2vec_maps.cc.tmpl').render( + maps=data_map, + data_type='unsigned int', + variable_name=FLAGS.variable_name + ) + with open(FLAGS.binary_file, "rb") as binary_file: binary_array = np.fromfile(binary_file, dtype=np.uint8) - data_map = {} - idx = 0 size, = struct.unpack("Q", binary_array[idx:idx+8]) print size diff --git a/tools/gcn.config b/tools/gcn.config index 85ea36b3..0a4480d1 100644 --- a/tools/gcn.config +++ b/tools/gcn.config @@ -1,2 +1,3 @@ TF_INPUT_NODE=input -TF_OUTPUT_NODE=softmax/Reshape_1 \ No newline at end of file +TF_OUTPUT_NODE=softmax/Reshape_1 +TF_OUTPUT_BR_NODE=GCN/br_result_2/fcn_br \ No newline at end of file diff --git a/tools/validate.py b/tools/validate.py index 46ada3d1..9a7b8901 100644 --- a/tools/validate.py +++ b/tools/validate.py @@ -21,7 +21,7 @@ from tensorflow import gfile def generate_data(shape): np.random.seed() - data = np.random.random(shape) * -1 + data = np.random.random(shape) * 2 - 1 print FLAGS.input_file data.astype(np.float32).tofile(FLAGS.input_file) print "Generate input file done." diff --git a/tools/validate_gcn_dsp.sh b/tools/validate_gcn_dsp.sh index 5bd30df4..d1babc6f 100755 --- a/tools/validate_gcn_dsp.sh +++ b/tools/validate_gcn_dsp.sh @@ -27,6 +27,9 @@ KERNEL_DIR="${PHONE_DATA_DIR}/cl/" CODEGEN_DIR=${MACE_SOURCE_DIR}/mace/codegen MODEL_CODEGEN_DIR=${CODEGEN_DIR}/models/${MODEL_TAG} VERSION_SOURCE_PATH=${CODEGEN_DIR}/version +CL_CODEGEN_DIR=${CODEGEN_DIR}/opencl +CL_BIN_DIR=${CODEGEN_DIR}/opencl_bin +TUNING_CODEGEN_DIR=${CODEGEN_DIR}/tuning build_and_run() { @@ -71,7 +74,7 @@ mkdir -p ${MODEL_CODEGEN_DIR} bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \ --output=${MODEL_CODEGEN_DIR}/mace_gcn${IMAGE_SIZE}.cc \ --input_node=${TF_INPUT_NODE} \ - --output_node=${TF_OUTPUT_NODE} \ + --output_node=${TF_OUTPUT_BR_NODE} \ --data_type=DT_UINT8 \ --runtime=dsp \ --output_type=source \ @@ -84,18 +87,30 @@ rm -rf ${VERSION_SOURCE_PATH} mkdir -p ${VERSION_SOURCE_PATH} bash mace/tools/git/gen_version_source.sh ${VERSION_SOURCE_PATH}/version.cc -echo "Step 4: Run model on the phone with files" +echo "Step 4: Generate OpenCL binary program and config code" +rm -rf ${CL_BIN_DIR} +mkdir -p ${CL_BIN_DIR} +python mace/python/tools/opencl_codegen.py \ + --cl_binary_dir=${CL_BIN_DIR} --output_path=${CL_CODEGEN_DIR}/opencl_compiled_program.cc + +echo "Step 5: Generate tuning source file" +rm -rf ${TUNING_CODEGEN_DIR} +mkdir -p ${TUNING_CODEGEN_DIR} +python mace/python/tools/binary_codegen.py \ + --binary_file=${CL_BIN_DIR}/mace_run.config --output_path=${TUNING_CODEGEN_DIR}/tuning_params.cc + +echo "Step 6: Run model on the phone with files" build_and_run -echo "Step 5: Pull the mace run result." +echo "Step 7: Pull the mace run result." rm -rf ${MODEL_DIR}/${OUTPUT_FILE_NAME} adb