コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
ファイル: bazel_adb_run.py プロジェクト: TTWuser/ttw
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)
コード例 #4
0
ファイル: bazel_adb_run.py プロジェクト: 10gic/mace
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)