Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processor renaming #245

Merged
merged 6 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 49 additions & 49 deletions spinn_machine/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# One dict for each number of processors (none dead)
standard_processors = {}
# One dict for the standard monitor processors
standard_monitor_processors = None # pylint: disable=invalid-name
standard_scamp_processors = None # pylint: disable=invalid-name


class Chip(object):
Expand All @@ -42,7 +42,7 @@ class Chip(object):
__slots__ = (
"_x", "_y", "_router", "_sdram", "_ip_address",
"_tag_ids", "_nearest_ethernet_x", "_nearest_ethernet_y",
"_user_processors", "_monitor_processors", "_parent_link",
"_placable_processors", "_scamp_processors", "_parent_link",
"_v_to_p_map"
)

Expand Down Expand Up @@ -88,8 +88,8 @@ def __init__(self, x: int, y: int, n_processors: int, router: Router,
"""
self._x = x
self._y = y
self._monitor_processors = self.__generate_monitors()
self._user_processors = self.__generate_processors(
self._scamp_processors = self.__generate_scamp()
self._placable_processors = self.__generate_processors(
n_processors, down_cores)
self._router = router
self._sdram = sdram
Expand All @@ -105,24 +105,24 @@ def __init__(self, x: int, y: int, n_processors: int, router: Router,
self._parent_link = parent_link
self._v_to_p_map = v_to_p_map

def __generate_monitors(self):
def __generate_scamp(self):
"""
Generates the monitors assuming all Chips have the same monitor cores
Generates the scamp assuming all Chips have the same scamp cores

:return: Dict[int, Processor]
"""
global standard_monitor_processors # pylint: disable=global-statement
if standard_monitor_processors is None:
standard_monitor_processors = dict()
global standard_scamp_processors # pylint: disable=global-statement
if standard_scamp_processors is None:
standard_scamp_processors = dict()
for i in range(
MachineDataView.get_machine_version().n_non_user_cores):
standard_monitor_processors[i] = Processor.factory(i, True)
return standard_monitor_processors
MachineDataView.get_machine_version().n_scamp_cores):
standard_scamp_processors[i] = Processor.factory(i, True)
return standard_scamp_processors

def __generate_processors(
self, n_processors: int,
down_cores: Optional[Collection[int]]) -> Dict[int, Processor]:
n_monitors = MachineDataView.get_machine_version().n_non_user_cores
n_monitors = MachineDataView.get_machine_version().n_scamp_cores
if down_cores is None:
if n_processors not in standard_processors:
processors = dict()
Expand Down Expand Up @@ -150,9 +150,9 @@ def is_processor_with_id(self, processor_id: int) -> bool:
:return: Whether the processor with the given ID exists
:rtype: bool
"""
if processor_id in self._user_processors:
if processor_id in self._placable_processors:
return True
return processor_id in self._monitor_processors
return processor_id in self._scamp_processors

def get_processor_with_id(self, processor_id: int) -> Optional[Processor]:
"""
Expand All @@ -165,9 +165,9 @@ def get_processor_with_id(self, processor_id: int) -> Optional[Processor]:
or ``None`` if no such processor
:rtype: Processor or None
"""
if processor_id in self._user_processors:
return self._user_processors[processor_id]
return self._monitor_processors.get(processor_id)
if processor_id in self._placable_processors:
return self._placable_processors[processor_id]
return self._scamp_processors.get(processor_id)

@property
def x(self) -> int:
Expand Down Expand Up @@ -204,8 +204,8 @@ def processors(self) -> Iterator[Processor]:

:rtype: iterable(Processor)
"""
yield from self._monitor_processors.values()
yield from self._user_processors.values()
yield from self._scamp_processors.values()
yield from self._placable_processors.values()

@property
def all_processor_ids(self) -> Iterator[int]:
Expand All @@ -214,8 +214,8 @@ def all_processor_ids(self) -> Iterator[int]:

:rtype: iterable(int)
"""
yield from self._monitor_processors.keys()
yield from self._user_processors.keys()
yield from self._scamp_processors.keys()
yield from self._placable_processors.keys()

@property
def n_processors(self) -> int:
Expand All @@ -224,61 +224,61 @@ def n_processors(self) -> int:

:rtype: int
"""
return len(self._monitor_processors) + len(self._user_processors)
return len(self._scamp_processors) + len(self._placable_processors)

@property
def user_processors(self) -> Iterator[Processor]:
def placeable_processors(self) -> Iterator[Processor]:
"""
An iterable of available user processors.
An iterable of available placable/ none scamp processors.

:rtype: iterable(Processor)
"""
yield from self._user_processors.values()
yield from self._placable_processors.values()

@property
def user_processors_ids(self) -> Iterator[int]:
def placable_processors_ids(self) -> Iterator[int]:
"""
An iterable of available user processors.
An iterable of available placable/ non scamp processor ids.

:rtype: iterable(Processor)
"""
yield from self._user_processors
yield from self._placable_processors

@property
def n_user_processors(self) -> int:
def n_placable_processors(self) -> int:
"""
The total number of processors that are not monitors.
The total number of processors that are placable / not used by scamp.

:rtype: int
"""
return len(self._user_processors)
return len(self._placable_processors)

@property
def monitor_processors(self) -> Iterator[Processor]:
def scamp_processors(self) -> Iterator[Processor]:
"""
An iterable of available monitor processors.
An iterable of available scamp processors.

:rtype: iterable(Processor)
"""
return self._monitor_processors.values()
return self._scamp_processors.values()

@property
def monitor_processors_ids(self) -> Iterator[int]:
def scamp_processors_ids(self) -> Iterator[int]:
"""
An iterable of available user processors.
An iterable of available scamp processors.

:rtype: iterable(Processor)
"""
yield from self._monitor_processors
yield from self._scamp_processors

@property
def n_monitor_processors(self) -> int:
def n_scamp_processors(self) -> int:
"""
The total number of processors that are not monitors.
The total number of processors that are used by scamp.

:rtype: int
"""
return len(self._monitor_processors)
return len(self._scamp_processors)

@property
def router(self) -> Router:
Expand Down Expand Up @@ -342,7 +342,7 @@ def get_first_none_monitor_processor(self) -> Processor:
:rtype: Processor
;raises StopIteration: If there is no user processor
"""
return next(iter(self._user_processors.values()))
return next(iter(self._placable_processors.values()))

@property
def parent_link(self) -> Optional[int]:
Expand Down Expand Up @@ -389,8 +389,8 @@ def __iter__(self) -> Iterator[Tuple[int, Processor]]:
* ``processor`` is the processor with the ID
:rtype: iterable(tuple(int,Processor))
"""
yield from self._monitor_processors.items()
yield from self._user_processors.items()
yield from self._scamp_processors.items()
yield from self._placable_processors.items()

def __len__(self) -> int:
"""
Expand All @@ -399,13 +399,13 @@ def __len__(self) -> int:
:return: The number of items in the underlying iterator.
:rtype: int
"""
return len(self._monitor_processors) + len(self._user_processors)
return len(self._scamp_processors) + len(self._placable_processors)

def __getitem__(self, processor_id: int) -> Processor:
if processor_id in self._user_processors:
return self._user_processors[processor_id]
if processor_id in self._monitor_processors:
return self._monitor_processors[processor_id]
if processor_id in self._placable_processors:
return self._placable_processors[processor_id]
if processor_id in self._scamp_processors:
return self._scamp_processors[processor_id]
# Note difference from get_processor_with_id(); this is to conform to
# standard Python semantics
raise KeyError(processor_id)
Expand Down
14 changes: 6 additions & 8 deletions spinn_machine/json_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ def _describe_chip(chip: Chip, standard, ethernet) -> JsonArray:
if chip.ip_address is not None:
details['ipAddress'] = chip.ip_address
# Write the Resources ONLY if different from the e_values
if (chip.n_processors - chip.n_user_processors) != ethernet.monitors:
exceptions["monitors"] = \
chip.n_processors - chip.n_user_processors
if (chip.n_scamp_processors) != ethernet.monitors:
exceptions["monitors"] = chip.n_scamp_processors
if router_entries != ethernet.router_entries:
exceptions["routerEntries"] = router_entries
if chip.sdram != ethernet.sdram:
Expand All @@ -215,9 +214,8 @@ def _describe_chip(chip: Chip, standard, ethernet) -> JsonArray:
exceptions["tags"] = tags
else:
# Write the Resources ONLY if different from the s_values
if (chip.n_processors - chip.n_user_processors) != standard.monitors:
exceptions["monitors"] = \
chip.n_processors - chip.n_user_processors
if (chip.n_scamp_processors) != standard.monitors:
exceptions["monitors"] = chip.n_scamp_processors
if router_entries != standard.router_entries:
exceptions["routerEntries"] = router_entries
if chip.sdram != standard.sdram:
Expand All @@ -243,7 +241,7 @@ def to_json() -> JsonObject:
for chip in machine.chips:
if chip.ip_address is None:
std = _Desc(
monitors=chip.n_processors - chip.n_user_processors,
monitors=chip.n_processors - chip.n_placable_processors,
router_entries=_int_value(
chip.router.n_available_multicast_entries),
sdram=chip.sdram,
Expand All @@ -255,7 +253,7 @@ def to_json() -> JsonObject:
# find the nth values to use for Ethernet chips
chip = machine.boot_chip
eth = _Desc(
monitors=chip.n_processors - chip.n_user_processors,
monitors=chip.n_processors - chip.n_placable_processors,
router_entries=_int_value(
chip.router.n_available_multicast_entries),
sdram=chip.sdram,
Expand Down
2 changes: 1 addition & 1 deletion spinn_machine/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ def total_available_user_cores(self) -> int:

:rtype: int
"""
return sum(chip.n_user_processors for chip in self.chips)
return sum(chip.n_placable_processors for chip in self.chips)

@property
def total_cores(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions spinn_machine/version/abstract_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def max_cores_per_chip(self) -> int:

@property
@abstractmethod
def n_non_user_cores(self) -> int:
def n_scamp_cores(self) -> int:
"""
The number of system cores per chip.
The number of scamp cores per chip.

:rtype: int
"""
Expand Down
4 changes: 2 additions & 2 deletions spinn_machine/version/version_spin1.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def __init__(self) -> None:
super().__init__(max_cores_per_chip=18, max_sdram_per_chip=123469792)

@property
@overrides(AbstractVersion.n_non_user_cores)
def n_non_user_cores(self) -> int:
@overrides(AbstractVersion.n_scamp_cores)
def n_scamp_cores(self) -> int:
return 1

@property
Expand Down
13 changes: 7 additions & 6 deletions unittests/test_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_create_chip(self):
self.assertEqual(new_chip.ip_address, self._ip)
self.assertEqual(new_chip.sdram, self._sdram)
self.assertEqual(new_chip.router, self._router)
self.assertEqual(new_chip.n_user_processors, self.n_processors - 1)
self.assertEqual(new_chip.n_placable_processors, self.n_processors - 1)
with self.assertRaises(KeyError):
self.assertIsNone(new_chip[42])
print(new_chip.__repr__())
Expand Down Expand Up @@ -117,13 +117,14 @@ def test_processors(self):
for id in new_chip.all_processor_ids:
all_p.add(new_chip[id])
self.assertEqual(len(all_p), new_chip.n_processors)
users = set(new_chip.user_processors)
self.assertEqual(len(users), new_chip.n_user_processors)
self.assertEqual(len(users), len(set(new_chip.user_processors_ids)))
monitors = set(new_chip.monitor_processors)
users = set(new_chip.placeable_processors)
self.assertEqual(len(users), new_chip.n_placable_processors)
self.assertEqual(len(users),
len(set(new_chip.placable_processors_ids)))
monitors = set(new_chip.scamp_processors)
self.assertEqual(users.union(monitors), all_p)
self.assertEqual(len(monitors),
len(set(new_chip.monitor_processors_ids)))
len(set(new_chip.scamp_processors_ids)))


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions unittests/test_json_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def test_monitor_exceptions(self):
MachineDataWriter.mock().set_machine(vm)
chip02 = vm[0, 2]
# Hack in an extra monitor
users = dict(chip02._user_processors)
monitors = dict(chip02._monitor_processors)
users = dict(chip02._placable_processors)
monitors = dict(chip02._scamp_processors)
monitors[1] = users.pop(1)
chip02._monitor_processors = monitors
chip02._user_processors = users
chip02._scamp_processors = monitors
chip02._placable_processors = users
jpath = mktemp("json")
# Should still be able to write json even with more than one monitor
to_json_path(jpath)
Expand Down
4 changes: 2 additions & 2 deletions unittests/test_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ def test_too_few_cores(self):
machine = virtual_machine(8, 8)
# Hack to get n_processors return a low number
chip01 = machine.get_chip_at(0, 1)
chip01._user_processors = dict(
list(chip01._user_processors.items())[:2])
chip01._placable_processors = dict(
list(chip01._placable_processors.items())[:2])
with self.assertRaises(SpinnMachineException):
machine.validate()

Expand Down
8 changes: 4 additions & 4 deletions unittests/test_virtual_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ def test_new_vm_with_max_cores(self):
vm = virtual_machine(2, 2, validate=True)
_chip = vm[1, 1]
self.assertEqual(n_cpus, _chip.n_processors)
self.assertEqual(n_cpus - 1, _chip.n_user_processors)
self.assertEqual(1, _chip.n_monitor_processors)
self.assertEqual(n_cpus - 1, len(list(_chip.user_processors)))
self.assertEqual(1, len(list(_chip.monitor_processors)))
self.assertEqual(n_cpus - 1, _chip.n_placable_processors)
self.assertEqual(1, _chip.n_scamp_processors)
self.assertEqual(n_cpus - 1, len(list(_chip.placeable_processors)))
self.assertEqual(1, len(list(_chip.scamp_processors)))
count = sum(_chip.n_processors for _chip in vm.chips)
self.assertEqual(count, 4 * n_cpus)

Expand Down
2 changes: 1 addition & 1 deletion unittests/version/test_version3.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_attributes(self):
version = Version3()
self.assertEqual(18, version.max_cores_per_chip)
self.assertEqual(123469792, version.max_sdram_per_chip)
self.assertEqual(1, version.n_non_user_cores)
self.assertEqual(1, version.n_scamp_cores)
self.assertEqual("Spin1 4 Chip", version.name)
self.assertEqual(3, version.number)
self.assertEqual((2, 2), version.board_shape)
Expand Down
2 changes: 1 addition & 1 deletion unittests/version/test_version5.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_attributes(self):
version = Version5()
self.assertEqual(18, version.max_cores_per_chip)
self.assertEqual(123469792, version.max_sdram_per_chip)
self.assertEqual(1, version.n_non_user_cores)
self.assertEqual(1, version.n_scamp_cores)
self.assertEqual("Spin1 48 Chip", version.name)
self.assertEqual(5, version.number)
self.assertEqual((8, 8), version.board_shape)
Expand Down
Loading