Skip to content

Commit

Permalink
Merge pull request #154 from SpiNNakerManchester/sdram_edges
Browse files Browse the repository at this point in the history
rubbered
  • Loading branch information
alan-stokes committed Aug 10, 2018
2 parents 221f1f5 + 464edc3 commit cc97c71
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 24 deletions.
1 change: 1 addition & 0 deletions pacman/model/graphs/common/edge_traffic_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ class EdgeTrafficType(Enum):

MULTICAST = 1
FIXED_ROUTE = 2
SDRAM = 3
10 changes: 4 additions & 6 deletions pacman/operations/placer_algorithms/one_to_one_placer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pacman.model.placements import Placement, Placements
from pacman.operations.placer_algorithms import RadialPlacer
from pacman.utilities.utility_objs import ResourceTracker
from pacman.utilities.algorithm_utilities \
import placer_algorithm_utilities as placer_utils
from pacman.utilities.algorithm_utilities.placer_algorithm_utilities \
import get_same_chip_vertex_groups, sort_vertices_by_known_constraints
from pacman.model.constraints.placer_constraints\
import SameChipAsConstraint
from pacman.utilities.utility_calls import is_single
Expand Down Expand Up @@ -37,8 +37,7 @@ def __call__(self, machine_graph, machine):
additional_placement_constraints={SameChipAsConstraint})

# Get which vertices must be placed on the same chip as another vertex
same_chip_vertex_groups = placer_utils.get_same_chip_vertex_groups(
machine_graph.vertices)
same_chip_vertex_groups = get_same_chip_vertex_groups(machine_graph)
sorted_vertices = self._sort_vertices_for_one_to_one_connection(
machine_graph, same_chip_vertex_groups)

Expand Down Expand Up @@ -120,8 +119,7 @@ def _sort_vertices_for_one_to_one_connection(
found_list = set()

# order vertices based on constraint priority
vertices = placer_utils.sort_vertices_by_known_constraints(
machine_graph.vertices)
vertices = sort_vertices_by_known_constraints(machine_graph.vertices)

for vertex in vertices:
if vertex not in found_list:
Expand Down
10 changes: 4 additions & 6 deletions pacman/operations/placer_algorithms/radial_placer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# pacman imports
from pacman.model.constraints.placer_constraints \
import RadialPlacementFromChipConstraint, SameChipAsConstraint
from pacman.utilities.algorithm_utilities \
import placer_algorithm_utilities as placer_utils
from pacman.utilities.algorithm_utilities.placer_algorithm_utilities \
import sort_vertices_by_known_constraints, get_same_chip_vertex_groups
from pacman.model.placements import Placement, Placements
from pacman.utilities.utility_calls import locate_constraints_of_type
from pacman.utilities.utility_objs import ResourceTracker
Expand All @@ -28,16 +28,14 @@ def __call__(self, machine_graph, machine):
self._check_constraints(machine_graph.vertices)

placements = Placements()
vertices = placer_utils.sort_vertices_by_known_constraints(
machine_graph.vertices)
vertices = sort_vertices_by_known_constraints(machine_graph.vertices)

# Iterate over vertices and generate placements
progress = ProgressBar(
machine_graph.n_vertices, "Placing graph vertices")
resource_tracker = ResourceTracker(
machine, self._generate_radial_chips(machine))
vertices_on_same_chip = placer_utils.get_same_chip_vertex_groups(
machine_graph.vertices)
vertices_on_same_chip = get_same_chip_vertex_groups(machine_graph)
all_vertices_placed = set()
for vertex in progress.over(vertices):
if vertex not in all_vertices_placed:
Expand Down
3 changes: 1 addition & 2 deletions pacman/operations/rigged_algorithms/hilbert_placer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def __call__(self, machine_graph, machine):
machine, self._generate_hilbert_chips(machine))

# get vertices which must be placed on the same chip
vertices_on_same_chip = \
get_same_chip_vertex_groups(machine_graph.vertices)
vertices_on_same_chip = get_same_chip_vertex_groups(machine_graph)

# iterate over vertices and generate placements
all_vertices_placed = set()
Expand Down
3 changes: 1 addition & 2 deletions pacman/operations/rigged_algorithms/random_placer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def __call__(self, machine_graph, machine):
"Placing graph vertices")
resource_tracker = ResourceTracker(
machine, self._generate_random_chips(machine))
vertices_on_same_chip = get_same_chip_vertex_groups(
machine_graph.vertices)
vertices_on_same_chip = get_same_chip_vertex_groups(machine_graph)
vertices_placed = set()
for vertex in progress.over(vertices):
if vertex not in vertices_placed:
Expand Down
18 changes: 12 additions & 6 deletions pacman/utilities/algorithm_utilities/placer_algorithm_utilities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pacman.model.constraints.placer_constraints\
import ChipAndCoreConstraint, SameChipAsConstraint
from pacman.model.graphs.common.edge_traffic_type import EdgeTrafficType
from pacman.model.constraints.placer_constraints \
import BoardConstraint, RadialPlacementFromChipConstraint
from pacman.utilities import VertexSorter, ConstraintOrder
Expand All @@ -18,25 +19,30 @@ def sort_vertices_by_known_constraints(vertices):
return sorter.sort(vertices)


def get_same_chip_vertex_groups(vertices):
""" Get a dictionary of vertex to vertex that must be placed on the same\
chip
def get_same_chip_vertex_groups(graph):
""" Get a dictionary of vertex to list of vertices that must be placed on\
the same chip
"""

# Dict of vertex to list of vertices on same chip (repeated lists expected)
same_chip_vertices = dict()

for vertex in vertices:
for vertex in graph.vertices:
# Find all vertices that have a same chip constraint associated with
# this vertex
same_chip_as_vertices = list()
for constraint in vertex.constraints:
if isinstance(constraint, SameChipAsConstraint):
same_chip_as_vertices.append(constraint.vertex)

for edge in filter(
lambda edge: edge.traffic_type == EdgeTrafficType.SDRAM,
graph.get_edges_starting_at_vertex(vertex)):
same_chip_as_vertices.append(edge.post_vertex)

if same_chip_as_vertices:
# Go through all the verts that want to be on the same chip as
# the top level vert
# Go through all the vertices that want to be on the same chip as
# the top level vertex
for same_as_chip_vertex in same_chip_as_vertices:
# Neither vertex has been seen
if (same_as_chip_vertex not in same_chip_vertices and
Expand Down
4 changes: 2 additions & 2 deletions pacman/utilities/rig_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
LocationConstraint, ReserveResourceConstraint, RouteEndpointConstraint
from rig.place_and_route.routing_tree import RoutingTree
from rig.routing_table import Routes
from six import iteritems
from six import iteritems, itervalues

from pacman.model.constraints.placer_constraints\
import ChipAndCoreConstraint, RadialPlacementFromChipConstraint
Expand Down Expand Up @@ -205,7 +205,7 @@ def create_rig_graph_constraints(machine_graph, machine):
constraints.append(LocationConstraint(
vertex, (constraint.x, constraint.y)))

for group in get_same_chip_vertex_groups(machine_graph.vertices).values():
for group in itervalues(get_same_chip_vertex_groups(machine_graph)):
if len(group) > 1:
constraints.append(SameChipConstraint(group))
return constraints
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from pacman.model.graphs.machine import MachineGraph, SimpleMachineVertex
from spinn_machine import VirtualMachine
from pacman.model.resources import ResourceContainer
from pacman.model.graphs.machine.machine_edge import MachineEdge
from pacman.model.graphs.common.edge_traffic_type import EdgeTrafficType
from pacman.operations.rig_algorithms.rig_place import RigPlace
from pacman.operations.placer_algorithms.one_to_one_placer \
import OneToOnePlacer
from pacman.operations.placer_algorithms import RadialPlacer
import random
import unittest


class TestSameChipConstraint(unittest.TestCase):

def _do_test(self, placer):
machine = VirtualMachine(width=8, height=8)
graph = MachineGraph("Test")

vertices = [
SimpleMachineVertex(ResourceContainer(), label="v{}".format(i))
for i in range(100)
]
for vertex in vertices:
graph.add_vertex(vertex)

same_vertices = [
SimpleMachineVertex(ResourceContainer(), label="same{}".format(i))
for i in range(10)
]
random.seed(12345)
sdram_edges = list()
for vertex in same_vertices:
graph.add_vertex(vertex)
for i in range(0, random.randint(1, 5)):
sdram_edge = MachineEdge(
vertex, vertices[random.randint(0, 99)],
traffic_type=EdgeTrafficType.SDRAM)
sdram_edges.append(sdram_edge)
graph.add_edge(sdram_edge, "Test")

placements = placer(graph, machine)
for edge in sdram_edges:
pre_place = placements.get_placement_of_vertex(edge.pre_vertex)
post_place = placements.get_placement_of_vertex(edge.post_vertex)
self.assert_(pre_place.x == post_place.x)
self.assert_(pre_place.y == post_place.y)

def test_one_to_one(self):
self._do_test(OneToOnePlacer())

def test_radial(self):
self._do_test(RadialPlacer())

def test_rig(self):
self._do_test(RigPlace())

0 comments on commit cc97c71

Please sign in to comment.