def report_run_statistics(stdout, abi, serialno, all_prepare, all_run_avg): metrics = [] for line in stdout.split('\n'): if line.startswith("benchmark:"): parts = line[10:].split(',') if len(parts) == 5: parts[1] = int(parts[1]) # framework parts[2] = int(parts[2]) # runtime parts[3] = str(float(parts[3])) # prepare parts[4] = str(float(parts[4])) # run_avg metrics.append(parts) props = sh_commands.adb_getprop_by_serialno(serialno) device_name = props.get("ro.product.model", "") target_soc = props.get("ro.board.platform", "") prepare = [] run_avg = [] for metric in metrics: record = [metric[0], device_name, target_soc, abi, RUNTIMES[int(metric[2])], metric[1]] prepare.append(record + [metric[3]]) run_avg.append(record + [metric[4]]) add_statistics(prepare, all_prepare) add_statistics(run_avg, all_run_avg)
def get_apu_version(self, enable_apu): if enable_apu: target_props = sh_commands.adb_getprop_by_serialno(self.address) target_soc = target_props["ro.board.platform"] android_ver = (int)(target_props["ro.build.version.release"]) return apu_utils.get_apu_version(enable_apu, android_ver, target_soc) else: return -1
def get_apu_ancient(self, enable_apu): if enable_apu: target_props = sh_commands.adb_getprop_by_serialno(self.address) mace_check( len(target_props) > 0, "", "When compile apu lib you need connect phone") android_ver = (int)(target_props["ro.build.version.release"]) if android_ver > 10: return False target_soc = target_props["ro.board.platform"] if target_soc.startswith("mt67"): return True return False
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_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 list_adb_device(cls): devices = [] adb_list = sh_commands.adb_devices() for adb in adb_list: prop = sh_commands.adb_getprop_by_serialno(adb) android = { YAMLKeyword.device_name: prop['ro.product.model'].replace(' ', ''), YAMLKeyword.target_abis: prop['ro.product.cpu.abilist'].split(','), YAMLKeyword.target_socs: prop['ro.board.platform'], YAMLKeyword.system: SystemType.android, YAMLKeyword.address: adb, YAMLKeyword.username: '', } if android not in devices: devices.append(android) return devices
def list_adb_device(cls): adb_list = sh.adb('devices').stdout.decode('utf-8'). \ strip().split('\n')[1:] adb_list = [tuple(pair.split('\t')) for pair in adb_list] devices = [] for adb in adb_list: prop = sh_commands.adb_getprop_by_serialno(adb[0]) android = { YAMLKeyword.device_name: prop['ro.product.model'].replace(' ', ''), YAMLKeyword.target_abis: prop['ro.product.cpu.abilist'].split(','), YAMLKeyword.target_socs: prop['ro.board.platform'], YAMLKeyword.system: SystemType.android, YAMLKeyword.address: adb[0], YAMLKeyword.username: '', } devices.append(android) return devices
def report_run_statistics(stdout, abi, serialno, model_name, device_type, output_dir, tuned): metrics = [0] * 3 for line in stdout.split('\n'): line = line.strip() parts = line.split() if len(parts) == 4 and parts[0].startswith("time"): metrics[0] = str(float(parts[1])) metrics[1] = str(float(parts[2])) metrics[2] = str(float(parts[3])) break device_name = "" target_soc = "" if abi != "host": props = sh_commands.adb_getprop_by_serialno(serialno) device_name = props.get("ro.product.model", "") target_soc = props.get("ro.board.platform", "") report_filename = output_dir + "/report.csv" if not os.path.exists(report_filename): with open(report_filename, 'w') as f: f.write("model_name,device_name,soc,abi,runtime," "init(ms),warmup(ms),run_avg(ms),tuned\n") data_str = "{model_name},{device_name},{soc},{abi},{device_type}," \ "{init},{warmup},{run_avg},{tuned}\n" \ .format(model_name=model_name, device_name=device_name, soc=target_soc, abi=abi, device_type=device_type, init=metrics[0], warmup=metrics[1], run_avg=metrics[2], tuned=tuned) with open(report_filename, 'a') as f: f.write(data_str)
def get_apu_so_paths(self): target_props = sh_commands.adb_getprop_by_serialno(self.address) target_soc = target_props["ro.board.platform"] android_ver = (int)(target_props["ro.build.version.release"]) return apu_utils.get_apu_so_paths_by_props(android_ver, target_soc)