def test_full_machine_routing(self):
        placements = Placements()
        self.placement1 = Placement(x=1, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=1, y=0, p=3, subvertex=self.subvert2)
        subvertices = list()
        for i in range(4 * 17): #51 atoms per each processor on 20 chips
            subvertices.append(PartitionedVertex(
                0, 50, get_resources_used_by_atoms(0, 50, []),
                "Subvertex " + str(i)))
        subedges = list()
        for i in range(len(subvertices)):
            subedges.append(AbstractPartitionedEdge(
                subvertices[i], subvertices[(i + 1)%len(subvertices)]))
        subgraph = PartitionedGraph("Subgraph", subvertices, subedges)
        p = 1
        x = 0
        y = 0
        for subvert in subvertices:
            placements.add_placement(Placement(subvert, x, y, p))
            p = (p + 1) % 18
            if p == 0:
                p += 1
                y += 1
                if y == 2:
                    y = 0
                    x += 1

        routing_info = RoutingInfo()
        subedge_routing_info = list()
        for i in range(len(subedges)):
            subedge_routing_info.append(SubedgeRoutingInfo(
                subedges[i], i<<11, constants.DEFAULT_MASK))

        for subedge_info in subedge_routing_info:
            routing_info.add_subedge_info(subedge_info)


        self.set_up_4_node_board()

        dijkstra_router = BasicDijkstraRouting()
        routing_tables = dijkstra_router.route(
            machine=self.machine, placements=placements,
            partitioned_graph=subgraph,
            routing_info_allocation=routing_info)

        for entry in routing_tables.routing_tables:
            print entry.x, entry.y
            for routing_entry in entry.multicast_routing_entries:
                print "\t\tProcessor_ids:{}, Link_ids:{}".format(
                    routing_entry.processor_ids,
                    routing_entry.link_ids)
    def test_routing_on_chip_custom_4_node_machine(self):
        self.placements = Placements()
        self.placement1 = Placement(x=1, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=1, y=0, p=3, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        # sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)

        self.set_up_4_node_board()

        dijkstra_router = BasicDijkstraRouting()
        routing_tables = dijkstra_router.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

        for entry in routing_tables.routing_tables:
            print entry.x, entry.y
            for routing_entry in entry.multicast_routing_entries:
                print "\t\tProcessor_ids:{}, Link_ids:{}".format(
                    routing_entry.processor_ids,
                    routing_entry.link_ids)
Exemplo n.º 3
0
    def __call__(self, partitioned_graph, machine):

        # check that the algorithm can handle the constraints
        utility_calls.check_algorithm_can_support_constraints(
            constrained_vertices=partitioned_graph.subvertices,
            supported_constraints=[
                PlacerRadialPlacementFromChipConstraint,
                TagAllocatorRequireIptagConstraint,
                TagAllocatorRequireReverseIptagConstraint,
                PlacerChipAndCoreConstraint],
            abstract_constraint_type=AbstractPlacerConstraint)

        placements = Placements()
        ordered_subverts = utility_calls.sort_objects_by_constraint_authority(
            partitioned_graph.subvertices)

        # Iterate over subvertices and generate placements
        progress_bar = ProgressBar(len(ordered_subverts),
                                   "Placing graph vertices")
        resource_tracker = ResourceTracker(
            machine, self._generate_radial_chips(machine))
        for vertex in ordered_subverts:
            self._place_vertex(vertex, resource_tracker, machine, placements)
            progress_bar.update()
        progress_bar.end()
        return {'placements': placements}
Exemplo n.º 4
0
    def test_get_placement_of_subvertex(self):
        """
        checks the placements get placement method
        :return:
        """
        subv = list()
        for i in range(5):
            subv.append(PartitionedVertex(None, ""))

        pl = list()
        for i in range(4):
            pl.append(Placement(subv[i], 0, 0, i))

        pls = Placements(pl)
        for i in range(4):
            self.assertEqual(pls.get_placement_of_subvertex(subv[i]), pl[i])
Exemplo n.º 5
0
    def test_get_subvertex_on_processor(self):
        """
        checks that from a placements object, you can get to the correct
        subvertex using the get_subvertex_on_processor() method
        :return:
        """
        subv = list()
        for i in range(5):
            subv.append(PartitionedVertex(None, ""))

        pl = list()
        for i in range(4):
            pl.append(Placement(subv[i], 0, 0, i))

        pls = Placements(pl)
        for i in range(4):
            self.assertEqual(pls.get_subvertex_on_processor(0, 0, i), subv[i])

        self.assertEqual(pls.get_placement_of_subvertex(subv[0]), pl[0])
    def setUp(self):
        # sort out graph
        self.vert1 = Vertex(10, "New AbstractConstrainedVertex 1")
        self.vert2 = Vertex(5, "New AbstractConstrainedVertex 2")
        self.edge1 = AbstractPartitionableEdge(self.vert1, self.vert2, "First edge")
        self.verts = [self.vert1, self.vert2]
        self.edges = [self.edge1]
        self.graph = PartitionableGraph("Graph", self.verts, self.edges)
        # sort out subgraph
        self.subgraph = PartitionedGraph()
        self.subvert1 = PartitionedVertex(
            0, 10, get_resources_used_by_atoms(0, 10, []))
        self.subvert2 = PartitionedVertex(
            0, 5, get_resources_used_by_atoms(0, 10, []))
        self.subedge = AbstractPartitionedEdge(self.subvert1, self.subvert2)
        self.subgraph.add_subvertex(self.subvert1)
        self.subgraph.add_subvertex(self.subvert2)
        self.subgraph.add_subedge(self.subedge)
        # sort out placements
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=1, y=1, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        # sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        # create machine
        flops = 1000
        (e, ne, n, w, sw, s) = range(6)

        processors = list()
        for i in range(18):
            processors.append(Processor(i, flops))
        _sdram = SDRAM(128 * (2 ** 20))
        ip = "192.162.240.253"
        chips = list()
        for x in range(10):
            for y in range(10):
                links = list()

                links.append(Link(x, y, 0, (x + 1) % 10, y, n, n))
                links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s))
                links.append(Link(x, y, 2, x, (y + 1) % 10, n, n))
                links.append(Link(x, y, 3, (x - 1) % 10, y, s, s))
                links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n))
                links.append(Link(x, y, 5, x, (y - 1) % 10, s, s))

                r = Router(links, False, 100, 1024)
                chips.append(Chip(x, y, processors, r, _sdram, ip))

        self.machine = Machine(chips)
Exemplo n.º 7
0
    def __call__(self, partitioned_graph, machine):
        """ Place a partitioned_graph so that each subvertex is placed on a\
                    core

        :param partitioned_graph: The partitioned_graph to place
        :type partitioned_graph:\
                    :py:class:`pacman.model.partitioned_graph.partitioned_graph.PartitionedGraph`
        :return: A set of placements
        :rtype: :py:class:`pacman.model.placements.placements.Placements`
        :raise pacman.exceptions.PacmanPlaceException: If something\
                   goes wrong with the placement
        """

        # check that the algorithm can handle the constraints
        utility_calls.check_algorithm_can_support_constraints(
            constrained_vertices=partitioned_graph.subvertices,
            supported_constraints=[PlacerChipAndCoreConstraint],
            abstract_constraint_type=AbstractPlacerConstraint)

        placements = Placements()
        ordered_subverts = utility_calls.sort_objects_by_constraint_authority(
            partitioned_graph.subvertices)

        # Iterate over subvertices and generate placements
        progress_bar = ProgressBar(len(ordered_subverts),
                                   "Placing graph vertices")
        resource_tracker = ResourceTracker(machine)
        for subvertex in ordered_subverts:

            # Create and store a new placement anywhere on the board
            (x, y, p, _, _) = resource_tracker.allocate_constrained_resources(
                subvertex.resources_required, subvertex.constraints)
            placement = Placement(subvertex, x, y, p)
            placements.add_placement(placement)
            progress_bar.update()
        progress_bar.end()
        return {'placements': placements}
Exemplo n.º 8
0
    def __call__(self, partitioned_graph, machine):
        """ Place a partitioned_graph so that each subvertex is placed on a\
                    core

        :param partitioned_graph: The partitioned_graph to place
        :type partitioned_graph:\
                    :py:class:`pacman.model.partitioned_graph.partitioned_graph.PartitionedGraph`
        :return: A set of placements
        :rtype: :py:class:`pacman.model.placements.placements.Placements`
        :raise pacman.exceptions.PacmanPlaceException: If something\
                   goes wrong with the placement
        """

        # check that the algorithm can handle the constraints
        utility_calls.check_algorithm_can_support_constraints(
            constrained_vertices=partitioned_graph.subvertices,
            supported_constraints=[PlacerChipAndCoreConstraint],
            abstract_constraint_type=AbstractPlacerConstraint)

        placements = Placements()
        ordered_subverts = utility_calls.sort_objects_by_constraint_authority(
            partitioned_graph.subvertices)

        # Iterate over subvertices and generate placements
        progress_bar = ProgressBar(len(ordered_subverts),
                                   "Placing graph vertices")
        resource_tracker = ResourceTracker(machine)
        for subvertex in ordered_subverts:

            # Create and store a new placement anywhere on the board
            (x, y, p, _, _) = resource_tracker.allocate_constrained_resources(
                subvertex.resources_required, subvertex.constraints)
            placement = Placement(subvertex, x, y, p)
            placements.add_placement(placement)
            progress_bar.update()
        progress_bar.end()
        return {'placements': placements}
def test_memory_io():
    vertex = MyVertex()
    graph = MachineGraph("Test")
    graph.add_vertex(vertex)
    placements = Placements()
    placements.add_placement(Placement(vertex, 0, 0, 1))
    transceiver = _MockTransceiver()
    temp = tempfile.mkdtemp()
    print("ApplicationDataFolder = {}".format(temp))
    inputs = {
        "MemoryTransceiver": transceiver,
        "MemoryMachineGraph": graph,
        "MemoryPlacements": placements,
        "IPAddress": "testing",
        "ApplicationDataFolder": temp,
        "APPID": 30
    }
    algorithms = ["WriteMemoryIOData"]
    executor = PACMANAlgorithmExecutor(
        algorithms, [],
        inputs, [], [], [],
        xml_paths=get_front_end_common_pacman_xml_paths())
    executor.execute_mapping()
    assert (vertex._test_tag == vertex._tag)
Exemplo n.º 10
0
 def test_router_with_one_hop_route_all_default_link_5(self):
     self.placements = Placements()
     self.placement1 = Placement(x=0, y=2, p=2, subvertex=self.subvert1)
     self.placement2 = Placement(x=0, y=0, p=2, subvertex=self.subvert2)
     self.placements.add_placement(self.placement1)
     self.placements.add_placement(self.placement2)
     #sort out routing infos
     self.routing_info = RoutingInfo()
     self.subedge_routing_info1 = \
         SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                            subedge=self.subedge)
     self.routing_info.add_subedge_info(self.subedge_routing_info1)
     #create machine
     self.machine = VirtualMachine(10, 10, False)
     self.routing = BasicDijkstraRouting()
     self.routing.route(
         machine=self.machine, placements=self.placements,
         partitioned_graph=self.subgraph,
         routing_info_allocation=self.routing_info)
Exemplo n.º 11
0
    def __call__(self, partitioned_graph, machine):

        sorted_vertices = self._sort_vertices_for_one_to_one_connection(
            partitioned_graph)

        # check that the algorithm can handle the constraints
        utility_calls.check_algorithm_can_support_constraints(
            constrained_vertices=partitioned_graph.subvertices,
            supported_constraints=[
                PlacerRadialPlacementFromChipConstraint,
                TagAllocatorRequireIptagConstraint,
                TagAllocatorRequireReverseIptagConstraint,
                PlacerChipAndCoreConstraint
            ],
            abstract_constraint_type=AbstractPlacerConstraint)

        placements = Placements()

        self._do_allocation(sorted_vertices, placements, machine)

        return {'placements': placements}
Exemplo n.º 12
0
def convert_from_rig_placements(rig_placements, rig_allocations,
                                partitioned_graph):
    placements = Placements()
    for vertex_id in rig_placements:
        vertex = partitioned_graph.get_subvertex_by_id(vertex_id)
        if vertex is not None:
            if isinstance(vertex, VirtualPartitionedVertex):
                placements.add_placement(
                    Placement(vertex, vertex.virtual_chip_x,
                              vertex.virtual_chip_y, None))
            else:
                x, y = rig_placements[vertex_id]
                p = rig_allocations[vertex_id]["cores"].start
                placements.add_placement(Placement(vertex, x, y, p))

    return placements
Exemplo n.º 13
0
import logging
import os

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
for handler in logging.root.handlers:
    handler.setFormatter(
        logging.Formatter(fmt="%(asctime)-15s %(levelname)s: %(message)s",
                          datefmt="%Y-%m-%d %H:%M:%S"))

application_data = list()
binaries = ExecutableTargets()
iptags = list()
reverse_iptags = list()
buffered_tags = Tags()
buffered_placements = Placements()

routing_tables = MulticastRoutingTables()
# database params
socket_addresses = list()

reports_states = ReportState(False, False, False, False, False, False, False,
                             False, False, False)
machine_name = "192.168.240.253"
machine_version = 3
bmp_details = "None"
down_chips = "None"
down_cores = "None"
number_of_boards = 1
height = None
width = None
    def __call__(self, placements, allocations, partitioned_graph,
                 extended_machine, constraints):
        """

        :param placements:
        :param allocations:
        :param partitioned_graph:
        :param extended_machine:
        :param constraints:
        :return:
        """

        # load the json files
        file_placements, core_allocations, constraints = \
            self._load_json_files(placements, allocations, constraints)

        # validate the json files against the schemas
        self._validate_file_read_data(
            file_placements, core_allocations, constraints)

        # drop the type and allocations bit of core allocations
        # (makes lower code simpler)
        core_allocations = core_allocations['allocations']

        memory_placements = Placements()

        # process placements
        for vertex_repr in file_placements:
            subvertex = \
                partitioned_graph.get_subvertex_with_repr(vertex_repr)
            if vertex_repr not in core_allocations:
                if subvertex is not None:
                    # virtual chip or tag chip
                    constraints_for_vertex = self._locate_constraints(
                        vertex_repr, constraints)
                    external_device_constraints = \
                        self._valid_constraints_for_external_device(
                            constraints_for_vertex)
                    if len(external_device_constraints) != 0:

                        # get data for virtual chip
                        route_constraint = \
                            external_device_constraints['end_point']
                        route_direction = constants.EDGES(
                            route_constraint['direction'].upper())
                        placement_constraint = \
                            external_device_constraints['placement']
                        coords = placement_constraint['location']

                        # locate virtual chip
                        link = extended_machine.get_chip_at(
                            coords[0], coords[1]).router.get_link(
                            route_direction.value)
                        destination_chip = extended_machine.get_chip_at(
                            link.destination_x, link.destination_y)

                        # create placement
                        placements.add_placement(Placement(
                            subvertex, destination_chip.x, destination_chip.y,
                            None))
                    else:
                        raise exceptions.PacmanConfigurationException(
                            "I don't recognise this pattern of constraints for"
                            " a vertex which does not have a placement")
            else:
                if subvertex is None:
                    raise exceptions.PacmanConfigurationException(
                        "Failed to locate the partitioned vertex in the "
                        "partitioned graph with label {}".format(vertex_repr))
                else:
                    memory_placements.add_placement(
                        Placement(x=file_placements[vertex_repr][0],
                                  y=file_placements[vertex_repr][1],
                                  p=core_allocations[vertex_repr][0],
                                  subvertex=subvertex))

        # return the file format
        return {"placements": memory_placements}
Exemplo n.º 15
0
class MyTestCase(unittest.TestCase):
    def setUp(self):
        # sort out graph
        self.vert1 = Vertex(10, "New AbstractConstrainedVertex 1")
        self.vert2 = Vertex(5, "New AbstractConstrainedVertex 2")
        self.edge1 = AbstractPartitionableEdge(self.vert1, self.vert2, "First edge")
        self.verts = [self.vert1, self.vert2]
        self.edges = [self.edge1]
        self.graph = PartitionableGraph("Graph", self.verts, self.edges)
        # sort out subgraph
        self.subgraph = PartitionedGraph()
        self.subvert1 = PartitionedVertex(
            0, 10, get_resources_used_by_atoms(0, 10, []))
        self.subvert2 = PartitionedVertex(
            0, 5, get_resources_used_by_atoms(0, 10, []))
        self.subedge = AbstractPartitionedEdge(self.subvert1, self.subvert2)
        self.subgraph.add_subvertex(self.subvert1)
        self.subgraph.add_subvertex(self.subvert2)
        self.subgraph.add_subedge(self.subedge)
        # sort out placements
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=1, y=1, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        # sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        # create machine
        flops = 1000
        (e, ne, n, w, sw, s) = range(6)

        processors = list()
        for i in range(18):
            processors.append(Processor(i, flops))
        _sdram = SDRAM(128 * (2 ** 20))
        ip = "192.162.240.253"
        chips = list()
        for x in range(10):
            for y in range(10):
                links = list()

                links.append(Link(x, y, 0, (x + 1) % 10, y, n, n))
                links.append(Link(x, y, 1, (x + 1) % 10, (y + 1) % 10, s, s))
                links.append(Link(x, y, 2, x, (y + 1) % 10, n, n))
                links.append(Link(x, y, 3, (x - 1) % 10, y, s, s))
                links.append(Link(x, y, 4, (x - 1) % 10, (y - 1) % 10, n, n))
                links.append(Link(x, y, 5, x, (y - 1) % 10, s, s))

                r = Router(links, False, 100, 1024)
                chips.append(Chip(x, y, processors, r, _sdram, ip))

        self.machine = Machine(chips)

    @unittest.skip("demonstrating skipping")
    def set_up_4_node_board(self):
        flops = 1000
        (e, ne, n, w, sw, s) = range(6)

        processors = list()
        for i in range(18):
            processors.append(Processor(i, flops))
        _sdram = SDRAM(128 * (2 ** 20))
        ip = "192.162.240.253"
        chips = list()
        for x in range(2):
            for y in range(2):
                links = list()

                links.append(Link(x, y, 0, (x + 1) % 2, y, n, n))
                links.append(Link(x, y, 1, (x + 1) % 2, (y + 1) % 2, s, s))
                links.append(Link(x, y, 2, x, (y + 1) % 2, n, n))
                links.append(Link(x, y, 3, (x - 1) % 2, y, s, s))
                links.append(Link(x, y, 4, (x - 1) % 2, (y - 1) % 2, n, n))
                links.append(Link(x, y, 5, x, (y - 1) % 2, s, s))

                r = Router(links, False, 100, 1024)
                chips.append(Chip(x, y, processors, r, _sdram, ip))

        self.machine = Machine(chips)

    @unittest.skip("demonstrating skipping")
    def test_new_basic_router(self):
        dijkstra_router = BasicDijkstraRouting()
        self.assertEqual(dijkstra_router._k, 1)
        self.assertEqual(dijkstra_router._l, 0)
        self.assertEqual(dijkstra_router._m, 0)
        self.assertEqual(dijkstra_router._bw_per_route_entry,
                         dijkstra_router.BW_PER_ROUTE_ENTRY)
        self.assertEqual(dijkstra_router._max_bw, dijkstra_router.MAX_BW)

    @unittest.skip("demonstrating skipping")
    def test_run_basic_routing_off_chip_custom_100_node_machine(self):
        dijkstra_router = BasicDijkstraRouting()
        routing_tables = dijkstra_router.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)
        for entry in routing_tables.routing_tables:
            print entry.x, entry.y
            for routing_entry in entry.multicast_routing_entries:
                print "\t\tProcessor_ids:{}, Link_ids:{}".format(
                    routing_entry.processor_ids,
                    routing_entry.link_ids)

    @unittest.skip("demonstrating skipping")
    def test_run_basic_routing_off_chip_custom_4_node_machine(self):
        self.set_up_4_node_board()
        dijkstra_router = BasicDijkstraRouting()
        routing_tables = dijkstra_router.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

        for entry in routing_tables.routing_tables:
            print entry.x, entry.y
            for routing_entry in entry.multicast_routing_entries:
                print "\t\tProcessor_ids:{}, Link_ids:{}".format(
                    routing_entry.processor_ids,
                    routing_entry.link_ids)

    @unittest.skip("demonstrating skipping")
    def test_bad_machine_setup(self):
        # create machine
        flops = 1000
        (e, ne, n, w, sw, s) = range(6)

        processors = list()
        for i in range(18):
            processors.append(Processor(i, flops))

        links = list()
        links.append(Link(0, 0, 0, 0, 1, s, s))

        _sdram = SDRAM(128 * (2 ** 20))

        links = list()

        links.append(Link(0, 0, 0, 1, 1, n, n))
        links.append(Link(0, 1, 1, 1, 0, s, s))
        links.append(Link(1, 1, 2, 0, 0, e, e))
        links.append(Link(1, 0, 3, 0, 1, w, w))
        r = Router(links, False, 100, 1024)

        ip = "192.162.240.253"
        chips = list()
        for x in range(5):
            for y in range(5):
                chips.append(Chip(x, y, processors, r, _sdram, ip))
        self.machine = Machine(chips)
        dijkstra_router = BasicDijkstraRouting()

        with self.assertRaises(PacmanRoutingException):
            dijkstra_router.route(
                machine=self.machine, placements=self.placements,
                partitioned_graph=self.subgraph,
                routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_routing_on_chip_custom_4_node_machine(self):
        self.placements = Placements()
        self.placement1 = Placement(x=1, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=1, y=0, p=3, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        # sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)

        self.set_up_4_node_board()

        dijkstra_router = BasicDijkstraRouting()
        routing_tables = dijkstra_router.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

        for entry in routing_tables.routing_tables:
            print entry.x, entry.y
            for routing_entry in entry.multicast_routing_entries:
                print "\t\tProcessor_ids:{}, Link_ids:{}".format(
                    routing_entry.processor_ids,
                    routing_entry.link_ids)

    @unittest.skip("demonstrating skipping")
    def test_full_machine_routing(self):
        placements = Placements()
        self.placement1 = Placement(x=1, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=1, y=0, p=3, subvertex=self.subvert2)
        subvertices = list()
        for i in range(4 * 17): #51 atoms per each processor on 20 chips
            subvertices.append(PartitionedVertex(
                0, 50, get_resources_used_by_atoms(0, 50, []),
                "Subvertex " + str(i)))
        subedges = list()
        for i in range(len(subvertices)):
            subedges.append(AbstractPartitionedEdge(
                subvertices[i], subvertices[(i + 1)%len(subvertices)]))
        subgraph = PartitionedGraph("Subgraph", subvertices, subedges)
        p = 1
        x = 0
        y = 0
        for subvert in subvertices:
            placements.add_placement(Placement(subvert, x, y, p))
            p = (p + 1) % 18
            if p == 0:
                p += 1
                y += 1
                if y == 2:
                    y = 0
                    x += 1

        routing_info = RoutingInfo()
        subedge_routing_info = list()
        for i in range(len(subedges)):
            subedge_routing_info.append(SubedgeRoutingInfo(
                subedges[i], i<<11, constants.DEFAULT_MASK))

        for subedge_info in subedge_routing_info:
            routing_info.add_subedge_info(subedge_info)


        self.set_up_4_node_board()

        dijkstra_router = BasicDijkstraRouting()
        routing_tables = dijkstra_router.route(
            machine=self.machine, placements=placements,
            partitioned_graph=subgraph,
            routing_info_allocation=routing_info)

        for entry in routing_tables.routing_tables:
            print entry.x, entry.y
            for routing_entry in entry.multicast_routing_entries:
                print "\t\tProcessor_ids:{}, Link_ids:{}".format(
                    routing_entry.processor_ids,
                    routing_entry.link_ids)

    @unittest.skip("demonstrating skipping")
    def test_routing_to_other_machine(self):
        self.assertEqual(True, False, "Test not implemented yet")
    def __call__(self, placements, allocations, partitioned_graph,
                 extended_machine, constraints):
        """

        :param placements:
        :param allocations:
        :param partitioned_graph:
        :param extended_machine:
        :param constraints:
        :return:
        """

        # load the json files
        file_placements, core_allocations, constraints = \
            self._load_json_files(placements, allocations, constraints)

        # validate the json files against the schemas
        self._validate_file_read_data(file_placements, core_allocations,
                                      constraints)

        # drop the type and allocations bit of core allocations
        # (makes lower code simpler)
        core_allocations = core_allocations['allocations']

        memory_placements = Placements()

        # process placements
        for vertex_id in file_placements:
            subvertex = partitioned_graph.get_subvertex_by_id(vertex_id)
            if vertex_id not in core_allocations:
                if subvertex is not None:

                    # virtual chip or tag chip
                    constraints_for_vertex = self._locate_constraints(
                        vertex_id, constraints)
                    external_device_constraints = \
                        self._valid_constraints_for_external_device(
                            constraints_for_vertex)
                    if len(external_device_constraints) != 0:

                        # get data for virtual chip
                        route_constraint = \
                            external_device_constraints['end_point']
                        route_direction = constants.EDGES(
                            route_constraint['direction'].upper())
                        placement_constraint = \
                            external_device_constraints['placement']
                        coords = placement_constraint['location']

                        # locate virtual chip
                        link = extended_machine.get_chip_at(
                            coords[0],
                            coords[1]).router.get_link(route_direction.value)
                        destination_chip = extended_machine.get_chip_at(
                            link.destination_x, link.destination_y)

                        # create placement
                        placements.add_placement(
                            Placement(subvertex, destination_chip.x,
                                      destination_chip.y, None))
                    else:
                        raise exceptions.PacmanConfigurationException(
                            "I don't recognise this pattern of constraints for"
                            " a vertex which does not have a placement")
            else:
                if subvertex is None:
                    raise exceptions.PacmanConfigurationException(
                        "Failed to locate the partitioned vertex in the "
                        "partitioned graph with label {}".format(vertex_id))
                else:
                    memory_placements.add_placement(
                        Placement(x=file_placements[vertex_id][0],
                                  y=file_placements[vertex_id][1],
                                  p=core_allocations[vertex_id][0],
                                  subvertex=subvertex))

        # return the file format
        return {"placements": memory_placements}
Exemplo n.º 17
0
scamp_connection_data = "None"
boot_port_num = None
reset_machine_on_start_up = False
max_sdram_per_chip = None

router_tables = MulticastRoutingTables()
iptags = list()
reverse_iptags = list()
app_data_runtime_folder = os.path.abspath(
    os.path.join(os.path.realpath("__file__"), os.pardir))
dsg_targets = dict()
exec_dse_on_host = True
dse_app_id = 31

buffered_tags = Tags()
buffered_placements = Placements()

wait_for_read_confirmation = True
database_socket_addresses = list()
database_file_path = r"None"
send_start_notification = True

executable_targets = ExecutableTargets()
app_id = 30
runtime = 100.0
time_scale_factor = 1
total_machine_timesteps = 100
time_threshold = 5

router_tables.add_routing_table(
    ReloadRoutingTable.reload("picked_routing_table_for_0_0"))
Exemplo n.º 18
0
import logging
import os

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
for handler in logging.root.handlers:
    handler.setFormatter(
        logging.Formatter(fmt="%(asctime)-15s %(levelname)s: %(message)s",
                          datefmt="%Y-%m-%d %H:%M:%S"))

application_data = list()
binaries = ExecutableTargets()
iptags = list()
reverse_iptags = list()
buffered_tags = Tags()
buffered_placements = Placements()

routing_tables = MulticastRoutingTables()
# database params
socket_addresses = list()

reports_states = ReportState(False, False, False, False, False, False, False,
                             False, False, False)
machine_name = "192.168.240.253"
machine_version = 3
bmp_details = "None"
down_chips = "None"
down_cores = "None"
number_of_boards = 1
height = None
width = None
Exemplo n.º 19
0
class TestRouter(unittest.TestCase):

    def setUp(self):
        #sort out graph
        self.vert1 = Vertex(10, "New AbstractConstrainedVertex 1")
        self.vert2 = Vertex(5, "New AbstractConstrainedVertex 2")
        self.edge1 = AbstractPartitionableEdge(self.vert1, self.vert2, "First edge")
        self.verts = [self.vert1, self.vert2]
        self.edges = [self.edge1]
        self.graph = PartitionableGraph("Graph", self.verts, self.edges)
        #sort out subgraph
        self.subgraph = PartitionedGraph()
        self.subvert1 = PartitionedVertex(
            0, 10, self.vert1.get_resources_used_by_atoms(0, 10, []))
        self.subvert2 = PartitionedVertex(
            0, 5, self.vert2.get_resources_used_by_atoms(0, 10, []))
        self.subedge = AbstractPartitionedEdge(self.subvert1, self.subvert2)
        self.subgraph.add_subvertex(self.subvert1)
        self.subgraph.add_subvertex(self.subvert2)
        self.subgraph.add_subedge(self.subedge)

    @unittest.skip("demonstrating skipping")
    def test_router_with_same_chip_route(self):
        #sort out placements
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=0, y=0, p=3, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_router_with_neighbour_chip(self):
        #sort out placements
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=1, y=1, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_router_with_one_hop_route_all_default_link_0(self):
        #sort out placements
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=2, y=0, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_router_with_one_hop_route_all_default_link_1(self):
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=2, y=2, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_router_with_one_hop_route_all_default_link_2(self):
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=0, y=2, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_router_with_one_hop_route_all_default_link_3(self):
        self.placements = Placements()
        self.placement1 = Placement(x=2, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=0, y=0, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_router_with_one_hop_route_all_default_link_4(self):
        self.placements = Placements()
        self.placement1 = Placement(x=2, y=2, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=0, y=0, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_router_with_one_hop_route_all_default_link_5(self):
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=2, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=0, y=0, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_router_with_one_hop_route_not_default(self):
        #sort out placements
        self.placements = Placements()
        self.placement1 = Placement(x=2, y=1, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=0, y=0, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_router_with_multi_hop_route_across_board(self):
        #sort out placements
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=8, y=7, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)

    @unittest.skip("demonstrating skipping")
    def test_new_router(self):
        report_folder = "..\reports"
        self.routing = BasicDijkstraRouting()
        self.assertEqual(self.routing._report_folder, report_folder)
        self.assertEqual(self.routing._graph, None)
        self.assertEqual(self.routing.report_states, None)
        self.assertEqual(self.routing._hostname, None)
        self.assertIsInstance(self.routing._router_algorithm,
                              BasicDijkstraRouting)
        self.assertEqual(self.routing._graph_to_subgraph_mappings, None)

    @unittest.skip("demonstrating skipping")
    def test_new_router_set_non_default_routing_algorithm(self):
        report_folder = "..\reports"
        self.routing = BasicDijkstraRouting()
        self.assertEqual(self.routing._report_folder, report_folder)
        self.assertEqual(self.routing._graph, None)
        self.assertEqual(self.routing.report_states, None)
        self.assertEqual(self.routing._hostname, None)
        self.assertEqual(self.routing._graph_to_subgraph_mappings, None)

    @unittest.skip("demonstrating skipping")
    def test_run_router(self):
        #sort out placements
        self.placements = Placements()
        self.placement1 = Placement(x=0, y=0, p=2, subvertex=self.subvert1)
        self.placement2 = Placement(x=1, y=1, p=2, subvertex=self.subvert2)
        self.placements.add_placement(self.placement1)
        self.placements.add_placement(self.placement2)
        #sort out routing infos
        self.routing_info = RoutingInfo()
        self.subedge_routing_info1 = \
            SubedgeRoutingInfo(key=2 << 11, mask=constants.DEFAULT_MASK,
                               subedge=self.subedge)
        self.routing_info.add_subedge_info(self.subedge_routing_info1)
        #create machine
        self.machine = VirtualMachine(10, 10, False)
        self.routing = BasicDijkstraRouting()
        self.routing.route(
            machine=self.machine, placements=self.placements,
            partitioned_graph=self.subgraph,
            routing_info_allocation=self.routing_info)