Skip to content

Commit

Permalink
cache of MachineDataView.get_machine_version().max_cores_per_chip
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Mar 13, 2024
1 parent da908cf commit 169f379
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion spinn_machine/multicast_routing_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
from __future__ import annotations
from typing import Any, FrozenSet, Iterable, Optional, Tuple, overload
from spinn_machine.router import Router
from spinn_machine.data import MachineDataView
from .exceptions import SpinnMachineInvalidParameterException

# cache of MachineDataView.get_machine_version().max_cores_per_chip
max_cores_per_chip: int = 0


class MulticastRoutingEntry(object):
"""
Expand Down Expand Up @@ -74,6 +78,10 @@ def __init__(self, routing_entry_key: int, mask: int, *,
:raise TypeError: if no spinnaker_route provided and either
processor_ids or link_ids is missing or `None`
"""
global max_cores_per_chip
if max_cores_per_chip == 0:
max_cores_per_chip = \
MachineDataView.get_machine_version().max_cores_per_chip
self._routing_entry_key: int = routing_entry_key
self._mask: int = mask
self._defaultable: bool = defaultable
Expand Down Expand Up @@ -271,7 +279,7 @@ def _calc_routing_ids(self) -> Tuple[FrozenSet[int], FrozenSet[int]]:
:rtype: tuple(frozenset(int), frozenset(int))
"""
processor_ids = (pi for pi in range(0, Router.MAX_CORES_PER_ROUTER)
processor_ids = (pi for pi in range(0, max_cores_per_chip)
if self._spinnaker_route & 1 <<
(Router.MAX_LINKS_PER_ROUTER + pi))
link_ids = (li for li in range(0, Router.MAX_LINKS_PER_ROUTER)
Expand Down
10 changes: 9 additions & 1 deletion spinn_machine/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
from __future__ import annotations
from typing import (
Dict, Iterable, Iterator, List, Optional, Tuple, Union, TYPE_CHECKING)
from spinn_machine.data import MachineDataView
from .exceptions import (
SpinnMachineAlreadyExistsException, SpinnMachineInvalidParameterException)
if TYPE_CHECKING:
from .link import Link
from .fixed_route_entry import FixedRouteEntry
from .multicast_routing_entry import MulticastRoutingEntry

# cache of MachineDataView.get_machine_version().max_cores_per_chip
max_cores_per_chip: int = 0


class Router(object):
"""
Expand Down Expand Up @@ -50,6 +54,10 @@ def __init__(
:raise ~spinn_machine.exceptions.SpinnMachineAlreadyExistsException:
If any two links have the same ``source_link_id``
"""
global max_cores_per_chip
if max_cores_per_chip == 0:
max_cores_per_chip = \
MachineDataView.get_machine_version().max_cores_per_chip
self._links: Dict[int, Link] = dict()
for link in links:
self.add_link(link)
Expand Down Expand Up @@ -178,7 +186,7 @@ def convert_spinnaker_route_to_routing_ids(route: int) -> Tuple[
:return: The list of processor IDs, and the list of link IDs.
:rtype: tuple(list(int), list(int))
"""
processor_ids = [pi for pi in range(0, Router.MAX_CORES_PER_ROUTER)
processor_ids = [pi for pi in range(0, max_cores_per_chip)
if route & 1 << (Router.MAX_LINKS_PER_ROUTER + pi)]
link_ids = [li for li in range(0, Router.MAX_LINKS_PER_ROUTER)
if route & 1 << li]
Expand Down

0 comments on commit 169f379

Please sign in to comment.