def test_create_constraints_to_file(tmpdir): # Construct the sample machine and graph machine = VirtualMachine(version=3, with_wrap_arounds=None) # TODO: define some extra monitor cores (how?) graph = MachineGraph("foo") tag1 = IPtagResource("1.2.3.4", 5, False, tag="footag") tag2 = ReverseIPtagResource(tag="bartag") v0 = SimpleMachineVertex(ResourceContainer(iptags=[tag1], reverse_iptags=[tag2]), constraints=[ChipAndCoreConstraint(1, 1, 3)]) graph.add_vertex(v0) v0_id = ident(v0) v1 = MachineSpiNNakerLinkVertex(2, constraints=[ChipAndCoreConstraint(1, 1)]) v1.set_virtual_chip_coordinates(0, 2) graph.add_vertex(v1) v1_id = ident(v1) algo = CreateConstraintsToFile() fn = tmpdir.join("foo.json") filename, mapping = algo(graph, machine, str(fn)) assert filename == str(fn) for vid in mapping: assert vid in [v0_id, v1_id] assert vid == ident(mapping[vid]) obj = json.loads(fn.read()) baseline = [{ "type": "reserve_resource", "location": None, "reservation": [0, 1], "resource": "cores" }, { "type": "location", "location": [1, 1], "vertex": v0_id }, { "type": "resource", "resource": "cores", "range": [3, 4], "vertex": v0_id }, { "type": "resource", "resource": "iptag", "range": [0, 1], "vertex": v0_id }, { "type": "resource", "resource": "reverse_iptag", "range": [0, 1], "vertex": v0_id }, { "type": "route_endpoint", "direction": "south", "vertex": v1_id }, { "type": "location", "location": [1, 0], "vertex": v1_id }] assert obj == baseline
def create_machine_vertex( self, vertex_slice, resources_required, label=None, constraints=None): machine_vertex = MachineSpiNNakerLinkVertex( self._spinnaker_link_id, self._board_address, label, constraints, self, vertex_slice) machine_vertex.set_virtual_chip_coordinates( self._virtual_chip_x, self._virtual_chip_y) if resources_required: assert (resources_required == machine_vertex.resources_required) return machine_vertex
def __init__(self, label, spinnaker_link_id, board_address, constraints=None): MachineSpiNNakerLinkVertex.__init__( self, spinnaker_link_id=spinnaker_link_id, board_address=board_address, label=label, constraints=constraints) AbstractSendMeMulticastCommandsVertex.__init__(self)
def __init__(self, label, spinnaker_link_id, board_address, constraints=None): MachineSpiNNakerLinkVertex.__init__( self, spinnaker_link_id=spinnaker_link_id, board_address=board_address, label=label, constraints=constraints)
def test_create_constraints_to_file(tmpdir): # Construct the sample machine and graph machine = VirtualMachine(version=3, with_wrap_arounds=None) # TODO: define some extra monitor cores (how?) graph = MachineGraph("foo") tag1 = IPtagResource("1.2.3.4", 5, False, tag="footag") tag2 = ReverseIPtagResource(tag="bartag") v0 = SimpleMachineVertex(ResourceContainer( iptags=[tag1], reverse_iptags=[tag2]), constraints=[ ChipAndCoreConstraint(1, 1, 3)]) graph.add_vertex(v0) v0_id = ident(v0) v1 = MachineSpiNNakerLinkVertex(0) v1.set_virtual_chip_coordinates(0, 2) graph.add_vertex(v1) v1_id = ident(v1) machine = MallocBasedChipIdAllocator()(machine, graph) algo = CreateConstraintsToFile() fn = tmpdir.join("foo.json") filename, mapping = algo(graph, machine, str(fn)) assert filename == str(fn) for vid in mapping: assert vid in [v0_id, v1_id] assert vid == ident(mapping[vid]) obj = json.loads(fn.read()) baseline = [ { "type": "reserve_resource", "location": None, "reservation": [0, 1], "resource": "cores"}, { "type": "location", "location": [1, 1], "vertex": v0_id}, { "type": "resource", "resource": "cores", "range": [3, 4], "vertex": v0_id}, { "type": "resource", "resource": "iptag", "range": [0, 1], "vertex": v0_id}, { "type": "resource", "resource": "reverse_iptag", "range": [0, 1], "vertex": v0_id}, { "type": "route_endpoint", "direction": "west", "vertex": v1_id}, { "type": "location", "location": [0, 0], "vertex": v1_id}] assert obj == baseline
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 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_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