Example #1
0
    def _do_allocation(self, index, base_element_id, n_elements):
        """ Allocate a given base element ID and number of elements into the\
            space at the given slot

        :param index: The index of the free space slot to check
        :param base_element_id: \
            The element ID to start with - must be inside the slot
        :param n_elements: \
            The number of elements to be allocated - should be power of 2
        """

        free_space_slot = self._free_space_tracker[index]
        if free_space_slot.start_address > base_element_id:
            raise PacmanElementAllocationException(
                "Trying to allocate a element in the wrong slot!")

        # Check if there is enough space to allocate
        space = self._check_allocation(index, base_element_id, n_elements)
        if space is None:
            raise PacmanElementAllocationException(
                "Not enough space to allocate {} elements starting at {}".
                format(n_elements, hex(base_element_id)))

        if (free_space_slot.start_address == base_element_id
                and free_space_slot.size == n_elements):

            # If the slot exactly matches the space, remove it
            del self._free_space_tracker[index]

        elif free_space_slot.start_address == base_element_id:

            # If the slot starts with the element ID, reduce the size
            self._free_space_tracker[index] = ElementFreeSpace(
                free_space_slot.start_address + n_elements,
                free_space_slot.size - n_elements)

        elif space == n_elements:

            # If the space at the end exactly matches the spot, reduce the size
            self._free_space_tracker[index] = ElementFreeSpace(
                free_space_slot.start_address,
                free_space_slot.size - n_elements)

        else:

            # Otherwise, the allocation lies in the middle of the region:
            # First, reduce the size of the space before the allocation
            self._free_space_tracker[index] = ElementFreeSpace(
                free_space_slot.start_address,
                base_element_id - free_space_slot.start_address)

            # Then add a new space after the allocation
            self._free_space_tracker.insert(
                index + 1,
                ElementFreeSpace(
                    base_element_id + n_elements,
                    free_space_slot.start_address + free_space_slot.size -
                    (base_element_id + n_elements)))
    def _convert_to_pacman_router_table(self,
                                        mundy_compressed_router_table_entries,
                                        router_x_coord, router_y_coord):
        """
        :param mundy_compressed_router_table_entries: rig version of the table
        :param router_x_coord: the x coord of this routing table
        :param router_y_coord: the y coord of this routing table
        :return: pacman version of the table
        """

        table = MulticastRoutingTable(router_x_coord, router_y_coord)
        if (len(mundy_compressed_router_table_entries) >
                self.max_supported_length):
            raise PacmanElementAllocationException(
                "The routing table {}:{} after compression will still not fit"
                " within the machines router ({} entries)".format(
                    router_x_coord, router_y_coord,
                    len(mundy_compressed_router_table_entries)))

        for entry in mundy_compressed_router_table_entries:
            table.add_multicast_routing_entry(
                MulticastRoutingEntry(
                    entry.key,
                    entry.mask,  # Key and mask
                    ((int(c) - 6) for c in entry.route if c.is_core),  # Cores
                    (int(l) for l in entry.route if l.is_link),  # Links
                    False))  # NOT defaultable
        return table
Example #3
0
 def verify_lengths(self, compressed):
     """
     :param MulticastRoutingTables compressed:
     :raises PacmanElementAllocationException:
         if the compressed table won't fit
     """
     problems = ""
     for table in compressed:
         if table.number_of_entries > self.MAX_SUPPORTED_LENGTH:
             problems += "(x:{},y:{})={} ".format(table.x, table.y,
                                                  table.number_of_entries)
     if len(problems) > 0:
         raise PacmanElementAllocationException(
             "The routing table after compression will still not fit"
             " within the machines router: {}".format(problems))
    def _allocate_elements(self, base_element_id, n_elements):
        """ Handle the allocating of space for a given set of elements

        :param int base_element_id: the first element ID to allocate
        :param int n_elements: the number of elements to allocate
        :raises PacmanRouteInfoAllocationException:
            when the ID cannot be assigned due to the number of elements
        """

        index = self._find_slot(base_element_id)
        if index is None:
            raise PacmanElementAllocationException(
                "Space for {} elements starting at {} has already "
                "been allocated".format(n_elements, base_element_id))

        # base element should be >= slot element at this point
        self.__do_allocation(index, base_element_id, n_elements)
Example #5
0
    def _check_allocation(self, index, base_element_id, n_elements):
        """ Check if there is enough space for a given set of element IDs\
            starting at a base element ID inside a given slot

        :param index: The index of the free space slot to check
        :param base_element_id: \
            The element ID to start with - must be inside the slot
        :param n_elements: \
            The number of elements to be allocated - should be power of 2
        """
        free_space_slot = self._free_space_tracker[index]
        space = (free_space_slot.size -
                 (base_element_id - free_space_slot.start_address))

        if free_space_slot.start_address > base_element_id:
            raise PacmanElementAllocationException(
                "Trying to allocate a element ID in the wrong slot!")

        # Check if there is enough space for the elements
        if space < n_elements:
            return None
        return space