def make_routing_tables():
    # Construct the vertices
    vertex_a = [object() for _ in range(17*2)]
    vertex_b = [object() for _ in range(2056)]
    vertex_c = [object() for _ in range(17*4)]

    # Construct the nets
    nets = list()

    # Fan out from A
    for a, bs in zip(vertex_a,
                     share_list(vertex_b, len(vertex_a))):
        nets.extend(Net(a, b) for b in bs)

    # Fan in to C
    for c, bs in zip(vertex_c,
                     share_list(vertex_b, len(vertex_c))):
        nets.extend(Net(b, c) for b in bs)

    # Construct constraints that place elements of vertex A together on the
    # same chip
    constraints = list()
    for aa in share_list(vertex_a, 2):
        constraints.append(SameChipConstraint(aa))

    # Add constraints that place elements of vertex C together on the same
    # chip.
    for cs in share_list(vertex_c, 4):
        constraints.append(SameChipConstraint(cs))

    # Each vertex will require 1 core
    vertices_resources = {a: {Cores: 1} for a in vertex_a}
    vertices_resources.update({b: {Cores: 1} for b in vertex_b})
    vertices_resources.update({c: {Cores: 1} for c in vertex_c})

    # Construct a faux-machine on which to place
    machine = Machine(12, 12)

    # Place and route the net
    placements = place(vertices_resources, nets, machine, constraints)
    allocations = allocate(vertices_resources, nets, machine, constraints,
                           placements)
    routes = route(vertices_resources, nets, machine, constraints, placements,
                   allocations)
Exemple #2
0
def make_routing_tables():
    # Construct the vertices
    vertex_a = [object() for _ in range(17 * 2)]
    vertex_b = [object() for _ in range(2056)]
    vertex_c = [object() for _ in range(17 * 4)]

    # Construct the nets
    nets = list()

    # Fan out from A
    for a, bs in zip(vertex_a, share_list(vertex_b, len(vertex_a))):
        nets.extend(Net(a, b) for b in bs)

    # Fan in to C
    for c, bs in zip(vertex_c, share_list(vertex_b, len(vertex_c))):
        nets.extend(Net(b, c) for b in bs)

    # Construct constraints that place elements of vertex A together on the
    # same chip
    constraints = list()
    for aa in share_list(vertex_a, 2):
        constraints.append(SameChipConstraint(aa))

    # Add constraints that place elements of vertex C together on the same
    # chip.
    for cs in share_list(vertex_c, 4):
        constraints.append(SameChipConstraint(cs))

    # Each vertex will require 1 core
    vertices_resources = {a: {Cores: 1} for a in vertex_a}
    vertices_resources.update({b: {Cores: 1} for b in vertex_b})
    vertices_resources.update({c: {Cores: 1} for c in vertex_c})

    # Construct a faux-machine on which to place
    machine = Machine(12, 12)

    # Place and route the net
    placements = place(vertices_resources, nets, machine, constraints)
    allocations = allocate(vertices_resources, nets, machine, constraints,
                           placements)
    routes = route(vertices_resources, nets, machine, constraints, placements,
                   allocations)
    def place_and_route(self,
                        constraints=None,
                        place=place, place_kwargs={},
                        allocate=allocate, allocate_kwargs={},
                        route=route, route_kwargs={}):
        """Place and route the vertices and nets in the current experiment, if
        required.

        If extra control is required over placement and routing of vertices and
        nets in an experiment, this method allows additional constraints and
        custom placement, allocation and routing options and algorithms to be
        used.

        The result of placement, allocation and routing can be found in
        :py:attr:`placements`, :py:attr:`allocations` and  :py:attr:`routes`
        respectively.

        If even greater control is required, :py:attr:`placements`,
        :py:attr:`allocations` and  :py:attr:`routes` may be set explicitly.
        Once these attributes have been set, this method will not alter them.

        Since many applications will not care strongly about placement,
        allocation and routing, this method is called implicitly by
        :py:meth:`.run`.

        Parameters
        ----------
        constraints : [constraint, ...]
            A list of additional constraints to apply. A
            :py:class:`rig.place_and_route.constraints.ReserveResourceConstraint`
            will be applied to reserve the monitor processor on top of this
            constraint.
        place : placer
            A Rig-API complaint placement algorithm.
        place_kwargs : dict
            Additional algorithm-specific keyword arguments to supply to the
            placer.
        allocate : allocator
            A Rig-API complaint allocation algorithm.
        allocate_kwargs : dict
            Additional algorithm-specific keyword arguments to supply to the
            allocator.
        route : router
            A Rig-API complaint route algorithm.
        route_kwargs : dict
            Additional algorithm-specific keyword arguments to supply to the
            router.
        """
        # Each traffic generator consumes a core and a negligible amount of
        # memory.
        vertices_resources = {vertex: {Cores: 1} for vertex in
                              self._vertices}

        # Reserve the monitor processor for each chip
        constraints = constraints or []
        constraints += [ReserveResourceConstraint(Cores, slice(0, 1))]

        # Reserve a core for packet reinjection on each chip (if required)
        if self._reinjection_used():
            constraints += [ReserveResourceConstraint(Cores, slice(1, 2))]

        if self.placements is None:
            logger.info("Placing vertices...")
            self.placements = place(vertices_resources=vertices_resources,
                                    nets=self._nets,
                                    machine=self.machine,
                                    constraints=constraints,
                                    **place_kwargs)
            self.allocations = None
            self.routes = None

        if self.allocations is None:
            logger.info("Allocating vertices...")
            self.allocations = allocate(vertices_resources=vertices_resources,
                                        nets=self._nets,
                                        machine=self.machine,
                                        constraints=constraints,
                                        placements=self.placements,
                                        **allocate_kwargs)
            self.routes = None

        if self.routes is None:
            logger.info("Routing vertices...")
            self.routes = route(vertices_resources=vertices_resources,
                                nets=self._nets,
                                machine=self.machine,
                                constraints=constraints,
                                placements=self.placements,
                                allocations=self.allocations,
                                **allocate_kwargs)