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 26, 2024
2 parents b357154 + ce3c3dd commit 1b35020
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 50 deletions.
42 changes: 11 additions & 31 deletions spinn_machine/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import (Collection, Iterable, Iterator, Optional, Tuple)
from typing import (Iterable, Iterator, Optional, Tuple)

from spinn_utilities.ordered_set import OrderedSet
from spinn_utilities.typing.coords import XY

from spinn_machine.data import MachineDataView
from .router import Router


Expand All @@ -29,29 +28,31 @@ class Chip(XY):
# tag 0 is reserved for stuff like IO STD
_IPTAG_IDS = OrderedSet(range(1, 8))

def __new__(cls, x: int, y: int, n_processors: int, router: Router,
def __new__(cls, x: int, y: int, scamp_processors: Iterable[int],
placable_processors: Iterable[int], router: Router,
sdram: int, nearest_ethernet_x: int, nearest_ethernet_y: int,
ip_address: Optional[str] = None,
tag_ids: Optional[Iterable[int]] = None,
down_cores: Optional[Collection[int]] = None,
parent_link: Optional[int] = None):
return tuple.__new__(cls, (x, y))

# pylint: disable=too-many-arguments, wrong-spelling-in-docstring
# pylint: disable=unused-argument
def __init__(self, x: int, y: int, n_processors: int, router: Router,
def __init__(self, x: int, y: int, scamp_processors: Iterable[int],
placable_processors: Iterable[int], router: Router,
sdram: int, nearest_ethernet_x: int, nearest_ethernet_y: int,
ip_address: Optional[str] = None,
tag_ids: Optional[Iterable[int]] = None,
down_cores: Optional[Collection[int]] = None,
parent_link: Optional[int] = None):
"""
:param int x: the x-coordinate of the chip's position in the
two-dimensional grid of chips
:param int y: the y-coordinate of the chip's position in the
two-dimensional grid of chips
:param int n_processors:
the number of processors including monitor processors.
:param iterable(int) scamp_processors:
the ids of scamp processors
:param iterable(int) placable_processors:
the ids of processors excluding scamp processors.
:param ~spinn_machine.Router router: a router for the chip
:param int sdram: an SDRAM for the chip
:param ip_address:
Expand All @@ -65,8 +66,6 @@ def __init__(self, x: int, y: int, n_processors: int, router: Router,
:type nearest_ethernet_x: int or None
:param nearest_ethernet_y: the nearest Ethernet y coordinate
:type nearest_ethernet_y: int or None
:param down_cores: Ids of cores that are down for this Chip
:type down_cores: iterable(int) or None
:param parent_link: The link down which the parent chips is found in
the tree of chips towards the root (boot) chip
:type parent_link: int or None
Expand All @@ -78,10 +77,8 @@ def __init__(self, x: int, y: int, n_processors: int, router: Router,
``processor_id``
"""
# X and Y set by new
self._scamp_processors = tuple(range(
MachineDataView.get_machine_version().n_scamp_cores))
self._placable_processors = self.__generate_processors(
n_processors, down_cores)
self._scamp_processors = tuple(scamp_processors)
self._placable_processors = tuple(placable_processors)
self._router = router
self._sdram = sdram
self._ip_address = ip_address
Expand All @@ -95,23 +92,6 @@ def __init__(self, x: int, y: int, n_processors: int, router: Router,
self._nearest_ethernet_y = nearest_ethernet_y
self._parent_link = parent_link

def __generate_processors(
self, n_processors: int,
down_cores: Optional[Collection[int]]) -> Tuple[int, ...]:
n_monitors = MachineDataView.get_machine_version().n_scamp_cores
if down_cores is None:
return tuple(range(n_monitors, n_processors))
else:
processors = list()
for i in range(n_monitors):
if i in down_cores:
raise NotImplementedError(
f"Declaring monitor core {i} as down is not supported")
for i in range(n_monitors, n_processors):
if i not in down_cores:
processors.append(i)
return tuple(processors)

def is_processor_with_id(self, processor_id: int) -> bool:
"""
Determines if a processor with the given ID exists in the chip.
Expand Down
3 changes: 2 additions & 1 deletion spinn_machine/json_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ def machine_from_json(j_machine: Union[JsonObject, str]) -> Machine:
router = Router(links, router_entries)

# Create and add a chip with this router
n_cores = _int(details["cores"])
chip = Chip(
source_x, source_y, _int(details["cores"]), router, sdram,
source_x, source_y, [0], range(1, n_cores), router, sdram,
_int(board_x), _int(board_y), ip_address, [
_int(tag) for tag in tag_ids])
machine.add_chip(chip)
Expand Down
3 changes: 2 additions & 1 deletion spinn_machine/machine_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def _machine_ignore(
links.append(link)
router = Router(links, chip.router.n_available_multicast_entries)
chip = Chip(
chip.x, chip.y, chip.n_processors, router, chip.sdram,
chip.x, chip.y, chip.scamp_processors_ids,
chip.placable_processors_ids, router, chip.sdram,
chip.nearest_ethernet_x, chip.nearest_ethernet_y,
chip.ip_address, chip.tag_ids)
new_machine.add_chip(chip)
Expand Down
8 changes: 5 additions & 3 deletions spinn_machine/virtual_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,14 @@ def _create_chip(self, xy: XY, configured_chips: Dict[XY, Tuple[XY, int]],

((eth_x, eth_y), n_cores) = configured_chips[xy]

down_cores = self._unused_cores.get(xy, None)
x, y = xy
sdram = MachineDataView.get_machine_version().max_sdram_per_chip
cores = list(range(1, n_cores))
for down_core in self._unused_cores.get(xy, []):
if down_core in cores:
cores.remove(down_core)
return Chip(
x, y, n_cores, chip_router, sdram, eth_x, eth_y,
ip_address, down_cores=down_cores)
x, y, [0], cores, chip_router, sdram, eth_x, eth_y, ip_address)

def _calculate_links(
self, xy: XY, configured_chips: Dict[XY, Tuple[XY, int]]
Expand Down
11 changes: 5 additions & 6 deletions unittests/test_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setUp(self):
self._ip = "192.162.240.253"

def _create_chip(self, x, y, processors, r, sdram, ip):
return Chip(x, y, processors, r, sdram, 0, 0, ip)
return Chip(x, y, [0], range(1, processors), r, sdram, 0, 0, ip)

def test_create_chip(self):
new_chip = self._create_chip(self._x, self._y, self.n_processors,
Expand All @@ -65,14 +65,13 @@ def test_create_chip(self):
self.assertTrue(new_chip.is_processor_with_id(3))

def test_0_down(self):
# Chip where 0 the monitor is down
with self.assertRaises(NotImplementedError):
Chip(1, 1, self.n_processors, self._router, self._sdram, 0, 0,
self._ip, down_cores=[0])
Chip(1, 1, [1], range(3, self.n_processors), self._router,
self._sdram, 0, 0, self._ip)

def test_1_chip(self):
# Chip with just 1 processor
new_chip = Chip(1, 1, 1, self._router, self._sdram, 0, 0, self._ip)
new_chip = Chip(1, 1, [0], [], self._router, self._sdram, 0, 0,
self._ip)
with self.assertRaises(Exception):
new_chip.get_first_none_monitor_processor()

Expand Down
8 changes: 4 additions & 4 deletions unittests/test_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ def setUp(self):
def _create_chip(self, x, y):
n_cores = MachineDataView.get_machine_version().max_cores_per_chip
if x == y == 0:
return Chip(x, y, n_cores, self._router, self._sdram,
self._nearest_ethernet_chip[0],
return Chip(x, y, [0], range(1, n_cores), self._router,
self._sdram, self._nearest_ethernet_chip[0],
self._nearest_ethernet_chip[1], self._ip)
return Chip(x, y, n_cores, self._router, self._sdram,
return Chip(x, y, [0], range(1, n_cores), self._router, self._sdram,
self._nearest_ethernet_chip[0],
self._nearest_ethernet_chip[1], None)

Expand Down Expand Up @@ -154,7 +154,7 @@ def test_chip_already_exists(self):
machine = virtual_machine_by_boards(1)
with self.assertRaises(SpinnMachineAlreadyExistsException):
machine.add_chip(Chip(
0, 0, 18, self._router, self._sdram,
0, 0, [0], range(1, 18), self._router, self._sdram,
self._nearest_ethernet_chip[0],
self._nearest_ethernet_chip[1], self._ip))

Expand Down
4 changes: 2 additions & 2 deletions unittests/test_virtual_machine201.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def _create_chip(self, x, y):
_ip = "192.162.240.253"

if (x == y == 0):
return Chip(x, y, n_processors, _router, _sdram,
return Chip(x, y, [0], range(1, n_processors), _router, _sdram,
nearest_ethernet_chip[0],
nearest_ethernet_chip[1], _ip)
else:
return Chip(x, y, n_processors, _router, _sdram,
return Chip(x, y, [0], range(1, n_processors), _router, _sdram,
nearest_ethernet_chip[0],
nearest_ethernet_chip[1], None)

Expand Down
4 changes: 2 additions & 2 deletions unittests/test_virtual_machine3.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def _create_chip(self, x, y):
_ip = "192.162.240.253"

if (x == y == 0):
return Chip(x, y, n_processors, _router, _sdram,
return Chip(x, y, [0], range(1, n_processors), _router, _sdram,
nearest_ethernet_chip[0],
nearest_ethernet_chip[1], _ip)
else:
return Chip(x, y, n_processors, _router, _sdram,
return Chip(x, y, [0], range(1, n_processors), _router, _sdram,
nearest_ethernet_chip[0],
nearest_ethernet_chip[1], None)

Expand Down

0 comments on commit 1b35020

Please sign in to comment.