Skip to content

Commit

Permalink
move supports_multiple_boards logic to version
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Apr 10, 2024
1 parent 25f0056 commit 1a0c508
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 33 deletions.
4 changes: 0 additions & 4 deletions spinn_machine/full_wrap_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class FullWrapMachine(Machine):
This class provides the more complex maths to deal with wraps.
"""
@overrides(Machine.multiple_48_chip_boards)
def multiple_48_chip_boards(self) -> bool:
return self._width % 12 == 0 and self._height % 12 == 0

@overrides(Machine.get_xys_by_ethernet)
def get_xys_by_ethernet(
self, ethernet_x: int, ethernet_y: int) -> Iterable[XY]:
Expand Down
4 changes: 0 additions & 4 deletions spinn_machine/horizontal_wrap_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class HorizontalWrapMachine(Machine):
This class provides the more complex maths to deal with wraps.
"""

@overrides(Machine.multiple_48_chip_boards)
def multiple_48_chip_boards(self) -> bool:
return self._width % 12 == 0 and (self._height - 4) % 12 == 0

@overrides(Machine.get_xys_by_ethernet)
def get_xys_by_ethernet(
self, ethernet_x: int, ethernet_y: int) -> Iterable[XY]:
Expand Down
19 changes: 2 additions & 17 deletions spinn_machine/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,6 @@ def __init__(self, width: int, height: int, chip_core_map: Dict[XY, int],
self._n_router_entries_counter: Counter[int] = Counter()
self._sdram_counter: Counter[int] = Counter()

@abstractmethod
def multiple_48_chip_boards(self) -> bool:
"""
Checks that the width and height correspond to the expected size for a
multi-board machine made up of more than one 48 chip board.
The assumption is that any size machine can be supported but that
only ones with an expected 48 chip board size can have more than one
Ethernet-enabled chip.
:return: True if this machine can have multiple 48 chip boards
:rtype: bool
"""
raise NotImplementedError

@abstractmethod
def get_xys_by_ethernet(
self, ethernet_x: int, ethernet_y: int) -> Iterable[XY]:
Expand Down Expand Up @@ -501,15 +486,15 @@ def validate(self) -> None:
if self._boot_ethernet_address is None:
raise SpinnMachineException(
"no ethernet chip at 0, 0 found")
version = MachineDataView.get_machine_version()
if len(self._ethernet_connected_chips) > 1:
if not self.multiple_48_chip_boards():
if not version.supports_multiple_boards:
raise SpinnMachineException(
f"A {self.wrap} machine of size {self._width}, "
f"{self._height} can not handle multiple ethernet chips")
# The fact that self._boot_ethernet_address is set means there is an
# Ethernet chip and it is at 0,0 so no need to check that

version = MachineDataView.get_machine_version()
for chip in self.chips:
if chip.x < 0:
raise SpinnMachineException(
Expand Down
4 changes: 0 additions & 4 deletions spinn_machine/no_wrap_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class NoWrapMachine(Machine):
This class provides the simpler maths that do not deal with wraps.
"""

@overrides(Machine.multiple_48_chip_boards)
def multiple_48_chip_boards(self) -> bool:
return (self._width - 4) % 12 == 0 and (self._height - 4) % 12 == 0

@overrides(Machine.get_xys_by_ethernet)
def get_xys_by_ethernet(
self, ethernet_x: int, ethernet_y: int) -> Iterable[XY]:
Expand Down
12 changes: 12 additions & 0 deletions spinn_machine/version/abstract_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,21 @@ def size_from_n_boards(self, n_boards: int) -> Tuple[int, int]:
# Override for versions that support multiple boards
if n_boards == 1:
return self.board_shape
if self.supports_multiple_boards:
raise NotImplementedError
raise SpinnMachineException(
f"Version {self} does not support multiple boards")

@property
@abstractmethod
def supports_multiple_boards(self) -> bool:
"""
Specifies if this version allows machines of more than one board
:return:
"""
raise NotImplementedError

def spinnaker_links(self) -> List[Tuple[int, int, int]]:
"""
The list of Local X, Y and link Id to add spinnaker links to
Expand Down
5 changes: 5 additions & 0 deletions spinn_machine/version/version_201.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def illegal_ethernet_message(self, x: int, y: int) -> Optional[str]:
return "Only Chip 0, 0 may be an Ethernet Chip"
return None

@property
@overrides(AbstractVersion.supports_multiple_boards)
def supports_multiple_boards(self) -> bool:
return False

@overrides(AbstractVersion.spinnaker_links)
def spinnaker_links(self) -> List[Tuple[int, int, int]]:
return []
Expand Down
5 changes: 5 additions & 0 deletions spinn_machine/version/version_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def illegal_ethernet_message(self, x: int, y: int) -> Optional[str]:
return "Only Chip 0, 0 may be an Ethernet Chip"
return None

@property
@overrides(VersionSpin1.supports_multiple_boards)
def supports_multiple_boards(self) -> bool:
return False

@overrides(VersionSpin1.spinnaker_links)
def spinnaker_links(self) -> List[Tuple[int, int, int]]:
return [(0, 0, 3), (1, 0, 0)]
Expand Down
5 changes: 5 additions & 0 deletions spinn_machine/version/version_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def size_from_n_boards(self, n_boards: int) -> Tuple[int, int]:
height = math.ceil(triads / width)
return width * 12 + 4, height * 12 + 4

@property
@overrides(VersionSpin1.supports_multiple_boards)
def supports_multiple_boards(self) -> bool:
return True

@overrides(VersionSpin1.spinnaker_links)
def spinnaker_links(self) -> List[Tuple[int, int, int]]:
return [(0, 0, 4)]
Expand Down
4 changes: 0 additions & 4 deletions spinn_machine/vertical_wrap_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class VerticalWrapMachine(Machine):
This class provides the more complex maths to deal with wraps.
"""

@overrides(Machine.multiple_48_chip_boards)
def multiple_48_chip_boards(self) -> bool:
return (self._width - 4) % 12 == 0 and self._height % 12 == 0

@overrides(Machine.get_xys_by_ethernet)
def get_xys_by_ethernet(
self, ethernet_x: int, ethernet_y: int) -> Iterable[XY]:
Expand Down

0 comments on commit 1a0c508

Please sign in to comment.