def create_app_less(): app_graph = ApplicationGraph("Test") mac_graph = MachineGraph("Test", app_graph) n_keys_map = DictBasedMachinePartitionNKeysMap() # An output vertex to aim things at (to make keys required) out_mac_vertex = SimpleMacVertex() mac_graph.add_vertex(out_mac_vertex) # Create 5 application vertices (3 bits) for app_index in range(5): # For each, create up to (5 x 4) + 1 = 21 machine vertices (5 bits) for mac_index in range((app_index * 4) + 1): mac_vertex = SimpleMacVertex() mac_graph.add_vertex(mac_vertex) # For each machine vertex create up to # (20 x 2) + 1 = 81(!) partitions (6 bits) for mac_edge_index in range((mac_index * 2) + 1): mac_edge = MachineEdge(mac_vertex, out_mac_vertex) part_name = "Part{}".format(mac_edge_index) mac_graph.add_edge(mac_edge, part_name) # Give the partition up to (40 x 4) + 1 = 161 keys (8 bits) p = mac_graph.get_outgoing_edge_partition_starting_at_vertex( mac_vertex, part_name) n_keys_map.set_n_keys_for_partition( p, (mac_edge_index * 4) + 1) return app_graph, mac_graph, n_keys_map
def _integration_setup(self): machine_graph = MachineGraph(label="test me you git") n_keys_map = DictBasedMachinePartitionNKeysMap() v1 = SimpleMachineVertex(ResourceContainer()) v2 = SimpleMachineVertex(ResourceContainer()) v3 = SimpleMachineVertex(ResourceContainer()) v4 = SimpleMachineVertex(ResourceContainer()) machine_graph.add_vertex(v1) machine_graph.add_vertex(v2) machine_graph.add_vertex(v3) machine_graph.add_vertex(v4) e1 = MachineEdge(v1, v2, label="e1") e2 = MachineEdge(v1, v3, label="e2") e3 = MachineEdge(v2, v3, label="e3") e4 = MachineEdge(v1, v4, label="e4") machine_graph.add_outgoing_edge_partition( MulticastEdgePartition(identifier="part1", pre_vertex=v1)) machine_graph.add_outgoing_edge_partition( MulticastEdgePartition(identifier="part2", pre_vertex=v2)) machine_graph.add_outgoing_edge_partition( MulticastEdgePartition(identifier="part2", pre_vertex=v1)) machine_graph.add_edge(e1, "part1") machine_graph.add_edge(e2, "part1") machine_graph.add_edge(e3, "part2") machine_graph.add_edge(e4, "part2") for partition in machine_graph.outgoing_edge_partitions: n_keys_map.set_n_keys_for_partition(partition, 24) return machine_graph, n_keys_map, v1, v2, v3, v4, e1, e2, e3, e4
def create_graphs_only_fixed(): app_graph = ApplicationGraph("Test") # An output vertex to aim things at (to make keys required) out_app_vertex = SimpleAppVertex() app_graph.add_vertex(out_app_vertex) # Create 5 application vertices (3 bits) app_vertex = SimpleAppVertex() app_graph.add_vertex(app_vertex) mac_graph = MachineGraph("Test", app_graph) n_keys_map = DictBasedMachinePartitionNKeysMap() # An output vertex to aim things at (to make keys required) out_mac_vertex = SimpleMacVertex(app_vertex=out_app_vertex) mac_graph.add_vertex(out_mac_vertex) mac_vertex = SimpleMacVertex(app_vertex=app_vertex) mac_graph.add_vertex(mac_vertex) for mac_edge_index in range(2): mac_edge = MachineEdge(mac_vertex, out_mac_vertex) part_name = "Part{}".format(mac_edge_index) mac_graph.add_edge(mac_edge, part_name) p = mac_graph.get_outgoing_edge_partition_starting_at_vertex( mac_vertex, part_name) if (mac_edge_index == 0): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x4c00000, 0xFFFFFFFE)])) if (mac_edge_index == 1): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x4c00000, 0xFFFFFFFF)])) n_keys_map.set_n_keys_for_partition( p, (mac_edge_index * 4) + 1) return app_graph, mac_graph, n_keys_map
def __call__(self, machine_graph): """ :param ~.MachineGraph machine_graph: :rtype: ~.DictBasedMachinePartitionNKeysMap :raises: ConfigurationException """ if machine_graph is None: raise ConfigurationException(self.ERROR_MSG) # Generate an n_keys map for the graph and add constraints n_keys_map = DictBasedMachinePartitionNKeysMap() # generate progress bar progress = ProgressBar(machine_graph.n_vertices, self.PROG_BAR_NAME) # iterate over each partition in the graph for vertex in progress.over(machine_graph.vertices): for partition in machine_graph.\ get_outgoing_edge_partitions_starting_at_vertex(vertex): if partition.traffic_type == EdgeTrafficType.MULTICAST: n_keys = partition.pre_vertex.get_n_keys_for_partition( partition) n_keys_map.set_n_keys_for_partition(partition, n_keys) return n_keys_map
def _integration_setup(self): machine_graph = MachineGraph(label="test me you git") n_keys_map = DictBasedMachinePartitionNKeysMap() v1 = SimpleMachineVertex(ResourceContainer()) v2 = SimpleMachineVertex(ResourceContainer()) v3 = SimpleMachineVertex(ResourceContainer()) v4 = SimpleMachineVertex(ResourceContainer()) machine_graph.add_vertex(v1) machine_graph.add_vertex(v2) machine_graph.add_vertex(v3) machine_graph.add_vertex(v4) e1 = MachineEdge(v1, v2, label="e1") e2 = MachineEdge(v1, v3, label="e2") e3 = MachineEdge(v2, v3, label="e3") e4 = MachineEdge(v1, v4, label="e4") machine_graph.add_edge(e1, "part1") machine_graph.add_edge(e2, "part1") machine_graph.add_edge(e3, "part2") machine_graph.add_edge(e4, "part2") for partition in machine_graph.outgoing_edge_partitions: n_keys_map.set_n_keys_for_partition(partition, 24) return machine_graph, n_keys_map, v1, v2, v3, v4, e1, e2, e3, e4
def test_dict_based_machine_partition_n_keys_map(self): pmap = DictBasedMachinePartitionNKeysMap() p1 = OutgoingEdgePartition("foo", None) p2 = OutgoingEdgePartition("bar", None) pmap.set_n_keys_for_partition(p1, 1) pmap.set_n_keys_for_partition(p2, 2) assert pmap.n_keys_for_partition(p1) == 1 assert pmap.n_keys_for_partition(p2) == 2
def test_dict_based_machine_partition_n_keys_map(self): pmap = DictBasedMachinePartitionNKeysMap() p1 = MulticastEdgePartition(None, "foo") p2 = MulticastEdgePartition(None, "bar") pmap.set_n_keys_for_partition(p1, 1) pmap.set_n_keys_for_partition(p2, 2) assert pmap.n_keys_for_partition(p1) == 1 assert pmap.n_keys_for_partition(p2) == 2
def test_virtual_vertices_spreader(): """ Test that the placer works with a virtual vertex """ # Create a graph with a virtual vertex machine_graph = MachineGraph("Test") virtual_vertex = MachineSpiNNakerLinkVertex( spinnaker_link_id=0, label="Virtual") machine_graph.add_vertex(virtual_vertex) # These vertices are fixed on 0, 0 misc_vertices = list() for i in range(3): misc_vertex = SimpleMachineVertex( resources=ResourceContainer(), constraints=[ ChipAndCoreConstraint(0, 0)], label="Fixed_0_0_{}".format(i)) machine_graph.add_vertex(misc_vertex) misc_vertices.append(misc_vertex) # These vertices are 1-1 connected to the virtual vertex one_to_one_vertices = list() for i in range(16): one_to_one_vertex = SimpleMachineVertex( resources=ResourceContainer(), label="Vertex_{}".format(i)) machine_graph.add_vertex(one_to_one_vertex) edge = MachineEdge(virtual_vertex, one_to_one_vertex) machine_graph.add_edge(edge, "SPIKES") one_to_one_vertices.append(one_to_one_vertex) n_keys_map = DictBasedMachinePartitionNKeysMap() partition = machine_graph.get_outgoing_edge_partition_starting_at_vertex( virtual_vertex, "SPIKES") n_keys_map.set_n_keys_for_partition(partition, 1) # Get and extend the machine for the virtual chip machine = virtual_machine(width=8, height=8) extended_machine = MallocBasedChipIdAllocator()(machine, machine_graph) # Do placements placements = SpreaderPlacer()( machine_graph, extended_machine, n_keys_map, plan_n_timesteps=1000) # The virtual vertex should be on a virtual chip placement = placements.get_placement_of_vertex(virtual_vertex) assert machine.get_chip_at(placement.x, placement.y).virtual # The 0, 0 vertices should be on 0, 0 for vertex in misc_vertices: placement = placements.get_placement_of_vertex(vertex) assert placement.x == placement.y == 0 # The other vertices should *not* be on a virtual chip for vertex in one_to_one_vertices: placement = placements.get_placement_of_vertex(vertex) assert not machine.get_chip_at(placement.x, placement.y).virtual
def test_sdram_links(): """ Test sdram edges which should explode """ # Create a graph machine_graph = MachineGraph("Test") # Connect a set of vertices in a chain of length 3 last_vertex = None for x in range(20): vertex = SimpleMachineVertex( resources=ResourceContainer(), label="Vertex_{}".format(x), sdram_cost=20) machine_graph.add_vertex(vertex) last_vertex = vertex for vertex in machine_graph.vertices: machine_graph.add_outgoing_edge_partition( ConstantSDRAMMachinePartition( identifier="SDRAM", pre_vertex=vertex, label="bacon")) edge = SDRAMMachineEdge(vertex, last_vertex, "bacon", app_edge=None) machine_graph.add_edge(edge, "SDRAM") n_keys_map = DictBasedMachinePartitionNKeysMap() # Do placements machine = virtual_machine(width=8, height=8) try: SpreaderPlacer()(machine_graph, machine, n_keys_map, plan_n_timesteps=1000) raise Exception("should blow up here") except PacmanException: pass
def test_virtual_placement(placer): machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") virtual_vertex = MachineSpiNNakerLinkVertex(spinnaker_link_id=0) graph.add_vertex(virtual_vertex) extended_machine = MallocBasedChipIdAllocator()(machine, graph) n_keys_map = DictBasedMachinePartitionNKeysMap() inputs = { "MemoryExtendedMachine": machine, "MemoryMachine": machine, "MemoryMachineGraph": graph, "PlanNTimeSteps": 1000, "MemoryMachinePartitionNKeysMap": n_keys_map } algorithms = [placer] xml_paths = [] executor = PACMANAlgorithmExecutor(algorithms, [], inputs, [], [], [], xml_paths) executor.execute_mapping() placements = executor.get_item("MemoryPlacements") placement = placements.get_placement_of_vertex(virtual_vertex) chip = extended_machine.get_chip_at(placement.x, placement.y) assert chip.virtual
def __call__(self, machine_graph=None, application_graph=None, graph_mapper=None): # Generate an n_keys map for the graph and add constraints n_keys_map = DictBasedMachinePartitionNKeysMap() if machine_graph is None: raise ConfigurationException( "A machine graph is required for this mapper. " "Please choose and try again") if (application_graph is None) != (graph_mapper is None): raise ConfigurationException( "Can only do one graph. semantically doing 2 graphs makes no " "sense. Please choose and try again") if application_graph is not None: # generate progress bar progress = ProgressBar( machine_graph.n_vertices, "Getting number of keys required by each edge using " "application graph") # iterate over each partition in the graph for vertex in progress.over(machine_graph.vertices): partitions = machine_graph.\ get_outgoing_edge_partitions_starting_at_vertex( vertex) for partition in partitions: added_constraints = False constraints = self._process_application_partition( partition, n_keys_map, graph_mapper) if not added_constraints: partition.add_constraints(constraints) else: self._check_constraints_equal( constraints, partition.constraints) else: # generate progress bar progress = ProgressBar( machine_graph.n_vertices, "Getting number of keys required by each edge using " "machine graph") for vertex in progress.over(machine_graph.vertices): partitions = machine_graph.\ get_outgoing_edge_partitions_starting_at_vertex( vertex) for partition in partitions: added_constraints = False constraints = self._process_machine_partition( partition, n_keys_map) if not added_constraints: partition.add_constraints(constraints) else: self._check_constraints_equal( constraints, partition.constraints) return n_keys_map
def _do_test(self, placer): machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") vertices = [ SimpleMachineVertex(ResourceContainer(), label="v{}".format(i)) for i in range(100) ] for vertex in vertices: graph.add_vertex(vertex) same_vertices = [ SimpleMachineVertex(ResourceContainer(), label="same{}".format(i)) for i in range(10) ] random.seed(12345) for vertex in same_vertices: graph.add_vertex(vertex) for _i in range(0, random.randint(1, 5)): vertex.add_constraint( SameChipAsConstraint( vertices[random.randint(0, 99)])) n_keys_map = DictBasedMachinePartitionNKeysMap() inputs = { "MemoryExtendedMachine": machine, "MemoryMachine": machine, "MemoryMachineGraph": graph, "PlanNTimeSteps": None, "MemoryMachinePartitionNKeysMap": n_keys_map } algorithms = [placer] xml_paths = [] executor = PACMANAlgorithmExecutor( algorithms, [], inputs, [], [], [], xml_paths) executor.execute_mapping() placements = executor.get_item("MemoryPlacements") for same in same_vertices: print("{0.vertex.label}, {0.x}, {0.y}, {0.p}: {1}".format( placements.get_placement_of_vertex(same), ["{0.vertex.label}, {0.x}, {0.y}, {0.p}".format( placements.get_placement_of_vertex(constraint.vertex)) for constraint in same.constraints])) placement = placements.get_placement_of_vertex(same) for constraint in same.constraints: if isinstance(constraint, SameChipAsConstraint): other_placement = placements.get_placement_of_vertex( constraint.vertex) self.assertTrue( other_placement.x == placement.x and other_placement.y == placement.y, "Vertex was not placed on the same chip as requested")
def _do_test(self, placer): machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") plan_n_timesteps = 100 vertices = [ SimpleMachineVertex(ResourceContainer(), label="v{}".format(i), sdram_cost=20) for i in range(100) ] for vertex in vertices: graph.add_vertex(vertex) same_vertices = [ SimpleMachineVertex(ResourceContainer(), label="same{}".format(i), sdram_cost=20) for i in range(10) ] random.seed(12345) sdram_edges = list() for vertex in same_vertices: graph.add_vertex(vertex) graph.add_outgoing_edge_partition( ConstantSDRAMMachinePartition(identifier="Test", pre_vertex=vertex, label="bacon")) for _i in range(0, random.randint(1, 5)): sdram_edge = SDRAMMachineEdge(vertex, vertices[random.randint(0, 99)], label="bacon", app_edge=None) sdram_edges.append(sdram_edge) graph.add_edge(sdram_edge, "Test") n_keys_map = DictBasedMachinePartitionNKeysMap() inputs = { "MemoryExtendedMachine": machine, "MemoryMachine": machine, "MemoryMachineGraph": graph, "PlanNTimeSteps": plan_n_timesteps, "MemoryMachinePartitionNKeysMap": n_keys_map } algorithms = [placer] xml_paths = [] executor = PACMANAlgorithmExecutor(algorithms, [], inputs, [], [], [], xml_paths) executor.execute_mapping() placements = executor.get_item("MemoryPlacements") for edge in sdram_edges: pre_place = placements.get_placement_of_vertex(edge.pre_vertex) post_place = placements.get_placement_of_vertex(edge.post_vertex) assert pre_place.x == post_place.x assert pre_place.y == post_place.y
def _do_test(self, placer): machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") vertices = [ SimpleMachineVertex(ResourceContainer(), label="v{}".format(i)) for i in range(100) ] for vertex in vertices: graph.add_vertex(vertex) same_vertices = [ SimpleMachineVertex(ResourceContainer(), label="same{}".format(i)) for i in range(10) ] random.seed(12345) for vertex in same_vertices: graph.add_vertex(vertex) for _i in range(0, random.randint(1, 5)): vertex.add_constraint( SameChipAsConstraint(vertices[random.randint(0, 99)])) n_keys_map = DictBasedMachinePartitionNKeysMap() if placer == "ConnectiveBasedPlacer": placements = connective_based_placer(graph, machine, None) elif placer == "OneToOnePlacer": placements = one_to_one_placer(graph, machine, None) elif placer == "RadialPlacer": placements = radial_placer(graph, machine, None) elif placer == "SpreaderPlacer": placements = spreader_placer(graph, machine, n_keys_map, None) else: raise NotImplementedError(placer) for same in same_vertices: print("{0.vertex.label}, {0.x}, {0.y}, {0.p}: {1}".format( placements.get_placement_of_vertex(same), [ "{0.vertex.label}, {0.x}, {0.y}, {0.p}".format( placements.get_placement_of_vertex(constraint.vertex)) for constraint in same.constraints ])) placement = placements.get_placement_of_vertex(same) for constraint in same.constraints: if isinstance(constraint, SameChipAsConstraint): other_placement = placements.get_placement_of_vertex( constraint.vertex) self.assertTrue( other_placement.x == placement.x and other_placement.y == placement.y, "Vertex was not placed on the same chip as requested")
def _do_test(self, placer): machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") vertices = [ MockMachineVertex(ResourceContainer(), label="v{}".format(i), sdram_requirement=20) for i in range(100) ] for vertex in vertices: graph.add_vertex(vertex) same_vertices = [ MockMachineVertex(ResourceContainer(), label="same{}".format(i), sdram_requirement=20) for i in range(10) ] random.seed(12345) sdram_edges = list() for vertex in same_vertices: graph.add_vertex(vertex) graph.add_outgoing_edge_partition( ConstantSDRAMMachinePartition(identifier="Test", pre_vertex=vertex, label="bacon")) for _i in range(0, random.randint(1, 5)): sdram_edge = SDRAMMachineEdge(vertex, vertices[random.randint(0, 99)], label="bacon", app_edge=None) sdram_edges.append(sdram_edge) graph.add_edge(sdram_edge, "Test") n_keys_map = DictBasedMachinePartitionNKeysMap() if placer == "ConnectiveBasedPlacer": placements = connective_based_placer(graph, machine, None) elif placer == "OneToOnePlacer": placements = one_to_one_placer(graph, machine, None) elif placer == "RadialPlacer": placements = radial_placer(graph, machine, None) elif placer == "SpreaderPlacer": placements = spreader_placer(graph, machine, n_keys_map, None) else: raise NotImplementedError(placer) for edge in sdram_edges: pre_place = placements.get_placement_of_vertex(edge.pre_vertex) post_place = placements.get_placement_of_vertex(edge.post_vertex) assert pre_place.x == post_place.x assert pre_place.y == post_place.y
def create_graphs_no_edge(): app_graph = ApplicationGraph("Test") # An output vertex to aim things at (to make keys required) out_app_vertex = SimpleAppVertex() app_graph.add_vertex(out_app_vertex) # Create 5 application vertices (3 bits) app_vertex = SimpleAppVertex() app_graph.add_vertex(app_vertex) mac_graph = MachineGraph("Test", app_graph) n_keys_map = DictBasedMachinePartitionNKeysMap() # An output vertex to aim things at (to make keys required) out_mac_vertex = SimpleMacVertex(app_vertex=out_app_vertex) mac_graph.add_vertex(out_mac_vertex) mac_vertex = SimpleMacVertex(app_vertex=app_vertex) mac_graph.add_vertex(mac_vertex) return app_graph, mac_graph, n_keys_map
def create_big(with_fixed): # This test shows how easy it is to trip up the allocator with a retina app_graph = ApplicationGraph("Test") # Create a single "big" vertex big_app_vertex = SimpleTestVertex(1, label="Retina") app_graph.add_vertex(big_app_vertex) # Create a single output vertex (which won't send) out_app_vertex = SimpleTestVertex(1, label="Destination") app_graph.add_vertex(out_app_vertex) # Create a load of middle vertex mid_app_vertex = SimpleTestVertex(1, "Population") app_graph.add_vertex(mid_app_vertex) mac_graph = MachineGraph("Test", app_graph) n_keys_map = DictBasedMachinePartitionNKeysMap() # Create a single big machine vertex big_mac_vertex = big_app_vertex.create_machine_vertex(None, None, label="RETINA") mac_graph.add_vertex(big_mac_vertex) # Create a single output vertex (which won't send) out_mac_vertex = out_app_vertex.create_machine_vertex(None, None) mac_graph.add_vertex(out_mac_vertex) # Create a load of middle vertices and connect them up for _ in range(2000): # 2000 needs 11 bits mid_mac_vertex = mid_app_vertex.create_machine_vertex(None, None) mac_graph.add_vertex(mid_mac_vertex) edge = MachineEdge(big_mac_vertex, mid_mac_vertex) mac_graph.add_edge(edge, "Test") edge_2 = MachineEdge(mid_mac_vertex, out_mac_vertex) mac_graph.add_edge(edge_2, "Test") mid_part = mac_graph.get_outgoing_edge_partition_starting_at_vertex( mid_mac_vertex, "Test") n_keys_map.set_n_keys_for_partition(mid_part, 100) big_mac_part = mac_graph.get_outgoing_edge_partition_starting_at_vertex( big_mac_vertex, "Test") if with_fixed: big_mac_part.add_constraint( FixedKeyAndMaskConstraint([BaseKeyAndMask(0x0, 0x180000)])) # Make the "retina" need 21 bits, so total is now 21 + 11 = 32 bits, # but the application vertices need some bits too n_keys_map.set_n_keys_for_partition(big_mac_part, 1024 * 768 * 2) return app_graph, mac_graph, n_keys_map
def test_virtual_placement(placer): unittest_setup() machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") virtual_vertex = MachineSpiNNakerLinkVertex(spinnaker_link_id=0) graph.add_vertex(virtual_vertex) extended_machine = malloc_based_chip_id_allocator(machine, graph) n_keys_map = DictBasedMachinePartitionNKeysMap() if placer == "ConnectiveBasedPlacer": placements = connective_based_placer(graph, machine, None) elif placer == "OneToOnePlacer": placements = one_to_one_placer(graph, machine, None) elif placer == "RadialPlacer": placements = radial_placer(graph, machine, None) elif placer == "SpreaderPlacer": placements = spreader_placer(graph, machine, n_keys_map, None) else: raise NotImplementedError(placer) placement = placements.get_placement_of_vertex(virtual_vertex) chip = extended_machine.get_chip_at(placement.x, placement.y) assert chip.virtual
def test_one_to_one(): """ Test normal 1-1 placement """ # Create a graph machine_graph = MachineGraph("Test") # Connect a set of vertices in a chain of length 3 n_keys_map = DictBasedMachinePartitionNKeysMap() one_to_one_chains = list() for i in range(10): last_vertex = None chain = list() for j in range(3): vertex = SimpleMachineVertex( resources=ResourceContainer(), label="Vertex_{}_{}".format(i, j)) machine_graph.add_vertex(vertex) if last_vertex is not None: edge = MachineEdge(last_vertex, vertex) machine_graph.add_edge(edge, "SPIKES") partition = machine_graph\ .get_outgoing_edge_partition_starting_at_vertex( last_vertex, "SPIKES") n_keys_map.set_n_keys_for_partition(partition, 1) last_vertex = vertex chain.append(vertex) one_to_one_chains.append(chain) # Connect a set of 20 vertices in a chain too_many_vertices = list() last_vertex = None for i in range(20): vertex = SimpleMachineVertex( resources=ResourceContainer(), label="Vertex_{}".format(i)) machine_graph.add_vertex(vertex) if last_vertex is not None: edge = MachineEdge(last_vertex, vertex) machine_graph.add_edge(edge, "SPIKES") partition = machine_graph\ .get_outgoing_edge_partition_starting_at_vertex( last_vertex, "SPIKES") n_keys_map.set_n_keys_for_partition(partition, 1) too_many_vertices.append(vertex) last_vertex = vertex # Do placements machine = virtual_machine(width=8, height=8) placements = SpreaderPlacer()( machine_graph, machine, n_keys_map, plan_n_timesteps=1000) # The 1-1 connected vertices should be on the same chip for chain in one_to_one_chains: first_placement = placements.get_placement_of_vertex(chain[0]) for i in range(1, 3): placement = placements.get_placement_of_vertex(chain[i]) assert placement.x == first_placement.x assert placement.y == first_placement.y # The other vertices should be on more than one chip too_many_chips = set() for vertex in too_many_vertices: placement = placements.get_placement_of_vertex(vertex) too_many_chips.add((placement.x, placement.y)) assert len(too_many_chips) > 1
def create_graphs1(with_fixed): app_graph = ApplicationGraph("Test") # An output vertex to aim things at (to make keys required) out_app_vertex = SimpleAppVertex() app_graph.add_vertex(out_app_vertex) # Create 5 application vertices (3 bits) app_vertices = list() for app_index in range(5): app_vertices.append(SimpleAppVertex()) app_graph.add_vertices(app_vertices) mac_graph = MachineGraph("Test", app_graph) n_keys_map = DictBasedMachinePartitionNKeysMap() # An output vertex to aim things at (to make keys required) out_mac_vertex = SimpleMacVertex(app_vertex=out_app_vertex) mac_graph.add_vertex(out_mac_vertex) # Create 5 application vertices (3 bits) for app_index, app_vertex in enumerate(app_vertices): # For each, create up to (5 x 4) + 1 = 21 machine vertices (5 bits) for mac_index in range((app_index * 4) + 1): mac_vertex = SimpleMacVertex(app_vertex=app_vertex) mac_graph.add_vertex(mac_vertex) # For each machine vertex create up to # (20 x 2) + 1 = 81(!) partitions (6 bits) for mac_edge_index in range((mac_index * 2) + 1): mac_edge = MachineEdge(mac_vertex, out_mac_vertex) part_name = "Part{}".format(mac_edge_index) mac_graph.add_edge(mac_edge, part_name) # Give the partition up to (40 x 4) + 1 = 161 keys (8 bits) p = mac_graph.get_outgoing_edge_partition_starting_at_vertex( mac_vertex, part_name) if with_fixed: if (app_index == 2 and mac_index == 4 and part_name == "Part7"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0xFE00000, 0xFFFFFFC0)])) if (app_index == 2 and mac_index == 0 and part_name == "Part1"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x4c00000, 0xFFFFFFFE)])) if (app_index == 2 and mac_index == 0 and part_name == "Part1"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x4c00000, 0xFFFFFFFF)])) if (app_index == 3 and mac_index == 0 and part_name == "Part1"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x3300000, 0xFFFFFFFF)])) if (app_index == 3 and mac_index == 0 and part_name == "Part1"): p.add_constraint(FixedKeyAndMaskConstraint( [BaseKeyAndMask(0x3300001, 0)])) n_keys_map.set_n_keys_for_partition( p, (mac_edge_index * 4) + 1) return app_graph, mac_graph, n_keys_map