def build_example(configs, target_abi, toolchain, enable_openmp, mace_lib_type): library_name = configs[YAMLKeyword.library_name] hexagon_mode = get_hexagon_mode(configs) build_tmp_binary_dir = get_build_binary_dir(library_name, target_abi) if os.path.exists(build_tmp_binary_dir): sh.rm("-rf", build_tmp_binary_dir) os.makedirs(build_tmp_binary_dir) symbol_hidden = True libmace_target = LIBMACE_STATIC_TARGET if mace_lib_type == MACELibType.dynamic: symbol_hidden = False libmace_target = LIBMACE_SO_TARGET sh_commands.bazel_build(libmace_target, abi=target_abi, toolchain=toolchain, enable_openmp=enable_openmp, enable_opencl=get_opencl_mode(configs), enable_quantize=get_quantize_mode(configs), hexagon_mode=hexagon_mode, address_sanitizer=flags.address_sanitizer, symbol_hidden=symbol_hidden) if os.path.exists(LIB_CODEGEN_DIR): sh.rm("-rf", LIB_CODEGEN_DIR) sh.mkdir("-p", LIB_CODEGEN_DIR) build_arg = "" if configs[YAMLKeyword.model_graph_format] == ModelFormat.code: mace_check(os.path.exists(ENGINE_CODEGEN_DIR), ModuleName.RUN, "You should convert model first.") model_lib_path = get_model_lib_output_path(library_name, target_abi) sh.cp("-f", model_lib_path, LIB_CODEGEN_DIR) build_arg = "--per_file_copt=mace/examples/cli/example.cc@-DMODEL_GRAPH_FORMAT_CODE" # noqa if mace_lib_type == MACELibType.dynamic: example_target = EXAMPLE_DYNAMIC_TARGET sh.cp("-f", LIBMACE_DYNAMIC_PATH, LIB_CODEGEN_DIR) else: example_target = EXAMPLE_STATIC_TARGET sh.cp("-f", LIBMACE_STATIC_PATH, LIB_CODEGEN_DIR) sh_commands.bazel_build(example_target, abi=target_abi, toolchain=toolchain, enable_openmp=enable_openmp, enable_opencl=get_opencl_mode(configs), enable_quantize=get_quantize_mode(configs), hexagon_mode=hexagon_mode, address_sanitizer=flags.address_sanitizer, extra_args=build_arg) target_bin = "/".join(sh_commands.bazel_target_to_bin(example_target)) sh.cp("-f", target_bin, build_tmp_binary_dir) if os.path.exists(LIB_CODEGEN_DIR): sh.rm("-rf", LIB_CODEGEN_DIR)
def main(unused_args): target_socs = None if FLAGS.target_socs != "all": target_socs = set(FLAGS.target_socs.split(',')) target_devices = sh_commands.get_target_socs_serialnos(target_socs) if not target_devices: print("No available device!") if not os.path.exists(FLAGS.output_dir): os.mkdir(FLAGS.output_dir) target_abis = FLAGS.target_abis.split(',') if FLAGS.frameworks != "all": frameworks = FLAGS.frameworks.split(',') else: frameworks = list(FRAMEWORKS) if FLAGS.runtimes != "all": runtimes = FLAGS.runtimes.split(',') else: runtimes = list(RUNTIMES) if FLAGS.model_names != "all": model_names = FLAGS.model_names.split(',') else: model_names = list(BENCHMARK_MODELS) target = FLAGS.target host_bin_path, bin_name = sh_commands.bazel_target_to_bin(target) configs = get_configs() if "MACE" in frameworks: sh_commands.get_mace(configs, FLAGS.target_abis, FLAGS.output_dir, FLAGS.build_mace) if "TFLITE" in frameworks: sh_commands.get_tflite(configs, FLAGS.output_dir) all_prepare = [] all_run_avg = [] for target_abi in target_abis: print("Prepare to run models on %s" % target_abi) if target_abi not in abi_types: print("Not supported abi: %s" % target_abi) continue if target_abi == "host": print("Unable to run target on host yet!") continue for serialno in target_devices: sh_commands.bazel_build(serialno, target, target_abi, frameworks, runtimes) if target_abi not in set( sh_commands.adb_supported_abis(serialno)): print("Skip device %s which does not support ABI %s" % (serialno, target_abi)) continue stdouts = sh_commands.adb_run( target_abi, serialno, configs, host_bin_path, bin_name, FLAGS.run_interval, FLAGS.num_threads, FLAGS.build_mace, FLAGS.max_time_per_lock, frameworks, model_names, runtimes, output_dir=FLAGS.output_dir) report_run_statistics(stdouts, target_abi, serialno, all_prepare, all_run_avg) write_all_statistics(all_prepare, all_run_avg, FLAGS.output_dir)
def main(unused_args): aibench_check(FLAGS.benchmark_option in base_pb2.BenchmarkOption.keys(), "Wrong benchmark option %s" % FLAGS.benchmark_option) benchmark_option = base_pb2.BenchmarkOption.Value(FLAGS.benchmark_option) target_socs = None if FLAGS.target_socs != "all": target_socs = set(FLAGS.target_socs.split(',')) target_devices = sh_commands.get_target_socs_serialnos(target_socs) if not target_devices: print("No available target!") if FLAGS.num_targets != 0 and FLAGS.num_targets < len(target_devices): random.shuffle(target_devices) target_devices = target_devices[:FLAGS.num_targets] if not os.path.exists(FLAGS.output_dir): os.mkdir(FLAGS.output_dir) target_abis = FLAGS.target_abis.split(',') target = FLAGS.target host_bin_path, bin_name = sh_commands.bazel_target_to_bin(target) executors, device_types, push_list, benchmark_list = \ sh_commands.prepare_all_models( FLAGS.executors, FLAGS.model_names, FLAGS.device_types, FLAGS.output_dir) configs = get_configs() input_dir = sh_commands.prepare_datasets(configs, FLAGS.output_dir, FLAGS.input_dir) if base_pb2.TFLITE in executors: sh_commands.get_tflite(configs, FLAGS.output_dir) result_files = [] for target_abi in target_abis: print("Prepare to run models on %s" % target_abi) if target_abi not in ABI_TYPES: print("Not supported abi: %s" % target_abi) continue if target_abi == "host": print("Unable to run on host yet!") continue for serialno in target_devices: sh_commands.bazel_build(serialno, target, target_abi, executors, device_types) if target_abi not in set(sh_commands.adb_supported_abis(serialno)): print("Skip device %s which does not support ABI %s" % (serialno, target_abi)) continue result_file = sh_commands.adb_run( target_abi, serialno, host_bin_path, bin_name, benchmark_option, input_dir, FLAGS.run_interval, FLAGS.num_threads, FLAGS.max_time_per_lock, push_list, benchmark_list, executors, DEVICE_PATH, FLAGS.output_dir) result_files.append(result_file) process_result(result_files)
def main(unused_args): target = FLAGS.target host_bin_path, bin_name = sh_commands.bazel_target_to_bin(target) target_abis = FLAGS.target_abis.split(',') dana_util = DanaUtil() for target_abi in target_abis: toolchain = infer_toolchain(target_abi) sh_commands.bazel_build(target, abi=target_abi, toolchain=toolchain, enable_neon=FLAGS.enable_neon, enable_quantize=FLAGS.enable_quantize, enable_bfloat16=FLAGS.enable_bfloat16, enable_fp16=FLAGS.enable_fp16, enable_rpcmem=FLAGS.enable_rpcmem, enable_hta=FLAGS.enable_hta, address_sanitizer=FLAGS.address_sanitizer, debug_mode=FLAGS.debug_mode) if FLAGS.run_target: target_devices = DeviceManager.list_devices(FLAGS.device_yml) if FLAGS.target_socs != TargetSOCTag.all and \ FLAGS.target_socs != TargetSOCTag.random: target_socs = set(FLAGS.target_socs.split(',')) target_devices = \ [dev for dev in target_devices if dev[YAMLKeyword.target_socs] in target_socs] if FLAGS.target_socs == TargetSOCTag.random: target_devices = sh_commands.choose_a_random_device( target_devices, target_abi) for dev in target_devices: if target_abi not in dev[YAMLKeyword.target_abis]: print("Skip device %s which does not support ABI %s" % (dev, target_abi)) continue device_wrapper = DeviceWrapper(dev) stdouts = device_wrapper.run( target_abi, host_bin_path, bin_name, args=FLAGS.args, opencl_profiling=True, vlog_level=FLAGS.vlog_level, out_of_range_check=True, address_sanitizer=FLAGS.address_sanitizer, simpleperf=FLAGS.simpleperf) globals()[FLAGS.stdout_processor](stdouts, dev, target_abi) if dana_util.service_available(): report_run_statistics(stdouts=stdouts, device=dev['device_name'], soc=dev['target_socs'], abi=target_abi, dana_util=dana_util)
def main(unused_args): target_socs = None if FLAGS.target_socs != "all" and FLAGS.target_socs != "random": target_socs = set(FLAGS.target_socs.split(',')) target_devices = sh_commands.get_target_socs_serialnos(target_socs) if FLAGS.target_socs == "random": unlocked_devices = \ [d for d in target_devices if not sh_commands.is_device_locked(d)] if len(unlocked_devices) > 0: target_devices = [random.choice(unlocked_devices)] else: target_devices = [random.choice(target_devices)] target = FLAGS.target host_bin_path, bin_name = sh_commands.bazel_target_to_bin(target) target_abis = FLAGS.target_abis.split(',') # generate sources sh_commands.gen_encrypted_opencl_source() sh_commands.gen_mace_version() sh_commands.gen_tuning_param_code([]) for target_abi in target_abis: sh_commands.bazel_build(target, abi=target_abi, enable_neon=FLAGS.enable_neon, address_sanitizer=FLAGS.address_sanitizer) if FLAGS.run_target: for serialno in target_devices: if target_abi not in set( sh_commands.adb_supported_abis(serialno)): print("Skip device %s which does not support ABI %s" % (serialno, target_abi)) continue stdouts = sh_commands.adb_run( target_abi, serialno, host_bin_path, bin_name, args=FLAGS.args, opencl_profiling=True, vlog_level=0, device_bin_path="/data/local/tmp/mace", out_of_range_check=True, address_sanitizer=FLAGS.address_sanitizer) device_properties = sh_commands.adb_getprop_by_serialno( serialno) globals()[FLAGS.stdout_processor](stdouts, device_properties, target_abi)
def main(unused_args): target = FLAGS.target host_bin_path, bin_name = sh_commands.bazel_target_to_bin(target) target_abis = FLAGS.target_abis.split(',') for target_abi in target_abis: toolchain = infer_toolchain(target_abi) sh_commands.bazel_build(target, abi=target_abi, toolchain=toolchain, enable_neon=FLAGS.enable_neon, address_sanitizer=FLAGS.address_sanitizer) if FLAGS.run_target: target_devices = DeviceManager.list_devices(FLAGS.device_yml) if FLAGS.target_socs != "all" and FLAGS.target_socs != "random": target_socs = set(FLAGS.target_socs.split(',')) target_devices = \ [dev for dev in target_devices if dev[YAMLKeyword.target_socs] in target_socs] if FLAGS.target_socs == "random": unlocked_devices = \ [d for d in target_devices if not sh_commands.is_device_locked(d)] if len(unlocked_devices) > 0: target_devices = [random.choice(unlocked_devices)] else: target_devices = [random.choice(target_devices)] for dev in target_devices: if target_abi not in dev[YAMLKeyword.target_abis]: print("Skip device %s which does not support ABI %s" % (dev, target_abi)) continue device_wrapper = DeviceWrapper(dev) stdouts = device_wrapper.run( target_abi, host_bin_path, bin_name, args=FLAGS.args, opencl_profiling=True, vlog_level=0, out_of_range_check=True, address_sanitizer=FLAGS.address_sanitizer, simpleperf=FLAGS.simpleperf) globals()[FLAGS.stdout_processor](stdouts, dev, target_abi)
def build_benchmark_model(configs, target_abi, toolchain, enable_openmp, mace_lib_type): library_name = configs[YAMLKeyword.library_name] hexagon_mode = get_hexagon_mode(configs) link_dynamic = mace_lib_type == MACELibType.dynamic if link_dynamic: symbol_hidden = False benchmark_target = BM_MODEL_DYNAMIC_TARGET else: symbol_hidden = True benchmark_target = BM_MODEL_STATIC_TARGET build_arg = "" if configs[YAMLKeyword.model_graph_format] == ModelFormat.code: mace_check(os.path.exists(ENGINE_CODEGEN_DIR), ModuleName.BENCHMARK, "You should convert model first.") build_arg = "--per_file_copt=mace/benchmark/benchmark_model.cc@-DMODEL_GRAPH_FORMAT_CODE" # noqa sh_commands.bazel_build(benchmark_target, abi=target_abi, toolchain=toolchain, enable_openmp=enable_openmp, enable_opencl=get_opencl_mode(configs), enable_quantize=get_quantize_mode(configs), hexagon_mode=hexagon_mode, symbol_hidden=symbol_hidden, extra_args=build_arg) # clear tmp binary dir build_tmp_binary_dir = get_build_binary_dir(library_name, target_abi) if os.path.exists(build_tmp_binary_dir): sh.rm("-rf", build_tmp_binary_dir) os.makedirs(build_tmp_binary_dir) target_bin = "/".join(sh_commands.bazel_target_to_bin(benchmark_target)) sh.cp("-f", target_bin, build_tmp_binary_dir)