Skip to content
Draft
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
199 changes: 197 additions & 2 deletions pacman/model/routing_info/routing_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# limitations under the License.
from __future__ import annotations
from collections import defaultdict
from typing import Dict, Iterator, Optional, Iterable, Set, TYPE_CHECKING
from typing import (
Dict, Iterator, Optional, Iterable, Set, Tuple, TYPE_CHECKING)
from deprecated import deprecated
from pacman.exceptions import PacmanAlreadyExistsException
if TYPE_CHECKING:
Expand All @@ -26,13 +27,27 @@ class RoutingInfo(object):
An association of machine vertices to a non-overlapping set of keys
and masks.
"""
__slots__ = ("_info", )
__slots__ = ("_info", "_ap_overlaps", "_mx_overlaps",
"_min_bits_machine_and_atoms",
"_max_bits_machine", "_max_bits_atoms",
"_size_app_part_bits", "_size_mac_atoms_bits",
"_target_machine_bits", "_target_atom_bits")

def __init__(self) -> None:
# Partition information indexed by edge pre-vertex and partition ID
# name
self._info: Dict[AbstractVertex,
Dict[str, VertexRoutingInfo]] = defaultdict(dict)
self._ap_overlaps: Set[Tuple[str, AbstractVertex]] = set()
self._mx_overlaps: Set[Tuple[str, AbstractVertex]] = set()
# Temp values to avoid Optionals
self._min_bits_machine_and_atoms = -1000
self._max_bits_machine = -1000
self._max_bits_atoms = -1000
self._size_app_part_bits = -1000
self._size_mac_atoms_bits = -1000
self._target_machine_bits = -1000
self._target_atom_bits = -1000

def add_routing_info(self, info: VertexRoutingInfo) -> None:
"""
Expand Down Expand Up @@ -213,3 +228,183 @@ def __iter__(self) -> Iterator[VertexRoutingInfo]:

def __len__(self) -> int:
return sum(len(v) for v in self._info.values())

def add_ap_overlap(
self, partition_id: str, vertex: AbstractVertex) -> None:
"""
Records that this vertex, partition pair overlaps top part of the key

These are the exceptions to the split between
the application vertex/ partition id bits and
the machine vertex / core parts

:param partition_id: Id of the partition
:param vertex: Application or Machine vertex
"""
self._ap_overlaps.add((partition_id, vertex))

def check_ap_overlap(
self, partition_id: str, vertex: AbstractVertex) -> bool:
"""
Checks if this vertex, partition pair overlaps top part of the key

:param partition_id: Id of the partition
:param vertex: Application or Machine vertex
:return: True if and only if there is an overlap
"""
return (partition_id, vertex) in self._ap_overlaps

def get_ap_overlaps(self) -> Iterator[Tuple[str, AbstractVertex]]:
"""
:returns: vertex, partition pairs that overlaps top part of the key
"""
for pair in self._ap_overlaps:
yield pair

def has_ap_overlap(self) -> bool:
"""
Checks if there are any overlaps top part of the key

:return: True if and only if there is at least one overlap
"""
return len(self._ap_overlaps) > 0

def add_mx_overlap(
self, partition_id: str, vertex: AbstractVertex) -> None:
"""
Records that this vertex, partition pair's atoms keys
overlap into the machine zone

These are the exceptions to the split between
the application vertex/ partition id bits and
the machine vertex / core parts

:param partition_id: Id of the partition
:param vertex: Application or Machine vertex
"""
self._mx_overlaps.add((partition_id, vertex))

def check_mx_overlap(
self, partition_id: str, vertex: AbstractVertex) -> bool:
"""
Checks if this vertex, partition pair air's atoms keys
overlap into the machine zone

All fixed key mask vertexes are included.

:param partition_id: Id of the partition
:param vertex: Application or Machine vertex
:return: True if and only if there is an overlap
"""
return (partition_id, vertex) in self._mx_overlaps

def get_mx_overlaps(self) -> Iterator[Tuple[str, AbstractVertex]]:
"""
Returns vertex, partition pairs whose atoms keys
overlap into the machine zone

All fixed key mask vertexes are included.

:returns: Partition ID, vertex pairs
"""
for pair in self._mx_overlaps:
yield pair

def has_mx_overlap(self) -> bool:
"""
Checks if there are any atoms into machine zone overlaps

True if there are any fixed key mask vertexes.

:return: True if and only if there is at least one overlap
"""
return len(self._mx_overlaps) > 0

def add_zones(
self, min_bits_machine_and_atoms: int, max_bits_machine: int,
max_bits_atoms: int, size_app_part_bits: int,
size_mac_atoms_bits: int, target_machine_bits: int,
target_atom_bits: int) -> None:
"""
Copy in the zone info from the allocator

:param min_bits_machine_and_atoms:
:param max_bits_machine:
:param max_bits_atoms:
:param size_app_part_bits:
:param size_mac_atoms_bits:
:param target_machine_bits:
:param target_atom_bits:
:return:
"""
self._min_bits_machine_and_atoms = min_bits_machine_and_atoms
self._max_bits_machine = max_bits_machine
self._max_bits_atoms = max_bits_atoms
self._size_app_part_bits = size_app_part_bits
self._size_mac_atoms_bits = size_mac_atoms_bits
self._target_machine_bits = target_machine_bits
self._target_atom_bits = target_atom_bits

@property
def min_bits_machine_and_atoms(self) -> int:
"""
Minimum size needed for the combined machine and atoms zone

This is the maximum needed to represent the keys and masks
for a single app vertex / partition ID
"""
return self._min_bits_machine_and_atoms

@property
def max_bits_machine(self) -> int:
"""
Maximum number of bits to represent the machines for any vertex
"""
return self._max_bits_machine

@property
def max_bits_atoms(self) -> int:
"""
Maximum number of bits to represent the atoms for any vertex
"""
return self._max_bits_atoms

@property
def size_app_part_bits(self) -> int:
"""
Size of the App vertex / Partition name zone
"""
return self._size_app_part_bits

@property
def size_mac_atoms_bits(self) -> int:
"""
Size of the machine and atoms part

This will always be 32 - size_app_part_bits
"""
return self._size_mac_atoms_bits

@property
def target_machine_bits(self) -> int:
"""
Size of the machine part for vertex.

It will be at least max_bits_machine,
but will include any extra bits if not all bits are needed.

It may however not be respected on vertices with a very large number
of atoms per core.
"""
return self._target_machine_bits

@property
def target_atom_bits(self) -> int:
"""
Size of the atoms part for vertex that fit the normal case

Ideally this will be the max_bits_atoms but may be smaller
if there is a mix of application vertices with many outgoing
and others with atoms per core.
"""
return self._target_atom_bits
Loading
Loading