diff --git a/mace/python/tools/binary_codegen.py b/mace/python/tools/binary_codegen.py index ed516f8c4edecce3e97cb33d0925abe934bce5f4..9a593fe337cd4dc959c5a4bf7b3f601474769e98 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 85ea36b3d706f4bc7518bee5c5e484d88dda9566..0a4480d196671271ec429f294b12d65fa4243b4b 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 46ada3d1606faca8db5c0de65fe025102cbc5fb9..9a7b890159af5497d721ae749cc2927d1154f431 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 5bd30df44822beca6c2f92f2b0e6c688de28a452..d1babc6f21f6aaf4b77e059114ba1d9e7849f914 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