提交 50507bd1 编写于 作者: W wuchenghui

Enable valgrind memory leak check in mace_run

上级 5e02dc0e
...@@ -91,7 +91,7 @@ def parse_args(): ...@@ -91,7 +91,7 @@ def parse_args():
parser.add_argument( parser.add_argument(
"--valgrind_path", "--valgrind_path",
type=str, type=str,
default="/data/local/valgrind", default="/data/local/tmp/valgrind",
help="Valgrind install path.") help="Valgrind install path.")
parser.add_argument( parser.add_argument(
"--valgrind_args", "--valgrind_args",
......
...@@ -197,7 +197,10 @@ def tuning_run(runtime, ...@@ -197,7 +197,10 @@ def tuning_run(runtime,
omp_num_threads, omp_num_threads,
cpu_affinity_policy, cpu_affinity_policy,
gpu_perf_hint, gpu_perf_hint,
gpu_priority_hint gpu_priority_hint,
valgrind=FLAGS.valgrind,
valgrind_path=FLAGS.valgrind_path,
valgrind_args=FLAGS.valgrind_args
) )
if running_round > 0 and FLAGS.collect_report: if running_round > 0 and FLAGS.collect_report:
...@@ -213,6 +216,12 @@ def build_mace_run_prod(hexagon_mode, runtime, target_abi, ...@@ -213,6 +216,12 @@ def build_mace_run_prod(hexagon_mode, runtime, target_abi,
limit_opencl_kernel_time, phone_data_dir, limit_opencl_kernel_time, phone_data_dir,
enable_openmp): enable_openmp):
mace_run_target = "//mace/tools/validation:mace_run" mace_run_target = "//mace/tools/validation:mace_run"
strip = "always"
debug = False
if FLAGS.valgrind:
strip = "never"
debug = True
if runtime == "gpu": if runtime == "gpu":
gen_opencl_and_tuning_code(target_abi, serialno, [], False) gen_opencl_and_tuning_code(target_abi, serialno, [], False)
sh_commands.bazel_build( sh_commands.bazel_build(
...@@ -243,10 +252,12 @@ def build_mace_run_prod(hexagon_mode, runtime, target_abi, ...@@ -243,10 +252,12 @@ def build_mace_run_prod(hexagon_mode, runtime, target_abi,
True) True)
sh_commands.bazel_build( sh_commands.bazel_build(
mace_run_target, mace_run_target,
strip,
abi=target_abi, abi=target_abi,
model_tag=model_name, model_tag=model_name,
production_mode=True, production_mode=True,
hexagon_mode=hexagon_mode, hexagon_mode=hexagon_mode,
debug=debug,
enable_openmp=enable_openmp enable_openmp=enable_openmp
) )
sh_commands.update_mace_run_lib(model_output_dir, target_abi, sh_commands.update_mace_run_lib(model_output_dir, target_abi,
...@@ -255,10 +266,12 @@ def build_mace_run_prod(hexagon_mode, runtime, target_abi, ...@@ -255,10 +266,12 @@ def build_mace_run_prod(hexagon_mode, runtime, target_abi,
gen_opencl_and_tuning_code(target_abi, serialno, [], False) gen_opencl_and_tuning_code(target_abi, serialno, [], False)
sh_commands.bazel_build( sh_commands.bazel_build(
mace_run_target, mace_run_target,
strip,
abi=target_abi, abi=target_abi,
model_tag=model_name, model_tag=model_name,
production_mode=True, production_mode=True,
hexagon_mode=hexagon_mode, hexagon_mode=hexagon_mode,
debug=debug,
enable_openmp=enable_openmp enable_openmp=enable_openmp
) )
sh_commands.update_mace_run_lib(model_output_dir, target_abi, sh_commands.update_mace_run_lib(model_output_dir, target_abi,
...@@ -490,6 +503,21 @@ def parse_args(): ...@@ -490,6 +503,21 @@ def parse_args():
type=str_to_caffe_env_type, type=str_to_caffe_env_type,
default='docker', default='docker',
help="[docker | local] caffe environment.") help="[docker | local] caffe environment.")
parser.add_argument(
"--valgrind",
type=bool,
default=False,
help="Whether to use valgrind to check memory error.")
parser.add_argument(
"--valgrind_path",
type=str,
default="/data/local/tmp/valgrind",
help="Valgrind install path.")
parser.add_argument(
"--valgrind_args",
type=str,
default="",
help="Valgrind command args.")
return parser.parse_known_args() return parser.parse_known_args()
......
...@@ -216,7 +216,7 @@ def adb_run(serialno, ...@@ -216,7 +216,7 @@ def adb_run(serialno,
def adb_run_valgrind(serialno, def adb_run_valgrind(serialno,
host_bin_path, host_bin_path,
bin_name, bin_name,
valgrind_path="/data/local/valgrind", valgrind_path="/data/local/tmp/valgrind",
valgrind_args="", valgrind_args="",
args="", args="",
opencl_profiling=1, opencl_profiling=1,
...@@ -581,6 +581,9 @@ def tuning_run(abi, ...@@ -581,6 +581,9 @@ def tuning_run(abi,
cpu_affinity_policy=1, cpu_affinity_policy=1,
gpu_perf_hint=3, gpu_perf_hint=3,
gpu_priority_hint=3, gpu_priority_hint=3,
valgrind=False,
valgrind_path="/data/local/tmp/valgrind",
valgrind_args="",
input_file_name="model_input", input_file_name="model_input",
output_file_name="model_out"): output_file_name="model_out"):
print("* Run '%s' with round=%s, restart_round=%s, tuning=%s, " print("* Run '%s' with round=%s, restart_round=%s, tuning=%s, "
...@@ -637,19 +640,22 @@ def tuning_run(abi, ...@@ -637,19 +640,22 @@ def tuning_run(abi,
stdout_buff = [] stdout_buff = []
process_output = make_output_processor(stdout_buff) process_output = make_output_processor(stdout_buff)
p = sh.adb( adb_cmd = [
"-s",
serialno,
"shell",
"LD_LIBRARY_PATH=%s" % phone_data_dir, "LD_LIBRARY_PATH=%s" % phone_data_dir,
"MACE_TUNING=%s" % int(tuning), "MACE_TUNING=%s" % int(tuning),
"MACE_OUT_OF_RANGE_CHECK=%s" % int(out_of_range_check), "MACE_OUT_OF_RANGE_CHECK=%s" % int(out_of_range_check),
"MACE_CPP_MIN_VLOG_LEVEL=%s" % vlog_level, "MACE_CPP_MIN_VLOG_LEVEL=%s" % vlog_level,
"MACE_RUN_PARAMETER_PATH=%s/mace_run.config" % "MACE_RUN_PARAMETER_PATH=%s/mace_run.config" % phone_data_dir,
phone_data_dir,
"MACE_CL_PROGRAM_PATH=%s/cl_program" % phone_data_dir, "MACE_CL_PROGRAM_PATH=%s/cl_program" % phone_data_dir,
"MACE_LIMIT_OPENCL_KERNEL_TIME=%s" % "MACE_LIMIT_OPENCL_KERNEL_TIME=%s" % limit_opencl_kernel_time,
limit_opencl_kernel_time, ]
if valgrind:
adb_cmd.extend([
"VALGRIND_LIB=%s" % valgrind_path + "/lib/valgrind",
valgrind_path + "/bin/valgrind",
valgrind_args
])
adb_cmd.extend([
"%s/mace_run" % phone_data_dir, "%s/mace_run" % phone_data_dir,
"--input_node=%s" % ",".join(input_nodes), "--input_node=%s" % ",".join(input_nodes),
"--output_node=%s" % ",".join(output_nodes), "--output_node=%s" % ",".join(output_nodes),
...@@ -665,6 +671,13 @@ def tuning_run(abi, ...@@ -665,6 +671,13 @@ def tuning_run(abi,
"--cpu_affinity_policy=%s" % cpu_affinity_policy, "--cpu_affinity_policy=%s" % cpu_affinity_policy,
"--gpu_perf_hint=%s" % gpu_perf_hint, "--gpu_perf_hint=%s" % gpu_perf_hint,
"--gpu_priority_hint=%s" % gpu_priority_hint, "--gpu_priority_hint=%s" % gpu_priority_hint,
])
adb_cmd = ' '.join(adb_cmd)
p = sh.adb(
"-s",
serialno,
"shell",
adb_cmd,
_out=process_output, _out=process_output,
_bg=True, _bg=True,
_err_to_out=True) _err_to_out=True)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册