예제 #1
0
    def test_new_multicast_routing_tables(self):
        key_combo = 0xff35
        mask = 0xffff
        proc_ids = list()
        link_ids = list()
        for i in range(18):
            proc_ids.append(i)
        for i in range(6):
            link_ids.append(i)
        multicast_entries1 = MulticastRoutingEntry(key_combo, mask, proc_ids,
                                                   link_ids, True)
        multicast_entries2 = MulticastRoutingEntry(key_combo - 1, mask - 1,
                                                   proc_ids, link_ids, True)
        mrt = list()

        t1 = UnCompressedMulticastRoutingTable(0, 0, [multicast_entries1])
        t2 = UnCompressedMulticastRoutingTable(1, 0, [multicast_entries2])
        mrt.append(t1)
        mrt.append(t2)
        tables = MulticastRoutingTables(mrt)
        retrieved_tables = tables.routing_tables
        self.assertEqual(len(retrieved_tables), len(mrt))
        for tab in retrieved_tables:
            self.assertIn(tab, mrt)

        self.assertEqual(tables.get_routing_table_for_chip(0, 0), t1)
        self.assertEqual(tables.get_routing_table_for_chip(1, 0), t2)
        self.assertEqual(tables.get_routing_table_for_chip(2, 0), None)

        json_obj = to_json(tables)
        file_format_schemas.validate(json_obj, "routing_tables.json")
        new_tables = from_json(json_obj)
        self.assertEqual(new_tables.get_routing_table_for_chip(0, 0), t1)
        self.assertEqual(new_tables.get_routing_table_for_chip(1, 0), t2)
        self.assertEqual(new_tables.get_routing_table_for_chip(2, 0), None)
예제 #2
0
    def _convert_bitfields_into_router_tables(self, router_table,
                                              bitfields_by_key,
                                              key_to_n_atoms_map):
        """ Converts the bitfield into router table entries for compression, \
            based off the entry located in the original router table.

        :param ~.UnCompressedMulticastRoutingTable router_table:
            the original routing table
        :param dict(int,list(_BitFieldData)) bitfields_by_key:
            the bitfields of the chip.
        :param dict(int,int) key_to_n_atoms_map:
        :return: routing tables.
        :rtype: list(~.AbsractMulticastRoutingTable)
        """
        bit_field_router_tables = list()

        # clone the original entries
        original_route_entries = list()
        original_route_entries.extend(router_table.multicast_routing_entries)

        # go through the bitfields and get the routing table for it
        for master_pop_key in bitfields_by_key.keys():

            bit_field_original_entry = \
                router_table.get_entry_by_routing_entry_key(master_pop_key)
            bit_field_entries = UnCompressedMulticastRoutingTable(
                router_table.x,
                router_table.y,
                multicast_routing_entries=(
                    self._generate_entries_from_bitfield(
                        bitfields_by_key[master_pop_key],
                        bit_field_original_entry, key_to_n_atoms_map)))

            # add to the list
            bit_field_router_tables.append(bit_field_entries)

            # remove entry
            original_route_entries.remove(bit_field_original_entry)

        # create reduced
        reduced_original_table = UnCompressedMulticastRoutingTable(
            router_table.x, router_table.y, original_route_entries)

        # add reduced to front of the tables
        bit_field_router_tables.insert(0, reduced_original_table)

        # return the bitfield tables and the reduced original table
        return bit_field_router_tables
 def _create_routing_table(self, chip, partitions_in_table, routing_infos,
                           info_by_app_vertex):
     """
     :param ~spinn_machine.Chip chip:
     :param partitions_in_table:
     :type partitions_in_table:
         dict(AbstractSingleSourcePartition,
         MulticastRoutingTableByPartitionEntry)
     :param RoutingInfo routing_infos:
     :param dict(ApplicationVertex,BaseKeyAndMask) info_by_app_vertex:
     :rtype: MulticastRoutingTable
     """
     table = UnCompressedMulticastRoutingTable(chip.x, chip.y)
     partitions_by_app_vertex = defaultdict(set)
     for partition in partitions_in_table:
         partitions_by_app_vertex[partition.pre_vertex.app_vertex].add(
             partition)
     for app_vertex in partitions_by_app_vertex:
         if app_vertex in info_by_app_vertex:
             shared_entry = self._find_shared_entry(
                 partitions_by_app_vertex[app_vertex], partitions_in_table)
         else:
             shared_entry = None
         if shared_entry is None:
             self._add_partition_based(partitions_by_app_vertex[app_vertex],
                                       routing_infos, partitions_in_table,
                                       table)
         else:
             self.__add_key_and_mask(info_by_app_vertex[app_vertex],
                                     shared_entry, table)
     return table
예제 #4
0
 def _create_routing_table(self, chip, partitions_in_table, routing_infos):
     """
     :param ~spinn_machine.Chip chip:
     :param partitions_in_table:
     :type partitions_in_table:
         dict(AbstractSingleSourcePartition,
         MulticastRoutingTableByPartitionEntry)
     :param RoutingInfo routing_infos:
     :rtype: MulticastRoutingTable
     """
     table = UnCompressedMulticastRoutingTable(chip.x, chip.y)
     for partition in partitions_in_table:
         r_info = routing_infos.get_routing_info_from_partition(partition)
         entry = partitions_in_table[partition]
         for key_and_mask in r_info.keys_and_masks:
             table.add_multicast_routing_entry(
                 self.__create_entry(key_and_mask, entry))
     return table
예제 #5
0
def test_router_compressor_on_error():
    routing_tables = MulticastRoutingTables(
        [UnCompressedMulticastRoutingTable(0, 0)])
    transceiver = MockTransceiverError()
    machine = virtual_machine(width=8, height=8)
    mundy_on_chip_router_compression(routing_tables,
                                     transceiver,
                                     machine,
                                     app_id=17,
                                     system_provenance_folder="")
예제 #6
0
 def test_new_multicast_routing_table_duplicate_entry(self):
     """
     test that adding multiple identical entries into a multicast table
     causes an error
     """
     key_combo = 0xff35
     mask = 0xff35
     proc_ids = list()
     link_ids = list()
     for i in range(18):
         proc_ids.append(i)
     for i in range(6):
         link_ids.append(i)
     multicast_entries = list()
     for i in range(5):
         multicast_entries.append(
             MulticastRoutingEntry(key_combo + i, mask + i, proc_ids,
                                   link_ids, True))
     mrt = UnCompressedMulticastRoutingTable(0, 0, multicast_entries)
     with self.assertRaises(PacmanAlreadyExistsException):
         mrt.add_multicast_routing_entry(multicast_entries[0])
예제 #7
0
    def test_add_routing_table_for_duplicate_chip(self):
        key_combo = 0xff35
        mask = 0xffff
        proc_ids = list()
        link_ids = list()
        for i in range(18):
            proc_ids.append(i)
        for i in range(6):
            link_ids.append(i)
        multicast_entries1 = MulticastRoutingEntry(key_combo, mask, proc_ids,
                                                   link_ids, True)

        multicast_entries2 = MulticastRoutingEntry(key_combo - 1, mask,
                                                   proc_ids, link_ids, True)
        mrt = list()
        mrt.append(
            UnCompressedMulticastRoutingTable(3, 0, [multicast_entries1]))
        mrt.append(
            UnCompressedMulticastRoutingTable(3, 0, [multicast_entries2]))
        with self.assertRaises(PacmanAlreadyExistsException):
            MulticastRoutingTables(mrt)
예제 #8
0
    def test_new_multicast_routing_table(self):
        """
        test that creating a multicast routing entry and adding it to the table
        works
        """
        key_combo = 0xff000
        mask = 0xff000
        proc_ids = list()
        link_ids = list()
        for i in range(18):
            proc_ids.append(i)
        for i in range(6):
            link_ids.append(i)
        multicast_entries = list()
        for i in range(5):
            multicast_entries.append(
                MulticastRoutingEntry(key_combo + i, mask + i, proc_ids,
                                      link_ids, True))
        mrt = UnCompressedMulticastRoutingTable(0, 0, multicast_entries)
        self.assertEqual(mrt.x, 0)
        self.assertEqual(mrt.y, 0)

        mre = mrt.multicast_routing_entries
        for entry in mre:
            self.assertIn(entry, multicast_entries)
        self.assertEqual(len(mre), len(multicast_entries))
        for i in range(5):
            self.assertEqual(
                mrt.get_multicast_routing_entry_by_routing_entry_key(
                    key_combo + i, mask + i), multicast_entries[i])
        self.assertEqual(
            mrt.get_multicast_routing_entry_by_routing_entry_key(
                key_combo + 5, mask + 5), None)
        self.assertEqual(
            mrt.get_multicast_routing_entry_by_routing_entry_key(
                key_combo - 1, mask - 1), None)
    def _add_routing_entry(self, x, y, key, processor_id=None, link_ids=None):
        """ Adds a routing entry on this chip, creating the table if needed.

        :param int x: chip.x
        :param int y: chip.y
        :param int key: The key to use
        :param int processor_id:
            placement.p of the monitor vertex if applicable
        :param int link_id: If of the link out if applicable
        """
        table = self._routing_tables.get_routing_table_for_chip(x, y)
        if table is None:
            table = UnCompressedMulticastRoutingTable(x, y)
            self._routing_tables.add_routing_table(table)
        if processor_id is None:
            processor_ids = []
        else:
            processor_ids = [processor_id]
        if link_ids is None:
            link_ids = []
        entry = MulticastRoutingEntry(
            routing_entry_key=key, mask=ROUTING_MASK,
            processor_ids=processor_ids, link_ids=link_ids, defaultable=False)
        table.add_multicast_routing_entry(entry)
예제 #10
0
    def test_new_multicast_routing_table_duplicate_key_combo(self):

        key_combo = 0xff35
        mask = 0xffff
        proc_ids = list()
        link_ids = list()
        for i in range(18):
            proc_ids.append(i)
        for i in range(6):
            link_ids.append(i)
        multicast_entries = list()
        for i in range(5):
            multicast_entries.append(
                MulticastRoutingEntry(key_combo, mask, proc_ids, link_ids,
                                      True))
        with self.assertRaises(PacmanAlreadyExistsException):
            UnCompressedMulticastRoutingTable(0, 0, multicast_entries)
예제 #11
0
 def test_new_multicast_routing_table_empty(self):
     """
     tests creating a basic multicast routing table
     """
     UnCompressedMulticastRoutingTable(0, 0)
예제 #12
0
 def setUp(self):
     self.original_tables = MulticastRoutingTables()
     original_table = UnCompressedMulticastRoutingTable(x=0, y=0)
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b0000, 0b1111, [1, 2], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b0001, 0b1111, [0], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b0101, 0b1111, [4], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b1000, 0b1111, [1, 2], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b1001, 0b1111, [0], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b1110, 0b1111, [4], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b1100, 0b1111, [1, 2], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b0010, 0b1011, [4, 5], [], False))
     self.original_tables.add_routing_table(original_table)
예제 #13
0
 def setUp(self):
     self.original_tables = MulticastRoutingTables()
     original_table = UnCompressedMulticastRoutingTable(x=0, y=0)
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b0000, 0b1111, [1, 2], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b0001, 0b1111, [0], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b0101, 0b1111, [4], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b1000, 0b1111, [1, 2], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b1001, 0b1111, [0], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b1110, 0b1111, [4], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b1100, 0b1111, [1, 2], [], False))
     original_table.add_multicast_routing_entry(
         MulticastRoutingEntry(0b0010, 0b1011, [4, 5], [], False))
     self.original_tables.add_routing_table(original_table)
     unittest_setup()
     set_config("Mapping", "router_table_compress_as_far_as_possible", True)