From 0feb9644ca76411f093e29d0dbaf9de24a34c7c6 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 27 Mar 2024 07:16:52 +0000 Subject: [PATCH 1/9] replace FixedRoueEntry with Shared RoutingEntry class --- spinn_front_end_common/data/fec_data_view.py | 8 ++++---- spinn_front_end_common/data/fec_data_writer.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spinn_front_end_common/data/fec_data_view.py b/spinn_front_end_common/data/fec_data_view.py index 1e862a5003..508757ae57 100644 --- a/spinn_front_end_common/data/fec_data_view.py +++ b/spinn_front_end_common/data/fec_data_view.py @@ -21,7 +21,7 @@ from spinn_utilities.socket_address import SocketAddress from spinn_utilities.typing.coords import XY -from spinn_machine import Chip, CoreSubsets, FixedRouteEntry +from spinn_machine import Chip, CoreSubsets, RoutingEntry from spinnman.data import SpiNNManDataView from spinnman.model import ExecutableTargets from spinnman.model.enums import ExecutableType @@ -170,7 +170,7 @@ def _hard_reset(self) -> None: self._ds_database_path: Optional[str] = None self._next_ds_reference = 0 self._executable_targets: Optional[ExecutableTargets] = None - self._fixed_routes: Optional[Dict[XY, FixedRouteEntry]] = None + self._fixed_routes: Optional[Dict[XY, RoutingEntry]] = None self._gatherer_map: \ Optional[Dict[Chip, DataSpeedUpPacketGatherMachineVertex]] = None self._ipaddress: Optional[str] = None @@ -743,11 +743,11 @@ def get_ipaddress(cls) -> str: # fixed_routes @classmethod - def get_fixed_routes(cls) -> Dict[XY, FixedRouteEntry]: + def get_fixed_routes(cls) -> Dict[XY, RoutingEntry]: """ Gets the fixed routes if they have been created. - :rtype: dict((int, int), ~spinn_machine.FixedRouteEntry) + :rtype: dict((int, int), ~spinn_machine.RoutingEntry) :raises ~spinn_utilities.exceptions.SpiNNUtilsException: If the fixed_routes is currently unavailable """ diff --git a/spinn_front_end_common/data/fec_data_writer.py b/spinn_front_end_common/data/fec_data_writer.py index 49fbf16b9b..1b057cf3ac 100644 --- a/spinn_front_end_common/data/fec_data_writer.py +++ b/spinn_front_end_common/data/fec_data_writer.py @@ -23,7 +23,7 @@ from spinn_utilities.log import FormatAdapter from spinn_utilities.overrides import overrides from spinn_utilities.typing.coords import XY -from spinn_machine import Chip, FixedRouteEntry, CoreSubsets +from spinn_machine import Chip, CoreSubsets, RoutingEntry from spinnman.data.spinnman_data_writer import SpiNNManDataWriter from spinnman.messages.scp.enums.signal import Signal from spinnman.model import ExecutableTargets @@ -432,11 +432,11 @@ def set_ipaddress(self, ip_address: str): self.__fec_data._ipaddress = ip_address def set_fixed_routes( - self, fixed_routes: Dict[Tuple[int, int], FixedRouteEntry]): + self, fixed_routes: Dict[Tuple[int, int], RoutingEntry]): """ :param fixed_routes: :type fixed_routes: - dict((int, int), ~spinn_machine.FixedRouteEntry) + dict((int, int), ~spinn_machine.RoutingEntry) """ if not isinstance(fixed_routes, dict): raise TypeError("fixed_routes must be a dict") From 12ecdca61c2d00fd18109e6f1279623157e1c2c6 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 28 Mar 2024 07:41:07 +0000 Subject: [PATCH 2/9] MulticastRoutingEntry wraps a RoutingEntry --- .../host_bit_field_router_compressor.py | 11 ++++++----- .../system_multicast_routing_generator.py | 7 +++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py index fbff16fe1f..181c6fcf53 100644 --- a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py +++ b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py @@ -22,7 +22,7 @@ from spinn_utilities.find_max_success import find_max_success from spinn_utilities.progress_bar import ProgressBar from spinn_utilities.ordered_set import OrderedSet -from spinn_machine import MulticastRoutingEntry, Chip +from spinn_machine import Chip, MulticastRoutingEntry, RoutingEntry from pacman.exceptions import ( PacmanAlgorithmFailedToGenerateOutputsException, PacmanElementAllocationException, MinimisationFailedError) @@ -372,13 +372,14 @@ def _convert_bitfields_into_router_table( # Add an Entry for each neuron for neuron in range(n_neurons): # build new entry for this neuron and add to table - new_table.add_multicast_routing_entry(MulticastRoutingEntry( - routing_entry_key=base_key + neuron, - mask=self._NEURON_LEVEL_MASK, link_ids=entry_links, + routing_entry = RoutingEntry(link_ids=entry_links, defaultable=False, processor_ids=( processor_id for processor_id in original_entry.processor_ids - if core_map[processor_id][neuron]))) + if core_map[processor_id][neuron])) + new_table.add_multicast_routing_entry(MulticastRoutingEntry( + routing_entry_key=base_key + neuron, + mask=self._NEURON_LEVEL_MASK, entry=routing_entry)) # return the bitfield tables and the reduced original table return new_table diff --git a/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py b/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py index ec1aad47b0..3adeae929f 100644 --- a/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py +++ b/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py @@ -20,7 +20,7 @@ from spinn_utilities.typing.coords import XY from spinn_utilities.progress_bar import ProgressBar -from spinn_machine import MulticastRoutingEntry, Chip +from spinn_machine import Chip, MulticastRoutingEntry, RoutingEntry from pacman.exceptions import (PacmanRoutingException) from pacman.model.routing_tables import ( @@ -196,9 +196,12 @@ def _add_routing_entry( processor_ids = [processor_id] if link_ids is None: link_ids = [] + routing_entry = RoutingEntry( + processor_ids=processor_ids, link_ids=link_ids, + defaultable=False) entry = MulticastRoutingEntry( routing_entry_key=key, mask=ROUTING_MASK, - processor_ids=processor_ids, link_ids=link_ids, defaultable=False) + routing_entry=routing_entry) table.add_multicast_routing_entry(entry) def _add_routing_entries( From 2b62aebab570b07b1fc0fc061c5211e1c1f7ef50 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 28 Mar 2024 10:51:46 +0000 Subject: [PATCH 3/9] use MulticastRoutingEntry instead of RTEntry --- .../host_bit_field_router_compressor.py | 9 ++++----- .../host_no_bitfield_router_compression.py | 2 +- .../system_multicast_routing_generator.py | 2 +- .../utilities/report_functions/reports.py | 2 +- .../extra_monitor_support_machine_vertex.py | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py index 181c6fcf53..fdc37e8f69 100644 --- a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py +++ b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py @@ -30,7 +30,6 @@ AbstractMulticastRoutingTable, MulticastRoutingTables, UnCompressedMulticastRoutingTable, CompressedMulticastRoutingTable) from pacman.utilities.algorithm_utilities.routes_format import format_route -from pacman.operations.router_compressors import RTEntry from pacman.operations.router_compressors.pair_compressor import ( _PairCompressor) from spinn_front_end_common.abstract_models import ( @@ -249,7 +248,7 @@ def __init__(self, key_to_n_atom_map: Dict[int, int], :param dict(Chip,dict(int,int)) most_costly_cores: Map of chip to processors to count of incoming on processor """ - self._best_routing_entries: List[RTEntry] = [] + self._best_routing_entries: List[MulticastRoutingEntry] = [] self._best_midpoint = -1 self._bit_fields_by_key: Dict[int, List[_BitFieldData]] = {} self._compression_attempts: Dict[int, str] = dict() @@ -354,7 +353,7 @@ def _convert_bitfields_into_router_table( # go through the routing tables and convert when needed for original_entry in router_table.multicast_routing_entries: - base_key = original_entry.routing_entry_key + base_key = original_entry.key if base_key not in self._bit_fields_by_key: continue n_neurons = self.__key_atom_map[base_key] @@ -378,7 +377,7 @@ def _convert_bitfields_into_router_table( for processor_id in original_entry.processor_ids if core_map[processor_id][neuron])) new_table.add_multicast_routing_entry(MulticastRoutingEntry( - routing_entry_key=base_key + neuron, + key=base_key + neuron, mask=self._NEURON_LEVEL_MASK, entry=routing_entry)) # return the bitfield tables and the reduced original table @@ -573,7 +572,7 @@ def _binary_search_check( def _run_algorithm( self, router_table: AbstractMulticastRoutingTable - ) -> List[RTEntry]: + ) -> List[MulticastRoutingEntry]: """ Attempts to covert the mega router tables into 1 router table. diff --git a/spinn_front_end_common/interface/interface_functions/host_no_bitfield_router_compression.py b/spinn_front_end_common/interface/interface_functions/host_no_bitfield_router_compression.py index 662fb805ce..04acdcb7a7 100644 --- a/spinn_front_end_common/interface/interface_functions/host_no_bitfield_router_compression.py +++ b/spinn_front_end_common/interface/interface_functions/host_no_bitfield_router_compression.py @@ -229,7 +229,7 @@ def _build_data(self, table: AbstractMulticastRoutingTable) -> bytes: for entry in table.multicast_routing_entries: data += _FOUR_WORDS.pack( - entry.routing_entry_key, entry.mask, + entry.key, entry.mask, Router.convert_routing_table_entry_to_spinnaker_route(entry), get_defaultable_source_id(entry)) return bytearray(data) diff --git a/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py b/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py index 3adeae929f..2c972d0e73 100644 --- a/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py +++ b/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py @@ -200,7 +200,7 @@ def _add_routing_entry( processor_ids=processor_ids, link_ids=link_ids, defaultable=False) entry = MulticastRoutingEntry( - routing_entry_key=key, mask=ROUTING_MASK, + key=key, mask=ROUTING_MASK, routing_entry=routing_entry) table.add_multicast_routing_entry(entry) diff --git a/spinn_front_end_common/utilities/report_functions/reports.py b/spinn_front_end_common/utilities/report_functions/reports.py index 1ee5b22366..b7d88d047c 100644 --- a/spinn_front_end_common/utilities/report_functions/reports.py +++ b/spinn_front_end_common/utilities/report_functions/reports.py @@ -790,6 +790,6 @@ def _locate_routing_entry( """ if current_router is not None: for entry in current_router.multicast_routing_entries: - if entry.mask & key == entry.routing_entry_key: + if entry.mask & key == entry.key: return entry return None diff --git a/spinn_front_end_common/utility_models/extra_monitor_support_machine_vertex.py b/spinn_front_end_common/utility_models/extra_monitor_support_machine_vertex.py index 66bef5e0d5..2de524bc14 100644 --- a/spinn_front_end_common/utility_models/extra_monitor_support_machine_vertex.py +++ b/spinn_front_end_common/utility_models/extra_monitor_support_machine_vertex.py @@ -350,7 +350,7 @@ def _generate_data_speed_up_in_config( assert table is not None spec.write_value(table.number_of_entries) for entry in table.multicast_routing_entries: - spec.write_value(entry.routing_entry_key) + spec.write_value(entry.key) spec.write_value(entry.mask) spec.write_value(self.__encode_route(entry)) From 087ea1074dddfd0758c668d2ab20cf8e57ce0325 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 28 Mar 2024 13:20:32 +0000 Subject: [PATCH 4/9] minor fixes --- .../host_bit_field_router_compressor.py | 9 +++++---- .../system_multicast_routing_generator.py | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py index fdc37e8f69..90c6b5cb68 100644 --- a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py +++ b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py @@ -371,11 +371,12 @@ def _convert_bitfields_into_router_table( # Add an Entry for each neuron for neuron in range(n_neurons): # build new entry for this neuron and add to table + processor_ids = ( + processor_id + for processor_id in original_entry.processor_ids + if core_map[processor_id][neuron]) routing_entry = RoutingEntry(link_ids=entry_links, - defaultable=False, processor_ids=( - processor_id - for processor_id in original_entry.processor_ids - if core_map[processor_id][neuron])) + defaultable=False, processor_ids=processor_ids) new_table.add_multicast_routing_entry(MulticastRoutingEntry( key=base_key + neuron, mask=self._NEURON_LEVEL_MASK, entry=routing_entry)) diff --git a/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py b/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py index 2c972d0e73..78db4d69c5 100644 --- a/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py +++ b/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py @@ -196,9 +196,8 @@ def _add_routing_entry( processor_ids = [processor_id] if link_ids is None: link_ids = [] - routing_entry = RoutingEntry( - processor_ids=processor_ids, link_ids=link_ids, - defaultable=False) + routing_entry = RoutingEntry( + processor_ids=processor_ids, link_ids=link_ids, defaultable=False) entry = MulticastRoutingEntry( key=key, mask=ROUTING_MASK, routing_entry=routing_entry) From 3dd292e125e50fa1a6235b861169512ed4078b26 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 2 Apr 2024 07:30:36 +0100 Subject: [PATCH 5/9] fixes found by pylint --- .../interface_functions/host_bit_field_router_compressor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py index 90c6b5cb68..daefa9836d 100644 --- a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py +++ b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py @@ -379,7 +379,7 @@ def _convert_bitfields_into_router_table( defaultable=False, processor_ids=processor_ids) new_table.add_multicast_routing_entry(MulticastRoutingEntry( key=base_key + neuron, - mask=self._NEURON_LEVEL_MASK, entry=routing_entry)) + mask=self._NEURON_LEVEL_MASK, routing_entry=routing_entry)) # return the bitfield tables and the reduced original table return new_table @@ -581,7 +581,7 @@ def _run_algorithm( the set of router tables that together need to be merged into 1 router table :return: compressor router table - :rtype: list(~.RoutingTableEntry) + :rtype: list(MulticastRoutingEntry) :throws MinimisationFailedError: if it fails to compress to the correct length. """ From 74973d7dbafdd4a77d6eb590428b30b4df52b912 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 2 Apr 2024 07:41:50 +0100 Subject: [PATCH 6/9] flake8 --- .../interface_functions/host_bit_field_router_compressor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py index daefa9836d..f012528877 100644 --- a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py +++ b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py @@ -375,8 +375,9 @@ def _convert_bitfields_into_router_table( processor_id for processor_id in original_entry.processor_ids if core_map[processor_id][neuron]) - routing_entry = RoutingEntry(link_ids=entry_links, - defaultable=False, processor_ids=processor_ids) + routing_entry = RoutingEntry( + link_ids=entry_links, defaultable=False, + processor_ids=processor_ids) new_table.add_multicast_routing_entry(MulticastRoutingEntry( key=base_key + neuron, mask=self._NEURON_LEVEL_MASK, routing_entry=routing_entry)) From 4b29dd42e7a30a0f497b72f56f141dfe0ef3e773 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 2 Apr 2024 07:59:47 +0100 Subject: [PATCH 7/9] type fixes --- .../host_bit_field_router_compressor.py | 8 +++----- .../system_multicast_routing_generator.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py index f012528877..7c3e1ee846 100644 --- a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py +++ b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py @@ -313,8 +313,7 @@ def compress_bitfields( if self._best_routing_entries: for entry in self._best_routing_entries: - best_router_table.add_multicast_routing_entry( - entry.to_multicast_routing_entry()) + best_router_table.add_multicast_routing_entry(entry) compressed_pacman_router_tables.add_routing_table(best_router_table) @@ -376,8 +375,7 @@ def _convert_bitfields_into_router_table( for processor_id in original_entry.processor_ids if core_map[processor_id][neuron]) routing_entry = RoutingEntry( - link_ids=entry_links, defaultable=False, - processor_ids=processor_ids) + link_ids=entry_links, processor_ids=processor_ids) new_table.add_multicast_routing_entry(MulticastRoutingEntry( key=base_key + neuron, mask=self._NEURON_LEVEL_MASK, routing_entry=routing_entry)) @@ -686,7 +684,7 @@ def _create_table_report( # Note: _best_routing_table is a list(), router_table is not for entry in self._best_routing_entries: index = entry_count & self._LOWER_16_BITS - entry_str = format_route(entry.to_multicast_routing_entry()) + entry_str = format_route(entry) entry_count += 1 if entry.defaultable: n_defaultable += 1 diff --git a/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py b/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py index 78db4d69c5..bf76b8fb63 100644 --- a/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py +++ b/spinn_front_end_common/interface/interface_functions/system_multicast_routing_generator.py @@ -197,7 +197,7 @@ def _add_routing_entry( if link_ids is None: link_ids = [] routing_entry = RoutingEntry( - processor_ids=processor_ids, link_ids=link_ids, defaultable=False) + processor_ids=processor_ids, link_ids=link_ids) entry = MulticastRoutingEntry( key=key, mask=ROUTING_MASK, routing_entry=routing_entry) From a6f6f1318fbb6a912a7c79fad1fdc334bac13aac Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 2 Apr 2024 08:10:52 +0100 Subject: [PATCH 8/9] typing --- .../interface_functions/host_bit_field_router_compressor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py index 7c3e1ee846..4d9034663e 100644 --- a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py +++ b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py @@ -370,7 +370,7 @@ def _convert_bitfields_into_router_table( # Add an Entry for each neuron for neuron in range(n_neurons): # build new entry for this neuron and add to table - processor_ids = ( + processor_ids: Tuple[int] = ( processor_id for processor_id in original_entry.processor_ids if core_map[processor_id][neuron]) From c57e6d76dfc41342d2912b8c9992bde07392932e Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 2 Apr 2024 11:15:23 +0100 Subject: [PATCH 9/9] use list --- .../interface_functions/host_bit_field_router_compressor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py index 4d9034663e..6796584794 100644 --- a/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py +++ b/spinn_front_end_common/interface/interface_functions/host_bit_field_router_compressor.py @@ -370,10 +370,10 @@ def _convert_bitfields_into_router_table( # Add an Entry for each neuron for neuron in range(n_neurons): # build new entry for this neuron and add to table - processor_ids: Tuple[int] = ( + processor_ids: List[int] = [ processor_id for processor_id in original_entry.processor_ids - if core_map[processor_id][neuron]) + if core_map[processor_id][neuron]] routing_entry = RoutingEntry( link_ids=entry_links, processor_ids=processor_ids) new_table.add_multicast_routing_entry(MulticastRoutingEntry(