Skip to content

Commit

Permalink
Merge pull request #553 from SpiNNakerManchester/app_placer3
Browse files Browse the repository at this point in the history
Refactor of the application Placer
  • Loading branch information
Christian-B authored Mar 26, 2024
2 parents 4eec619 + 23ed9eb commit ffb4b36
Show file tree
Hide file tree
Showing 12 changed files with 734 additions and 557 deletions.
20 changes: 11 additions & 9 deletions pacman/data/pacman_data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
import logging
from typing import (Iterable, List, Optional, Sequence, Type, TypeVar,
TYPE_CHECKING)

from spinn_utilities.log import FormatAdapter
from spinn_utilities.typing.coords import XY

from spinn_machine.data import MachineDataView

from pacman.exceptions import PacmanNotPlacedError
from pacman.model.graphs.application import ApplicationGraph
from pacman.model.resources import AbstractSDRAM, ConstantSDRAM

if TYPE_CHECKING:
from pacman.model.graphs import AbstractEdgePartition
from pacman.model.graphs.application import (
Expand Down Expand Up @@ -360,29 +365,26 @@ def iterate_placements_by_vertex_type(
iterate_placements_by_vertex_type(vertex_type)

@classmethod
def iterate_placements_on_core(cls, x: int, y: int) -> Iterable[Placement]:
def iterate_placements_on_core(cls, xy: XY) -> Iterable[Placement]:
"""
Iterate over placements with this x and y.
:param int x: x coordinate to find placements for.
:param int y: y coordinate to find placements for.
:param tuple(int, int) xy: x and y coordinates to find placements for.
:rtype: iterable(Placement)
:raises ~spinn_utilities.exceptions.SpiNNUtilsException:
If the placements are currently unavailable
"""
if cls.__pacman_data._placements is None:
raise cls._exception("placements")
return cls.__pacman_data._placements.iterate_placements_on_core(x, y)
return cls.__pacman_data._placements.iterate_placements_on_core(xy)

@classmethod
def iterate_placements_by_xy_and_type(
cls, x: int, y: int,
vertex_type: Type[VTX]) -> Iterable[Placement]:
cls, xy: XY, vertex_type: Type[VTX]) -> Iterable[Placement]:
"""
Iterate over placements with this x, y and type.
:param int x: x coordinate to find placements for.
:param int y: y coordinate to find placements for.
:param tuple(int, int) xy: x and y coordinates to find placements for.
:param type vertex_type: Class of vertex to find
:rtype: iterable(Placement)
:raises ~spinn_utilities.exceptions.SpiNNUtilsException:
Expand All @@ -391,7 +393,7 @@ def iterate_placements_by_xy_and_type(
if cls.__pacman_data._placements is None:
raise cls._exception("placements")
return cls.__pacman_data._placements.\
iterate_placements_by_xy_and_type(x, y, vertex_type)
iterate_placements_by_xy_and_type(xy, vertex_type)

@classmethod
def get_n_placements(cls) -> int:
Expand Down
16 changes: 16 additions & 0 deletions pacman/model/graphs/application/application_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,19 @@ def get_raster_ordered_indices(self, indices):
cum_size *= atoms_shape[n]

return global_index.astype(numpy.uint32)

def has_fixed_location(self):
"""
Check if this vertex or any machine vertex has a fixed location.
:rtype: bool
:returns: True if the Application Vertex or any one of its
Machine Vertices has a fixed location
False if None of the Vertices has a none None fixed location
"""
if self.get_fixed_location() is not None:
return True
for vertex in self._machine_vertices:
if vertex.get_fixed_location() is not None:
return True
return False
33 changes: 14 additions & 19 deletions pacman/model/placements/placements.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from collections import defaultdict
from typing import Dict, Iterable, Iterator
from typing import Collection, Dict, Iterable, Iterator

from spinn_utilities.typing.coords import XY

Expand Down Expand Up @@ -142,28 +142,25 @@ def is_processor_occupied(self, x: int, y: int, p: int) -> bool:
"""
return (pr := self._placements.get((x, y))) is not None and p in pr

def iterate_placements_on_core(
self, x: int, y: int) -> Iterable[Placement]:
def iterate_placements_on_core(self, xy: XY) -> Iterable[Placement]:
"""
Iterate over placements with this x and y.
:param int x: x coordinate to find placements for.
:param int y: y coordinate to find placements for.
:param tuple(int, int) xy: x and y coordinates to find placements for.
:rtype: iterable(Placement)
"""
return self._placements[x, y].values()
return self._placements[xy].values()

def iterate_placements_by_xy_and_type(
self, x: int, y: int, vertex_type: type) -> Iterable[Placement]:
self, xy: XY, vertex_type: type) -> Iterable[Placement]:
"""
Iterate over placements with this x, y and this vertex_type.
:param int x: x coordinate to find placements for.
:param int y: y coordinate to find placements for.
:param tuple(int, int) xy: x and y coordinate to find placements for.
:param class vertex_type: Class of vertex to find
:rtype: iterable(Placement)
"""
for placement in self._placements[x, y].values():
for placement in self._placements[xy].values():
if isinstance(placement.vertex, vertex_type):
yield placement

Expand All @@ -179,17 +176,16 @@ def iterate_placements_by_vertex_type(
if isinstance(placement.vertex, vertex_type):
yield placement

def n_placements_on_chip(self, x: int, y: int) -> int:
def n_placements_on_chip(self, xy: XY) -> int:
"""
The number of placements on the given chip.
:param int x: x coordinate of chip.
:param int y: y coordinate of chip.
:param tuple(int, int) xy: x and y coordinate of chip.
:rtype: int
"""
if (x, y) not in self._placements:
if xy not in self._placements:
return 0
return len(self._placements[x, y])
return len(self._placements[xy])

@property
def placements(self) -> Iterable[Placement]:
Expand All @@ -201,15 +197,14 @@ def placements(self) -> Iterable[Placement]:
"""
return iter(self._machine_vertices.values())

def placements_on_chip(self, x: int, y: int) -> Iterable[Placement]:
def placements_on_chip(self, xy: XY) -> Collection[Placement]:
"""
Get the placements on a specific chip.
:param int x: The x-coordinate of the chip
:param int y: The y-coordinate of the chip
:param tuple(int , int) xy: The x and y coordinates of the chip
:rtype: iterable(Placement)
"""
return self._placements[x, y].values()
return self._placements[xy].values()

@property
def chips_with_placements(self) -> Iterable[XY]:
Expand Down
2 changes: 1 addition & 1 deletion pacman/operations/fixed_route_router/fixed_route_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def __locate_destination(self, chip: Chip) -> int:
:raises PacmanConfigurationException: if no placement processor found
"""
for placement in PacmanDataView.iterate_placements_by_xy_and_type(
chip.x, chip.y, self._destination_class):
chip, self._destination_class):
return placement.p
raise PacmanConfigurationException(
f"no destination vertex found on Ethernet chip {chip.x}:{chip.y}")
Loading

0 comments on commit ffb4b36

Please sign in to comment.