Exemple #1
0
def do_scheduling(args):
    """
    Get optimal scheduling for given problem. Return a result schedule.
    """

    # Resource.
    arch_info, dataflow_info = extract_info(args.arch, args.dataflow)
    resource = Resource.arch(arch_info)

    # Unroll loop lower bound
    loop_lower_bound = LoopLowerBound.dataflow(dataflow_info)

    # Network.
    batch_size.init(args.batch)
    network = import_network(args.net)
    print(network)

    cost_model = CostModel(network, resource)

    # optimal schedule
    sg = ScheduleGenerator(network, resource, cost_model, loop_lower_bound)
    schedule_info_list, _ = sg.schedule_search()
    cost, access = res_parse(schedule_info_list, resource, cost_model, sg,
                             network, loop_lower_bound, args.path, arch_info)

    return schedule_info_list, cost
Exemple #2
0
def do_scheduling_woFullSpace1():
    """
    Get optimal scheduling for given problem. Return a result schedule.
    """

    # Resource.
    arch_info, dataflow_info = extract_info(arch_file, dataflow_file)
    resource = Resource.arch(arch_info)

    # Unroll loop lower bound
    loop_lower_bound = LoopLowerBound.dataflow(dataflow_info)

    # batch size = 4
    access_list = []
    batch_size.init(4)
    for net in all_networks():
        # Network.
        network = import_network(net)
        print("\n============================================")
        print(network.net_name)
        print("waiting...")
        cost_model = CostModel(network, resource)

        # optimal schedule
        sg = ScheduleGenerator(network, resource, cost_model, loop_lower_bound, d_fusion=True)
        schedule_info_list, _ = sg.schedule_search()
        print("done!\n\n")
        _, access = res_parse(schedule_info_list, resource,
                              cost_model, sg, network,
                              loop_lower_bound,
                              './result/analysis/woFullSpace1', arch_info, True, is_access=True)

        access_list.append(int(access))

    return access_list
Exemple #3
0
def do_scheduling():
    """
    Get optimal scheduling for given problem. Return a result schedule.
    """

    buffer = [128, 128, 256, 256, 512, 512, 512, 512]
    pe_array = [16, 32, 16, 32, 16, 16, 32, 64]

    # Network.
    batch_size.init(4)
    network = import_network("squeezenet")

    dataflow_info = extract_dataflow_info(
        './fusion/dataflow/dataflow_Ow_Cout.json')

    access_list = []
    energy_list = []

    for pe, bf in zip(pe_array, buffer):
        arch_file = './fusion/arch/3_level_mem_{}KB.json'.format(bf)
        arch_info = extract_arch_info(arch_file)
        arch_info["parallel_count"][0] = pe**2
        if pe == 8:
            arch_info["parallel_cost"][0] = 0.05
        resource = Resource.arch(arch_info)

        # Unroll loop lower bound
        dataflow_info["partitioning_size"] = [pe] * len(
            dataflow_info["partitioning_size"])
        loop_lower_bound = LoopLowerBound.dataflow(dataflow_info)

        print("\n===========================================================")
        print('PE-array: {}x{}, buffer size: {}(KB)'.format(pe, pe, bf))
        print("waiting...")
        cost_model = CostModel(network, resource)

        # optimal schedule
        sg = ScheduleGenerator(network, resource, cost_model, loop_lower_bound)
        schedule_info_list, _ = sg.schedule_search()
        print("done!\n\n")
        energy, access = res_parse(schedule_info_list, resource, cost_model,
                                   sg, network, loop_lower_bound,
                                   './result/pe_array', arch_info)
        energy_list.append(energy)
        access_list.append(access)

    x = [
        "16x16,128", "32x32,128", "16x16,256", "32x32,256", "8x8,512",
        "16x16,512", "32x32,512", "64x64,512"
    ]
    energy_list = np.array(energy_list) / energy_list[0]
    access_list = np.array(access_list) / access_list[0]
    plt.figure(figsize=(8, 2))
    plt.plot(x, energy_list, label="Normalized Energy")
    plt.plot(x, access_list, label="Normalized DRAM Access")
    plt.ylim(0.2, 1.2)
    plt.legend()
    plt.savefig('./result/pe_array/pe_array.png')
    plt.show()
Exemple #4
0
 def test_import_network(self):
     """
     Get import_network.
     """
     batch_size.init(3)
     for name in nns.all_networks():
         network = nns.import_network(name)
         self.assertIsInstance(network, Network)
Exemple #5
0
def do_scheduling_dnnvm():
    """
    Get optimal scheduling for given problem. Return a result schedule.
    """

    # Resource.
    arch_info, dataflow_info = extract_info(arch_file, dataflow_file)
    num_bytes = arch_info["precision"] / 8

    # Unroll loop lower bound
    loop_lower_bound = LoopLowerBound.dataflow(dataflow_info)

    # Network.
    batch_size.init(4)
    network = import_network("squeezenet")
    buffers = [
        16, 32, 64, 96, 128, 160, 192, 224, 256, 320, 384, 448, 512, 640, 768,
        896, 1024
    ]
    access_list = []
    for bf in buffers:
        if type(arch_info["capacity"][1]) is list:
            arch_info["capacity"][1] = [bf * 1024 / num_bytes] * len(
                arch_info["capacity"][1])
        else:
            arch_info["capacity"][1] = bf * 1024 / num_bytes
        resource = Resource.arch(arch_info)
        print("\n===========================================================")
        print('buffer size: {}(KB)'.format(bf))
        print("waiting...")
        cost_model = CostModel(network, resource)

        # optimal schedule
        sg = ScheduleGenerator(network,
                               resource,
                               cost_model,
                               loop_lower_bound,
                               d_fusion=True,
                               womincost=True)
        schedule_info_list, _ = sg.schedule_search()
        print("done!\n\n")
        _, access = res_parse(schedule_info_list,
                              resource,
                              cost_model,
                              sg,
                              network,
                              loop_lower_bound,
                              './result/buffer_size/dnnvm',
                              arch_info,
                              True,
                              is_access=True)
        access_list.append(access)
    x = [str(bf) for bf in buffers]
    access_list = [access / 1024 for access in access_list]
    return x, access_list
Exemple #6
0
def do_scheduling_woFusion(arch_file,
                           dataflow_file,
                           store_path,
                           is_shiDianNao=False):
    """
    Get optimal scheduling for given problem. Return a result schedule.
    """

    # Resource.
    arch_info, dataflow_info = extract_info(arch_file, dataflow_file)
    resource = Resource.arch(arch_info)

    # Unroll loop lower bound
    loop_lower_bound = LoopLowerBound.dataflow(dataflow_info)

    access_list = []
    # batch size = 4
    batch_size.init(4)
    for net in networks:
        # Network.
        network = import_network(net)
        # print("\n============================================")
        # print(network.net_name)
        # print("waiting...")
        cost_model = CostModel(network, resource)

        # optimal schedule
        sg = ScheduleGenerator(network,
                               resource,
                               cost_model,
                               loop_lower_bound,
                               wofusion=True,
                               is_shiDianNao=is_shiDianNao)
        schedule_info_list, _ = sg.schedule_search()
        # print("done!\n\n")
        _, access = res_parse(schedule_info_list,
                              resource,
                              cost_model,
                              sg,
                              network,
                              loop_lower_bound,
                              store_path,
                              arch_info,
                              True,
                              is_access=True,
                              is_print=False)
        access_list.append(access)
    return access_list
Exemple #7
0
def do_scheduling():
    """
    Get optimal scheduling for given problem. Return a result schedule.
    """

    dataflow_dir = './fusion/dataflow/'
    name = os.listdir(dataflow_dir)
    # batch size = 4
    batch_size.init(4)
    network = import_network("squeezenet")
    for rfs in [64, 512]:
        print("\n\n" + "*" * 80)
        print("\nRFs: {}B/PE".format(rfs))
        arch = './fusion/arch/3_level_mem_{}Reg.json'.format(rfs)
        for dataflow in name:
            if dataflow[-4:] == "json":
                # Resource.
                arch_info, dataflow_info = extract_info(
                    arch, dataflow_dir + dataflow)

                resource = Resource.arch(arch_info)

                # Unroll loop lower bound
                loop_lower_bound = LoopLowerBound.dataflow(dataflow_info)

                print("\n")
                print("=" * 50)
                print(dataflow[:-5])
                print("waiting...")
                cost_model = CostModel(network, resource)

                # optimal schedule
                sg = ScheduleGenerator(network, resource, cost_model,
                                       loop_lower_bound)
                schedule_info_list, _ = sg.schedule_search()
                print("done!\n\n")
                energy, access = res_parse(schedule_info_list, resource,
                                           cost_model, sg, network,
                                           loop_lower_bound,
                                           './result/dataflow', arch_info)
Exemple #8
0
def do_scheduling_efficients():
    """
    Get optimal scheduling for given problem. Return a result schedule.
    """

    # Resource.
    arch_info, dataflow_info = extract_info(arch_file, dataflow_file)
    resource = Resource.arch(arch_info)

    # Unroll loop lower bound
    loop_lower_bound = LoopLowerBound.dataflow(dataflow_info)

    # Network.
    for net in ['vggnet', 'squeezenet']:
        for bs in [1, 2, 4, 6, 8, 16, 32]:
            batch_size.init(bs)
            network = import_network(net)
            for layer in network.layer_dict:
                network[layer].nimg = bs

            print("\n============================================")
            print('{}, batch size {}:'.format(network.net_name, bs))
            print("waiting...")
            cost_model = CostModel(network, resource)

            # optimal schedule
            sg = ScheduleGenerator(network,
                                   resource,
                                   cost_model,
                                   loop_lower_bound,
                                   z_fusion=True,
                                   womincost=True)
            schedule_info_list, _ = sg.schedule_search()
            print("done!\n\n")
            energy, access = res_parse(schedule_info_list, resource,
                                       cost_model, sg, network,
                                       loop_lower_bound,
                                       './result/batch_size/efficients',
                                       arch_info, True)