def test_partition_with_more_sdram_than_default(self): """ test that the partitioner works when its machine is slightly malformed in that it has more SDRAM available """ self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) links = list() links.append(Link(0, 0, e, 0, 1)) _sdram = SDRAM(128 * (2**21)) 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) self.sp(self.graph, self.machine, 3000)
def test_partition_with_more_sdram_than_default(self): """ test that the partitioner works when its machine is slightly malformed in that it has more sdram avilable """ self.setup() flops = 20000000 (e, _, n, w, _, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) links = list() links.append(Link(0, 0, 0, 0, 1, s, s)) _sdram = SDRAM(128 * (2**21)) links = list() links.append(Link(0, 0, 0, 1, 1, n, n)) links.append(Link(0, 1, 1, 1, 0, s, s)) links.append(Link(1, 1, 2, 0, 0, e, e)) links.append(Link(1, 0, 3, 0, 1, w, w)) r = Router(links, False, 100, 1024) ip = TestBasicPartitioner.TheTestAddress chips = list() for x in range(5): for y in range(5): chips.append(Chip(x, y, processors, r, _sdram, 0, 0, ip)) self.machine = Machine(chips, 0, 0) self.bp(self.graph, self.machine)
def test_partition_with_more_sdram_than_default(self): """ test that the partitioner works when its machine is slightly malformed in that it has more SDRAM available """ n_processors = 18 (e, ne, n, w, _, _) = range(6) links = list() links.append(Link(0, 0, e, 0, 1)) _sdram = SDRAM(128 * (2**21)) 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 = "192.162.240.253" 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) splitter_partitioner(self.graph, self.machine, 3000, PreAllocatedResourceContainer())
def create_virtual_chip(machine, link_data, virtual_chip_x, virtual_chip_y): # If the chip already exists, return the data if machine.is_chip_at(virtual_chip_x, virtual_chip_y): if not machine.get_chip_at(virtual_chip_x, virtual_chip_y).virtual: raise Exception( "Attempting to add virtual chip in place of a real chip") return # Create link to the virtual chip from the real chip virtual_link_id = (link_data.connected_link + 3) % 6 to_virtual_chip_link = Link( destination_x=virtual_chip_x, destination_y=virtual_chip_y, source_x=link_data.connected_chip_x, source_y=link_data.connected_chip_y, multicast_default_from=virtual_link_id, multicast_default_to=virtual_link_id, source_link_id=link_data.connected_link) # Create link to the real chip from the virtual chip from_virtual_chip_link = Link( destination_x=link_data.connected_chip_x, destination_y=link_data.connected_chip_y, source_x=virtual_chip_x, source_y=virtual_chip_y, multicast_default_from=link_data.connected_link, multicast_default_to=link_data.connected_link, source_link_id=virtual_link_id) # create the router links = [from_virtual_chip_link] router_object = Router( links=links, emergency_routing_enabled=False, clock_speed=Router.ROUTER_DEFAULT_CLOCK_SPEED, n_available_multicast_entries=sys.maxsize) # create the processors processors = list() for virtual_core_id in range(0, constants.CORES_PER_VIRTUAL_CHIP): processors.append(Processor.factory(virtual_core_id)) # connect the real chip with the virtual one connected_chip = machine.get_chip_at( link_data.connected_chip_x, link_data.connected_chip_y) connected_chip.router.add_link(to_virtual_chip_link) machine.add_chip(Chip( processors=processors, router=router_object, sdram=SDRAM(size=0), x=virtual_chip_x, y=virtual_chip_y, virtual=True, nearest_ethernet_x=None, nearest_ethernet_y=None))
def create_virtual_chip(machine, link_data, virtual_chip_x, virtual_chip_y): """ Create a virtual chip on a real machine. :param ~spinn_machine.Machine machine: :param ~spinn_machine.link_data_objects.AbstractLinkData link_data: Describes the link from the real machine. :param int virtual_chip_x: Virtual chip coordinate :param int virtual_chip_y: Virtual chip coordinate """ # If the chip already exists, return the data if machine.is_chip_at(virtual_chip_x, virtual_chip_y): if not machine.get_chip_at(virtual_chip_x, virtual_chip_y).virtual: raise Exception( "Attempting to add virtual chip in place of a real chip") return # Create link to the virtual chip from the real chip virtual_link_id = (link_data.connected_link + 3) % 6 to_virtual_chip_link = Link(destination_x=virtual_chip_x, destination_y=virtual_chip_y, source_x=link_data.connected_chip_x, source_y=link_data.connected_chip_y, source_link_id=link_data.connected_link) # Create link to the real chip from the virtual chip from_virtual_chip_link = Link(destination_x=link_data.connected_chip_x, destination_y=link_data.connected_chip_y, source_x=virtual_chip_x, source_y=virtual_chip_y, source_link_id=virtual_link_id) # create the router links = [from_virtual_chip_link] router_object = Router(links=links, emergency_routing_enabled=False, n_available_multicast_entries=sys.maxsize) # connect the real chip with the virtual one connected_chip = machine.get_chip_at(link_data.connected_chip_x, link_data.connected_chip_y) connected_chip.router.add_link(to_virtual_chip_link) machine.add_virtual_chip( Chip(n_processors=constants.CORES_PER_VIRTUAL_CHIP, router=router_object, sdram=SDRAM(size=0), x=virtual_chip_x, y=virtual_chip_y, virtual=True, nearest_ethernet_x=None, nearest_ethernet_y=None))
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 setup(self): """ setup for all basic partitioner tests """ self.vert1 = SimpleTestVertex(10, "New AbstractConstrainedVertex 1") self.vert2 = SimpleTestVertex(5, "New AbstractConstrainedVertex 2") self.vert3 = SimpleTestVertex(3, "New AbstractConstrainedVertex 3") self.edge1 = ApplicationEdge(self.vert1, self.vert2, None, "First edge") self.edge2 = ApplicationEdge(self.vert2, self.vert1, None, "Second edge") self.edge3 = ApplicationEdge(self.vert1, self.vert3, None, "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") flops = 200000000 (e, _, n, w, _, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) links = list() links.append(Link(0, 0, 0, 0, 1, s, s)) _sdram = SDRAM(128 * (2**20)) links = list() links.append(Link(0, 0, 0, 1, 1, n, n)) links.append(Link(0, 1, 1, 1, 0, s, s)) links.append(Link(1, 1, 2, 0, 0, e, e)) links.append(Link(1, 0, 3, 0, 1, w, w)) r = Router(links, False, 100, 1024) ip = TestBasicPartitioner.TheTestAddress chips = list() for x in range(5): for y in range(5): chips.append(Chip(x, y, processors, r, _sdram, 0, 0, ip)) self.machine = Machine(chips, 0, 0) self.bp = BasicPartitioner()
def test_partition_with_barely_sufficient_space(self): """ test that partitioning will work when close to filling the machine """ self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) links = list() links.append(Link(0, 0, e, 0, 1)) _sdram = SDRAM(2**12) 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 = "192.162.240.253" 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) n_neurons = 17 * 5 * 5 singular_vertex = SimpleTestVertex(n_neurons, "Large vertex", max_atoms_per_core=1) singular_vertex.splitter = SplitterSliceLegacy() self.assertEqual(singular_vertex._model_based_max_atoms_per_core, 1) self.graph = ApplicationGraph("Graph with large vertex") self.graph.add_vertex(singular_vertex) graph, _ = self.bp( self.graph, self.machine, plan_n_time_steps=100, pre_allocated_resources=PreAllocatedResourceContainer()) self.assertEqual(singular_vertex._model_based_max_atoms_per_core, 1) self.assertEqual(len(list(graph.vertices)), n_neurons)
def test_partition_with_insufficient_space(self): """ test that if there's not enough space, the test the partitioner will raise an error """ self.setup() n_processors = 18 (e, ne, n, w, _, _) = range(6) links = list() links.append(Link(0, 0, e, 0, 1)) _sdram = SDRAM(2**11) 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 = "192.162.240.253" 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) large_vertex = SimpleTestVertex(3000, "Large vertex", max_atoms_per_core=1) large_vertex.splitter = SplitterSliceLegacy() self.assertEqual(large_vertex._model_based_max_atoms_per_core, 1) self.graph = ApplicationGraph("Graph with large vertex") self.graph.add_vertex(large_vertex) with self.assertRaises(PacmanValueError): self.bp(self.graph, self.machine, 3000, PreAllocatedResourceContainer())
def test_partition_with_insufficient_space(self): """ test that if there's not enough space, the test the partitioner will raise an error """ self.setup() flops = 1000 (e, _, n, w, _, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) links = list() links.append(Link(0, 0, 0, 0, 1, s, s)) _sdram = SDRAM(2**11) links = list() links.append(Link(0, 0, 0, 1, 1, n, n)) links.append(Link(0, 1, 1, 1, 0, s, s)) links.append(Link(1, 1, 2, 0, 0, e, e)) links.append(Link(1, 0, 3, 0, 1, w, w)) r = Router(links, False, 100, 1024) ip = TestBasicPartitioner.TheTestAddress chips = list() for x in range(5): for y in range(5): chips.append(Chip(x, y, processors, r, _sdram, 0, 0, ip)) self.machine = Machine(chips, 0, 0) large_vertex = SimpleTestVertex(3000, "Large vertex", max_atoms_per_core=1) self.assertEqual(large_vertex._model_based_max_atoms_per_core, 1) self.graph = ApplicationGraph("Graph with large vertex") self.graph.add_vertex(large_vertex) with self.assertRaises(PacmanPartitionException): self.bp(self.graph, self.machine)
def test_partition_with_barely_sufficient_space(self): """ test that partitioning will work when close to filling the machine """ self.setup() flops = 20000000 (e, _, n, w, _, s) = range(6) processors = list() for i in range(18): processors.append(Processor(i, flops)) links = list() links.append(Link(0, 0, 0, 0, 1, s, s)) _sdram = SDRAM(2**12) links = list() links.append(Link(0, 0, 0, 1, 1, n, n)) links.append(Link(0, 1, 1, 1, 0, s, s)) links.append(Link(1, 1, 2, 0, 0, e, e)) links.append(Link(1, 0, 3, 0, 1, w, w)) r = Router(links, False, 100, 1024) ip = TestBasicPartitioner.TheTestAddress chips = list() for x in range(5): for y in range(5): chips.append(Chip(x, y, processors, r, _sdram, 0, 0, ip)) self.machine = Machine(chips, 0, 0) singular_vertex = SimpleTestVertex(450, "Large vertex", max_atoms_per_core=1) self.assertEqual(singular_vertex._model_based_max_atoms_per_core, 1) self.graph = ApplicationGraph("Graph with large vertex") self.graph.add_vertex(singular_vertex) graph, _, _ = self.bp(self.graph, self.machine) self.assertEqual(singular_vertex._model_based_max_atoms_per_core, 1) self.assertEqual(len(list(graph.vertices)), 450)
def test_link_setters(self): lnk = Link(0, 0, 0, 0, 1, None, None) lnk.multicast_default_from = 2 with self.assertRaises(SpinnMachineAlreadyExistsException): lnk.multicast_default_from = 3 lnk.multicast_default_to = 4 with self.assertRaises(SpinnMachineAlreadyExistsException): lnk.multicast_default_to = 5 lnk = Link(0, 0, 0, 0, 1, 1, 1) with self.assertRaises(SpinnMachineAlreadyExistsException): lnk.multicast_default_from = 3 with self.assertRaises(SpinnMachineAlreadyExistsException): lnk.multicast_default_to = 5
def _make_router(self, chip_info, machine): """ :param ChipSummaryInfo chip_info: :param ~spinn_machine.Machine machine: :rtype: ~spinn_machine.Router """ links = list() for link in chip_info.working_links: dest_xy = machine.xy_over_link(chip_info.x, chip_info.y, link) if dest_xy in self._chip_info: links.append( Link(chip_info.x, chip_info.y, link, dest_xy[0], dest_xy[1])) else: logger.warning( "Link {},{}:{} points to {} but that is not included ", chip_info.x, chip_info.y, link, dest_xy) return Router(links=links, n_available_multicast_entries=( chip_info.n_free_multicast_routing_entries))
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)