Ejemplo n.º 1
0
def test_memory_instruction_generator():
    Component.reset_ids()
    cwd = Path(f"{__file__}").parent
    # base_path = f"{cwd}/../benchmarks/dfgs/tabla_generated"
    base_path = f"{cwd}/test_dfgs"
    # dfg_name = "linear_784.json"
    dfg_name = "pm_linear3.json"
    file_path = f"{base_path}/{dfg_name}"

    with open("config.json") as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    test_sched = Schedule()
    test_sched.load_dfg(file_path)
    new_arch = test_sched.schedule_graph(new_arch)

    data = [
        edge for edge in test_sched._dfg_edges
        if edge.is_src_edge and edge.dtype == "input"
    ]

    n_axi = 4
    n_lanes = 16
    pes_per_lane = 4

    meminst_gen = MemoryInstructionGenerator(data, n_axi, n_lanes,
                                             pes_per_lane, new_arch)
    meminst_gen.gen_inst(base_path)
    meminst_gen.gen_binary(base_path)
Ejemplo n.º 2
0
def test_embedded_weights():
    Component.reset_ids()
    optimizations = {
        'reorder_instr': False,
        'unused_ni_opt': True,
        'apply_reuse': True
    }
    package_name = "backprop_20_20_5"
    # package_name = "reco_138_130_10"
    dfg_name = f"{package_name}.json"
    package_path = f"{Path(f'{__file__}').parent}/../{package_name}"

    file_path = f"tests/dfg_json_files/{dfg_name}"
    cfg_path = f'config.json'
    if Path(package_path).exists():
        shutil.rmtree(package_path)
    compile(file_path,
            cfg_path,
            f"{package_name}_input_data.txt",
            f"{package_name}_input_weights.txt",
            "meta.txt",
            sort_alg="custom",
            gen_sched_file=False,
            save_data=True,
            gen_mem_instr=True,
            debug=False,
            show_ns_utilization=["ND", "NI", "NW"],
            optimizations=optimizations)
Ejemplo n.º 3
0
def test_pes_per_pu():

    Component.reset_ids()
    with open("config.json") as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    assert new_arch.pes_per_pu == 8
Ejemplo n.º 4
0
def test_depth_order():
    Component.reset_ids()

    base_path = Path(f"{__file__}").parent
    package_name = "linear54"
    dfg_file = f"{package_name}.json"
    dfg_file_path = f"{base_path}/../{dfg_file}"
    sched = Schedule()
    sched.load_dfg(dfg_file_path, sort_type="custom")
    check_graph_order(sched)
Ejemplo n.º 5
0
    def __init__(self,
                 arch_scheduled: TablaTemplate,
                 config,
                 schedule,
                 interactive_mode=False):
        # Scheduled architecture
        self.arch_scheduled = arch_scheduled[0]
        # Dictionary from PE to list of instructions
        self.instructions = self.get_instructions()
        # self.print_instructions()

        # Needed for instantiating an architecture for second time
        Component.reset_ids()
        self.architecture = TablaTemplate(config)
        self.pes = [
            pe for _, pe in
            self.architecture.category_component_dict["pe"].items()
            if isinstance(pe, PE)
        ]
        self.buses = [
            bus for _, bus in
            self.architecture.category_component_dict["bus"].items()
            if isinstance(bus, Bus)
        ]
        self.pus = [
            pu for _, pu in
            self.architecture.category_component_dict["pu"].items()
            if isinstance(pu, PU)
        ]

        # Set instructions to respective PE
        # self.set_instructions()

        # To keep track of cycles
        self.cycle = 0
        self.weight_read_cycles = 0
        self.data_read_cycles = 0

        self.interactive_mode = interactive_mode
        self.commands = {}

        # PE Global Bus Arbiters for each PU
        self.pegb_arbiters = {
            pu_id: PEGBArbiter(pu)
            for pu_id, pu in enumerate(self.pus)
        }

        # PU Global Bus Arbiter
        pugb = self.architecture.bus_map["PUGB"]
        self.pugb_arbiter = PUGBArbiter(pugb, self.architecture.num_pus)
        self.pugb = pugb

        self.schedule = schedule
Ejemplo n.º 6
0
def test_pu_creation():
    Component.reset_ids()
    num_pes = 6
    namespace_size = 256
    namespace_interim_size = 256
    test_pu = PU(num_pes, -1, namespace_size, namespace_interim_size)
    assert str(test_pu) == "Type: pu\n\t" \
                           "PE IDs: [0, 1, 2, 3, 4, 5]\n\t" \
                           "ID: 0"
    second_pu = PU(num_pes, -1, namespace_size, namespace_interim_size)
    assert str(second_pu) == "Type: pu\n\t" \
                           "PE IDs: [6, 7, 8, 9, 10, 11]\n\t" \
                           "ID: 44"
Ejemplo n.º 7
0
def test_compile():
    cleanup = True
    Component.reset_ids()
    package_name = "pm_linear55"

    base_path = f"tests/test_dfgs"

    dfg_name = f"{package_name}.json"
    file_path = f"{base_path}/{dfg_name}"
    cfg_path = f'tests/config.json'
    compile(file_path, cfg_path, "../input_data.txt", "../input_weights.txt")
    if cleanup:
        shutil.rmtree(f"{base_path}/{package_name}")
Ejemplo n.º 8
0
def test_pu_creation():
    """
    Test all the PUs are created correctly as specified in the config.
    # TODO Currently we're only checking the string representation of PU object matches, but we can do more thorough testing in the future.

    Returns
    -------
    None

    """
    Component.reset_ids()
    with open("config.json") as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    pu_map = new_arch.pu_map
    assert len(pu_map) == 8

    pu0 = pu_map["PU0"]
    assert str(pu0) == "Type: pu\n\t" \
                                "PE IDs: [0, 1, 2, 3, 4, 5, 6, 7]\n\t" \
                                "ID: 2"
    pu1 = pu_map["PU1"]
    assert str(pu1) == "Type: pu\n\t" \
                                "PE IDs: [8, 9, 10, 11, 12, 13, 14, 15]\n\t" \
                                "ID: 60"
    pu2 = pu_map["PU2"]
    assert str(pu2) == "Type: pu\n\t" \
                                "PE IDs: [16, 17, 18, 19, 20, 21, 22, 23]\n\t" \
                                "ID: 118"
    pu3 = pu_map["PU3"]
    assert str(pu3) == "Type: pu\n\t" \
                                "PE IDs: [24, 25, 26, 27, 28, 29, 30, 31]\n\t" \
                                "ID: 176"
    pu4 = pu_map["PU4"]
    assert str(pu4) == "Type: pu\n\t" \
                                "PE IDs: [32, 33, 34, 35, 36, 37, 38, 39]\n\t" \
                                "ID: 234"
    pu5 = pu_map["PU5"]
    assert str(pu5) == "Type: pu\n\t" \
                                "PE IDs: [40, 41, 42, 43, 44, 45, 46, 47]\n\t" \
                                "ID: 292"
    pu6 = pu_map["PU6"]
    assert str(pu6) == "Type: pu\n\t" \
                                "PE IDs: [48, 49, 50, 51, 52, 53, 54, 55]\n\t" \
                                "ID: 350"
    pu7 = pu_map["PU7"]
    assert str(pu7) == "Type: pu\n\t" \
                                "PE IDs: [56, 57, 58, 59, 60, 61, 62, 63]\n\t" \
                                "ID: 408"
Ejemplo n.º 9
0
def test_bus_string():
    Component.reset_ids()
    new_bus = Bus('PENB')
    assert str(new_bus) == "Type: bus\n\t" \
                           "Subtype: PENB\n\t" \
                           "ID: 0"

    second_bus = Bus('PUGB')
    assert str(new_bus) == "Type: bus\n\t" \
                           "Subtype: PENB\n\t" \
                           "ID: 0"
    assert str(second_bus) == "Type: bus\n\t" \
                           "Subtype: PUGB\n\t" \
                           "ID: 1"
Ejemplo n.º 10
0
def test_linear_dfg():
    Component.reset_ids()
    cwd = Path(f"{__file__}").parent
    base_path = f"{cwd}/test_dfgs"
    dfg_name = "linear_dfg.json"
    file_path = f"{base_path}/{dfg_name}"
    with open(f'{cwd}/config.json') as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    test_sched = Schedule()
    test_sched.load_dfg(file_path)
    test_sched.schedule_graph(new_arch)
    validate_instructions(new_arch)
Ejemplo n.º 11
0
def test_pe_creation():
    """
    # TODO: Test all PEs are created correctly as specified in the config.

    Returns
    -------
    None

    """
    Component.reset_ids()
    with open("config.json") as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    pu_map = new_arch.pu_map
Ejemplo n.º 12
0
def test_pu_global_bus_creation():
    """
    # TODO: Test the PU Global Bus is created correctly as specified in the config.

    Returns
    -------
    None

    """
    Component.reset_ids()
    with open("config.json") as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    bus_map = new_arch.bus_map
    assert len(bus_map) == 9
Ejemplo n.º 13
0
def test_class():
    Component.reset_ids()
    base_path = "./test_dfgs"
    package_name = "class_dfg"
    dfg_name = f"{package_name}.json"
    file_path = f"{base_path}/{dfg_name}"
    with open('config.json') as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    test_sched = Schedule()
    test_sched.load_dfg(file_path)
    test_sched.schedule_graph(new_arch)
    validate_instructions(new_arch)

    generate_pe_instructions(test_sched, new_arch, package_name)
Ejemplo n.º 14
0
def test_pu_neighbor_bus_creation():
    """
    # TODO: Test all PU Neighbor Buses are created correctly as specified in the config.
    # TODO: Add API to Bus that returns source PE/PU and destination PE/PU and test it here.

    Returns
    -------
    None

    """
    Component.reset_ids()
    with open("config.json") as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    bus_map = new_arch.bus_map
    assert len(bus_map) == 9
Ejemplo n.º 15
0
def test_neighbor_vals():

    Component.reset_ids()
    with open("config.json") as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    head_pe = new_arch.cat_component_map['pe'][8]
    assert new_arch.get_pe_neighbor(head_pe.component_id) == 67

    non_head_pe = new_arch.cat_component_map['pe'][15]
    assert new_arch.get_pe_neighbor(non_head_pe.component_id) == 61

    head_pu = new_arch.cat_component_map['pu'][0]
    assert new_arch.get_pu_neighbor(head_pu.component_id) == 60

    non_head_pu = new_arch.cat_component_map['pu'][7]
    assert new_arch.get_pu_neighbor(non_head_pu.component_id) == 2
Ejemplo n.º 16
0
def test_reco():
    Component.reset_ids()
    cwd = Path(f"{__file__}").parent
    base_path = f"{cwd}/test_dfgs"
    package_name = "reco_dfg"
    dfg_name = f"{package_name}.json"
    file_path = f"{base_path}/{dfg_name}"

    with open(f'{cwd}/config.json') as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    test_sched = Schedule(optimize=False)
    test_sched.load_dfg(file_path)
    test_sched.schedule_graph(new_arch)
    validate_instructions(new_arch)

    generate_pe_instructions(test_sched, new_arch, package_name)
Ejemplo n.º 17
0
def test_component_map():
    """
    # TODO: Test component map returns components correctly.

    Returns
    -------
    None

    """
    Component.reset_ids()
    with open("config.json") as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    comp_map = new_arch.component_map
    pu_map = new_arch.pu_map
    pu4_component_id = 234  # Number 233 was obtained by printing out the IDs beforehand.
    pu4 = comp_map[pu4_component_id]
    assert pu4 == pu_map["PU4"]
Ejemplo n.º 18
0
def test_benchmark_logistic():
    Component.reset_ids()
    package_name = "pm_linear55"
    cwd = Path(f"{__file__}").parent
    # base_path = f"{cwd}/../benchmarks/dfgs/tabla_generated"
    base_path = f"{cwd}/test_dfgs"

    # dfg_name = "linear_784.json"
    dfg_name = f"{package_name}.json"
    file_path = f"{base_path}/{dfg_name}"

    with open(f'{cwd}/config.json') as config_file:
        data = json.load(config_file)

    new_arch = TablaTemplate(data)
    test_sched = Schedule(optimize=True)
    test_sched.load_dfg(file_path)
    test_sched.schedule_graph(new_arch)

    test_sched.print_schedule_graph(f"{cwd}/test_outputs/schedule_{dfg_name}")
    # pprint.pprint(new_arch.namespace_utilization())

    generate_pe_instructions(test_sched, new_arch, package_name)
Ejemplo n.º 19
0
def test_find_avail_pe():
    Component.reset_ids()
    cycle = 0
    dest1_id = 0
    dest2_id = 1

    dest1_data_id = 0
    dest2_data_id = 1
    pu = PU(8, -1, 256, 256)
    pe = pu.get_pe(0)
    assert pe.category_id == 0
    pe.get_namespace('ND').insert_data(cycle, dest1_id, dest1_data_id)
    pe.get_namespace('NW').insert_data(cycle, dest2_id, dest2_data_id)
    nd_pe = pe.get_namespace('ND')
    nw_pe = pe.get_namespace('NW')

    dst1_ns = pe.get_namespace('NI').component_id
    inst = Instruction(0, '+')
    inst.add_source(dest1_id, 'ND', dest1_data_id, 0)
    inst.add_source(dest2_id, 'NW', dest2_data_id, 0)

    inst.add_dest(2, 'NI', dst1_ns, 0)
    assert pu.find_avail_pe(0, inst) == 0
Ejemplo n.º 20
0
def test_ns_string():
    Component.reset_ids()
    ns = Namespace('NG', 256)
    assert str(ns) == "Type: namespace\n\t" \
                      "Subtype: NG\n\t" \
                      "ID: 0"
Ejemplo n.º 21
0
def test_get_bus():
    Component.reset_ids()
    pu = PU(8, -1, 256, 256)
    bus = pu.get_bus('PEGB')
    assert bus.component_type == 'bus'
    assert bus.component_subtype == 'PEGB'
Ejemplo n.º 22
0
def test_are_sources_ready():
    Component.reset_ids()
    pu = PU(8, -1, 256, 256)
    assert pu.are_sources_ready(0, []) == True
Ejemplo n.º 23
0
def test_is_valid_instruction():
    Component.reset_ids()
    pu = PU(8, -1, 256, 256)
    inst = Instruction(0, '+')
    assert pu.is_valid_instruction(0, inst) == True