def test_get_vertex_from_vertex(self): """ test that the graph mapper can retrieve a vertex from a given vertex """ vertices = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) vertex1 = SimpleMachineVertex(None, "") vertex2 = SimpleMachineVertex(None, "") graph_mapper = GraphMapper() vert = SimpleTestVertex(10, "Some testing vertex") vertex_slice = Slice(0, 1) graph_mapper.add_vertex_mapping(vertex1, vertex_slice, vert) vertex_slice = Slice(2, 3) graph_mapper.add_vertex_mapping(vertex2, vertex_slice, vert) self.assertEqual( vert, graph_mapper.get_application_vertex(vertex1)) self.assertEqual( vert, graph_mapper.get_application_vertex(vertex2)) self.assertEqual( None, graph_mapper.get_application_vertex(vertices[0])) self.assertEqual( None, graph_mapper.get_application_vertex(vertices[1]))
def test_many_vertices(self): vertices = list() for i in range(20 * 17): # 51 atoms per each processor on 20 chips vertices.append( SimpleMachineVertex(0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) placements = self.bp.place(self.graph, self.graph_mapper) unorderdered_info = list() for placement in placements.placements: unorderdered_info.append( (placement.vertex.label.split(" ")[0], "{:<4}".format(placement.vertex.label.split(" ")[1]), placement.vertex.n_atoms, 'x: ', placement.x, 'y: ', placement.y, 'p: ', placement.p)) sorted_info = sorted(unorderdered_info, key=itemgetter(4, 6, 8)) pp(sorted_info) pp("{}".format("=" * 50)) sorted_info = sorted(unorderdered_info, key=lambda x: int(x[1])) pp(sorted_info)
def test_place_where_vertices_have_vertices(self): self.bp = RadialPlacer(self.machine, self.graph) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices, self.vert1) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p)
def test_with_application_vertices(self): """ Test that an application vertex's data is rewritten correctly """ # Create a default SDRAM to set the max to default SDRAM() reload_region_data = [(0, [0] * 10), (1, [1] * 20)] vertex = _TestApplicationVertex(10, reload_region_data) m_slice_1 = Slice(0, 4) m_slice_2 = Slice(5, 9) m_vertex_1 = vertex.create_machine_vertex(m_slice_1, None, None, None) m_vertex_2 = vertex.create_machine_vertex(m_slice_2, None, None, None) graph_mapper = GraphMapper() graph_mapper.add_vertex_mapping(m_vertex_1, m_slice_1, vertex) graph_mapper.add_vertex_mapping(m_vertex_2, m_slice_2, vertex) placements = Placements( [Placement(m_vertex_1, 0, 0, 1), Placement(m_vertex_2, 0, 0, 2)]) user_0_addresses = { (placement.x, placement.y, placement.p): i * 1000 for i, placement in enumerate(placements.placements) } region_addresses = [i for i in range(MAX_MEM_REGIONS)] transceiver = _MockTransceiver(user_0_addresses, region_addresses) reloader = DSGRegionReloader() reloader.__call__(transceiver, placements, "localhost", "test", False, "test", graph_mapper) regions_rewritten = transceiver.regions_rewritten # Check that the number of times the data has been regenerated is # correct self.assertEqual(vertex.regenerate_call_count, placements.n_placements) # Check that the number of regions rewritten is correct self.assertEqual(len(transceiver.regions_rewritten), placements.n_placements * len(reload_region_data)) # Check that the data rewritten is correct for i, placement in enumerate(placements.placements): user_0_address = user_0_addresses[placement.x, placement.y, placement.p] for j in range(len(reload_region_data)): pos = (i * len(reload_region_data)) + j region, data = reload_region_data[j] address = get_region_base_address_offset( user_0_address, 0) + region_addresses[region] data = bytearray(numpy.array(data, dtype="uint32").tobytes()) # Check that the base address and data written is correct self.assertEqual(regions_rewritten[pos], (address, data)) # Delete data files shutil.rmtree("test")
def test_get_vertex_from_vertex(self): """ test that the graph mapper can retrieve a vertex from a given vertex """ vertices = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) vertex1 = SimpleMachineVertex(None, "") vertex2 = SimpleMachineVertex(None, "") graph_mapper = GraphMapper() vert = SimpleTestVertex(10, "Some testing vertex") vertex_slice = Slice(0, 1) graph_mapper.add_vertex_mapping(vertex1, vertex_slice, vert) vertex_slice = Slice(2, 3) graph_mapper.add_vertex_mapping(vertex2, vertex_slice, vert) self.assertEqual( vert, graph_mapper.get_application_vertex(vertex1)) self.assertEqual( vert, graph_mapper.get_application_vertex(vertex2)) self.assertEqual( None, graph_mapper.get_application_vertex(vertices[0])) self.assertEqual( None, graph_mapper.get_application_vertex(vertices[1]))
def test_get_edge_from_machine_edge(self): """ test that tests getting a edge from a graph mapper """ vertices = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) edges = list() edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(vertices[1], vertices[1])) sube = MachineEdge(vertices[1], vertices[0]) edges.append(sube) # Create the graph mapper graph = GraphMapper() edge = SimpleTestEdge(SimpleTestVertex(10, "pre"), SimpleTestVertex(5, "post")) graph.add_edge_mapping(sube, edge) graph.add_edge_mapping(edges[0], edge) edge_from_machine_edge = graph.get_application_edge(sube) self.assertEqual(edge_from_machine_edge, edge) self.assertEqual( graph.get_application_edge(edges[0]), edge) self.assertIsNone(graph.get_application_edge(edges[1]))
def test_place_vertex_too_big_with_vertex(self): large_vertex = T_AppVertex(500, "Large vertex 500") large_machine_vertex = large_vertex.create_machine_vertex( 0, 499, get_resources_used_by_atoms(0, 499, [])) self.graph.add_vertex(large_vertex) self.graph = ApplicationGraph("Graph", [large_vertex]) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices([large_machine_vertex], large_vertex) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=[large_machine_vertex]) with self.assertRaises(PacmanPlaceException): self.bp.place(self.graph, self.graph_mapper)
def test_fill_machine(self): vertices = list() for i in range(99 * 17): # 50 atoms per each processor on 20 chips vertices.append( SimpleTestVertex(0, 50, get_resources_used_by_atoms(0, 50, []), "SimpleMachineVertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = BasicPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) self.bp.place(self.graph, self.graph_mapper)
def test_get_edge_from_machine_edge(self): """ test that tests getting a edge from a graph mapper """ vertices = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) edges = list() edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(vertices[1], vertices[1])) sube = MachineEdge(vertices[1], vertices[0]) edges.append(sube) # Create the graph mapper graph = GraphMapper() edge = SimpleTestEdge(SimpleTestVertex(10, "pre"), SimpleTestVertex(5, "post")) graph.add_edge_mapping(sube, edge) graph.add_edge_mapping(edges[0], edge) edge_from_machine_edge = graph.get_application_edge(sube) self.assertEqual(edge_from_machine_edge, edge) self.assertEqual( graph.get_application_edge(edges[0]), edge) self.assertIsNone(graph.get_application_edge(edges[1]))
def test_too_many_vertices(self): vertices = list() for i in range(100 * 17): # 50 atoms per each processor on 20 chips vertices.append( SimpleMachineVertex(0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) with self.assertRaises(PacmanPlaceException): self.bp.place(self.graph, self.graph_mapper)
def test_many_vertices(self): vertices = list() for i in range(20 * 17): # 51 atoms per each processor on 20 chips vertices.append(SimpleMachineVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) placements = self.bp.place(self.graph, self.graph_mapper) unorderdered_info = list() for placement in placements.placements: unorderdered_info.append( (placement.vertex.label.split(" ")[0], "{:<4}".format(placement.vertex.label.split(" ")[1]), placement.vertex.n_atoms, 'x: ', placement.x, 'y: ', placement.y, 'p: ', placement.p)) sorted_info = sorted(unorderdered_info, key=itemgetter(4, 6, 8)) pp(sorted_info) pp("{}".format("=" * 50)) sorted_info = sorted(unorderdered_info, key=lambda x: int(x[1])) pp(sorted_info)
def __call__(self, machine_graph, graph_mapper): """ :param machine_graph: the machine_graph whose edges are to be filtered :param graph_mapper: the graph mapper between graphs :return: a new graph mapper and machine graph """ new_machine_graph = MachineGraph(label=machine_graph.label) new_graph_mapper = GraphMapper() # create progress bar progress = ProgressBar( machine_graph.n_vertices + machine_graph.n_outgoing_edge_partitions, "Filtering edges") # add the vertices directly, as they wont be pruned. for vertex in progress.over(machine_graph.vertices, False): self._add_vertex_to_new_graph(vertex, graph_mapper, new_machine_graph, new_graph_mapper) # start checking edges to decide which ones need pruning.... for partition in progress.over(machine_graph.outgoing_edge_partitions): for edge in partition.edges: if self._is_filterable(edge, graph_mapper): logger.debug("this edge was pruned %s", edge) continue logger.debug("this edge was not pruned %s", edge) self._add_edge_to_new_graph(edge, partition, graph_mapper, new_machine_graph, new_graph_mapper) # returned the pruned graph and graph_mapper return new_machine_graph, new_graph_mapper
def test_many_vertices(self): vertices = list() for i in range(20 * 17): # 50 atoms per each processor on 20 chips vertices.append( SimpleTestVertex(0, 50, get_resources_used_by_atoms(0, 50, []), "SimpleMachineVertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = BasicPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p)
def test_place_where_vertices_have_vertices(self): self.bp = RadialPlacer(self.machine, self.graph) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices, self.vert1) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p)
def test_get_vertices_from_vertex(self): """ test getting the vertex from a graph mapper via the vertex """ vertices = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) vertex1 = SimpleMachineVertex(None, "") vertex2 = SimpleMachineVertex(None, "") edges = list() edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(vertices[1], vertices[1])) graph_mapper = GraphMapper() vert = SimpleTestVertex(4, "Some testing vertex") vertex_slice = Slice(0, 1) graph_mapper.add_vertex_mapping(vertex1, vertex_slice, vert) vertex_slice = Slice(2, 3) graph_mapper.add_vertex_mapping(vertex2, vertex_slice, vert) returned_vertices = graph_mapper.get_machine_vertices(vert) self.assertIn(vertex1, returned_vertices) self.assertIn(vertex2, returned_vertices) for v in vertices: self.assertNotIn(v, returned_vertices)
def test_deal_with_constraint_placement_vertices_have_vertices(self): self.bp = RadialPlacer(self.machine, self.graph) self.vertex1.add_constraint(ChipAndCoreConstraint(1, 5, 2)) self.assertIsInstance(self.vertex1.constraints[0], ChipAndCoreConstraint) self.vertex2.add_constraint(ChipAndCoreConstraint(3, 5, 7)) self.vertex3.add_constraint(ChipAndCoreConstraint(2, 4, 6)) self.vertex4.add_constraint(ChipAndCoreConstraint(6, 7, 16)) self.vertices = list() self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices, self.vert1) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p)
def test_place_vertex_too_big_with_vertex(self): large_vertex = T_AppVertex(500, "Large vertex 500") large_machine_vertex = large_vertex.create_machine_vertex( 0, 499, get_resources_used_by_atoms(0, 499, [])) self.graph.add_vertex(large_vertex) self.graph = ApplicationGraph("Graph", [large_vertex]) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices([large_machine_vertex], large_vertex) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=[large_machine_vertex]) with self.assertRaises(PacmanPlaceException): self.bp.place(self.graph, self.graph_mapper)
def test_get_vertices_from_vertex(self): """ test getting the vertex from a graph mapper via the vertex """ vertices = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) vertex1 = SimpleMachineVertex(None, "") vertex2 = SimpleMachineVertex(None, "") edges = list() edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(vertices[1], vertices[1])) graph_mapper = GraphMapper() vert = SimpleTestVertex(4, "Some testing vertex") vertex_slice = Slice(0, 1) graph_mapper.add_vertex_mapping(vertex1, vertex_slice, vert) vertex_slice = Slice(2, 3) graph_mapper.add_vertex_mapping(vertex2, vertex_slice, vert) returned_vertices = graph_mapper.get_machine_vertices(vert) self.assertIn(vertex1, returned_vertices) self.assertIn(vertex2, returned_vertices) for v in vertices: self.assertNotIn(v, returned_vertices)
def test_fill_machine(self): vertices = list() for i in range(99 * 17): # 50 atoms per each processor on 20 chips vertices.append(SimpleMachineVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) self.bp.place(self.graph, self.graph_mapper)
def test_too_many_vertices(self): vertices = list() for i in range(100 * 17): # 50 atoms per each processor on 20 chips vertices.append(SimpleMachineVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) with self.assertRaises(PacmanPlaceException): self.bp.place(self.graph, self.graph_mapper)
def test_many_vertices(self): vertices = list() for i in range(20 * 17): # 50 atoms per each processor on 20 chips vertices.append(SimpleTestVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "SimpleMachineVertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = BasicPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p)
def test_deal_with_constraint_placement_vertices_have_vertices(self): self.bp = RadialPlacer(self.machine, self.graph) self.vertex1.add_constraint(ChipAndCoreConstraint(1, 5, 2)) self.assertIsInstance(self.vertex1.constraints[0], ChipAndCoreConstraint) self.vertex2.add_constraint(ChipAndCoreConstraint(3, 5, 7)) self.vertex3.add_constraint(ChipAndCoreConstraint(2, 4, 6)) self.vertex4.add_constraint(ChipAndCoreConstraint(6, 7, 16)) self.vertices = list() self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices, self.vert1) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p)
def test_get_edges_from_edge(self): """ test getting the edges from a graph mapper from a edge """ vertices = list() edges = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(vertices[1], vertices[1])) sube = MachineEdge(vertices[1], vertices[0]) edges.append(sube) graph = GraphMapper() edge = SimpleTestEdge(SimpleTestVertex(10, "pre"), SimpleTestVertex(5, "post")) graph.add_edge_mapping(sube, edge) graph.add_edge_mapping(edges[0], edge) edges_from_edge = graph.get_machine_edges(edge) self.assertIn(sube, edges_from_edge) self.assertIn(edges[0], edges_from_edge) self.assertNotIn(edges[1], edges_from_edge)
def __call__(self, graph, machine): """ :param graph: The application_graph to partition :type graph:\ :py:class:`pacman.model.graphs.application.ApplicationGraph` :param machine:\ The machine with respect to which to partition the application\ graph :type machine: :py:class:`spinn_machine.Machine` :return: A machine graph :rtype:\ :py:class:`pacman.model.graphs.machine.MachineGraph` :raise pacman.exceptions.PacmanPartitionException:\ If something goes wrong with the partitioning """ ResourceTracker.check_constraints(graph.vertices) utility_calls.check_algorithm_can_support_constraints( constrained_vertices=graph.vertices, supported_constraints=[ MaxVertexAtomsConstraint, FixedVertexAtomsConstraint ], abstract_constraint_type=AbstractPartitionerConstraint) # start progress bar progress = ProgressBar(graph.n_vertices, "Partitioning graph vertices") machine_graph = MachineGraph("Machine graph for " + graph.label) graph_mapper = GraphMapper() resource_tracker = ResourceTracker(machine) # Partition one vertex at a time for vertex in progress.over(graph.vertices): self._partition_one_application_vertex(vertex, resource_tracker, machine_graph, graph_mapper) utils.generate_machine_edges(machine_graph, graph_mapper, graph) return machine_graph, graph_mapper, resource_tracker.chips_used
def test_get_edges_from_edge(self): """ test getting the edges from a graph mapper from a edge """ vertices = list() edges = list() vertices.append(SimpleMachineVertex(None, "")) vertices.append(SimpleMachineVertex(None, "")) edges.append(MachineEdge(vertices[0], vertices[1])) edges.append(MachineEdge(vertices[1], vertices[1])) sube = MachineEdge(vertices[1], vertices[0]) edges.append(sube) graph = GraphMapper() edge = SimpleTestEdge(SimpleTestVertex(10, "pre"), SimpleTestVertex(5, "post")) graph.add_edge_mapping(sube, edge) graph.add_edge_mapping(edges[0], edge) edges_from_edge = graph.get_machine_edges(edge) self.assertIn(sube, edges_from_edge) self.assertIn(edges[0], edges_from_edge) self.assertNotIn(edges[1], edges_from_edge)
def __call__(self, graph, machine, preallocated_resources=None): """ :param graph: The application_graph to partition :type graph:\ :py:class:`pacman.model.graph.application.ApplicationGraph` :param machine: The machine with respect to which to partition the\ application_graph :type machine: :py:class:`spinn_machine.Machine` :return: \ A machine_graph of partitioned vertices and partitioned edges :rtype:\ :py:class:`pacman.model.graph.machine.MachineGraph` :raise pacman.exceptions.PacmanPartitionException: \ If something goes wrong with the partitioning """ ResourceTracker.check_constraints(graph.vertices) utils.check_algorithm_can_support_constraints( constrained_vertices=graph.vertices, abstract_constraint_type=AbstractPartitionerConstraint, supported_constraints=[MaxVertexAtomsConstraint, SameAtomsAsVertexConstraint, FixedVertexAtomsConstraint]) # Load the vertices and create the machine_graph to fill machine_graph = MachineGraph( label="partitioned graph for {}".format(graph.label)) graph_mapper = GraphMapper() # sort out vertex's by placement constraints vertices = placer_utils.sort_vertices_by_known_constraints( graph.vertices) # Set up the progress n_atoms = 0 for vertex in vertices: n_atoms += vertex.n_atoms progress = ProgressBar(n_atoms, "Partitioning graph vertices") resource_tracker = ResourceTracker( machine, preallocated_resources=preallocated_resources) # Group vertices that are supposed to be the same size vertex_groups = partition_utils.get_same_size_vertex_groups(vertices) # Partition one vertex at a time for vertex in vertices: # check that the vertex hasn't already been partitioned machine_vertices = graph_mapper.get_machine_vertices(vertex) # if not, partition if machine_vertices is None: self._partition_vertex( vertex, machine_graph, graph_mapper, resource_tracker, progress, vertex_groups) progress.end() partition_utils.generate_machine_edges( machine_graph, graph_mapper, graph) return machine_graph, graph_mapper, resource_tracker.chips_used
class TestRadialPlacer(unittest.TestCase): def setUp(self): ####################################################################### # Setting up vertices, edges and graph # ####################################################################### self.vert1 = T_AppVertex(100, "New AbstractConstrainedVertex 1") self.vert2 = T_AppVertex(5, "New AbstractConstrainedVertex 2") self.vert3 = T_AppVertex(3, "New AbstractConstrainedVertex 3") self.edge1 = ApplicationEdge(self.vert1, self.vert2, "First edge") self.edge2 = ApplicationEdge(self.vert2, self.vert1, "Second edge") self.edge3 = ApplicationEdge(self.vert1, self.vert3, "Third edge") self.verts = [self.vert1, self.vert2, self.vert3] self.edges = [self.edge1, self.edge2, self.edge3] self.graph = ApplicationGraph("Graph", self.verts, self.edges) ####################################################################### # Setting up machine # ####################################################################### flops = 1000 (_, _, n, _, _, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) _sdram = SDRAM(128 * (2**20)) ip = "192.168.240.253" chips = list() for x in range(10): for y in range(10): links = list() links.append(Link(x, y, 0, (x + 1) % 10, y, n, n)) links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s)) links.append(Link(x, y, 2, x, (y + 1) % 10, n, n)) links.append(Link(x, y, 3, (x - 1) % 10, y, s, s)) links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n)) links.append(Link(x, y, 5, x, (y - 1) % 10, s, s)) r = Router(links, False, 100, 1024) chips.append(Chip(x, y, processors, r, _sdram, ip)) self.machine = Machine(chips) ####################################################################### # Setting up graph and graph_mapper # ####################################################################### self.vertices = list() self.vertex1 = T_MachineVertex(0, 1, get_resources_used_by_atoms(0, 1, []), "First vertex") self.vertex2 = T_MachineVertex(1, 5, get_resources_used_by_atoms(1, 5, []), "Second vertex") self.vertex3 = T_MachineVertex(5, 10, get_resources_used_by_atoms(5, 10, []), "Third vertex") self.vertex4 = T_MachineVertex( 10, 100, get_resources_used_by_atoms(10, 100, []), "Fourth vertex") self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices) @unittest.skip("demonstrating skipping") def test_new_basic_placer(self): self.bp = RadialPlacer(self.machine, self.graph) self.assertEqual(self.bp._machine, self.machine) self.assertEqual(self.bp._graph, self.graph) @unittest.skip("demonstrating skipping") def test_place_where_vertices_dont_have_vertex(self): self.bp = RadialPlacer(self.machine, self.graph) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p) @unittest.skip("demonstrating skipping") def test_place_where_vertices_have_vertices(self): self.bp = RadialPlacer(self.machine, self.graph) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices, self.vert1) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p) @unittest.skip("demonstrating skipping") def test_place_vertex_too_big_with_vertex(self): large_vertex = T_AppVertex(500, "Large vertex 500") large_machine_vertex = large_vertex.create_machine_vertex( 0, 499, get_resources_used_by_atoms(0, 499, [])) self.graph.add_vertex(large_vertex) self.graph = ApplicationGraph("Graph", [large_vertex]) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices([large_machine_vertex], large_vertex) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=[large_machine_vertex]) with self.assertRaises(PacmanPlaceException): self.bp.place(self.graph, self.graph_mapper) @unittest.skip("demonstrating skipping") def test_try_to_place(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_deal_with_constraint_placement_vertices_dont_have_vertex(self): self.bp = RadialPlacer(self.machine, self.graph) self.vertex1.add_constraint(ChipAndCoreConstraint(8, 3, 2)) self.assertIsInstance(self.vertex1.constraints[0], ChipAndCoreConstraint) self.vertex2.add_constraint(ChipAndCoreConstraint(3, 5, 7)) self.vertex3.add_constraint(ChipAndCoreConstraint(2, 4, 6)) self.vertex4.add_constraint(ChipAndCoreConstraint(6, 4, 16)) self.vertices = list() self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p) @unittest.skip("demonstrating skipping") def test_deal_with_constraint_placement_vertices_have_vertices(self): self.bp = RadialPlacer(self.machine, self.graph) self.vertex1.add_constraint(ChipAndCoreConstraint(1, 5, 2)) self.assertIsInstance(self.vertex1.constraints[0], ChipAndCoreConstraint) self.vertex2.add_constraint(ChipAndCoreConstraint(3, 5, 7)) self.vertex3.add_constraint(ChipAndCoreConstraint(2, 4, 6)) self.vertex4.add_constraint(ChipAndCoreConstraint(6, 7, 16)) self.vertices = list() self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices, self.vert1) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p) @unittest.skip("demonstrating skipping") def test_unsupported_non_placer_constraint(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_unsupported_placer_constraint(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_unsupported_placer_constraints(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_many_vertices(self): vertices = list() for i in range(20 * 17): # 51 atoms per each processor on 20 chips vertices.append( SimpleMachineVertex(0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) placements = self.bp.place(self.graph, self.graph_mapper) unorderdered_info = list() for placement in placements.placements: unorderdered_info.append( (placement.vertex.label.split(" ")[0], "{:<4}".format(placement.vertex.label.split(" ")[1]), placement.vertex.n_atoms, 'x: ', placement.x, 'y: ', placement.y, 'p: ', placement.p)) sorted_info = sorted(unorderdered_info, key=itemgetter(4, 6, 8)) pp(sorted_info) pp("{}".format("=" * 50)) sorted_info = sorted(unorderdered_info, key=lambda x: int(x[1])) pp(sorted_info) @unittest.skip("demonstrating skipping") def test_too_many_vertices(self): vertices = list() for i in range(100 * 17): # 50 atoms per each processor on 20 chips vertices.append( SimpleMachineVertex(0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) with self.assertRaises(PacmanPlaceException): self.bp.place(self.graph, self.graph_mapper) @unittest.skip("demonstrating skipping") def test_fill_machine(self): vertices = list() for i in range(99 * 17): # 50 atoms per each processor on 20 chips vertices.append( SimpleMachineVertex(0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) self.bp.place(self.graph, self.graph_mapper)
def setUp(self): ####################################################################### # Setting up vertices, edges and graph # ####################################################################### self.vert1 = T_AppVertex(100, "New AbstractConstrainedVertex 1") self.vert2 = T_AppVertex(5, "New AbstractConstrainedVertex 2") self.vert3 = T_AppVertex(3, "New AbstractConstrainedVertex 3") self.edge1 = ApplicationEdge(self.vert1, self.vert2, "First edge") self.edge2 = ApplicationEdge(self.vert2, self.vert1, "Second edge") self.edge3 = ApplicationEdge(self.vert1, self.vert3, "Third edge") self.verts = [self.vert1, self.vert2, self.vert3] self.edges = [self.edge1, self.edge2, self.edge3] self.graph = ApplicationGraph("Graph", self.verts, self.edges) ####################################################################### # Setting up machine # ####################################################################### flops = 1000 (_, _, n, _, _, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) _sdram = SDRAM(128*(2**20)) ip = "192.168.240.253" chips = list() for x in range(10): for y in range(10): links = list() links.append(Link(x, y, 0, (x + 1) % 10, y, n, n)) links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s)) links.append(Link(x, y, 2, x, (y + 1) % 10, n, n)) links.append(Link(x, y, 3, (x - 1) % 10, y, s, s)) links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n)) links.append(Link(x, y, 5, x, (y - 1) % 10, s, s)) r = Router(links, False, 100, 1024) chips.append(Chip(x, y, processors, r, _sdram, ip)) self.machine = Machine(chips) ####################################################################### # Setting up graph and graph_mapper # ####################################################################### self.vertices = list() self.vertex1 = T_MachineVertex( 0, 1, get_resources_used_by_atoms(0, 1, []), "First vertex") self.vertex2 = T_MachineVertex( 1, 5, get_resources_used_by_atoms(1, 5, []), "Second vertex") self.vertex3 = T_MachineVertex( 5, 10, get_resources_used_by_atoms(5, 10, []), "Third vertex") self.vertex4 = T_MachineVertex( 10, 100, get_resources_used_by_atoms(10, 100, []), "Fourth vertex") self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices)
class TestRadialPlacer(unittest.TestCase): def setUp(self): ####################################################################### # Setting up vertices, edges and graph # ####################################################################### self.vert1 = T_AppVertex(100, "New AbstractConstrainedVertex 1") self.vert2 = T_AppVertex(5, "New AbstractConstrainedVertex 2") self.vert3 = T_AppVertex(3, "New AbstractConstrainedVertex 3") self.edge1 = ApplicationEdge(self.vert1, self.vert2, "First edge") self.edge2 = ApplicationEdge(self.vert2, self.vert1, "Second edge") self.edge3 = ApplicationEdge(self.vert1, self.vert3, "Third edge") self.verts = [self.vert1, self.vert2, self.vert3] self.edges = [self.edge1, self.edge2, self.edge3] self.graph = ApplicationGraph("Graph", self.verts, self.edges) ####################################################################### # Setting up machine # ####################################################################### flops = 1000 (_, _, n, _, _, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) _sdram = SDRAM(128*(2**20)) ip = "192.168.240.253" chips = list() for x in range(10): for y in range(10): links = list() links.append(Link(x, y, 0, (x + 1) % 10, y, n, n)) links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s)) links.append(Link(x, y, 2, x, (y + 1) % 10, n, n)) links.append(Link(x, y, 3, (x - 1) % 10, y, s, s)) links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n)) links.append(Link(x, y, 5, x, (y - 1) % 10, s, s)) r = Router(links, False, 100, 1024) chips.append(Chip(x, y, processors, r, _sdram, ip)) self.machine = Machine(chips) ####################################################################### # Setting up graph and graph_mapper # ####################################################################### self.vertices = list() self.vertex1 = T_MachineVertex( 0, 1, get_resources_used_by_atoms(0, 1, []), "First vertex") self.vertex2 = T_MachineVertex( 1, 5, get_resources_used_by_atoms(1, 5, []), "Second vertex") self.vertex3 = T_MachineVertex( 5, 10, get_resources_used_by_atoms(5, 10, []), "Third vertex") self.vertex4 = T_MachineVertex( 10, 100, get_resources_used_by_atoms(10, 100, []), "Fourth vertex") self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices) @unittest.skip("demonstrating skipping") def test_new_basic_placer(self): self.bp = RadialPlacer(self.machine, self.graph) self.assertEqual(self.bp._machine, self.machine) self.assertEqual(self.bp._graph, self.graph) @unittest.skip("demonstrating skipping") def test_place_where_vertices_dont_have_vertex(self): self.bp = RadialPlacer(self.machine, self.graph) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p) @unittest.skip("demonstrating skipping") def test_place_where_vertices_have_vertices(self): self.bp = RadialPlacer(self.machine, self.graph) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices, self.vert1) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p) @unittest.skip("demonstrating skipping") def test_place_vertex_too_big_with_vertex(self): large_vertex = T_AppVertex(500, "Large vertex 500") large_machine_vertex = large_vertex.create_machine_vertex( 0, 499, get_resources_used_by_atoms(0, 499, [])) self.graph.add_vertex(large_vertex) self.graph = ApplicationGraph("Graph", [large_vertex]) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices([large_machine_vertex], large_vertex) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=[large_machine_vertex]) with self.assertRaises(PacmanPlaceException): self.bp.place(self.graph, self.graph_mapper) @unittest.skip("demonstrating skipping") def test_try_to_place(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_deal_with_constraint_placement_vertices_dont_have_vertex(self): self.bp = RadialPlacer(self.machine, self.graph) self.vertex1.add_constraint(ChipAndCoreConstraint(8, 3, 2)) self.assertIsInstance(self.vertex1.constraints[0], ChipAndCoreConstraint) self.vertex2.add_constraint(ChipAndCoreConstraint(3, 5, 7)) self.vertex3.add_constraint(ChipAndCoreConstraint(2, 4, 6)) self.vertex4.add_constraint(ChipAndCoreConstraint(6, 4, 16)) self.vertices = list() self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p) @unittest.skip("demonstrating skipping") def test_deal_with_constraint_placement_vertices_have_vertices(self): self.bp = RadialPlacer(self.machine, self.graph) self.vertex1.add_constraint(ChipAndCoreConstraint(1, 5, 2)) self.assertIsInstance(self.vertex1.constraints[0], ChipAndCoreConstraint) self.vertex2.add_constraint(ChipAndCoreConstraint(3, 5, 7)) self.vertex3.add_constraint(ChipAndCoreConstraint(2, 4, 6)) self.vertex4.add_constraint(ChipAndCoreConstraint(6, 7, 16)) self.vertices = list() self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices, self.vert1) placements = self.bp.place(self.graph, self.graph_mapper) for placement in placements.placements: print(placement.vertex.label, placement.vertex.n_atoms, 'x:', placement.x, 'y:', placement.y, 'p:', placement.p) @unittest.skip("demonstrating skipping") def test_unsupported_non_placer_constraint(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_unsupported_placer_constraint(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_unsupported_placer_constraints(self): self.assertEqual(True, False, "Test not implemented yet") @unittest.skip("demonstrating skipping") def test_many_vertices(self): vertices = list() for i in range(20 * 17): # 51 atoms per each processor on 20 chips vertices.append(SimpleMachineVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) placements = self.bp.place(self.graph, self.graph_mapper) unorderdered_info = list() for placement in placements.placements: unorderdered_info.append( (placement.vertex.label.split(" ")[0], "{:<4}".format(placement.vertex.label.split(" ")[1]), placement.vertex.n_atoms, 'x: ', placement.x, 'y: ', placement.y, 'p: ', placement.p)) sorted_info = sorted(unorderdered_info, key=itemgetter(4, 6, 8)) pp(sorted_info) pp("{}".format("=" * 50)) sorted_info = sorted(unorderdered_info, key=lambda x: int(x[1])) pp(sorted_info) @unittest.skip("demonstrating skipping") def test_too_many_vertices(self): vertices = list() for i in range(100 * 17): # 50 atoms per each processor on 20 chips vertices.append(SimpleMachineVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) with self.assertRaises(PacmanPlaceException): self.bp.place(self.graph, self.graph_mapper) @unittest.skip("demonstrating skipping") def test_fill_machine(self): vertices = list() for i in range(99 * 17): # 50 atoms per each processor on 20 chips vertices.append(SimpleMachineVertex( 0, 50, get_resources_used_by_atoms(0, 50, []), "vertex " + str(i))) self.graph = ApplicationGraph("Graph", vertices) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(vertices) self.bp = RadialPlacer(self.machine, self.graph) self.graph = MachineGraph(vertices=vertices) self.bp.place(self.graph, self.graph_mapper)
def test_write_synaptic_matrix_and_master_population_table(self): MockSimulator.setup() # Add an sdram so maxsdram is high enough SDRAM(10000) default_config_paths = os.path.join( os.path.dirname(abstract_spinnaker_common.__file__), AbstractSpiNNakerCommon.CONFIG_FILE_NAME) config = conf_loader.load_config( AbstractSpiNNakerCommon.CONFIG_FILE_NAME, default_config_paths) config.set("Simulation", "one_to_one_connection_dtcm_max_bytes", 40) machine_time_step = 1000.0 pre_app_vertex = SimpleApplicationVertex(10) pre_vertex = SimpleMachineVertex(resources=None) pre_vertex_slice = Slice(0, 9) post_app_vertex = SimpleApplicationVertex(10) post_vertex = SimpleMachineVertex(resources=None) post_vertex_slice = Slice(0, 9) post_slice_index = 0 one_to_one_connector_1 = OneToOneConnector(None) one_to_one_connector_1.set_projection_information( pre_app_vertex, post_app_vertex, None, machine_time_step) one_to_one_connector_2 = OneToOneConnector(None) one_to_one_connector_2.set_projection_information( pre_app_vertex, post_app_vertex, None, machine_time_step) all_to_all_connector = AllToAllConnector(None) all_to_all_connector.set_projection_information( pre_app_vertex, post_app_vertex, None, machine_time_step) direct_synapse_information_1 = SynapseInformation( one_to_one_connector_1, SynapseDynamicsStatic(), 0, 1.5, 1.0) direct_synapse_information_2 = SynapseInformation( one_to_one_connector_2, SynapseDynamicsStatic(), 1, 2.5, 2.0) all_to_all_synapse_information = SynapseInformation( all_to_all_connector, SynapseDynamicsStatic(), 0, 4.5, 4.0) app_edge = ProjectionApplicationEdge( pre_app_vertex, post_app_vertex, direct_synapse_information_1) app_edge.add_synapse_information(direct_synapse_information_2) app_edge.add_synapse_information(all_to_all_synapse_information) machine_edge = ProjectionMachineEdge( app_edge.synapse_information, pre_vertex, post_vertex) partition_name = "TestPartition" graph = MachineGraph("Test") graph.add_vertex(pre_vertex) graph.add_vertex(post_vertex) graph.add_edge(machine_edge, partition_name) graph_mapper = GraphMapper() graph_mapper.add_vertex_mapping( pre_vertex, pre_vertex_slice, pre_app_vertex) graph_mapper.add_vertex_mapping( post_vertex, post_vertex_slice, post_app_vertex) graph_mapper.add_edge_mapping(machine_edge, app_edge) weight_scales = [4096.0, 4096.0] key = 0 routing_info = RoutingInfo() routing_info.add_partition_info(PartitionRoutingInfo( [BaseKeyAndMask(key, 0xFFFFFFF0)], graph.get_outgoing_edge_partition_starting_at_vertex( pre_vertex, partition_name))) temp_spec = tempfile.mktemp() spec_writer = FileDataWriter(temp_spec) spec = DataSpecificationGenerator(spec_writer, None) master_pop_sz = 1000 master_pop_region = 0 all_syn_block_sz = 2000 synapse_region = 1 direct_region = 2 spec.reserve_memory_region(master_pop_region, master_pop_sz) spec.reserve_memory_region(synapse_region, all_syn_block_sz) synaptic_manager = SynapticManager( n_synapse_types=2, ring_buffer_sigma=5.0, spikes_per_second=100.0, config=config) # UGLY but the mock transceiver NEED generate_on_machine be False abstract_generate_connector_on_machine.IS_PYNN_8 = False synaptic_manager._write_synaptic_matrix_and_master_population_table( spec, [post_vertex_slice], post_slice_index, post_vertex, post_vertex_slice, all_syn_block_sz, weight_scales, master_pop_region, synapse_region, direct_region, routing_info, graph_mapper, graph, machine_time_step) spec.end_specification() spec_writer.close() spec_reader = FileDataReader(temp_spec) executor = DataSpecificationExecutor( spec_reader, master_pop_sz + all_syn_block_sz) executor.execute() master_pop_table = executor.get_region(0) synaptic_matrix = executor.get_region(1) direct_matrix = executor.get_region(2) all_data = bytearray() all_data.extend(master_pop_table.region_data[ :master_pop_table.max_write_pointer]) all_data.extend(synaptic_matrix.region_data[ :synaptic_matrix.max_write_pointer]) all_data.extend(direct_matrix.region_data[ :direct_matrix.max_write_pointer]) master_pop_table_address = 0 synaptic_matrix_address = master_pop_table.max_write_pointer direct_synapses_address = ( synaptic_matrix_address + synaptic_matrix.max_write_pointer) direct_synapses_address += 4 indirect_synapses_address = synaptic_matrix_address placement = Placement(None, 0, 0, 1) transceiver = MockTransceiverRawData(all_data) # Get the master population table details items = synaptic_manager._poptable_type\ .extract_synaptic_matrix_data_location( key, master_pop_table_address, transceiver, placement.x, placement.y) # The first entry should be direct, but the rest should be indirect; # the second is potentially direct, but has been restricted by the # restriction on the size of the direct matrix assert len(items) == 3 assert items[0][2] assert not items[1][2] assert not items[2][2] data_1, row_len_1 = synaptic_manager._retrieve_synaptic_block( transceiver=transceiver, placement=placement, master_pop_table_address=master_pop_table_address, indirect_synapses_address=indirect_synapses_address, direct_synapses_address=direct_synapses_address, key=key, n_rows=pre_vertex_slice.n_atoms, index=0, using_extra_monitor_cores=False) connections_1 = synaptic_manager._synapse_io.read_synapses( direct_synapse_information_1, pre_vertex_slice, post_vertex_slice, row_len_1, 0, 2, weight_scales, data_1, None, app_edge.n_delay_stages, machine_time_step) # The first matrix is a 1-1 matrix, so row length is 1 assert row_len_1 == 1 # Check that all the connections have the right weight and delay assert len(connections_1) == post_vertex_slice.n_atoms assert all([conn["weight"] == 1.5 for conn in connections_1]) assert all([conn["delay"] == 1.0 for conn in connections_1]) data_2, row_len_2 = synaptic_manager._retrieve_synaptic_block( transceiver=transceiver, placement=placement, master_pop_table_address=master_pop_table_address, indirect_synapses_address=indirect_synapses_address, direct_synapses_address=direct_synapses_address, key=key, n_rows=pre_vertex_slice.n_atoms, index=1, using_extra_monitor_cores=False) connections_2 = synaptic_manager._synapse_io.read_synapses( direct_synapse_information_2, pre_vertex_slice, post_vertex_slice, row_len_2, 0, 2, weight_scales, data_2, None, app_edge.n_delay_stages, machine_time_step) # The second matrix is a 1-1 matrix, so row length is 1 assert row_len_2 == 1 # Check that all the connections have the right weight and delay assert len(connections_2) == post_vertex_slice.n_atoms assert all([conn["weight"] == 2.5 for conn in connections_2]) assert all([conn["delay"] == 2.0 for conn in connections_2]) data_3, row_len_3 = synaptic_manager._retrieve_synaptic_block( transceiver=transceiver, placement=placement, master_pop_table_address=master_pop_table_address, indirect_synapses_address=indirect_synapses_address, direct_synapses_address=direct_synapses_address, key=key, n_rows=pre_vertex_slice.n_atoms, index=2, using_extra_monitor_cores=False) connections_3 = synaptic_manager._synapse_io.read_synapses( all_to_all_synapse_information, pre_vertex_slice, post_vertex_slice, row_len_3, 0, 2, weight_scales, data_3, None, app_edge.n_delay_stages, machine_time_step) # The third matrix is an all-to-all matrix, so length is n_atoms assert row_len_3 == post_vertex_slice.n_atoms # Check that all the connections have the right weight and delay assert len(connections_3) == \ post_vertex_slice.n_atoms * pre_vertex_slice.n_atoms assert all([conn["weight"] == 4.5 for conn in connections_3]) assert all([conn["delay"] == 4.0 for conn in connections_3])
def test_create_new_mapper(self): """ test creating a empty graph mapper """ GraphMapper()
def __call__( self, graph, machine, plan_n_timesteps, preallocated_resources=None): """ :param graph: The application_graph to partition :type graph:\ :py:class:`pacman.model.graph.application.ApplicationGraph` :param machine: The machine with respect to which to partition the\ application_graph :type machine: :py:class:`spinn_machine.Machine` :param plan_n_timesteps: number of timesteps to plan for :type plan_n_timesteps: int :return: \ A machine_graph of partitioned vertices and partitioned edges :rtype:\ :py:class:`pacman.model.graph.machine.MachineGraph` :raise pacman.exceptions.PacmanPartitionException: \ If something goes wrong with the partitioning """ ResourceTracker.check_constraints(graph.vertices) utils.check_algorithm_can_support_constraints( constrained_vertices=graph.vertices, abstract_constraint_type=AbstractPartitionerConstraint, supported_constraints=[MaxVertexAtomsConstraint, SameAtomsAsVertexConstraint, FixedVertexAtomsConstraint]) # Load the vertices and create the machine_graph to fill machine_graph = MachineGraph( label="partitioned graph for {}".format(graph.label)) graph_mapper = GraphMapper() # sort out vertex's by placement constraints vertices = sort_vertices_by_known_constraints(graph.vertices) # Set up the progress n_atoms = 0 for vertex in vertices: n_atoms += vertex.n_atoms progress = ProgressBar(n_atoms, "Partitioning graph vertices") resource_tracker = ResourceTracker( machine, plan_n_timesteps, preallocated_resources=preallocated_resources) # Group vertices that are supposed to be the same size vertex_groups = get_same_size_vertex_groups(vertices) # Partition one vertex at a time for vertex in vertices: # check that the vertex hasn't already been partitioned machine_vertices = graph_mapper.get_machine_vertices(vertex) # if not, partition if machine_vertices is None: self._partition_vertex( vertex, plan_n_timesteps, machine_graph, graph_mapper, resource_tracker, progress, vertex_groups) progress.end() generate_machine_edges(machine_graph, graph_mapper, graph) return machine_graph, graph_mapper, resource_tracker.chips_used
def test_write_synaptic_matrix_and_master_population_table(self): MockSimulator.setup() default_config_paths = os.path.join( os.path.dirname(abstract_spinnaker_common.__file__), AbstractSpiNNakerCommon.CONFIG_FILE_NAME) config = conf_loader.load_config( AbstractSpiNNakerCommon.CONFIG_FILE_NAME, default_config_paths) config.set("Simulation", "one_to_one_connection_dtcm_max_bytes", 40) machine_time_step = 1000.0 pre_app_vertex = SimpleApplicationVertex(10) pre_vertex = SimpleMachineVertex(resources=None) pre_vertex_slice = Slice(0, 9) post_app_vertex = SimpleApplicationVertex(10) post_vertex = SimpleMachineVertex(resources=None) post_vertex_slice = Slice(0, 9) post_slice_index = 0 one_to_one_connector_1 = OneToOneConnector(None) one_to_one_connector_1.set_projection_information( pre_app_vertex, post_app_vertex, None, machine_time_step) one_to_one_connector_1.set_weights_and_delays(1.5, 1.0) one_to_one_connector_2 = OneToOneConnector(None) one_to_one_connector_2.set_projection_information( pre_app_vertex, post_app_vertex, None, machine_time_step) one_to_one_connector_2.set_weights_and_delays(2.5, 2.0) all_to_all_connector = AllToAllConnector(None) all_to_all_connector.set_projection_information( pre_app_vertex, post_app_vertex, None, machine_time_step) all_to_all_connector.set_weights_and_delays(4.5, 4.0) direct_synapse_information_1 = SynapseInformation( one_to_one_connector_1, SynapseDynamicsStatic(), 0) direct_synapse_information_2 = SynapseInformation( one_to_one_connector_2, SynapseDynamicsStatic(), 1) all_to_all_synapse_information = SynapseInformation( all_to_all_connector, SynapseDynamicsStatic(), 0) app_edge = ProjectionApplicationEdge(pre_app_vertex, post_app_vertex, direct_synapse_information_1) app_edge.add_synapse_information(direct_synapse_information_2) app_edge.add_synapse_information(all_to_all_synapse_information) machine_edge = ProjectionMachineEdge(app_edge.synapse_information, pre_vertex, post_vertex) partition_name = "TestPartition" graph = MachineGraph("Test") graph.add_vertex(pre_vertex) graph.add_vertex(post_vertex) graph.add_edge(machine_edge, partition_name) graph_mapper = GraphMapper() graph_mapper.add_vertex_mapping(pre_vertex, pre_vertex_slice, pre_app_vertex) graph_mapper.add_vertex_mapping(post_vertex, post_vertex_slice, post_app_vertex) graph_mapper.add_edge_mapping(machine_edge, app_edge) weight_scales = [4096.0, 4096.0] key = 0 routing_info = RoutingInfo() routing_info.add_partition_info( PartitionRoutingInfo( [BaseKeyAndMask(key, 0xFFFFFFF0)], graph.get_outgoing_edge_partition_starting_at_vertex( pre_vertex, partition_name))) temp_spec = tempfile.mktemp() spec_writer = FileDataWriter(temp_spec) spec = DataSpecificationGenerator(spec_writer, None) master_pop_sz = 1000 master_pop_region = 0 all_syn_block_sz = 2000 synapse_region = 1 spec.reserve_memory_region(master_pop_region, master_pop_sz) spec.reserve_memory_region(synapse_region, all_syn_block_sz) synapse_type = MockSynapseType() synaptic_manager = SynapticManager(synapse_type=synapse_type, ring_buffer_sigma=5.0, spikes_per_second=100.0, config=config) synaptic_manager._write_synaptic_matrix_and_master_population_table( spec, [post_vertex_slice], post_slice_index, post_vertex, post_vertex_slice, all_syn_block_sz, weight_scales, master_pop_region, synapse_region, routing_info, graph_mapper, graph, machine_time_step) spec.end_specification() spec_writer.close() spec_reader = FileDataReader(temp_spec) executor = DataSpecificationExecutor(spec_reader, master_pop_sz + all_syn_block_sz) executor.execute() master_pop_table = executor.get_region(0) synaptic_matrix = executor.get_region(1) all_data = bytearray() all_data.extend( master_pop_table.region_data[:master_pop_table.max_write_pointer]) all_data.extend( synaptic_matrix.region_data[:synaptic_matrix.max_write_pointer]) master_pop_table_address = 0 synaptic_matrix_address = master_pop_table.max_write_pointer direct_synapses_address = struct.unpack_from( "<I", synaptic_matrix.region_data)[0] direct_synapses_address += synaptic_matrix_address + 8 indirect_synapses_address = synaptic_matrix_address + 4 placement = Placement(None, 0, 0, 1) transceiver = MockTransceiverRawData(all_data) # Get the master population table details items = synaptic_manager._poptable_type\ .extract_synaptic_matrix_data_location( key, master_pop_table_address, transceiver, placement.x, placement.y) # The first entry should be direct, but the rest should be indirect; # the second is potentially direct, but has been restricted by the # restriction on the size of the direct matrix assert len(items) == 3 # TODO: This has been changed because direct matrices are disabled! assert not items[0][2] assert not items[1][2] assert not items[2][2] data_1, row_len_1 = synaptic_manager._retrieve_synaptic_block( transceiver=transceiver, placement=placement, master_pop_table_address=master_pop_table_address, indirect_synapses_address=indirect_synapses_address, direct_synapses_address=direct_synapses_address, key=key, n_rows=pre_vertex_slice.n_atoms, index=0, using_extra_monitor_cores=False) connections_1 = synaptic_manager._synapse_io.read_synapses( direct_synapse_information_1, pre_vertex_slice, post_vertex_slice, row_len_1, 0, 2, weight_scales, data_1, None, app_edge.n_delay_stages, machine_time_step) # The first matrix is a 1-1 matrix, so row length is 1 assert row_len_1 == 1 # Check that all the connections have the right weight and delay assert len(connections_1) == post_vertex_slice.n_atoms assert all([conn["weight"] == 1.5 for conn in connections_1]) assert all([conn["delay"] == 1.0 for conn in connections_1]) data_2, row_len_2 = synaptic_manager._retrieve_synaptic_block( transceiver=transceiver, placement=placement, master_pop_table_address=master_pop_table_address, indirect_synapses_address=indirect_synapses_address, direct_synapses_address=direct_synapses_address, key=key, n_rows=pre_vertex_slice.n_atoms, index=1, using_extra_monitor_cores=False) connections_2 = synaptic_manager._synapse_io.read_synapses( direct_synapse_information_2, pre_vertex_slice, post_vertex_slice, row_len_2, 0, 2, weight_scales, data_2, None, app_edge.n_delay_stages, machine_time_step) # The second matrix is a 1-1 matrix, so row length is 1 assert row_len_2 == 1 # Check that all the connections have the right weight and delay assert len(connections_2) == post_vertex_slice.n_atoms assert all([conn["weight"] == 2.5 for conn in connections_2]) assert all([conn["delay"] == 2.0 for conn in connections_2]) data_3, row_len_3 = synaptic_manager._retrieve_synaptic_block( transceiver=transceiver, placement=placement, master_pop_table_address=master_pop_table_address, indirect_synapses_address=indirect_synapses_address, direct_synapses_address=direct_synapses_address, key=key, n_rows=pre_vertex_slice.n_atoms, index=2, using_extra_monitor_cores=False) connections_3 = synaptic_manager._synapse_io.read_synapses( all_to_all_synapse_information, pre_vertex_slice, post_vertex_slice, row_len_3, 0, 2, weight_scales, data_3, None, app_edge.n_delay_stages, machine_time_step) # The third matrix is an all-to-all matrix, so length is n_atoms assert row_len_3 == post_vertex_slice.n_atoms # Check that all the connections have the right weight and delay assert len(connections_3) == \ post_vertex_slice.n_atoms * pre_vertex_slice.n_atoms assert all([conn["weight"] == 4.5 for conn in connections_3]) assert all([conn["delay"] == 4.0 for conn in connections_3])
def test_local_verts_go_to_local_lpgs_app_graph(self): machine = VirtualMachine(width=12, height=12, with_wrap_arounds=True) graph = MachineGraph("Test") app_graph = ApplicationGraph("Test") app_graph_mapper = GraphMapper() default_params = { 'use_prefix': False, 'key_prefix': None, 'prefix_type': None, 'message_type': EIEIOType.KEY_32_BIT, 'right_shift': 0, 'payload_as_time_stamps': True, 'use_payload_prefix': True, 'payload_prefix': None, 'payload_right_shift': 0, 'number_of_packets_sent_per_time_step': 0, 'hostname': None, 'port': None, 'strip_sdp': None, 'board_address': None, 'tag': None} # data stores needed by algorithm live_packet_gatherers = dict() extended = dict(default_params) extended.update({'partition_id': "EVENTS"}) default_params_holder = LivePacketGatherParameters(**extended) live_packet_gatherers[default_params_holder] = list() live_packet_gatherers_to_vertex_mapping = defaultdict(dict) placements = Placements() # add LPG's (1 for each Ethernet connected chip for chip in machine.ethernet_connected_chips: vertex = LivePacketGather(**default_params) app_graph.add_vertex(vertex) vertex_slice = Slice(0, 0) resources_required = vertex.get_resources_used_by_atoms( vertex_slice) mac_vertex = vertex.create_machine_vertex( vertex_slice, resources_required) graph.add_vertex(mac_vertex) app_graph_mapper.add_vertex_mapping( mac_vertex, Slice(0, 0), vertex) placements.add_placement( Placement(x=chip.x, y=chip.y, p=2, vertex=mac_vertex)) live_packet_gatherers_to_vertex_mapping[ default_params_holder][chip.x, chip.y] = mac_vertex # tracker of wirings verts_expected = defaultdict(list) positions = list() positions.append([0, 0, 0, 0]) positions.append([4, 4, 0, 0]) positions.append([1, 1, 0, 0]) positions.append([2, 2, 0, 0]) positions.append([8, 4, 8, 4]) positions.append([11, 4, 8, 4]) positions.append([4, 11, 4, 8]) positions.append([4, 8, 4, 8]) positions.append([0, 11, 8, 4]) positions.append([11, 11, 4, 8]) positions.append([8, 8, 4, 8]) positions.append([4, 0, 0, 0]) positions.append([7, 7, 0, 0]) # add graph vertices which reside on areas of the machine to ensure # spread over boards. for x, y, eth_x, eth_y in positions: vertex = SimpleTestVertex(1) app_graph.add_vertex(vertex) vertex_slice = Slice(0, 0) resources_required = vertex.get_resources_used_by_atoms( vertex_slice) mac_vertex = vertex.create_machine_vertex( vertex_slice, resources_required) graph.add_vertex(mac_vertex) app_graph_mapper.add_vertex_mapping( mac_vertex, vertex_slice, vertex) live_packet_gatherers[default_params_holder].append(vertex) verts_expected[eth_x, eth_y].append(mac_vertex) placements.add_placement( Placement(x=x, y=y, p=5, vertex=mac_vertex)) # run edge inserter that should go boom edge_inserter = InsertEdgesToLivePacketGatherers() edge_inserter( live_packet_gatherer_parameters=live_packet_gatherers, placements=placements, live_packet_gatherers_to_vertex_mapping=( live_packet_gatherers_to_vertex_mapping), machine=machine, machine_graph=graph, application_graph=app_graph, graph_mapper=app_graph_mapper) # verify edges are in the right place for chip in machine.ethernet_connected_chips: edges = graph.get_edges_ending_at_vertex( live_packet_gatherers_to_vertex_mapping[ default_params_holder][chip.x, chip.y]) for edge in edges: self.assertIn(edge.pre_vertex, verts_expected[chip.x, chip.y]) # check app graph for chip in machine.ethernet_connected_chips: app_verts_expected = [ app_graph_mapper.get_application_vertex(vert) for vert in verts_expected[chip.x, chip.y]] lpg_machine = live_packet_gatherers_to_vertex_mapping[ default_params_holder][chip.x, chip.y] lpg_app = app_graph_mapper.get_application_vertex(lpg_machine) edges = app_graph.get_edges_ending_at_vertex(lpg_app) for edge in edges: self.assertIn(edge.pre_vertex, app_verts_expected)
def test_local_verts_go_to_local_lpgs_app_graph(self): machine = VirtualMachine(width=12, height=12, with_wrap_arounds=True) graph = MachineGraph("Test") app_graph = ApplicationGraph("Test") app_graph_mapper = GraphMapper() default_params = { 'use_prefix': False, 'key_prefix': None, 'prefix_type': None, 'message_type': EIEIOType.KEY_32_BIT, 'right_shift': 0, 'payload_as_time_stamps': True, 'use_payload_prefix': True, 'payload_prefix': None, 'payload_right_shift': 0, 'number_of_packets_sent_per_time_step': 0, 'hostname': None, 'port': None, 'strip_sdp': None, 'board_address': None, 'tag': None, 'label': "test" } # data stores needed by algorithm live_packet_gatherers = dict() extended = dict(default_params) extended.update({'partition_id': "EVENTS"}) default_params_holder = LivePacketGatherParameters(**extended) live_packet_gatherers[default_params_holder] = list() live_packet_gatherers_to_vertex_mapping = defaultdict(dict) placements = Placements() # add LPG's (1 for each Ethernet connected chip for chip in machine.ethernet_connected_chips: vertex = LivePacketGather(**default_params) app_graph.add_vertex(vertex) vertex_slice = Slice(0, 0) resources_required = vertex.get_resources_used_by_atoms( vertex_slice) mac_vertex = vertex.create_machine_vertex(vertex_slice, resources_required) graph.add_vertex(mac_vertex) app_graph_mapper.add_vertex_mapping(mac_vertex, Slice(0, 0), vertex) placements.add_placement( Placement(x=chip.x, y=chip.y, p=2, vertex=mac_vertex)) live_packet_gatherers_to_vertex_mapping[default_params_holder][ chip.x, chip.y] = mac_vertex # tracker of wirings verts_expected = defaultdict(list) positions = list() positions.append([0, 0, 0, 0]) positions.append([4, 4, 0, 0]) positions.append([1, 1, 0, 0]) positions.append([2, 2, 0, 0]) positions.append([8, 4, 8, 4]) positions.append([11, 4, 8, 4]) positions.append([4, 11, 4, 8]) positions.append([4, 8, 4, 8]) positions.append([0, 11, 8, 4]) positions.append([11, 11, 4, 8]) positions.append([8, 8, 4, 8]) positions.append([4, 0, 0, 0]) positions.append([7, 7, 0, 0]) # add graph vertices which reside on areas of the machine to ensure # spread over boards. for x, y, eth_x, eth_y in positions: vertex = TestVertex(1) app_graph.add_vertex(vertex) vertex_slice = Slice(0, 0) resources_required = vertex.get_resources_used_by_atoms( vertex_slice) mac_vertex = vertex.create_machine_vertex(vertex_slice, resources_required) graph.add_vertex(mac_vertex) app_graph_mapper.add_vertex_mapping(mac_vertex, vertex_slice, vertex) live_packet_gatherers[default_params_holder].append(vertex) verts_expected[eth_x, eth_y].append(mac_vertex) placements.add_placement( Placement(x=x, y=y, p=5, vertex=mac_vertex)) # run edge inserter that should go boom edge_inserter = InsertEdgesToLivePacketGatherers() edge_inserter(live_packet_gatherer_parameters=live_packet_gatherers, placements=placements, live_packet_gatherers_to_vertex_mapping=( live_packet_gatherers_to_vertex_mapping), machine=machine, machine_graph=graph, application_graph=app_graph, graph_mapper=app_graph_mapper) # verify edges are in the right place for chip in machine.ethernet_connected_chips: edges = graph.get_edges_ending_at_vertex( live_packet_gatherers_to_vertex_mapping[default_params_holder][ chip.x, chip.y]) for edge in edges: self.assertIn(edge.pre_vertex, verts_expected[chip.x, chip.y]) # check app graph for chip in machine.ethernet_connected_chips: app_verts_expected = [ app_graph_mapper.get_application_vertex(vert) for vert in verts_expected[chip.x, chip.y] ] lpg_machine = live_packet_gatherers_to_vertex_mapping[ default_params_holder][chip.x, chip.y] lpg_app = app_graph_mapper.get_application_vertex(lpg_machine) edges = app_graph.get_edges_ending_at_vertex(lpg_app) for edge in edges: self.assertIn(edge.pre_vertex, app_verts_expected)
def test_that_6_lpgs_are_generated_2_on_each_eth_chip_app_graph(self): machine = VirtualMachine(width=12, height=12, with_wrap_arounds=True) graph = MachineGraph("Test") app_graph = ApplicationGraph("Test") app_graph_mapper = GraphMapper() default_params = { 'use_prefix': False, 'key_prefix': None, 'prefix_type': None, 'message_type': EIEIOType.KEY_32_BIT, 'right_shift': 0, 'payload_as_time_stamps': True, 'use_payload_prefix': True, 'payload_prefix': None, 'payload_right_shift': 0, 'number_of_packets_sent_per_time_step': 0, 'hostname': None, 'port': None, 'strip_sdp': None, 'board_address': None, 'tag': None, 'label': "test" } # data stores needed by algorithm live_packet_gatherers = dict() extended = dict(default_params) extended.update({'partition_id': "EVENTS"}) default_params_holder = LivePacketGatherParameters(**extended) live_packet_gatherers[default_params_holder] = list() # and special LPG on Ethernet connected chips index = 1 chip_special = dict() for chip in machine.ethernet_connected_chips: extended['label'] = "test{}".format(index) extended['board_address'] = chip.ip_address default_params_holder2 = LivePacketGatherParameters(**extended) live_packet_gatherers[default_params_holder2] = list() chip_special[(chip.x, chip.y)] = default_params_holder2 # run edge inserter that should go boom edge_inserter = InsertLivePacketGatherersToGraphs() lpg_verts_mapping = edge_inserter( live_packet_gatherer_parameters=live_packet_gatherers, machine=machine, machine_graph=graph, application_graph=app_graph, graph_mapper=app_graph_mapper) self.assertEqual(len(lpg_verts_mapping[default_params_holder]), 3) for eth_chip in chip_special: params = chip_special[eth_chip] self.assertEqual(len(lpg_verts_mapping[params]), 1) vertex = lpg_verts_mapping[params][eth_chip] self.assertEqual(eth_chip[0], list(vertex.constraints)[0].x) self.assertEqual(eth_chip[1], list(vertex.constraints)[0].y) verts = list(lpg_verts_mapping[default_params_holder].values()) for params in chip_special.values(): verts.extend(lpg_verts_mapping[params].values()) for vertex in graph.vertices: self.assertIn(vertex, verts) app_verts = set() for vertex in verts: app_vertex = app_graph_mapper.get_application_vertex(vertex) self.assertNotEqual(app_vertex, None) self.assertIsInstance(app_vertex, ApplicationVertex) app_verts.add(app_vertex) self.assertEqual(len(app_verts), 6)
def test_that_3_lpgs_are_generated_on_3_board_app_graph(self): machine = VirtualMachine(width=12, height=12, with_wrap_arounds=True) graph = MachineGraph("Test") app_graph = ApplicationGraph("Test") app_graph_mapper = GraphMapper() default_params = { 'use_prefix': False, 'key_prefix': None, 'prefix_type': None, 'message_type': EIEIOType.KEY_32_BIT, 'right_shift': 0, 'payload_as_time_stamps': True, 'use_payload_prefix': True, 'payload_prefix': None, 'payload_right_shift': 0, 'number_of_packets_sent_per_time_step': 0, 'hostname': None, 'port': None, 'strip_sdp': None, 'board_address': None, 'tag': None, 'label': "test" } # data stores needed by algorithm live_packet_gatherers = dict() extended = dict(default_params) extended.update({'partition_id': "EVENTS"}) default_params_holder = LivePacketGatherParameters(**extended) live_packet_gatherers[default_params_holder] = list() # run edge inserter that should go boom edge_inserter = InsertLivePacketGatherersToGraphs() lpg_verts_mapping = edge_inserter( live_packet_gatherer_parameters=live_packet_gatherers, machine=machine, machine_graph=graph, application_graph=app_graph, graph_mapper=app_graph_mapper) self.assertEqual(len(lpg_verts_mapping[default_params_holder]), 3) locs = list() locs.append((0, 0)) locs.append((4, 8)) locs.append((8, 4)) for vertex in lpg_verts_mapping[default_params_holder].itervalues(): x = list(vertex.constraints)[0].x y = list(vertex.constraints)[0].y key = (x, y) locs.remove(key) self.assertEqual(len(locs), 0) verts = lpg_verts_mapping[default_params_holder].values() for vertex in graph.vertices: self.assertIn(vertex, verts) app_verts = set() for vertex in lpg_verts_mapping[default_params_holder].itervalues(): app_vertex = app_graph_mapper.get_application_vertex(vertex) self.assertNotEqual(app_vertex, None) self.assertIsInstance(app_vertex, ApplicationVertex) app_verts.add(app_vertex) self.assertEqual(len(app_verts), 3)
def setUp(self): ####################################################################### # Setting up vertices, edges and graph # ####################################################################### self.vert1 = T_AppVertex(100, "New AbstractConstrainedVertex 1") self.vert2 = T_AppVertex(5, "New AbstractConstrainedVertex 2") self.vert3 = T_AppVertex(3, "New AbstractConstrainedVertex 3") self.edge1 = ApplicationEdge(self.vert1, self.vert2, "First edge") self.edge2 = ApplicationEdge(self.vert2, self.vert1, "Second edge") self.edge3 = ApplicationEdge(self.vert1, self.vert3, "Third edge") self.verts = [self.vert1, self.vert2, self.vert3] self.edges = [self.edge1, self.edge2, self.edge3] self.graph = ApplicationGraph("Graph", self.verts, self.edges) ####################################################################### # Setting up machine # ####################################################################### flops = 1000 (_, _, n, _, _, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) _sdram = SDRAM(128 * (2**20)) ip = "192.168.240.253" chips = list() for x in range(10): for y in range(10): links = list() links.append(Link(x, y, 0, (x + 1) % 10, y, n, n)) links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s)) links.append(Link(x, y, 2, x, (y + 1) % 10, n, n)) links.append(Link(x, y, 3, (x - 1) % 10, y, s, s)) links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n)) links.append(Link(x, y, 5, x, (y - 1) % 10, s, s)) r = Router(links, False, 100, 1024) chips.append(Chip(x, y, processors, r, _sdram, ip)) self.machine = Machine(chips) ####################################################################### # Setting up graph and graph_mapper # ####################################################################### self.vertices = list() self.vertex1 = T_MachineVertex(0, 1, get_resources_used_by_atoms(0, 1, []), "First vertex") self.vertex2 = T_MachineVertex(1, 5, get_resources_used_by_atoms(1, 5, []), "Second vertex") self.vertex3 = T_MachineVertex(5, 10, get_resources_used_by_atoms(5, 10, []), "Third vertex") self.vertex4 = T_MachineVertex( 10, 100, get_resources_used_by_atoms(10, 100, []), "Fourth vertex") self.vertices.append(self.vertex1) self.vertices.append(self.vertex2) self.vertices.append(self.vertex3) self.vertices.append(self.vertex4) self.edges = list() self.graph = MachineGraph(self.vertices, self.edges) self.graph_mapper = GraphMapper() self.graph_mapper.add_vertices(self.vertices)