diff --git a/spinn_machine/multicast_routing_entry.py b/spinn_machine/multicast_routing_entry.py index 755a9fff..af06ec8d 100644 --- a/spinn_machine/multicast_routing_entry.py +++ b/spinn_machine/multicast_routing_entry.py @@ -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): """ @@ -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 @@ -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) diff --git a/spinn_machine/router.py b/spinn_machine/router.py index d634d748..6ddd8dfd 100644 --- a/spinn_machine/router.py +++ b/spinn_machine/router.py @@ -14,6 +14,7 @@ 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: @@ -21,6 +22,9 @@ 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): """ @@ -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) @@ -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]