def __call__(self, subgraph, n_keys_map, routing_paths): # check that this algorithm supports the constraints utility_calls.check_algorithm_can_support_constraints( constrained_vertices=subgraph.subedges, supported_constraints=[ KeyAllocatorFixedMaskConstraint, KeyAllocatorFixedKeyAndMaskConstraint, KeyAllocatorContiguousRangeContraint], abstract_constraint_type=AbstractKeyAllocatorConstraint) routing_tables = MulticastRoutingTables() # Get the partitioned edges grouped by those that require the same key same_key_groups = \ routing_info_allocator_utilities.get_edge_groups(subgraph) # Go through the groups and allocate keys progress_bar = ProgressBar(len(same_key_groups), "Allocating routing keys") routing_infos = RoutingInfo() for group in same_key_groups: # Check how many keys are needed for the edges of the group edge_n_keys = None for edge in group: n_keys = n_keys_map.n_keys_for_partitioned_edge(edge) if edge_n_keys is None: edge_n_keys = n_keys elif edge_n_keys != n_keys: raise PacmanRouteInfoAllocationException( "Two edges require the same keys but request a" " different number of keys") # Get any fixed keys and masks from the group and attempt to # allocate them keys_and_masks = routing_info_allocator_utilities.\ get_fixed_key_and_mask(group) fixed_mask, fields = \ routing_info_allocator_utilities.get_fixed_mask(group) if keys_and_masks is not None: self._allocate_fixed_keys_and_masks(keys_and_masks, fixed_mask) else: keys_and_masks = self._allocate_keys_and_masks( fixed_mask, fields, edge_n_keys) # Allocate the routing information for edge in group: subedge_info = SubedgeRoutingInfo(keys_and_masks, edge) routing_infos.add_subedge_info(subedge_info) # update routing tables with entries routing_info_allocator_utilities.add_routing_key_entries( routing_paths, subedge_info, edge, routing_tables) progress_bar.update() progress_bar.end() return {'routing_infos': routing_infos, 'routing_tables': routing_tables}
def __call__(self, subgraph, placements, n_keys_map, routing_paths): """ Allocates routing information to the partitioned edges in a\ partitioned graph :param subgraph: The partitioned graph to allocate the routing info for :type subgraph:\ :py:class:`pacman.model.partitioned_graph.partitioned_graph.PartitionedGraph` :param placements: The placements of the subvertices :type placements:\ :py:class:`pacman.model.placements.placements.Placements` :param n_keys_map: A map between the partitioned edges and the number\ of keys required by the edges :type n_keys_map:\ :py:class:`pacman.model.routing_info.abstract_partitioned_edge_n_keys_map.AbstractPartitionedEdgeNKeysMap` :param routing_paths: the paths each partitioned edge takes to get\ from source to destination. :type routing_paths: :py:class:`pacman.model.routing_paths.multicast_routing_paths.MulticastRoutingPaths :return: The routing information :rtype: :py:class:`pacman.model.routing_info.routing_info.RoutingInfo`, :py:class:`pacman.model.routing_tables.multicast_routing_table.MulticastRoutingTable :raise pacman.exceptions.PacmanRouteInfoAllocationException: If\ something goes wrong with the allocation """ # check that this algorithm supports the constraints put onto the # partitioned_edges supported_constraints = [RequiresRoutingInfoPartitionedVertex] utility_calls.check_algorithm_can_support_constraints( constrained_vertices=subgraph.subedges, supported_constraints=supported_constraints, abstract_constraint_type=AbstractKeyAllocatorConstraint) # take each subedge and create keys from its placement progress_bar = ProgressBar(len(subgraph.subvertices), "Allocating routing keys") routing_infos = RoutingInfo() routing_tables = MulticastRoutingTables() for subvert in subgraph.subvertices: out_going_subedges = subgraph.outgoing_subedges_from_subvertex( subvert) for out_going_subedge in out_going_subedges: n_keys = n_keys_map.n_keys_for_partitioned_edge( out_going_subedge) if n_keys > MAX_KEYS_SUPPORTED: raise PacmanRouteInfoAllocationException( "This routing info allocator can only support up to {}" " keys for any given subedge; cannot therefore" " allocate keys to {}, which is requesting {} keys" .format(MAX_KEYS_SUPPORTED, out_going_subedge, n_keys)) placement = placements.get_placement_of_subvertex(subvert) if placement is not None: key = self._get_key_from_placement(placement) keys_and_masks = list([BaseKeyAndMask(base_key=key, mask=MASK)]) subedge_routing_info = SubedgeRoutingInfo( keys_and_masks, out_going_subedge) routing_infos.add_subedge_info(subedge_routing_info) else: raise PacmanRouteInfoAllocationException( "This subvertex '{}' has no placement! this should " "never occur, please fix and try again." .format(subvert)) # update routing tables with entries routing_info_allocator_utilities.add_routing_key_entries( routing_paths, subedge_routing_info, out_going_subedge, routing_tables) progress_bar.update() progress_bar.end() return {'routing_infos': routing_infos, 'routing_tables': routing_tables}