def __call__(self, machine, placements): """ See :py:meth:`AbstractTagAllocatorAlgorithm.allocate_tags` """ resource_tracker = ResourceTracker(machine) # Keep track of ports allocated to reverse IP tags and tags that still # need a port to be allocated ports_to_allocate = dict() tags_to_allocate_ports = list() # Check that the algorithm can handle the constraints progress = ProgressBar(placements.n_placements, "Discovering tags") placements_with_tags = list() for placement in progress.over(placements.placements): self._gather_placements_with_tags(placement, placements_with_tags) # Go through and allocate the IP tags and constrained reverse IP tags tags = Tags() progress = ProgressBar(placements_with_tags, "Allocating tags") for placement in progress.over(placements_with_tags): self._allocate_tags_for_placement(placement, resource_tracker, tags, ports_to_allocate, tags_to_allocate_ports) # Finally allocate ports to the unconstrained reverse IP tags self._allocate_ports_for_reverse_ip_tags(tags_to_allocate_ports, ports_to_allocate, tags) return list(tags.ip_tags), list(tags.reverse_ip_tags), tags
def test_call(self): """ Test calling the tags loader """ vertex = _TestVertex() tag_1 = IPTag("127.0.0.1", 0, 0, 1, "localhost", 12345, True, "Test") tag_2 = IPTag("127.0.0.1", 0, 0, 2, "localhost", 54321, True, "Test") rip_tag_1 = ReverseIPTag("127.0.0.1", 3, 12345, 0, 0, 0, 0) rip_tag_2 = ReverseIPTag("127.0.0.1", 4, 12346, 0, 0, 0, 0) tags = Tags() tags.add_ip_tag(tag_1, vertex) tags.add_ip_tag(tag_2, vertex) tags.add_reverse_ip_tag(rip_tag_1, vertex) tags.add_reverse_ip_tag(rip_tag_2, vertex) txrx = _MockTransceiver() loader = TagsLoader() loader.__call__(txrx, tags) self.assertIn(tag_1, txrx.ip_tags) self.assertIn(tag_2, txrx.ip_tags) self.assertIn(rip_tag_1, txrx.reverse_ip_tags) self.assertIn(rip_tag_2, txrx.reverse_ip_tags)
def test_adding_a_reverse_iptag(self): """ check that adding a reverse iptag works correctly """ tag_info = Tags() reverse_iptag = ReverseIPTag("", 1, 23, 0, 0, 1, 1) machine_vertex = SimpleMachineVertex(None, "") tag_info.add_reverse_ip_tag(reverse_iptag, machine_vertex)
def test_adding_a_iptag_to_tag_info(self): """ check that adding a tag after initialisation works """ tag_info = Tags() iptag = IPTag("", 0, 0, 1, "122.2.2.2", 1, False) machine_vertex = SimpleMachineVertex(None, "") tag_info.add_ip_tag(iptag, machine_vertex)
def test_listener_creation(self): # Test of buffer manager listener creation problem, where multiple # listeners were being created for the buffer manager traffic from # individual boards, where it's preferred all traffic is received by # a single listener # Create two vertices v1 = _TestVertex(10, "v1", 256) v2 = _TestVertex(10, "v2", 256) # Create two tags - important thing is port=None t1 = IPTag(board_address='127.0.0.1', destination_x=0, destination_y=1, tag=1, port=None, ip_address=None, strip_sdp=True, traffic_identifier='BufferTraffic') t2 = IPTag(board_address='127.0.0.1', destination_x=0, destination_y=2, tag=1, port=None, ip_address=None, strip_sdp=True, traffic_identifier='BufferTraffic') # Create 'Tags' object and add tags t = Tags() t.add_ip_tag(t1, v1) t.add_ip_tag(t2, v2) # Create board connections connections = [] connections.append(SCAMPConnection( remote_host=None)) connections.append(EIEIOConnection()) # Create two placements and 'Placements' object pl1 = Placement(v1, 0, 1, 1) pl2 = Placement(v2, 0, 2, 1) pl = Placements([pl1, pl2]) # Create transceiver trnx = Transceiver(version=5, connections=connections) # Alternatively, one can register a udp listener for testing via: # trnx.register_udp_listener(callback=None, # connection_class=EIEIOConnection) # Create buffer manager bm = BufferManager(pl, t, trnx) # Register two listeners, and check the second listener uses the # first rather than creating a new one bm._add_buffer_listeners(vertex=v1) bm._add_buffer_listeners(vertex=v2) number_of_listeners = 0 for i in bm._transceiver._udp_listenable_connections_by_class[ EIEIOConnection]: # Check if listener is registered on connection - we only expect # one listener to be registered, as all connections can use the # same listener for the buffer manager if not i[1] is None: number_of_listeners += 1 print i self.assertEqual(number_of_listeners, 1)
def test_add_reverse_iptag_then_locate_tag(self): """ check that asking for a reverse iptag for a specific machine vertex works """ tag_info = Tags() reverse_iptag = ReverseIPTag("", 1, 23, 0, 0, 1, 1) machine_vertex = SimpleMachineVertex(None, "") tag_info.add_reverse_ip_tag(reverse_iptag, machine_vertex) gotton_tag = tag_info.get_reverse_ip_tags_for_vertex(machine_vertex) self.assertEqual(gotton_tag[0], reverse_iptag)
def test_add_iptag_then_locate_tag(self): """ check that locating a iptag via get_ip_tags_for_vertex function """ tag_info = Tags() iptag = IPTag("", 0, 0, 1, "122.2.2.2", 1, False) machine_vertex = SimpleMachineVertex(None, "") tag_info.add_ip_tag(iptag, machine_vertex) gotton_tag = tag_info.get_ip_tags_for_vertex(machine_vertex) self.assertEqual(gotton_tag[0], iptag)
def test_add_reverse_iptag_then_not_locate_tag(self): """ check that asking for a reverse iptag with a incorrect machine vertex will cause a none returned """ tag_info = Tags() reverse_iptag = ReverseIPTag("", 1, 23, 0, 0, 1, 1) machine_vertex = SimpleMachineVertex(None, "") machine_vertex2 = SimpleMachineVertex(None, "") tag_info.add_reverse_ip_tag(reverse_iptag, machine_vertex2) gotton_tag = tag_info.get_reverse_ip_tags_for_vertex(machine_vertex) self.assertEqual(gotton_tag, None)
def test_add_iptag_then_fail_to_locate(self): """ test that asking for a invalid iptag returns a None value """ tag_info = Tags() iptag = IPTag("", 0, 0, 1, "122.2.2.2", 1, False) machine_vertex = SimpleMachineVertex(None, "") machine_vertex_2 = SimpleMachineVertex(None, "") tag_info.add_ip_tag(iptag, machine_vertex) gotton_tag = tag_info.get_ip_tags_for_vertex(machine_vertex_2) self.assertEqual(gotton_tag, None)
def test_add_conflicting_ip_tag(self): tags = Tags() tag1 = IPTag("", 0, 0, 1, "122.2.2.2", 1, False) tag2 = IPTag("", 0, 7, 1, "122.2.2.3", 1, False) tag3 = ReverseIPTag("", 1, 23, 0, 0, 1, 1) machine_vertex = SimpleMachineVertex(None, "") tags.add_ip_tag(tag1, machine_vertex) with self.assertRaises(PacmanInvalidParameterException) as e: tags.add_ip_tag(tag2, machine_vertex) self.assertIn( "The tag specified has already been assigned with " "different properties", str(e.exception)) with self.assertRaises(PacmanInvalidParameterException) as e: tags.add_reverse_ip_tag(tag3, machine_vertex) self.assertIn("The tag has already been assigned on the given board", str(e.exception)) with self.assertRaises(PacmanInvalidParameterException) as e: tags.add_ip_tag(tag3, machine_vertex) self.assertIn("Only add IP tags with this method.", str(e.exception))
def basic_tag_allocator(machine, plan_n_timesteps, placements): """ Basic tag allocator that goes though the boards available and applies\ the IP tags and reverse IP tags as needed. :param ~spinn_machine.Machine machine: The machine with respect to which to partition the application graph :param int plan_n_timesteps: number of timesteps to plan for :param Placements placements: :return: list of IP Tags, list of Reverse IP Tags, tag allocation holder :rtype: tuple(list(~spinn_machine.tags.IPTag), list(~spinn_machine.tags.ReverseIPTag), Tags) """ resource_tracker = ResourceTracker(machine, plan_n_timesteps) # Keep track of ports allocated to reverse IP tags and tags that still # need a port to be allocated ports_to_allocate = dict() tags_to_allocate_ports = list() # Check that the algorithm can handle the constraints progress = ProgressBar(placements.n_placements, "Discovering tags") placements_with_tags = list() for placement in progress.over(placements.placements): __gather_placements_with_tags(placement, placements_with_tags) # Go through and allocate the IP tags and constrained reverse IP tags tags = Tags() progress = ProgressBar(placements_with_tags, "Allocating tags") for placement in progress.over(placements_with_tags): __allocate_tags_for_placement(placement, resource_tracker, tags, ports_to_allocate, tags_to_allocate_ports) # Finally allocate ports to the unconstrained reverse IP tags __allocate_ports_for_reverse_ip_tags(tags_to_allocate_ports, ports_to_allocate, tags) return tags
def test_new_tag_info(self): """ test that creating a empty tag object works """ Tags()