From bc491393456b69c3f37d9db9b2bed89bc016db7e Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Fri, 14 Jul 2023 16:21:20 +0100 Subject: [PATCH] use per chip n router entries --- .../ordered_covering.py | 14 ++------------ .../ordered_covering_compressor.py | 12 +++++++++++- .../router_compressors/pair_compressor.py | 11 ++++++++--- .../test_checked_unordered_pair_compression.py | 8 +++++++- .../router_compressor_tests/test_compressors.py | 1 + .../test_ordered_covering_compression.py | 8 ++++++-- .../test_pair_compression.py | 8 ++++++-- .../test_range_compressor.py | 1 + .../test_unordered_pair_compression.py | 8 ++++++-- unittests/test_fixed_route_router.py | 14 +++++++------- 10 files changed, 55 insertions(+), 30 deletions(-) diff --git a/pacman/operations/router_compressors/ordered_covering_router_compressor/ordered_covering.py b/pacman/operations/router_compressors/ordered_covering_router_compressor/ordered_covering.py index 1b47b826e..1f048f77c 100644 --- a/pacman/operations/router_compressors/ordered_covering_router_compressor/ordered_covering.py +++ b/pacman/operations/router_compressors/ordered_covering_router_compressor/ordered_covering.py @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from spinn_utilities.config_holder import get_config_bool -from spinn_machine import Machine -from pacman.data import PacmanDataView from pacman.operations.router_compressors import Entry from pacman.exceptions import MinimisationFailedError from .remove_default_routes import remove_default_routes @@ -24,7 +21,7 @@ def minimise( - routing_table, use_timer_cut_off=False, + routing_table, target_length, use_timer_cut_off=False, time_to_run_for_before_raising_exception=None): """ Reduce the size of a routing table by merging together entries where @@ -46,6 +43,7 @@ def minimise( :param list(Entry) routing_table: Routing entries to be merged. + :param int target_length: How far to compress :param bool use_timer_cut_off: flag for timing cut-off to be used. :param time_to_run_for_before_raising_exception: The time to run for in seconds before raising an exception @@ -56,14 +54,6 @@ def minimise( If the smallest table that can be produced is larger than ``target_length``. """ - if get_config_bool( - "Mapping", "router_table_compress_as_far_as_possible"): - # Compress as much as possible - target_length = None - else: - chip = PacmanDataView.get_chip_at(routing_table.x, routing_table .y) - target_length = chip.router.n_available_multicast_entries - # Keep None values as that flags as much as possible table, _ = ordered_covering( routing_table=routing_table, target_length=target_length, diff --git a/pacman/operations/router_compressors/ordered_covering_router_compressor/ordered_covering_compressor.py b/pacman/operations/router_compressors/ordered_covering_router_compressor/ordered_covering_compressor.py index 4c24e5d69..e7388169c 100644 --- a/pacman/operations/router_compressors/ordered_covering_router_compressor/ordered_covering_compressor.py +++ b/pacman/operations/router_compressors/ordered_covering_router_compressor/ordered_covering_compressor.py @@ -13,7 +13,9 @@ # limitations under the License. import logging +from spinn_utilities.config_holder import get_config_bool from spinn_utilities.log import FormatAdapter +from pacman.data import PacmanDataView from pacman.operations.router_compressors import (AbstractCompressor, Entry) from .ordered_covering import minimise @@ -46,6 +48,14 @@ def compress_table(self, router_table): :param UnCompressedMulticastRoutingTable router_table: :rtype: list(Entry) """ + if get_config_bool( + "Mapping", "router_table_compress_as_far_as_possible"): + # Compress as much as possible + target_length = None + else: + chip = PacmanDataView.get_chip_at(router_table.x, router_table.y) + target_length = chip.router.n_available_multicast_entries + # convert to rig inspired format entries = list() @@ -55,5 +65,5 @@ def compress_table(self, router_table): entries.append(Entry.from_MulticastRoutingEntry(router_entry)) # compress the router entries - compressed_router_table_entries = minimise(entries) + compressed_router_table_entries = minimise(entries, target_length) return compressed_router_table_entries diff --git a/pacman/operations/router_compressors/pair_compressor.py b/pacman/operations/router_compressors/pair_compressor.py index 8774f4682..403b8c6e3 100644 --- a/pacman/operations/router_compressors/pair_compressor.py +++ b/pacman/operations/router_compressors/pair_compressor.py @@ -13,6 +13,7 @@ # limitations under the License. from spinn_machine import Machine +from pacman.data import PacmanDataView from pacman.exceptions import PacmanElementAllocationException from .abstract_compressor import AbstractCompressor from .entry import Entry @@ -43,7 +44,9 @@ def verify_lengths(compressed): """ problems = "" for table in compressed: - if table.number_of_entries > Machine.ROUTER_ENTRIES: + chip = PacmanDataView.get_chip_at(table.x, table.y) + n_entries = chip.router.n_available_multicast_entries + if table.number_of_entries > n_entries: problems += f"(x:{table.x},y:{table.y})={table.number_of_entries} " if len(problems) > 0: raise PacmanElementAllocationException( @@ -385,8 +388,10 @@ def compress_table(self, router_table): self._all_entries = [] self._routes_count = 0 # Imitate creating fixed size arrays - self._routes = Machine.ROUTER_ENTRIES * [None] - self._routes_frequency = Machine.ROUTER_ENTRIES * [None] + chip = PacmanDataView.get_chip_at(router_table.x, router_table.y) + n_routes = chip.router.n_available_multicast_entries + self._routes = n_routes * [None] + self._routes_frequency = n_routes * [None] for entry in router_table.multicast_routing_entries: self._all_entries.append( diff --git a/unittests/operations_tests/router_compressor_tests/test_checked_unordered_pair_compression.py b/unittests/operations_tests/router_compressor_tests/test_checked_unordered_pair_compression.py index fb8869b97..67747d97c 100644 --- a/unittests/operations_tests/router_compressor_tests/test_checked_unordered_pair_compression.py +++ b/unittests/operations_tests/router_compressor_tests/test_checked_unordered_pair_compression.py @@ -16,6 +16,8 @@ import sys import unittest +from spinn_utilities.config_holder import set_config +from spinn_machine import virtual_machine from pacman.config_setup import unittest_setup from pacman.data.pacman_data_writer import PacmanDataWriter from pacman.model.routing_tables.multicast_routing_tables import (from_json) @@ -28,14 +30,18 @@ class TestUnorderedPairCompressor(unittest.TestCase): def setUp(self): unittest_setup() + set_config("Machine", "version", 5) def test_onordered_pair_big(self): + class_file = sys.modules[self.__module__].__file__ path = os.path.dirname(os.path.abspath(class_file)) j_router = os.path.join(path, "many_to_one.json.gz") original_tables = from_json(j_router) - PacmanDataWriter.mock().set_precompressed(original_tables) + writer = PacmanDataWriter.mock() + writer.set_precompressed(original_tables) + writer.set_machine(virtual_machine(24, 24)) with self.assertRaises(PacmanElementAllocationException): pair_compressor( ordered=False, accept_overflow=False, verify=True) diff --git a/unittests/operations_tests/router_compressor_tests/test_compressors.py b/unittests/operations_tests/router_compressor_tests/test_compressors.py index 669fe766b..7d51da718 100644 --- a/unittests/operations_tests/router_compressor_tests/test_compressors.py +++ b/unittests/operations_tests/router_compressor_tests/test_compressors.py @@ -53,6 +53,7 @@ def setUp(self): unittest_setup() set_config( "Mapping", "router_table_compress_as_far_as_possible", True) + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() writer.set_uncompressed(original_tables) writer.set_precompressed(original_tables) diff --git a/unittests/operations_tests/router_compressor_tests/test_ordered_covering_compression.py b/unittests/operations_tests/router_compressor_tests/test_ordered_covering_compression.py index bf61ec35a..1205c8436 100644 --- a/unittests/operations_tests/router_compressor_tests/test_ordered_covering_compression.py +++ b/unittests/operations_tests/router_compressor_tests/test_ordered_covering_compression.py @@ -16,6 +16,8 @@ import sys import unittest +from spinn_utilities.config_holder import set_config +from spinn_machine import virtual_machine from pacman.config_setup import unittest_setup from pacman.data.pacman_data_writer import PacmanDataWriter from pacman.model.routing_tables.multicast_routing_tables import (from_json) @@ -29,6 +31,7 @@ class TestOrderedCoveringCompressor(unittest.TestCase): def setUp(self): unittest_setup() + set_config("Machine", "version", 5) def test_oc_big(self): class_file = sys.modules[self.__module__].__file__ @@ -36,8 +39,9 @@ def test_oc_big(self): j_router = os.path.join(path, "many_to_one.json.gz") original_tables = from_json(j_router) - PacmanDataWriter.mock().set_precompressed( - original_tables) + writer = PacmanDataWriter.mock() + writer.set_precompressed(original_tables) + writer.set_machine(virtual_machine(24, 24)) compressed_tables = ordered_covering_compressor() for original in original_tables: diff --git a/unittests/operations_tests/router_compressor_tests/test_pair_compression.py b/unittests/operations_tests/router_compressor_tests/test_pair_compression.py index 3acf3dbd6..6c51e20b0 100644 --- a/unittests/operations_tests/router_compressor_tests/test_pair_compression.py +++ b/unittests/operations_tests/router_compressor_tests/test_pair_compression.py @@ -16,6 +16,8 @@ import sys import unittest +from spinn_utilities.config_holder import set_config +from spinn_machine import virtual_machine from pacman.config_setup import unittest_setup from pacman.data.pacman_data_writer import PacmanDataWriter from pacman.model.routing_tables.multicast_routing_tables import (from_json) @@ -28,14 +30,16 @@ class TestPairCompressor(unittest.TestCase): def setUp(self): unittest_setup() + set_config("Machine", "version", 5) def test_pair_big(self): class_file = sys.modules[self.__module__].__file__ path = os.path.dirname(os.path.abspath(class_file)) j_router = os.path.join(path, "many_to_one.json.gz") original_tables = from_json(j_router) - PacmanDataWriter.mock().set_precompressed( - original_tables) + writer = PacmanDataWriter.mock() + writer.set_precompressed(original_tables) + writer.set_machine(virtual_machine(24, 24)) compressed_tables = pair_compressor() for original in original_tables: diff --git a/unittests/operations_tests/router_compressor_tests/test_range_compressor.py b/unittests/operations_tests/router_compressor_tests/test_range_compressor.py index 50a7c3d5b..ce029feee 100644 --- a/unittests/operations_tests/router_compressor_tests/test_range_compressor.py +++ b/unittests/operations_tests/router_compressor_tests/test_range_compressor.py @@ -31,6 +31,7 @@ class TestRangeCompressor(unittest.TestCase): def setUp(self): unittest_setup() + set_config("Machine", "version", 5) set_config( "Mapping", "router_table_compress_as_far_as_possible", True) diff --git a/unittests/operations_tests/router_compressor_tests/test_unordered_pair_compression.py b/unittests/operations_tests/router_compressor_tests/test_unordered_pair_compression.py index a271fc026..f0dbf32e9 100644 --- a/unittests/operations_tests/router_compressor_tests/test_unordered_pair_compression.py +++ b/unittests/operations_tests/router_compressor_tests/test_unordered_pair_compression.py @@ -16,6 +16,8 @@ import sys import unittest +from spinn_utilities.config_holder import set_config +from spinn_machine import virtual_machine from pacman.config_setup import unittest_setup from pacman.data.pacman_data_writer import PacmanDataWriter from pacman.model.routing_tables.multicast_routing_tables import (from_json) @@ -29,14 +31,16 @@ class TestUnorderedPairCompressor(unittest.TestCase): def setUp(self): unittest_setup() + set_config("Machine", "version", 5) def test_onordered_pair_big(self): class_file = sys.modules[self.__module__].__file__ path = os.path.dirname(os.path.abspath(class_file)) j_router = os.path.join(path, "many_to_one.json.gz") original_tables = from_json(j_router) - PacmanDataWriter.mock().set_precompressed( - original_tables) + writer = PacmanDataWriter.mock() + writer.set_precompressed(original_tables) + writer.set_machine(virtual_machine(24, 24)) # Hack to stop it throwing a wobly for too many entries compressed_tables = pair_compressor(ordered=False) diff --git a/unittests/test_fixed_route_router.py b/unittests/test_fixed_route_router.py index 0079b581b..767dbc31a 100644 --- a/unittests/test_fixed_route_router.py +++ b/unittests/test_fixed_route_router.py @@ -67,20 +67,20 @@ def _check_setup(width, height): @pytest.mark.parametrize( - "width,height", - [(2, 2), - (8, 8), - (12, 12), - (16, 16)]) + "version, width,height", + [(3, 2, 2), + (5, 8, 8), + (5, 12, 12), + (5, 16, 16)]) @pytest.mark.parametrize( "with_down_links,with_down_chips", [(False, False), (True, False), (False, True), (True, True)]) -def test_all_working(width, height, with_down_links, with_down_chips): +def test_all_working(width, height, version, with_down_links, with_down_chips): unittest_setup() - set_config("Machine", "version", 5) + set_config("Machine", "version", version) temp_machine = virtual_machine(width=width, height=height) down_links = None if with_down_links: