Skip to content

Commit

Permalink
Merge pull request #516 from SpiNNakerManchester/interdimensional_com…
Browse files Browse the repository at this point in the history
…patibility

Interdimensional compatibility
  • Loading branch information
Christian-B committed Nov 28, 2023
2 parents 1d0bcdc + 699d909 commit 084f2c7
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from spinn_utilities.overrides import overrides
from spinn_utilities.typing.coords import XY
from pacman.exceptions import PacmanConfigurationException
from pacman.utilities.utility_calls import get_n_bits
from pacman.utilities.utility_calls import get_n_bits, is_power_of_2
from pacman.utilities.constants import BITS_IN_KEY
from pacman.model.routing_info.base_key_and_mask import BaseKeyAndMask
from pacman.model.graphs.application import ApplicationVertex
Expand All @@ -41,7 +41,7 @@ class Abstract2DDeviceVertex(object, metaclass=AbstractBase):

@property
@abstractmethod
def _width(self) -> int:
def width(self) -> int:
"""
The width of the device.
Expand All @@ -51,7 +51,7 @@ def _width(self) -> int:

@property
@abstractmethod
def _height(self) -> int:
def height(self) -> int:
"""
The height of the device.
Expand All @@ -61,7 +61,7 @@ def _height(self) -> int:

@property
@abstractmethod
def _sub_width(self) -> int:
def sub_width(self) -> int:
"""
The width of the sub-rectangles to divide the input into.
Expand All @@ -71,7 +71,7 @@ def _sub_width(self) -> int:

@property
@abstractmethod
def _sub_height(self) -> int:
def sub_height(self) -> int:
"""
The height of the sub-rectangles to divide the input into.
Expand All @@ -85,33 +85,24 @@ def _sub_height(self) -> int:
def atoms_shape(self) -> Tuple[int, ...]:
raise NotImplementedError

def __is_power_of_2(self, v: int) -> bool:
"""
Determine if a value is a power of 2.
:param int v: The value to test
:rtype: bool
"""
return (v & (v - 1) == 0) and (v != 0)

def _verify_sub_size(self) -> None:
"""
Ensure the sub width and height are within restrictions.
"""
if not self.__is_power_of_2(self._sub_width):
if not is_power_of_2(self.sub_width):
raise PacmanConfigurationException(
f"sub_width ({self._sub_width}) must be a power of 2")
if not self.__is_power_of_2(self._sub_height):
f"sub_width ({self.sub_width}) must be a power of 2")
if not is_power_of_2(self.sub_height):
raise PacmanConfigurationException(
f"sub_height ({self._sub_height}) must be a power of 2")
if self._sub_width > self._width:
f"sub_height ({self.sub_height}) must be a power of 2")
if self.sub_width > self.width:
raise PacmanConfigurationException(
f"sub_width ({self._sub_width}) must not be greater than "
f"width ({self._width})")
if self._sub_height > self._height:
f"sub_width ({self.sub_width}) must not be greater than "
f"width ({self.width})")
if self.sub_height > self.height:
raise PacmanConfigurationException(
f"sub_height ({self._sub_height}) must not be greater than "
f"height ({self._height})")
f"sub_height ({self.sub_height}) must not be greater than "
f"height ({self.height})")

@property
def _n_sub_rectangles(self) -> int:
Expand All @@ -120,8 +111,8 @@ def _n_sub_rectangles(self) -> int:
:rtype: int
"""
return (int(math.ceil(self._width / self._sub_width)) *
int(math.ceil(self._height / self._sub_height)))
return (int(math.ceil(self.width / self.sub_width)) *
int(math.ceil(self.height / self.sub_height)))

def _sub_square_from_index(self, index: int) -> XY:
"""
Expand All @@ -131,7 +122,7 @@ def _sub_square_from_index(self, index: int) -> XY:
:rtype: tuple(int, int)
"""
n_squares_per_row = int(math.ceil(
self._width / self._sub_width))
self.width / self.sub_width))
x_index = index % n_squares_per_row
y_index = index // n_squares_per_row

Expand All @@ -146,13 +137,13 @@ def _get_slice(self, index: int) -> MDSlice:
:rtype: Slice
"""
x_index, y_index = self._sub_square_from_index(index)
lo_atom_x = x_index * self._sub_width
lo_atom_y = y_index * self._sub_height
n_atoms_per_subsquare = self._sub_width * self._sub_height
lo_atom_x = x_index * self.sub_width
lo_atom_y = y_index * self.sub_height
n_atoms_per_subsquare = self.sub_width * self.sub_height
lo_atom = index * n_atoms_per_subsquare
hi_atom = (lo_atom + n_atoms_per_subsquare) - 1
return MDSlice(
lo_atom, hi_atom, (self._sub_width, self._sub_height),
lo_atom, hi_atom, (self.sub_width, self.sub_height),
(lo_atom_x, lo_atom_y), self.atoms_shape)

def _get_key_and_mask(self, base_key: int, index: int) -> BaseKeyAndMask:
Expand Down Expand Up @@ -185,26 +176,14 @@ def _mask(self) -> int:
(sub_y_mask << self._y_index_shift) +
(sub_x_mask << self._x_index_shift))

@property
def _key_fields(self) -> Tuple[
Tuple[int, int, int, int], Tuple[int, int, int, int]]:
"""
The fields in the key for X and Y.
:return: (start, size, mask, shift) for each of X and Y
:rtype: tuple(tuple(int, int, int int), tuple(int, int, int, int))
"""
return ((0, self._width, self._source_x_mask, self._source_x_shift),
(0, self._height, self._source_y_mask, self._source_y_shift))

@property
def _x_bits(self) -> int:
"""
The number of bits to use for X.
:rtype: int
"""
return get_n_bits(self._width)
return get_n_bits(self.width)

@property
def _y_bits(self) -> int:
Expand All @@ -213,7 +192,7 @@ def _y_bits(self) -> int:
:rtype: int
"""
return get_n_bits(self._height)
return get_n_bits(self.height)

@property
def _sub_x_bits(self) -> int:
Expand All @@ -222,7 +201,7 @@ def _sub_x_bits(self) -> int:
:rtype: int
"""
n_per_row = int(math.ceil(self._width / self._sub_width))
n_per_row = int(math.ceil(self.width / self.sub_width))
return get_n_bits(n_per_row)

@property
Expand All @@ -232,7 +211,7 @@ def _sub_y_bits(self) -> int:
:rtype: int
"""
n_per_col = int(math.ceil(self._height / self._sub_height))
n_per_col = int(math.ceil(self.height / self.sub_height))
return get_n_bits(n_per_col)

@property
Expand Down
16 changes: 8 additions & 8 deletions pacman/model/graphs/application/application_2d_fpga_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ def __init__(
self._verify_sub_size()

@property
@overrides(Abstract2DDeviceVertex._width)
def _width(self) -> int:
@overrides(Abstract2DDeviceVertex.width)
def width(self) -> int:
return self.__width

@property
@overrides(Abstract2DDeviceVertex._height)
def _height(self) -> int:
@overrides(Abstract2DDeviceVertex.height)
def height(self) -> int:
return self.__height

@property
@overrides(Abstract2DDeviceVertex._sub_width)
def _sub_width(self) -> int:
@overrides(Abstract2DDeviceVertex.sub_width)
def sub_width(self) -> int:
return self.__sub_width

@property
@overrides(Abstract2DDeviceVertex._sub_height)
def _sub_height(self) -> int:
@overrides(Abstract2DDeviceVertex.sub_height)
def sub_height(self) -> int:
return self.__sub_height

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ def __init__(
self._verify_sub_size()

@property
@overrides(Abstract2DDeviceVertex._width)
def _width(self) -> int:
@overrides(Abstract2DDeviceVertex.width)
def width(self) -> int:
return self.__width

@property
@overrides(Abstract2DDeviceVertex._height)
def _height(self) -> int:
@overrides(Abstract2DDeviceVertex.height)
def height(self) -> int:
return self.__height

@property
@overrides(Abstract2DDeviceVertex._sub_width)
def _sub_width(self) -> int:
@overrides(Abstract2DDeviceVertex.sub_width)
def sub_width(self) -> int:
return self.__sub_width

@property
@overrides(Abstract2DDeviceVertex._sub_height)
def _sub_height(self) -> int:
@overrides(Abstract2DDeviceVertex.sub_height)
def sub_height(self) -> int:
return self.__sub_height

@property
Expand Down

0 comments on commit 084f2c7

Please sign in to comment.