Skip to content

Commit

Permalink
Merge pull request #217 from SpiNNakerManchester/version
Browse files Browse the repository at this point in the history
Version
  • Loading branch information
rowleya authored Jul 28, 2023
2 parents 3871bf4 + 1934485 commit 17f47d4
Show file tree
Hide file tree
Showing 28 changed files with 1,233 additions and 481 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ init-import=no
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,
__new__,
_clear,
_hard_reset,
setUp

Expand Down
3 changes: 1 addition & 2 deletions spinn_machine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@
from .spinnaker_triad_geometry import SpiNNakerTriadGeometry
from .virtual_machine import virtual_machine
from .fixed_route_entry import FixedRouteEntry
from .machine_factory import machine_from_chips, machine_from_size


__all__ = ["Chip", "CoreSubset", "CoreSubsets", "FixedRouteEntry",
"Link", "Machine", "MulticastRoutingEntry",
"Processor", "Router", "SpiNNakerTriadGeometry",
"virtual_machine", "machine_from_chips", "machine_from_size"]
"virtual_machine"]
7 changes: 4 additions & 3 deletions spinn_machine/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from spinn_utilities.ordered_set import OrderedSet
from .machine import Machine
from spinn_machine.data import MachineDataView
from .processor import Processor

standard_processors = {}
Expand Down Expand Up @@ -112,8 +112,9 @@ def __generate_processors(self, n_processors, down_cores):
for i in range(1, n_processors):
if i not in down_cores:
processors[i] = Processor.factory(i)
self._n_user_processors = \
n_processors - Machine.NON_USER_CORES - len(down_cores)
self._n_user_processors = (
n_processors - len(down_cores) -
MachineDataView.get_machine_version().n_non_user_cores)
return processors

def is_processor_with_id(self, processor_id):
Expand Down
33 changes: 33 additions & 0 deletions spinn_machine/data/machine_data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from spinn_utilities.data import UtilsDataView
from spinn_machine.version.version_factory import version_factory
# pylint: disable=protected-access


Expand All @@ -37,6 +38,7 @@ class _MachineDataModel(object):
# Data values cached
"_machine",
"_machine_generator",
"_machine_version",
"_user_accessed_machine"
]

Expand All @@ -55,6 +57,7 @@ def _clear(self):
"""
self._hard_reset()
self._machine_generator = None
self._machine_version = None

def _hard_reset(self):
"""
Expand Down Expand Up @@ -94,11 +97,26 @@ def has_machine(cls):
"""
Reports if a machine is currently set or can be mocked.
Unlike has_existing_machine for unit tests this will return True even
if a Machine has not yet been created
:rtype: bool
"""
return (cls.__data._machine is not None or
cls._is_mocked())

@classmethod
def has_existing_machine(cls):
"""
Reports if a machine is currently already created.
Unlike has_machine this method returns false if a machine could be
mocked
:rtype: bool
"""
return cls.__data._machine

@classmethod
def get_machine(cls):
"""
Expand Down Expand Up @@ -217,3 +235,18 @@ def where_is_chip(cls, chip):
if cls.__data._machine is None:
return "Chip is from a previous machine"
return str(ex)

@classmethod
def get_machine_version(cls):
"""
Returns the Machine Version if it has or can be set.
` May call version_factory to create the version
:return: A superclass of AbstractVersion
:rtype: ~spinn_machine.version.abstract_version.py
:raises SpinnMachineException: If the cfg version is not set correctly
"""
if cls.__data._machine_version is None:
cls.__data._machine_version = version_factory()
return cls.__data._machine_version
18 changes: 6 additions & 12 deletions spinn_machine/full_wrap_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,28 @@ def multiple_48_chip_boards(self):

@overrides(Machine.get_xys_by_ethernet)
def get_xys_by_ethernet(self, ethernet_x, ethernet_y):
for (x, y) in self._local_xys:
for (x, y) in self._chip_core_map:
chip_x = (x + ethernet_x) % self._width
chip_y = (y + ethernet_y) % self._height
yield (chip_x, chip_y)

@overrides(Machine.get_xy_cores_by_ethernet)
def get_xy_cores_by_ethernet(self, ethernet_x, ethernet_y):
if (self._width == self._height == 2):
n_cores = Machine.max_cores_per_chip()
for (x, y) in self._local_xys:
# if ethernet_x/y != 0 GIGO mode so ignore ethernet
yield (x, y), n_cores
else:
for (x, y), n_cores in self.CHIPS_PER_BOARD.items():
yield (((x + ethernet_x) % self._width,
(y + ethernet_y) % self._height), n_cores)
for (x, y), n_cores in self._chip_core_map.items():
yield (((x + ethernet_x) % self._width,
(y + ethernet_y) % self._height), n_cores)

@overrides(Machine.get_existing_xys_by_ethernet)
def get_existing_xys_by_ethernet(self, ethernet_x, ethernet_y):
for (x, y) in self._local_xys:
for (x, y) in self._chip_core_map:
chip_xy = ((x + ethernet_x) % self._width,
(y + ethernet_y) % self._height)
if chip_xy in self._chips:
yield chip_xy

@overrides(Machine.get_down_xys_by_ethernet)
def get_down_xys_by_ethernet(self, ethernet_x, ethernet_y):
for (x, y) in self._local_xys:
for (x, y) in self._chip_core_map:
chip_xy = ((x + ethernet_x) % self._width,
(y + ethernet_y) % self._height)
if (chip_xy) not in self._chips:
Expand Down
8 changes: 4 additions & 4 deletions spinn_machine/horizontal_wrap_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ def multiple_48_chip_boards(self):

@overrides(Machine.get_xys_by_ethernet)
def get_xys_by_ethernet(self, ethernet_x, ethernet_y):
for (x, y) in self._local_xys:
for (x, y) in self._chip_core_map:
chip_x = (x + ethernet_x) % self._width
chip_y = (y + ethernet_y)
yield (chip_x, chip_y)

@overrides(Machine.get_xy_cores_by_ethernet)
def get_xy_cores_by_ethernet(self, ethernet_x, ethernet_y):
for (x, y), n_cores in self.CHIPS_PER_BOARD.items():
for (x, y), n_cores in self._chip_core_map.items():
yield ((x + ethernet_x) % self._width, (y + ethernet_y)), n_cores

@overrides(Machine.get_existing_xys_by_ethernet)
def get_existing_xys_by_ethernet(self, ethernet_x, ethernet_y):
for (x, y) in self._local_xys:
for (x, y) in self._chip_core_map:
chip_xy = ((x + ethernet_x) % self._width,
(y + ethernet_y))
if chip_xy in self._chips:
yield chip_xy

@overrides(Machine.get_down_xys_by_ethernet)
def get_down_xys_by_ethernet(self, ethernet_x, ethernet_y):
for (x, y) in self._local_xys:
for (x, y) in self._chip_core_map:
chip_xy = ((x + ethernet_x) % self._width,
(y + ethernet_y))
if (chip_xy) not in self._chips:
Expand Down
4 changes: 2 additions & 2 deletions spinn_machine/json_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from .chip import Chip
from .router import Router
from .link import Link
from .machine_factory import machine_from_size


logger = FormatAdapter(logging.getLogger(__name__))
Expand Down Expand Up @@ -58,7 +57,8 @@ def machine_from_json(j_machine):
width = j_machine["width"]
height = j_machine["height"]

machine = machine_from_size(width, height, origin="Json")
machine = MachineDataView.get_machine_version().create_machine(
width, height, origin="Json")
s_monitors = j_machine["standardResources"]["monitors"]
s_router_entries = j_machine["standardResources"]["routerEntries"]
s_sdram = j_machine["standardResources"]["sdram"]
Expand Down
Loading

0 comments on commit 17f47d4

Please sign in to comment.