Example #1
0
    def allocate_constrained_resources(self, resources, constraints,
                                       chips=None):
        """ Attempts to use the given resources of the machine, constrained\
            by the given placement constraints.

        :param resources: The resources to be allocated
        :type resources:\
                    :py:class:`pacman.model.resources.resource_container.ResourceContainer`
        :param constraints: An iterable of constraints containing the\
                    :py:class:`pacman.model.constraints.placer_constraints.placer_chip_and_core_constraint.PlacerChipAndCoreConstraint`;\
                    note that other types are ignored and no exception will be\
                    thrown
        :type constraints: iterable of \
                    :py:class:`pacman.model.constraints.abstract_constraints.abstract_constraint.AbstractConstraint`
        :param chips: The optional list of (x, y) tuples of chip coordinates\
                    of chips that can be used.  Note that any chips passed in\
                    previously will be ignored
        :type chips: iterable of (int, int)
        :return: The x and y coordinates of the used chip, the processor_id,\
                 and the ip tag and reverse ip tag allocation tuples
        :rtype: (int, int, int, list((int, int)), list((int, int)))
        :raise PacmanValueError: If the constraints cannot be met given the\
                    current allocation of resources
        """
        (x, y, p) = utility_calls.get_chip_and_core(constraints, chips)
        (board_address, ip_tags, reverse_ip_tags) = \
            utility_calls.get_ip_tag_info(constraints)
        chips = None
        if x is not None and y is not None:
            chips = [(x, y)]

        return self.allocate_resources(resources, chips, p, board_address,
                                       ip_tags, reverse_ip_tags)
    def allocate_constrained_resources(self,
                                       resources,
                                       constraints,
                                       chips=None):
        """ Attempts to use the given resources of the machine, constrained\
            by the given placement constraints.

        :param resources: The resources to be allocated
        :type resources:\
                    :py:class:`pacman.model.resources.resource_container.ResourceContainer`
        :param constraints: An iterable of constraints containing the\
                    :py:class:`pacman.model.constraints.placer_constraints.placer_chip_and_core_constraint.PlacerChipAndCoreConstraint`;\
                    note that other types are ignored and no exception will be\
                    thrown
        :type constraints: iterable of \
                    :py:class:`pacman.model.constraints.abstract_constraints.abstract_constraint.AbstractConstraint`
        :param chips: The optional list of (x, y) tuples of chip coordinates\
                    of chips that can be used.  Note that any chips passed in\
                    previously will be ignored
        :type chips: iterable of (int, int)
        :return: The x and y coordinates of the used chip, the processor_id,\
                 and the ip tag and reverse ip tag allocation tuples
        :rtype: (int, int, int, list((int, int)), list((int, int)))
        :raise PacmanValueError: If the constraints cannot be met given the\
                    current allocation of resources
        """
        (x, y, p) = utility_calls.get_chip_and_core(constraints, chips)
        (board_address, ip_tags, reverse_ip_tags) = \
            utility_calls.get_ip_tag_info(constraints)
        chips = None
        if x is not None and y is not None:
            chips = [(x, y)]

        return self.allocate_resources(resources, chips, p, board_address,
                                       ip_tags, reverse_ip_tags)
Example #3
0
    def get_maximum_constrained_resources_available(self, constraints,
                                                    chips=None):
        """ Get the maximum resources available given the constraints

        :param constraints: the constraints to match
        :type: iterable of\
                    :py:class:`pacman.model.constraints.abstract_constraint.AbstractConstraint`
        :param chips: the chips to locate the max available resources of
        :type chips: iterable of spinnmachine.chip.Chip
        """
        (x, y, p) = utility_calls.get_chip_and_core(constraints, chips)
        (board_address, ip_tags, reverse_ip_tags) = \
            utility_calls.get_ip_tag_info(constraints)
        chips = None
        if x is not None and y is not None:
            chips = [(x, y)]
        return self.get_maximum_resources_available(chips, p, board_address,
                                                    ip_tags, reverse_ip_tags)
    def get_maximum_constrained_resources_available(self,
                                                    constraints,
                                                    chips=None):
        """ Get the maximum resources available given the constraints

        :param constraints: the constraints to match
        :type: iterable of\
                    :py:class:`pacman.model.constraints.abstract_constraint.AbstractConstraint`
        :param chips: the chips to locate the max available resources of
        :type chips: iterable of spinnmachine.chip.Chip
        """
        (x, y, p) = utility_calls.get_chip_and_core(constraints, chips)
        (board_address, ip_tags, reverse_ip_tags) = \
            utility_calls.get_ip_tag_info(constraints)
        chips = None
        if x is not None and y is not None:
            chips = [(x, y)]
        return self.get_maximum_resources_available(chips, p, board_address,
                                                    ip_tags, reverse_ip_tags)
    def allocate_group(self, group_resources, placement_constraint,
                       ip_tag_constraint, reverse_ip_tag_constraint):
        """
        allocates a group of cores for these resources
        :param group_resources: the groups resources
        :param placement_constraint: placement constraint
        :param ip_tag_constraint: ipt_tag constraint
        :param reverse_ip_tag_constraint: reverse_ip_tag_constraint
        :return: list of The x and y coordinates of the used chip,
                    the processor_id, and the ip tag and reverse ip tag
                    allocation tuples
        :rtype: iterable of (int, int, int, list((int, int)), list((int, int)))
        """
        elements = list()
        if placement_constraint is not None:
            x = placement_constraint.x
            y = placement_constraint.y
            p = placement_constraint.p
        else:
            x = None
            y = None
            p = None

        tag_constraints = ip_tag_constraint + reverse_ip_tag_constraint
        (board_address, ip_tags, reverse_ip_tags) = \
            utility_calls.get_ip_tag_info(tag_constraints)
        chips = None
        if x is not None and y is not None:
            chips = [(x, y)]

        for resources in group_resources:
            element = self.allocate_resources(resources, chips, p,
                                              board_address, ip_tags,
                                              reverse_ip_tags)
            elements.append(element)
        return elements
Example #6
0
    def __call__(self, machine, placements):
        """ see AbstractTagAllocatorAlgorithm.allocate_tags
        """

        resource_tracker = ResourceTracker(machine)

        # Check that the algorithm can handle the constraints
        progress_bar = ProgressBar(placements.n_placements,
                                   "Allocating tags")
        placements_with_tags = list()
        for placement in placements.placements:
            utility_calls.check_algorithm_can_support_constraints(
                constrained_vertices=[placement.subvertex],
                supported_constraints=[
                    TagAllocatorRequireIptagConstraint,
                    TagAllocatorRequireReverseIptagConstraint
                ],
                abstract_constraint_type=AbstractTagAllocatorConstraint)
            if len(utility_calls.locate_constraints_of_type(
                    placement.subvertex.constraints,
                    AbstractTagAllocatorConstraint)):
                placements_with_tags.append(placement)
            progress_bar.update()

        # Go through and allocate the tags
        tags = Tags()
        for placement in placements_with_tags:
            vertex = placement.subvertex

            # Get the constraint details for the tags
            (board_address, ip_tags, reverse_ip_tags) =\
                utility_calls.get_ip_tag_info(vertex.constraints)

            # Allocate the tags, first-come, first-served, using the
            # fixed placement of the vertex, and the required resources
            chips = [(placement.x, placement.y)]
            resources = vertex.resources_required
            (_, _, _, returned_ip_tags, returned_reverse_ip_tags) = \
                resource_tracker.allocate_resources(
                    resources, chips, placement.p, board_address, ip_tags,
                    reverse_ip_tags)

            # Put the allocated ip tag information into the tag object
            if returned_ip_tags is not None:
                for (tag_constraint, (board_address, tag)) in zip(
                        ip_tags, returned_ip_tags):
                    ip_tag = IPTag(
                        board_address, tag, tag_constraint.ip_address,
                        tag_constraint.port, tag_constraint.strip_sdp)
                    tags.add_ip_tag(ip_tag, vertex)

            # Put the allocated reverse ip tag information into the tag object
            if returned_reverse_ip_tags is not None:
                for (tag_constraint, (board_address, tag)) in zip(
                        reverse_ip_tags, returned_reverse_ip_tags):
                    reverse_ip_tag = ReverseIPTag(
                        board_address, tag, tag_constraint.port, placement.x,
                        placement.y, placement.p, tag_constraint.sdp_port)
                    tags.add_reverse_ip_tag(reverse_ip_tag, vertex)

        progress_bar.end()
        return {'tags': tags}
    def __call__(self, machine, placements):
        """ see AbstractTagAllocatorAlgorithm.allocate_tags
        """

        resource_tracker = ResourceTracker(machine)

        # Check that the algorithm can handle the constraints
        progress_bar = ProgressBar(placements.n_placements, "Allocating tags")
        placements_with_tags = list()
        for placement in placements.placements:
            utility_calls.check_algorithm_can_support_constraints(
                constrained_vertices=[placement.subvertex],
                supported_constraints=[
                    TagAllocatorRequireIptagConstraint,
                    TagAllocatorRequireReverseIptagConstraint
                ],
                abstract_constraint_type=AbstractTagAllocatorConstraint)
            if len(
                    utility_calls.locate_constraints_of_type(
                        placement.subvertex.constraints,
                        AbstractTagAllocatorConstraint)):
                placements_with_tags.append(placement)
            progress_bar.update()

        # Go through and allocate the tags
        tags = Tags()
        for placement in placements_with_tags:
            vertex = placement.subvertex

            # Get the constraint details for the tags
            (board_address, ip_tags, reverse_ip_tags) =\
                utility_calls.get_ip_tag_info(vertex.constraints)

            # Allocate the tags, first-come, first-served, using the
            # fixed placement of the vertex, and the required resources
            chips = [(placement.x, placement.y)]
            resources = vertex.resources_required
            (_, _, _, returned_ip_tags, returned_reverse_ip_tags) = \
                resource_tracker.allocate_resources(
                    resources, chips, placement.p, board_address, ip_tags,
                    reverse_ip_tags)

            # Put the allocated ip tag information into the tag object
            if returned_ip_tags is not None:
                for (tag_constraint, (board_address,
                                      tag)) in zip(ip_tags, returned_ip_tags):
                    ip_tag = IPTag(board_address, tag,
                                   tag_constraint.ip_address,
                                   tag_constraint.port,
                                   tag_constraint.strip_sdp)
                    tags.add_ip_tag(ip_tag, vertex)

            # Put the allocated reverse ip tag information into the tag object
            if returned_reverse_ip_tags is not None:
                for (tag_constraint, (board_address,
                                      tag)) in zip(reverse_ip_tags,
                                                   returned_reverse_ip_tags):
                    reverse_ip_tag = ReverseIPTag(board_address, tag,
                                                  tag_constraint.port,
                                                  placement.x, placement.y,
                                                  placement.p,
                                                  tag_constraint.sdp_port)
                    tags.add_reverse_ip_tag(reverse_ip_tag, vertex)

        progress_bar.end()
        return {'tags': tags}