Skip to content

Commit

Permalink
merged in master
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Apr 16, 2024
2 parents 424c430 + 5b5f752 commit b973ab2
Show file tree
Hide file tree
Showing 24 changed files with 202 additions and 596 deletions.
18 changes: 5 additions & 13 deletions pacman/model/routing_info/app_vertex_routing_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
import math
from typing import Iterable, List, Tuple, TYPE_CHECKING
from spinn_utilities.overrides import overrides
from spinn_machine.multicast_routing_entry import MulticastRoutingEntry
from spinn_machine import MulticastRoutingEntry, RoutingEntry
from .vertex_routing_info import VertexRoutingInfo
if TYPE_CHECKING:
from pacman.model.graphs.application import ApplicationVertex
from pacman.model.routing_info import BaseKeyAndMask
from pacman.model.routing_table_by_partition import (
MulticastRoutingTableByPartitionEntry)
from .machine_vertex_routing_info import MachineVertexRoutingInfo

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -58,16 +56,15 @@ def __init__(
self.__max_machine_index = max_machine_index

def merge_machine_entries(self, entries: List[Tuple[
MulticastRoutingTableByPartitionEntry,
RoutingEntry,
MachineVertexRoutingInfo]]) -> Iterable[MulticastRoutingEntry]:
"""
Merge the machine entries.
:param entries:
The entries to merge
:type entries:
list(tuple(
MulticastRoutingTableByPartitionEntry, VertexRoutingInfo))
list(tuple(RoutingEntry, VertexRoutingInfo))
:rtype: iterable(~spinn_machine.MulticastRoutingEntry)
"""
n_entries = len(entries)
Expand All @@ -82,9 +79,7 @@ def merge_machine_entries(self, entries: List[Tuple[
# If that is OK, we can just use them
if next_entries <= (n_entries - i) or is_last:
mask = self.__group_mask(next_entries)
yield MulticastRoutingEntry(
r_info.key, mask, defaultable=entry.defaultable,
spinnaker_route=entry.spinnaker_route)
yield MulticastRoutingEntry(r_info.key, mask, entry)
i += next_entries

# Otherwise, we have to break down into powers of two
Expand All @@ -94,10 +89,7 @@ def merge_machine_entries(self, entries: List[Tuple[
next_entries = 2 ** int(math.log2(entries_to_go))
mask = self.__group_mask(next_entries)
(entry, r_info) = entries[i]
yield MulticastRoutingEntry(
r_info.key, mask,
defaultable=entry.defaultable,
spinnaker_route=entry.spinnaker_route)
yield MulticastRoutingEntry(r_info.key, mask, entry)
entries_to_go -= next_entries
i += next_entries

Expand Down
5 changes: 1 addition & 4 deletions pacman/model/routing_table_by_partition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@

from .multicast_routing_table_by_partition import (
MulticastRoutingTableByPartition)
from .multicast_routing_table_by_partition_entry import (
MulticastRoutingTableByPartitionEntry)

__all__ = ["MulticastRoutingTableByPartition",
"MulticastRoutingTableByPartitionEntry"]
__all__ = ["MulticastRoutingTableByPartition"]
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import logging
from typing import Dict, Iterator, Optional, Tuple, TYPE_CHECKING
from spinn_utilities.typing.coords import XY
from spinn_machine import RoutingEntry
from pacman.model.graphs.application import ApplicationVertex
from pacman.exceptions import PacmanInvalidParameterException
from pacman.model.graphs.machine import MachineVertex
if TYPE_CHECKING:
from pacman.model.graphs import AbstractVertex
from .multicast_routing_table_by_partition_entry import (
MulticastRoutingTableByPartitionEntry)

log = logging.getLogger(__name__)

Expand All @@ -38,17 +37,16 @@ class MulticastRoutingTableByPartition(object):

def __init__(self) -> None:
self._router_to_entries_map: Dict[XY, Dict[
Tuple[AbstractVertex, str],
MulticastRoutingTableByPartitionEntry]] = dict()
Tuple[AbstractVertex, str], RoutingEntry]] = dict()

def add_path_entry(
self, entry: MulticastRoutingTableByPartitionEntry,
self, entry: RoutingEntry,
router_x: int, router_y: int,
source_vertex: AbstractVertex, partition_id: str):
"""
Adds a multicast routing path entry.
:param MulticastRoutingTableByPartitionEntry entry: the entry to add
:param RoutingEntry entry: the entry to add
:param int router_x: the X coordinate of the router
:param int router_y: the Y coordinate of the router
:param source_vertex: The source that will send via this entry
Expand Down Expand Up @@ -82,7 +80,7 @@ def add_path_entry(
entries[source_key] = entry
else:
try:
entries[source_key] = entry.merge_entry(entries[source_key])
entries[source_key] = entry.merge(entries[source_key])
except PacmanInvalidParameterException as e:
log.error(
"Error merging entries on %s for %s", key, source_key)
Expand All @@ -106,24 +104,22 @@ def n_routers(self) -> int:
return len(self._router_to_entries_map)

def get_entries_for_router(self, router_x: int, router_y: int) -> Optional[
Dict[Tuple[AbstractVertex, str],
MulticastRoutingTableByPartitionEntry]]:
Dict[Tuple[AbstractVertex, str], RoutingEntry]]:
"""
Get the set of multicast path entries assigned to this router.
:param int router_x: the X coordinate of the router
:param int router_y: the Y coordinate of the router
:return: all router_path_entries for the router.
:rtype: dict(tuple((ApplicationVertex or MachineVertex), str),
MulticastRoutingTableByPartitionEntry)
RoutingEntry)
"""
key = (router_x, router_y)
return self._router_to_entries_map.get(key)

def get_entry_on_coords_for_edge(
self, source_vertex: AbstractVertex, partition_id: str,
router_x: int, router_y: int) -> Optional[
MulticastRoutingTableByPartitionEntry]:
router_x: int, router_y: int) -> Optional[RoutingEntry]:
"""
Get an entry from a specific coordinate.
Expand All @@ -132,7 +128,7 @@ def get_entry_on_coords_for_edge(
:param str partition_id:
:param int router_x: the X coordinate of the router
:param int router_y: the Y coordinate of the router
:rtype: MulticastRoutingTableByPartitionEntry or None
:rtype: RoutingEntry or None
"""
entries = self.get_entries_for_router(router_x, router_y)
if entries is None:
Expand Down
Loading

0 comments on commit b973ab2

Please sign in to comment.