Skip to content

Commit

Permalink
Merge pull request #534 from SpiNNakerManchester/check_fixed
Browse files Browse the repository at this point in the history
Check fixed key and masks don't overlap
  • Loading branch information
rowleya committed Nov 27, 2023
2 parents b9c1c42 + 08c5a5b commit 1d0bcdc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ def allocate(self, extra_allocations: _XAlloc) -> RoutingInfo:

return self.__allocate()

def __insert_fixed(
self, identifier: str, vertex: AbstractVertex, km: BaseKeyAndMask):
is_app = isinstance(vertex, ApplicationVertex)
for (_, vertex2), km2 in self.__fixed_partitions.items():
if is_app and isinstance(vertex2, MachineVertex) and \
(vertex == vertex2.app_vertex):
continue
# check if any keys could overlap
if (km.key & km2.mask) == (km2.key & km.mask):
raise PacmanRouteInfoAllocationException(
f"{vertex} has {km} which overlaps with {vertex2} {km2}")
self.__fixed_partitions[identifier, vertex] = km

def __find_fixed(self) -> None:
"""
Looks for FixedKeyAmdMask Constraints and keeps track of these.
Expand Down Expand Up @@ -186,7 +199,7 @@ def __find_fixed(self) -> None:
f"For application vertex {pre}, the fixed key for "
f"machine vertex {vert} of {key_and_mask} does "
f"not align with the app key {app_key_and_mask}")
self.__fixed_partitions[identifier, vert] = key_and_mask
self.__insert_fixed(identifier, vert, key_and_mask)
else:
if is_fixed_m_key:
raise PacmanRouteInfoAllocationException(
Expand All @@ -203,9 +216,8 @@ def __find_fixed(self) -> None:
f"On {pre} only a fixed app key has been provided,"
" but there is more than one machine vertex.")
# pylint:disable=undefined-loop-variable
self.__fixed_partitions[
identifier, vert] = app_key_and_mask
self.__fixed_partitions[identifier, pre] = app_key_and_mask
self.__insert_fixed(identifier, vert, app_key_and_mask)
self.__insert_fixed(identifier, pre, app_key_and_mask)

def __calculate_zones(self) -> None:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from spinn_utilities.overrides import overrides
from pacman.config_setup import unittest_setup
from pacman.data import PacmanDataView
from pacman.exceptions import PacmanRouteInfoAllocationException
from pacman.operations.routing_info_allocator_algorithms.\
zoned_routing_info_allocator import (flexible_allocate, global_allocate)
from pacman.model.graphs.application import ApplicationEdge, ApplicationVertex
Expand Down Expand Up @@ -162,15 +163,21 @@ def create_graphs1(with_fixed):
ApplicationEdge(app_vertex, out_app_vertex), f"Part{i}")


def create_graphs_only_fixed():
def create_graphs_only_fixed(overlap: bool):
# An output vertex to aim things at (to make keys required)
out_app_vertex = MockAppVertex(splitter=MockSplitter())
PacmanDataView.add_vertex(out_app_vertex)

fixed_keys_by_partition = {
"Part0": BaseKeyAndMask(0x4c00000, 0xFFFFFFFE),
"Part1": BaseKeyAndMask(0x4c00000, 0xFFFFFFFF)
}
if overlap:
fixed_keys_by_partition = {
"Part0": BaseKeyAndMask(0x0, 0xffff0000),
"Part1": BaseKeyAndMask(0x1000, 0xfffff800)
}
else:
fixed_keys_by_partition = {
"Part0": BaseKeyAndMask(0x0, 0xFFFFFFFE),
"Part1": BaseKeyAndMask(0x4c00000, 0xFFFFFFFF)
}
app_vertex = MockAppVertex(
splitter=MockSplitter(),
fixed_keys_by_partition=fixed_keys_by_partition)
Expand Down Expand Up @@ -281,12 +288,22 @@ def test_flexible_allocator_no_fixed():

def test_fixed_only():
unittest_setup()
create_graphs_only_fixed()
create_graphs_only_fixed(overlap=False)
flexible_allocate([])
routing_info = global_allocate([])
assert len(list(routing_info)) == 4


def test_overlap():
unittest_setup()
create_graphs_only_fixed(overlap=True)
try:
flexible_allocate([])
raise ValueError
except PacmanRouteInfoAllocationException:
pass


def test_no_edge():
unittest_setup()
create_graphs_no_edge()
Expand Down

0 comments on commit 1d0bcdc

Please sign in to comment.