def test_ner_route_default(): unittest_setup() graph = MachineGraph("Test") machine = virtual_machine(8, 8) placements = Placements() source_vertex = SimpleMachineVertex(None) graph.add_vertex(source_vertex) placements.add_placement(Placement(source_vertex, 0, 0, 1)) target_vertex = SimpleMachineVertex(None) graph.add_vertex(target_vertex) placements.add_placement(Placement(target_vertex, 0, 2, 1)) edge = MachineEdge(source_vertex, target_vertex) graph.add_edge(edge, "Test") partition = graph.get_outgoing_partition_for_edge(edge) routes = ner_route(graph, machine, placements) source_route = routes.get_entries_for_router(0, 0)[partition] assert (not source_route.defaultable) mid_route = routes.get_entries_for_router(0, 1)[partition] print(mid_route.incoming_link, mid_route.link_ids) assert (mid_route.defaultable) end_route = routes.get_entries_for_router(0, 2)[partition] assert (not end_route.defaultable)
def setUp(self): unittest_setup() self.machine = virtual_machine(8, 8) self.mach_graph = MachineGraph("machine") self.vertices = list() self.vertex1 = get_resourced_machine_vertex(0, 1, "First vertex") self.vertex2 = get_resourced_machine_vertex(1, 5, "Second vertex") self.vertex3 = get_resourced_machine_vertex(5, 10, "Third vertex") self.vertex4 = get_resourced_machine_vertex(10, 100, "Fourth vertex") self.vertices.append(self.vertex1) self.mach_graph.add_vertex(self.vertex1) self.vertices.append(self.vertex2) self.mach_graph.add_vertex(self.vertex2) self.vertices.append(self.vertex3) self.mach_graph.add_vertex(self.vertex3) self.vertices.append(self.vertex4) self.mach_graph.add_vertex(self.vertex4) self.edges = list() edge1 = MachineEdge(self.vertex2, self.vertex3) self.edges.append(edge1) self.mach_graph.add_edge(edge1, "packet") edge2 = MachineEdge(self.vertex2, self.vertex4) self.edges.append(edge2) self.mach_graph.add_edge(edge2, "packet") edge3 = MachineEdge(self.vertex3, self.vertex4) self.edges.append(edge3) self.mach_graph.add_edge(edge3, "packet") edge4 = MachineEdge(self.vertex3, self.vertex1) self.edges.append(edge4) self.plan_n_timesteps = 100
def test_1_chip_no_pre_allocated_too_much_sdram(self): unittest_setup() machine = virtual_machine(width=8, height=8) graph = ApplicationGraph("Test") eight_meg = 8 * 1024 * 1024 # add graph vertices which reside on 0,0 for _ in range(0, 13): vertex = SimpleTestVertex( constraints=[ChipAndCoreConstraint(x=0, y=0)], n_atoms=1, fixed_sdram_value=eight_meg) vertex.splitter = SplitterSliceLegacy() graph.add_vertex(vertex) # add pre-allocated resources for cores on 0,0 pre_allocated_res = PreAllocatedResourceContainer() # run partitioner that should go boom try: splitter_partitioner(graph, machine, plan_n_time_steps=None, pre_allocated_resources=pre_allocated_res) except Exception as e: raise Exception("should have blown up here") from e
def test_no_app_level_flexible(): unittest_setup() app_graph, mac_graph, n_keys_map = create_app_less() # The number of bits is 1 + 11 + 21 = 33, so it shouldn't fail routing_info = flexible_allocate(mac_graph, n_keys_map) # all but the bottom 8 bits should be the same app_mask = 0xFFFFFF00 check_keys_for_application_partition_pairs(app_graph, mac_graph, routing_info, app_mask)
def test_big_flexible_no_fixed(): unittest_setup() app_graph, mac_graph, n_keys_map = create_big(False) # The number of bits is 1 + 11 + 21 = 33, so it shouldn't fail routing_info = flexible_allocate(mac_graph, n_keys_map) # The number of bits is 1 + 21 = 22, so it shouldn't fail # all but the bottom 21 bits should be the same app_mask = 0xFFE00000 check_keys_for_application_partition_pairs(app_graph, mac_graph, routing_info, app_mask)
def test_flexible_allocator_with_fixed(): unittest_setup() # Allocate something and check it does the right thing app_graph, mac_graph, n_keys_map = create_graphs1(True) # The number of bits is 7 + 11 = 20, so it shouldn't fail routing_info = flexible_allocate(mac_graph, n_keys_map) # all but the bottom 11 bits should be the same app_mask = 0xFFFFF800 check_keys_for_application_partition_pairs(app_graph, mac_graph, routing_info, app_mask)
def setUp(self): """ setup for all basic partitioner tests """ unittest_setup() self.vert1 = SimpleTestVertex(10, "New AbstractConstrainedVertex 1") self.vert1.splitter = SplitterSliceLegacy() self.vert2 = SimpleTestVertex(5, "New AbstractConstrainedVertex 2") self.vert2.splitter = SplitterSliceLegacy() self.vert3 = SimpleTestVertex(3, "New AbstractConstrainedVertex 3") self.vert3.splitter = SplitterSliceLegacy() self.edge1 = ApplicationEdge(self.vert1, self.vert2, label="First edge") self.edge2 = ApplicationEdge(self.vert2, self.vert1, label="Second edge") self.edge3 = ApplicationEdge(self.vert1, self.vert3, label="Third edge") self.verts = [self.vert1, self.vert2, self.vert3] self.edges = [self.edge1, self.edge2, self.edge3] self.graph = ApplicationGraph("Graph") self.graph.add_vertices(self.verts) self.graph.add_edges(self.edges, "foo") n_processors = 18 (e, ne, n, w, _, _) = range(6) links = list() links.append(Link(0, 0, e, 0, 1)) _sdram = SDRAM(128 * (2**20)) links = list() links.append(Link(0, 0, e, 1, 1)) links.append(Link(0, 1, ne, 1, 0)) links.append(Link(1, 1, n, 0, 0)) links.append(Link(1, 0, w, 0, 1)) r = Router(links, False, 1024) ip = TestBasicPartitioner.TheTestAddress chips = list() for x in range(5): for y in range(5): if x == y == 0: chips.append(Chip(x, y, n_processors, r, _sdram, 0, 0, ip)) else: chips.append(Chip(x, y, n_processors, r, _sdram, 0, 0)) self.machine = machine_from_chips(chips)
def test_big_global_fixed(): unittest_setup() app_graph, mac_graph, n_keys_map = create_big(True) # Make the call, and it should fail routing_info = global_allocate(mac_graph, n_keys_map) # 7 bit atoms is 7 as it ignore the retina mask = 0xFFFFFF80 check_masks_all_the_same(routing_info, mask) # The number of bits is 1 + 11 + 21, so it will not fit # So flexible for the retina # Others mask all bit minimum app bits (1) # all but the top 1 bits should be the same app_mask = 0xFFFC0000 check_keys_for_application_partition_pairs(app_graph, mac_graph, routing_info, app_mask)
def test_big_global_no_fixed(): unittest_setup() app_graph, mac_graph, n_keys_map = create_big(False) # Make the call, and it should fail routing_info = global_allocate(mac_graph, n_keys_map) # 1 for app 11 for machine so where possible use 20 for atoms mask = 0xFFF00000 check_masks_all_the_same(routing_info, mask) # The number of bits is 1 + 11 + 21, so it will not fit # So flexible for the retina # Others mask all bit minimum app bits (1) # all but the top 1 bits should be the same app_mask = 0x80000000 check_keys_for_application_partition_pairs(app_graph, mac_graph, routing_info, app_mask)
def test_global_allocator(): unittest_setup() # Allocate something and check it does the right thing app_graph, mac_graph, n_keys_map = create_graphs1(False) # The number of bits is 7 + 5 + 8 = 20, so it shouldn't fail routing_info = global_allocate(mac_graph, n_keys_map) # Last 8 for buts mask = 0xFFFFFF00 check_masks_all_the_same(routing_info, mask) # all but the bottom 13 bits should be the same app_mask = 0xFFFFE000 check_keys_for_application_partition_pairs(app_graph, mac_graph, routing_info, app_mask)
def test_mask_generator(): """ This checks behaviour, but with restricted bitfield sizes. """ unittest_setup() assert frozenset(get_possible_masks(2, 4, False)) == frozenset({14, 13, 11, 7}) assert frozenset(get_possible_masks(2, 4, True)) == frozenset({14}) assert frozenset(get_possible_masks(5, 4, False)) == frozenset({1, 2, 4, 8}) assert frozenset(get_possible_masks(5, 5, False)) == frozenset( {3, 5, 6, 9, 10, 12, 17, 18, 20, 24}) assert frozenset(get_possible_masks(7, 5, False)) == frozenset( {3, 5, 6, 9, 10, 12, 17, 18, 20, 24}) assert frozenset(get_possible_masks(7, 3, False)) == frozenset({0}) with pytest.raises(AssertionError): # Can't fit get_possible_masks(7, 2, False)
def test_all_working(width, height, with_down_links, with_down_chips): unittest_setup() temp_machine = virtual_machine(width=width, height=height) down_links = None if with_down_links: down_links = set() for ethernet_chip in temp_machine.ethernet_connected_chips: down_links.add((ethernet_chip.x + 1, ethernet_chip.y, 5)) down_links.add((ethernet_chip.x, ethernet_chip.y + 1, 3)) down_str = ":".join([f"{x},{y},{link}" for x, y, link in down_links]) set_config("Machine", "down_links", down_str) down_chips = None if with_down_chips: down_chips = set( (ethernet_chip.x + 1, ethernet_chip.y + 1) for ethernet_chip in temp_machine.ethernet_connected_chips) down_str = ":".join([f"{x},{y}" for x, y in down_chips]) set_config("Machine", "down_chips", down_str) _check_setup(width, height)
def setUp(self): self.original_tables = MulticastRoutingTables() original_table = UnCompressedMulticastRoutingTable(x=0, y=0) original_table.add_multicast_routing_entry( MulticastRoutingEntry(0b0000, 0b1111, [1, 2], [], False)) original_table.add_multicast_routing_entry( MulticastRoutingEntry(0b0001, 0b1111, [0], [], False)) original_table.add_multicast_routing_entry( MulticastRoutingEntry(0b0101, 0b1111, [4], [], False)) original_table.add_multicast_routing_entry( MulticastRoutingEntry(0b1000, 0b1111, [1, 2], [], False)) original_table.add_multicast_routing_entry( MulticastRoutingEntry(0b1001, 0b1111, [0], [], False)) original_table.add_multicast_routing_entry( MulticastRoutingEntry(0b1110, 0b1111, [4], [], False)) original_table.add_multicast_routing_entry( MulticastRoutingEntry(0b1100, 0b1111, [1, 2], [], False)) original_table.add_multicast_routing_entry( MulticastRoutingEntry(0b0010, 0b1011, [4, 5], [], False)) self.original_tables.add_routing_table(original_table) unittest_setup() set_config("Mapping", "router_table_compress_as_far_as_possible", True)
def test_virtual_placement(placer): unittest_setup() machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") virtual_vertex = MachineSpiNNakerLinkVertex(spinnaker_link_id=0) graph.add_vertex(virtual_vertex) extended_machine = malloc_based_chip_id_allocator(machine, graph) n_keys_map = DictBasedMachinePartitionNKeysMap() if placer == "ConnectiveBasedPlacer": placements = connective_based_placer(graph, machine, None) elif placer == "OneToOnePlacer": placements = one_to_one_placer(graph, machine, None) elif placer == "RadialPlacer": placements = radial_placer(graph, machine, None) elif placer == "SpreaderPlacer": placements = spreader_placer(graph, machine, n_keys_map, None) else: raise NotImplementedError(placer) placement = placements.get_placement_of_vertex(virtual_vertex) chip = extended_machine.get_chip_at(placement.x, placement.y) assert chip.virtual
def setUp(self): unittest_setup()
def setUp(cls): unittest_setup()
import json import time from spinn_utilities.config_holder import set_config from spinn_machine import Machine from pacman.model.routing_tables.multicast_routing_tables import (from_json) from pacman.model.routing_tables.multicast_routing_tables import (to_json) from pacman.model.routing_tables import (MulticastRoutingTables) from pacman.operations.router_compressors.routing_compression_checker import ( compare_tables) from pacman.operations.router_compressors.ordered_covering_router_compressor \ import ordered_covering_compressor from pacman.operations.router_compressors import pair_compressor from pacman.config_setup import unittest_setup unittest_setup() # original_tables = from_json("routing_table_15_25.json") original_tables = from_json("malloc_hard_routing_tables.json.gz") # original_tables = from_json("routing_tables_speader_big.json.gz") SPLIT = False if SPLIT: bad = MulticastRoutingTables() good = MulticastRoutingTables() for original in original_tables: if original.x == 19 and original.y == 22: good.add_routing_table(original) else: bad.add_routing_table(original)
def test_unreachable(): unittest_setup() set_config("Machine", "down_chips", "0,2:1,3:1,4") with pytest.raises(PacmanRoutingException): _check_setup(8, 8)
def setUpClass(cls): unittest_setup()
def setUp(self): unittest_setup() set_config("Mapping", "router_table_compress_as_far_as_possible", True)
def test_no_edge(): unittest_setup() app_graph, mac_graph, n_keys_map = create_graphs_no_edge() flexible_allocate(mac_graph, n_keys_map) routing_info = global_allocate(mac_graph, n_keys_map) assert len(list(routing_info)) == 0