From b8dfcd0403bd050e1d4985198cd72f0b4e460f8d Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 12 Jul 2023 13:10:18 +0100 Subject: [PATCH 1/7] get n_cores from Version classes --- pacman/operations/placer_algorithms/application_placer.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pacman/operations/placer_algorithms/application_placer.py b/pacman/operations/placer_algorithms/application_placer.py index 5317656aa..9a709dc4b 100644 --- a/pacman/operations/placer_algorithms/application_placer.py +++ b/pacman/operations/placer_algorithms/application_placer.py @@ -224,10 +224,11 @@ def _check_could_fit(app_vertex, vertices_to_place, sdram): :param int sdram: :raises PacmanTooBigToPlace: """ + version = PacmanDataView.get_machine_version() max_sdram = ( Machine.DEFAULT_SDRAM_BYTES - PacmanDataView.get_monitor_sdram()) max_cores = ( - Machine.DEFAULT_MAX_CORES_PER_CHIP - Machine.NON_USER_CORES - + version.max_cores_per_chip - Machine.NON_USER_CORES - PacmanDataView.get_monitor_cores()) n_cores = len(vertices_to_place) if sdram <= max_sdram and n_cores <= max_cores: @@ -244,10 +245,10 @@ def _check_could_fit(app_vertex, vertices_to_place, sdram): message += f"after monitors only {max_sdram} bytes are available " message += "Lowering max_core_per_chip may resolve this." raise PacmanTooBigToPlace(message) - if n_cores > Machine.DEFAULT_MAX_CORES_PER_CHIP: + if n_cores > version.max_cores_per_chip: message += " is more vertices than the number of cores on a chip." raise PacmanTooBigToPlace(message) - user_cores = Machine.DEFAULT_MAX_CORES_PER_CHIP - Machine.NON_USER_CORES + user_cores = version.max_cores_per_chip - Machine.NON_USER_CORES if n_cores > user_cores: message += ( f"is more vertices than the user cores ({user_cores}) " From cbf14b127f51d5d8f83728671fdba8ac6f744405 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 12 Jul 2023 13:32:52 +0100 Subject: [PATCH 2/7] n_non_user_cores via Version --- pacman/operations/placer_algorithms/application_placer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pacman/operations/placer_algorithms/application_placer.py b/pacman/operations/placer_algorithms/application_placer.py index 9a709dc4b..fb5dc6984 100644 --- a/pacman/operations/placer_algorithms/application_placer.py +++ b/pacman/operations/placer_algorithms/application_placer.py @@ -228,7 +228,7 @@ def _check_could_fit(app_vertex, vertices_to_place, sdram): max_sdram = ( Machine.DEFAULT_SDRAM_BYTES - PacmanDataView.get_monitor_sdram()) max_cores = ( - version.max_cores_per_chip - Machine.NON_USER_CORES - + version.max_cores_per_chip - version.n_non_user_cores - PacmanDataView.get_monitor_cores()) n_cores = len(vertices_to_place) if sdram <= max_sdram and n_cores <= max_cores: @@ -248,7 +248,7 @@ def _check_could_fit(app_vertex, vertices_to_place, sdram): if n_cores > version.max_cores_per_chip: message += " is more vertices than the number of cores on a chip." raise PacmanTooBigToPlace(message) - user_cores = version.max_cores_per_chip - Machine.NON_USER_CORES + user_cores = version.max_cores_per_chip - version.n_non_user_cores if n_cores > user_cores: message += ( f"is more vertices than the user cores ({user_cores}) " From d66b0d3aa26e59d9851bf9d6505b1c2fd4a7d8ad Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Wed, 12 Jul 2023 15:11:53 +0100 Subject: [PATCH 3/7] max_sdram_per_chip via version --- .../placer_algorithms_tests/test_application_placer.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/unittests/operations_tests/placer_algorithms_tests/test_application_placer.py b/unittests/operations_tests/placer_algorithms_tests/test_application_placer.py index ff4d4f04c..06ff10438 100644 --- a/unittests/operations_tests/placer_algorithms_tests/test_application_placer.py +++ b/unittests/operations_tests/placer_algorithms_tests/test_application_placer.py @@ -132,8 +132,9 @@ def test_application_placer_late_fixed(): def test_sdram_bigger_than_chip(): unittest_setup() writer = PacmanDataWriter.mock() + max_sdram = writer.get_machine_version().max_sdram_per_chip _make_vertices(writer, 1, 1, 5, "big_app_vertex", - sdram=Machine.DEFAULT_SDRAM_BYTES + 24) + sdram=max_sdram + 24) try: place_application_graph(Placements()) raise AssertionError("Error not raise") @@ -144,13 +145,12 @@ def test_sdram_bigger_than_chip(): def test_sdram_bigger_monitors(): unittest_setup() writer = PacmanDataWriter.mock() - monitor = SimpleMachineVertex( - ConstantSDRAM(Machine.DEFAULT_SDRAM_BYTES // 2)) + max_sdram = writer.get_machine_version().max_sdram_per_chip + monitor = SimpleMachineVertex(ConstantSDRAM(max_sdram // 2)) # This is purely an info call so test check directly writer.add_monitor_all_chips(monitor) try: - _check_could_fit("app_test", ["m_vertex]"], - sdram=Machine.DEFAULT_SDRAM_BYTES // 2 + 5) + _check_could_fit("app_test", ["m_vertex]"], sdram=max_sdram // 2 + 5) raise AssertionError("Error not raise") except PacmanTooBigToPlace as ex: assert ("after monitors only" in str(ex)) From 0bac6287177b7240343d76106325a44d1563da6a Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 13 Jul 2023 10:45:52 +0100 Subject: [PATCH 4/7] use Version classes --- .../placer_algorithms/application_placer.py | 6 +++--- .../test_application_placer.py | 10 +++++++++- .../router_algorithms_tests/test_routers.py | 16 ++++++++++++++++ .../routing_table_generator_tests/test_basic.py | 2 ++ .../routing_table_generator_tests/test_merged.py | 2 ++ .../test_tags_board_addresses.py | 2 ++ unittests/test_fixed_route_router.py | 2 ++ 7 files changed, 36 insertions(+), 4 deletions(-) diff --git a/pacman/operations/placer_algorithms/application_placer.py b/pacman/operations/placer_algorithms/application_placer.py index fb5dc6984..2e954da6b 100644 --- a/pacman/operations/placer_algorithms/application_placer.py +++ b/pacman/operations/placer_algorithms/application_placer.py @@ -226,7 +226,7 @@ def _check_could_fit(app_vertex, vertices_to_place, sdram): """ version = PacmanDataView.get_machine_version() max_sdram = ( - Machine.DEFAULT_SDRAM_BYTES - PacmanDataView.get_monitor_sdram()) + version.max_sdram_per_chip - PacmanDataView.get_monitor_sdram()) max_cores = ( version.max_cores_per_chip - version.n_non_user_cores - PacmanDataView.get_monitor_cores()) @@ -239,8 +239,8 @@ def _check_could_fit(app_vertex, vertices_to_place, sdram): f"the reason is that {vertices_to_place} ") if sdram > max_sdram: message += f"requires {sdram} bytes but " - if sdram > Machine.DEFAULT_SDRAM_BYTES: - message += f"a Chip only has {Machine.DEFAULT_SDRAM_BYTES} bytes " + if sdram > version.max_sdram_per_chip: + message += f"a Chip only has {version.max_sdram_per_chip} bytes " else: message += f"after monitors only {max_sdram} bytes are available " message += "Lowering max_core_per_chip may resolve this." diff --git a/unittests/operations_tests/placer_algorithms_tests/test_application_placer.py b/unittests/operations_tests/placer_algorithms_tests/test_application_placer.py index 06ff10438..a46e88708 100644 --- a/unittests/operations_tests/placer_algorithms_tests/test_application_placer.py +++ b/unittests/operations_tests/placer_algorithms_tests/test_application_placer.py @@ -13,7 +13,7 @@ # limitations under the License. import unittest -from spinn_machine import Machine +from spinn_utilities.config_holder import set_config from spinn_machine.virtual_machine import virtual_machine from pacman.data.pacman_data_writer import PacmanDataWriter from pacman.exceptions import ( @@ -96,6 +96,7 @@ def _make_vertices( def test_application_placer(): unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() # fixed early works as this vertex is looked at first fixed = SimpleTestVertex(10, "FIXED", max_atoms_per_core=1) @@ -111,6 +112,7 @@ def test_application_placer(): def test_application_placer_late_fixed(): unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() for i in range(56): _make_vertices(writer, 1000, 14, 5, f"app_vertex_{i}") @@ -131,6 +133,7 @@ def test_application_placer_late_fixed(): def test_sdram_bigger_than_chip(): unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() max_sdram = writer.get_machine_version().max_sdram_per_chip _make_vertices(writer, 1, 1, 5, "big_app_vertex", @@ -144,6 +147,7 @@ def test_sdram_bigger_than_chip(): def test_sdram_bigger_monitors(): unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() max_sdram = writer.get_machine_version().max_sdram_per_chip monitor = SimpleMachineVertex(ConstantSDRAM(max_sdram // 2)) @@ -158,6 +162,7 @@ def test_sdram_bigger_monitors(): def test_more_cores_than_chip(): unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() _make_vertices(writer, 1, 1, 19, "big_app_vertex") try: @@ -169,6 +174,7 @@ def test_more_cores_than_chip(): def test_more_cores_than_user(): unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() _make_vertices(writer, 1, 1, 18, "big_app_vertex") try: @@ -180,6 +186,7 @@ def test_more_cores_than_user(): def test_more_cores_with_monitor(): unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() monitor = SimpleMachineVertex(ConstantSDRAM(4000)) # This is purely an info call so test check directly @@ -194,6 +201,7 @@ def test_more_cores_with_monitor(): def test_could_fit(): unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() monitor = SimpleMachineVertex(ConstantSDRAM(0)) writer.add_monitor_all_chips(monitor) diff --git a/unittests/operations_tests/router_algorithms_tests/test_routers.py b/unittests/operations_tests/router_algorithms_tests/test_routers.py index 31c324274..96b66693f 100644 --- a/unittests/operations_tests/router_algorithms_tests/test_routers.py +++ b/unittests/operations_tests/router_algorithms_tests/test_routers.py @@ -441,6 +441,7 @@ def _route_and_time(algorithm): def test_simple(params): algorithm, _n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() source_vertex = _make_vertices(writer, 1000, n_m_vertices, "source") target_vertex = _make_vertices(writer, 1000, n_m_vertices, "target") @@ -454,6 +455,7 @@ def test_simple(params): def test_self(params): algorithm, _n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() source_vertex = _make_vertices(writer, 1000, n_m_vertices, "self") writer.add_edge(ApplicationEdge(source_vertex, source_vertex), "Test") @@ -466,6 +468,7 @@ def test_self(params): def test_simple_self(params): algorithm, _n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() source_vertex = _make_vertices(writer, 1000, n_m_vertices, "source") target_vertex = _make_vertices(writer, 1000, n_m_vertices, "target") @@ -481,6 +484,7 @@ def test_simple_self(params): def test_multi(params): algorithm, n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() for i in range(n_vertices): _make_vertices(writer, 1000, n_m_vertices, f"app_vertex_{i}") @@ -497,6 +501,7 @@ def test_multi(params): def test_multi_self(params): algorithm, n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() for i in range(n_vertices): _make_vertices(writer, 1000, n_m_vertices, f"app_vertex_{i}") @@ -512,6 +517,7 @@ def test_multi_self(params): def test_multi_split(params): algorithm, n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() for i in range(n_vertices): _make_vertices_split(writer, 1000, 3, 2, n_m_vertices, @@ -530,6 +536,7 @@ def test_multi_split(params): def test_multi_self_split(params): algorithm, n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() for i in range(n_vertices): _make_vertices_split(writer, 1000, 3, 2, n_m_vertices, @@ -547,6 +554,7 @@ def test_multi_self_split(params): def test_multi_down_chips_and_links(params): algorithm, n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() for i in range(n_vertices): _make_vertices(writer, 1000, n_m_vertices, f"app_vertex_{i}") @@ -602,6 +610,7 @@ def test_multi_down_chips_and_links(params): def test_internal_only(params): algorithm, _n_vertices, _n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() _make_vertices_split( writer, 1000, 3, 2, 2, "app_vertex", @@ -616,6 +625,7 @@ def test_internal_only(params): def test_internal_and_split(params): algorithm, n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() for i in range(n_vertices): _make_vertices_split( @@ -635,6 +645,7 @@ def test_internal_and_split(params): def test_spinnaker_link(params): algorithm, n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() in_device = ApplicationSpiNNakerLinkVertex(100, 0) in_device.splitter = SplitterExternalDevice() @@ -658,6 +669,7 @@ def test_spinnaker_link(params): def test_fpga_link(params): algorithm, n_vertices, n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() in_device = ApplicationFPGAVertex( 100, [FPGAConnection(0, 0, None, None)], None) @@ -684,6 +696,7 @@ def test_fpga_link(params): def test_fpga_link_overlap(params): algorithm, _n_vertices, _n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() set_config("Machine", "down_chips", "6,1") writer.set_machine(virtual_machine(12, 12)) @@ -705,6 +718,7 @@ def test_fpga_link_overlap(params): def test_odd_case(params): algorithm, _n_vertices, _n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() target_vertex = _make_vertices(writer, 200, 20, "app_vertex") delay_vertex = _make_one_to_one_vertices(writer, 200, 20, "delay_vtx") @@ -740,6 +754,7 @@ def test_with_ethernet_system_placements(params): # to one of them algorithm, _n_vertices, _n_m_vertices = params unittest_setup() + set_config("Machine", "version", 5) writer = PacmanDataWriter.mock() writer.set_machine(virtual_machine(16, 16)) source_vertex = _make_vertices(writer, 200, 3, "app_vertex") @@ -782,6 +797,7 @@ def _check_path(source, nodes_fixed, machine, target): def test_route_around(): unittest_setup() + set_config("Machine", "version", 5) # Take out all the chips around 3,3 except one then make a path that goes # through it # 3,4 4,4 diff --git a/unittests/operations_tests/routing_table_generator_tests/test_basic.py b/unittests/operations_tests/routing_table_generator_tests/test_basic.py index 5339a03c7..5b717bf63 100644 --- a/unittests/operations_tests/routing_table_generator_tests/test_basic.py +++ b/unittests/operations_tests/routing_table_generator_tests/test_basic.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest +from spinn_utilities.config_holder import set_config from pacman.config_setup import unittest_setup from pacman.data.pacman_data_writer import PacmanDataWriter from pacman.model.graphs.application import ApplicationEdge @@ -35,6 +36,7 @@ class TestBasic(unittest.TestCase): def setUp(self): unittest_setup() + set_config("Machine", "version", 5) def create_graphs3(self, writer): v1 = SimpleTestVertex( diff --git a/unittests/operations_tests/routing_table_generator_tests/test_merged.py b/unittests/operations_tests/routing_table_generator_tests/test_merged.py index a47193174..50ed5973c 100644 --- a/unittests/operations_tests/routing_table_generator_tests/test_merged.py +++ b/unittests/operations_tests/routing_table_generator_tests/test_merged.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest +from spinn_utilities.config_holder import set_config from pacman.config_setup import unittest_setup from pacman.data.pacman_data_writer import PacmanDataWriter from pacman.exceptions import PacmanRoutingException @@ -37,6 +38,7 @@ class TestMerged(unittest.TestCase): def setUp(self): unittest_setup() + set_config("Machine", "version", 5) def create_graphs1(self, writer): v1 = SimpleTestVertex( diff --git a/unittests/operations_tests/tag_allocator_tests/test_tags_board_addresses.py b/unittests/operations_tests/tag_allocator_tests/test_tags_board_addresses.py index 14fcf9864..b0a62ba04 100644 --- a/unittests/operations_tests/tag_allocator_tests/test_tags_board_addresses.py +++ b/unittests/operations_tests/tag_allocator_tests/test_tags_board_addresses.py @@ -14,6 +14,7 @@ import unittest from collections import defaultdict +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 @@ -30,6 +31,7 @@ class TestTagsBoardAddresses(unittest.TestCase): """ def setUp(self): unittest_setup() + set_config("Machine", "version", 5) def test_ip_tags(self): writer = PacmanDataWriter.mock() diff --git a/unittests/test_fixed_route_router.py b/unittests/test_fixed_route_router.py index 2c94580a2..0079b581b 100644 --- a/unittests/test_fixed_route_router.py +++ b/unittests/test_fixed_route_router.py @@ -80,6 +80,7 @@ def _check_setup(width, height): (True, True)]) def test_all_working(width, height, with_down_links, with_down_chips): unittest_setup() + set_config("Machine", "version", 5) temp_machine = virtual_machine(width=width, height=height) down_links = None if with_down_links: @@ -101,6 +102,7 @@ def test_all_working(width, height, with_down_links, with_down_chips): def test_unreachable(): unittest_setup() + set_config("Machine", "version", 5) set_config("Machine", "down_chips", "0,2:1,3:1,4") with pytest.raises(PacmanRoutingException): _check_setup(8, 8) From 8a2c6e3dcfafb26b5e2c87e7344fa99fdd24b1f6 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Fri, 14 Jul 2023 08:17:20 +0100 Subject: [PATCH 5/7] n_router_entries from Version and machine object --- .../router_compressors/abstract_compressor.py | 19 ++++++++++--------- .../ordered_covering.py | 4 +++- .../router_compressors/ranged_compressor.py | 9 ++++++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/pacman/operations/router_compressors/abstract_compressor.py b/pacman/operations/router_compressors/abstract_compressor.py index 0be732635..a4376e332 100644 --- a/pacman/operations/router_compressors/abstract_compressor.py +++ b/pacman/operations/router_compressors/abstract_compressor.py @@ -18,6 +18,9 @@ from abc import abstractmethod import logging + +import sys + from spinn_utilities.config_holder import get_config_bool from spinn_utilities.log import FormatAdapter from spinn_utilities.progress_bar import ProgressBar @@ -70,7 +73,7 @@ def compress_tables(self, router_tables, progress): """ Compress all the unordered routing tables. - Tables who start of smaller than target_length are not compressed + Tables who start of smaller than global_target are not compressed :param MulticastRoutingTables router_tables: Routing tables :param ~spinn_utilities.progress_bar.ProgressBar progress: @@ -80,14 +83,12 @@ def compress_tables(self, router_tables, progress): :raises MinimisationFailedError: on failure """ compressed_tables = MulticastRoutingTables() - if get_config_bool( - "Mapping", "router_table_compress_as_far_as_possible"): - # Compress as much as possible - target_length = 0 - else: - target_length = Machine.ROUTER_ENTRIES + as_needed = not(get_config_bool( + "Mapping", "router_table_compress_as_far_as_possible")) for table in progress.over(router_tables.routing_tables): - if table.number_of_entries < target_length: + chip = PacmanDataView.get_chip_at(table.x, table.y) + target = chip.router.n_available_multicast_entries + if as_needed and table.number_of_entries <= target: new_table = table else: compressed_table = self.compress_table(table) @@ -97,7 +98,7 @@ def compress_tables(self, router_tables, progress): for entry in compressed_table: new_table.add_multicast_routing_entry( entry.to_MulticastRoutingEntry()) - if new_table.number_of_entries > Machine.ROUTER_ENTRIES: + if new_table.number_of_entries > target: self._problems += ( f"(x:{new_table.x},y:{new_table.y})=" f"{new_table.number_of_entries} ") 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 ce787270e..1b47b826e 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 @@ -14,6 +14,7 @@ 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 @@ -60,7 +61,8 @@ def minimise( # Compress as much as possible target_length = None else: - target_length = Machine.ROUTER_ENTRIES + 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( diff --git a/pacman/operations/router_compressors/ranged_compressor.py b/pacman/operations/router_compressors/ranged_compressor.py index 072a12ea9..a3ba9b1df 100644 --- a/pacman/operations/router_compressors/ranged_compressor.py +++ b/pacman/operations/router_compressors/ranged_compressor.py @@ -44,8 +44,9 @@ def range_compressor(accept_overflow=True): compressed_tables = MulticastRoutingTables() for table in progress.over(router_tables.routing_tables): new_table = compressor.compress_table(table) - if (new_table.number_of_entries > Machine.ROUTER_ENTRIES and - not accept_overflow): + chip = PacmanDataView.get_chip_at(table.x, table.y) + target = chip.router.n_available_multicast_entries + if (new_table.number_of_entries > target and not accept_overflow): raise MinimisationFailedError( f"The routing table {table.x} {table.y} with " f"{table.number_of_entries} entries after compression " @@ -87,7 +88,9 @@ def compress_table(self, uncompressed): # Check you need to compress if not get_config_bool( "Mapping", "router_table_compress_as_far_as_possible"): - if uncompressed.number_of_entries < Machine.ROUTER_ENTRIES: + chip = PacmanDataView.get_chip_at(uncompressed.x, uncompressed.y) + target = chip.router.n_available_multicast_entries + if uncompressed.number_of_entries < target: return uncompressed # Step 1 get the entries and make sure they are sorted by key From bc491393456b69c3f37d9db9b2bed89bc016db7e Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Fri, 14 Jul 2023 16:21:20 +0100 Subject: [PATCH 6/7] 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: From 9620b4db6c994a7c8d32bd3065d57110d81a8a0a Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 20 Jul 2023 16:02:27 +0100 Subject: [PATCH 7/7] flake8 --- .../operations/placer_algorithms/application_placer.py | 10 ++++------ .../router_compressors/abstract_compressor.py | 5 +---- .../operations/router_compressors/pair_compressor.py | 1 - .../operations/router_compressors/ranged_compressor.py | 2 +- unittests/test_fixed_route_router.py | 3 ++- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/pacman/operations/placer_algorithms/application_placer.py b/pacman/operations/placer_algorithms/application_placer.py index 2e954da6b..550c21073 100644 --- a/pacman/operations/placer_algorithms/application_placer.py +++ b/pacman/operations/placer_algorithms/application_placer.py @@ -23,8 +23,6 @@ from spinn_utilities.ordered_set import OrderedSet from spinn_utilities.progress_bar import ProgressBar -from spinn_machine import Machine - from pacman.data import PacmanDataView from pacman.model.placements import Placements, Placement from pacman.model.graphs import AbstractVirtual @@ -138,7 +136,7 @@ def _place_error( :param Placements system_placements: :param PacmanPlaceException exception: :param int plan_n_timesteps: - :param Machine machine: + :param ~spinn_machine.Machine machine: :raises PacmanPlaceException: """ unplaceable = list() @@ -333,7 +331,7 @@ def _do_fixed_location(vertices, sdram, placements, machine, next_chip_space): :param list(MachineVertex) vertices: :param int sdram: :param Placements placements: - :param Machine machine: + :param ~spinn_machine.Machine machine: :param _ChipWithSpace next_chip_space: :rtype: bool :raise PacmanConfigurationException: @@ -402,7 +400,7 @@ class _Spaces(object): def __init__(self, machine, placements, plan_n_timesteps): """ - :param Machine machine: + :param ~spinn_machine.Machine machine: :param Placements placements: :param int plan_n_timesteps: """ @@ -608,7 +606,7 @@ def __repr__(self): def _chip_order(machine): """ - :param Machine machine: + :param ~spinn_machine.Machine machine: :rtype: iterable(Chip) """ s_x, s_y = get_config_str("Mapping", "placer_start_chip").split(",") diff --git a/pacman/operations/router_compressors/abstract_compressor.py b/pacman/operations/router_compressors/abstract_compressor.py index a4376e332..980af073d 100644 --- a/pacman/operations/router_compressors/abstract_compressor.py +++ b/pacman/operations/router_compressors/abstract_compressor.py @@ -19,12 +19,9 @@ from abc import abstractmethod import logging -import sys - from spinn_utilities.config_holder import get_config_bool from spinn_utilities.log import FormatAdapter from spinn_utilities.progress_bar import ProgressBar -from spinn_machine import Machine from pacman.data import PacmanDataView from pacman.model.routing_tables import ( CompressedMulticastRoutingTable, MulticastRoutingTables) @@ -83,7 +80,7 @@ def compress_tables(self, router_tables, progress): :raises MinimisationFailedError: on failure """ compressed_tables = MulticastRoutingTables() - as_needed = not(get_config_bool( + as_needed = not (get_config_bool( "Mapping", "router_table_compress_as_far_as_possible")) for table in progress.over(router_tables.routing_tables): chip = PacmanDataView.get_chip_at(table.x, table.y) diff --git a/pacman/operations/router_compressors/pair_compressor.py b/pacman/operations/router_compressors/pair_compressor.py index 403b8c6e3..9e8da771a 100644 --- a/pacman/operations/router_compressors/pair_compressor.py +++ b/pacman/operations/router_compressors/pair_compressor.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from spinn_machine import Machine from pacman.data import PacmanDataView from pacman.exceptions import PacmanElementAllocationException from .abstract_compressor import AbstractCompressor diff --git a/pacman/operations/router_compressors/ranged_compressor.py b/pacman/operations/router_compressors/ranged_compressor.py index a3ba9b1df..dae27fc52 100644 --- a/pacman/operations/router_compressors/ranged_compressor.py +++ b/pacman/operations/router_compressors/ranged_compressor.py @@ -17,7 +17,7 @@ from spinn_utilities.config_holder import get_config_bool from spinn_utilities.log import FormatAdapter from spinn_utilities.progress_bar import ProgressBar -from spinn_machine import Machine, MulticastRoutingEntry +from spinn_machine import MulticastRoutingEntry from pacman.data import PacmanDataView from pacman.model.routing_tables import ( CompressedMulticastRoutingTable, MulticastRoutingTables) diff --git a/unittests/test_fixed_route_router.py b/unittests/test_fixed_route_router.py index 767dbc31a..aa93c3937 100644 --- a/unittests/test_fixed_route_router.py +++ b/unittests/test_fixed_route_router.py @@ -78,7 +78,8 @@ def _check_setup(width, height): (True, False), (False, True), (True, True)]) -def test_all_working(width, height, version, 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", version) temp_machine = virtual_machine(width=width, height=height)