Skip to content

Commit

Permalink
use per chip n router entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jul 14, 2023
1 parent 8a2c6e3 commit bc49139
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand All @@ -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
11 changes: 8 additions & 3 deletions pacman/operations/router_compressors/pair_compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,15 +31,17 @@ 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__
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 = ordered_covering_compressor()
for original in original_tables:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions unittests/test_fixed_route_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bc49139

Please sign in to comment.