def test_order_vertices_for_dependent_splitters(self): vertices = list() v1 = MockVertex(SplitterSliceLegacy(), "v1") vertices.append(v1) s2 = SplitterSliceLegacy() v2 = MockVertex(s2, "v2") s3 = SplitterSliceLegacy() s2a = MockDependant(s2, "depends on v2") v2a = MockVertex(MockDependant(s2, "depends on v2"), "A depends on v2") s2a.set_governed_app_vertex(v2a) v2aa = MockVertex(MockDependant(s2a, "depends on v2a"), "A depends on v2a") vertices.append(v2aa) v3a = MockVertex(MockDependant(s3, "depends on v3"), "A depends on v3") vertices.append(v3a) vertices.append(v2a) v2b = MockVertex(MockDependant(s2, "depends on v2"), "B depends on v2") vertices.append(v2b) vertices.append(v2) v3 = MockVertex(s3, "v3") vertices.append(v3) v4 = MockVertex(SplitterSliceLegacy(), "v4") vertices.append(v4) sp = SplitterPartitioner() sp.order_vertices_for_dependent_splitters(vertices) self.assertLess(vertices.index(v1), vertices.index(v2)) self.assertLess(vertices.index(v2), vertices.index(v3)) self.assertLess(vertices.index(v3), vertices.index(v4)) self.assertLess(vertices.index(v2), vertices.index(v2a)) self.assertLess(vertices.index(v2a), vertices.index(v2aa)) self.assertLess(vertices.index(v2), vertices.index(v2b)) self.assertLess(vertices.index(v3), vertices.index(v3a))
def test_partition_with_fixed_atom_constraints(self): """ test a partitioning with a graph with fixed atom constraint """ # Create a 2x2 machine with 10 cores per chip (so 40 cores), # but 1MB off 2MB per chip (so 19MB per chip) n_cores_per_chip = 10 sdram_per_chip = (n_cores_per_chip * 2) - 1 machine = virtual_machine( width=2, height=2, n_cpus_per_chip=n_cores_per_chip, sdram_per_chip=sdram_per_chip) # Create a vertex where each atom requires 1MB (default) of SDRAM # but which can't be subdivided lower than 2 atoms per core. # The vertex has 1 atom per MB of SDRAM, and so would fit but will # be disallowed by the fixed atoms per core constraint vertex = SimpleTestVertex( sdram_per_chip * machine.n_chips, max_atoms_per_core=2, constraints=[FixedVertexAtomsConstraint(2)]) vertex.splitter = SplitterSliceLegacy() app_graph = ApplicationGraph("Test") app_graph.add_vertex(vertex) # Do the partitioning - this should result in an error with self.assertRaises(PacmanValueError): partitioner = SplitterPartitioner() partitioner(app_graph, machine, 3000)
def test_partition_with_fixed_atom_constraints_at_limit(self): """ test a partitioning with a graph with fixed atom constraint which\ should fit but is close to the limit """ # Create a 2x2 machine with 1 core per chip (so 4 cores), # and 8MB SDRAM per chip n_cores_per_chip = 2 # Remember 1 core is the monitor sdram_per_chip = 8 machine = virtual_machine( width=2, height=2, n_cpus_per_chip=n_cores_per_chip, sdram_per_chip=sdram_per_chip) # Create a vertex which will need to be split perfectly into 4 cores # to work and which max atoms per core must be ignored vertex = SimpleTestVertex( sdram_per_chip * 2, max_atoms_per_core=sdram_per_chip, constraints=[FixedVertexAtomsConstraint(sdram_per_chip // 2)]) vertex.splitter = SplitterSliceLegacy() app_graph = ApplicationGraph("Test") app_graph.add_vertex(vertex) # Do the partitioning - this should just work partitioner = SplitterPartitioner() machine_graph, _ = partitioner(app_graph, machine, 3000) self.assertEqual(4, len(machine_graph.vertices))
def test_1_chip_no_pre_allocated_too_much_sdram(self): machine = virtual_machine(width=8, height=8) graph = ApplicationGraph("Test") partitioner = SplitterPartitioner() 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: partitioner(graph, machine, plan_n_time_steps=None, pre_allocated_resources=pre_allocated_res) except Exception: raise Exception("should have blown up here")
def test_1_chip_pre_allocated_same_core(self): machine = virtual_machine(width=8, height=8) graph = ApplicationGraph("Test") partitioner = SplitterPartitioner() # add graph vertices which reside on 0,0 for p in range(0, 13): vertex = SimpleTestVertex( constraints=[ChipAndCoreConstraint(x=0, y=0, p=p)], n_atoms=1) vertex.splitter = SplitterSliceLegacy() graph.add_vertex(vertex) # add pre-allocated resources for cores on 0,0 core_pre = SpecificCoreResource( chip=machine.get_chip_at(0, 0), cores=[4]) pre_allocated_res = PreAllocatedResourceContainer( specific_core_resources=[core_pre]) # run partitioner that should go boom try: partitioner(graph, machine, plan_n_time_steps=None, pre_allocated_resources=pre_allocated_res) raise Exception("should have blown up here") except PacmanValueError: pass except Exception: raise Exception("should have blown up here")
def test_1_chip_pre_allocated_too_much_sdram(self): machine = virtual_machine(width=8, height=8) graph = ApplicationGraph("Test") partitioner = SplitterPartitioner() 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 twenty_meg = ConstantSDRAM(20 * 1024 * 1024) core_pre = SpecificChipSDRAMResource( chip=machine.get_chip_at(0, 0), sdram_usage=twenty_meg) pre_allocated_res = PreAllocatedResourceContainer( specific_sdram_usage=[core_pre]) # run partitioner that should go boom try: partitioner(graph, machine, plan_n_time_steps=None, pre_allocated_resources=pre_allocated_res) raise Exception("should have blown up here") except PacmanPartitionException: pass except Exception: exc_info = sys.exc_info() six.reraise(*exc_info)
def test_partitioning_with_2_massive_pops(self): self.setup() constrained_vertex = SimpleTestVertex(16000, "Constrained") constrained_vertex.splitter = SplitterSliceLegacy() self.graph.add_vertex(constrained_vertex) constrained_vertex = SimpleTestVertex(16000, "Constrained") constrained_vertex.splitter = SplitterSliceLegacy() self.graph.add_vertex(constrained_vertex) partitioner = SplitterPartitioner() partitioner(self.graph, self.machine, 3000, PreAllocatedResourceContainer())
def setup(self): """setup for all basic partitioner tests """ 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 = "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) self.bp = SplitterPartitioner()
def test_operation_with_same_size_as_vertex_constraint_exception(self): """ test that a partition same as constraint with different size atoms causes errors """ with self.assertRaises(NotImplementedError): self.setup() constrained_vertex = SimpleTestVertex(100, "Constrained") constrained_vertex.add_constraint( SameAtomsAsVertexConstraint(self.vert2)) constrained_vertex.splitter_object = SplitterSliceLegacy() self.graph.add_vertex(constrained_vertex) partitioner = SplitterPartitioner() self.assertRaises(PacmanPartitionException, partitioner, self.graph, self.machine, 1000, PreAllocatedResourceContainer())
def test_operation_with_same_size_as_vertex_constraint_chain(self): """ Test that a chain of same size constraints works even when the\ order of vertices is not correct for the chain """ with self.assertRaises(NotImplementedError): graph = ApplicationGraph("Test") vertex_1 = SimpleTestVertex(10, "Vertex_1", 5) vertex_1.splitter_object = SplitterSliceLegacy() vertex_2 = SimpleTestVertex(10, "Vertex_2", 4) vertex_3 = SimpleTestVertex(10, "Vertex_3", 2) vertex_3.add_constraint(SameAtomsAsVertexConstraint(vertex_2)) vertex_2.add_constraint(SameAtomsAsVertexConstraint(vertex_1)) vertex_2.splitter_object = SplitterSliceLegacy() vertex_3.splitter_object = SplitterSliceLegacy() graph.add_vertices([vertex_1, vertex_2, vertex_3]) machine = virtual_machine(width=2, height=2) partitioner = SplitterPartitioner() partitioner(graph, machine, plan_n_time_steps=None) subvertices_1 = list(vertex_1.machine_vertices) subvertices_2 = list(vertex_2.machine_vertices) subvertices_3 = list(vertex_3.machine_vertices) self.assertEqual(len(subvertices_1), len(subvertices_2)) self.assertEqual(len(subvertices_2), len(subvertices_3))