Skip to content

Commit

Permalink
Revert "multi-boot for 105 machine works ish. Has some itermident issues
Browse files Browse the repository at this point in the history
with cores repeating id of 0"
  • Loading branch information
rowleya committed Jun 17, 2015
1 parent 8278b5a commit a954505
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pacman/model/partitioned_graph/partitioned_graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pacman.exceptions import PacmanInvalidParameterException
from pacman.exceptions import PacmanAlreadyExistsException

from spinn_machine.utilities.ordered_set import OrderedSet
from pacman.utilities.ordered_set import OrderedSet


class PartitionedGraph(object):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""
AbstractRoutingInfoAllocatorAlgorithm
"""
from abc import ABCMeta
from abc import abstractmethod
from collections import OrderedDict
from six import add_metaclass

# pacamn imports
from pacman.utilities import utility_calls

from pacman.exceptions import PacmanValueError

from pacman.model.constraints.key_allocator_constraints\
.key_allocator_contiguous_range_constraint \
import KeyAllocatorContiguousRangeContraint
Expand All @@ -17,15 +19,7 @@
from pacman.model.constraints.key_allocator_constraints\
.key_allocator_same_keys_constraint \
import KeyAllocatorSameKeysConstraint

# spinnmachine imports
from spinn_machine.utilities.ordered_set import OrderedSet

# general imports
from abc import ABCMeta
from abc import abstractmethod
from collections import OrderedDict
from six import add_metaclass
from pacman.utilities.ordered_set import OrderedSet


@add_metaclass(ABCMeta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def place(self, partitioned_graph, machine):
"for placing the partitioned_graphs "
"subvertices")
resource_tracker = ResourceTracker(
machine, machine.generate_radial_chips())
machine, self._generate_radial_chips(machine))
for vertex in constrained_vertices:
self._place_vertex(vertex, resource_tracker, machine, placements)
progress_bar.update()
Expand Down
42 changes: 30 additions & 12 deletions pacman/operations/placer_algorithms/radial_placer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
"""
RadialPlacer
"""

# pacman imports
from pacman.model.constraints.placer_constraints\
.placer_chip_and_core_constraint import PlacerChipAndCoreConstraint
from pacman.model.constraints.tag_allocator_constraints.\
Expand All @@ -19,15 +14,15 @@
from pacman.model.placements.placements import Placements
from pacman.model.placements.placement import Placement
from pacman.utilities import utility_calls
from pacman.utilities.ordered_set import OrderedSet
from pacman.utilities.resource_tracker import ResourceTracker
from pacman.utilities.progress_bar import ProgressBar
from pacman.exceptions import PacmanPlaceException
from pacman.operations.abstract_algorithms.abstract_placer_algorithm \
import AbstractPlacerAlgorithm

# general imports
from collections import deque
import logging

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -65,7 +60,7 @@ def place(self, partitioned_graph, machine):
"for placing the partitioned_graphs "
"subvertices")
resource_tracker = ResourceTracker(
machine, machine.generate_radial_chips())
machine, self._generate_radial_chips(machine))
for vertex in ordered_subverts:
self._place_vertex(vertex, resource_tracker, machine, placements)
progress_bar.update()
Expand All @@ -77,8 +72,8 @@ def _place_vertex(self, vertex, resource_tracker, machine, placements):
# Check for the radial placement constraint
radial_constraints = utility_calls.locate_constraints_of_type(
[vertex], PlacerRadialPlacementFromChipConstraint)
start_x = None
start_y = None
start_x = 0
start_y = 0
for constraint in radial_constraints:
if start_x is None:
start_x = constraint.x
Expand All @@ -90,11 +85,34 @@ def _place_vertex(self, vertex, resource_tracker, machine, placements):
raise PacmanPlaceException("Non-matching constraints")
chips = None
if start_x is not None and start_y is not None:
chips = machine.generate_radial_chips(
resource_tracker, start_x, start_y)
chips = self._generate_radial_chips(machine, resource_tracker,
start_x, start_y)

# Create and store a new placement
(x, y, p, _, _) = resource_tracker.allocate_constrained_resources(
vertex.resources_required, vertex.constraints, chips)
placement = Placement(vertex, x, y, p)
placements.add_placement(placement)

def _generate_radial_chips(self, machine, resource_tracker=None,
start_chip_x=0, start_chip_y=0):
first_chip = machine.get_chip_at(start_chip_x, start_chip_y)
done_chips = set()
found_chips = OrderedSet()
search = deque([first_chip])
while len(search) > 0:
chip = search.pop()
if (resource_tracker is None or
resource_tracker.is_chip_available(chip.x, chip.y)):
found_chips.add((chip.x, chip.y))
done_chips.add(chip)

# Examine the links of the chip to find the next chips
for link in chip.router.links:
next_chip = machine.get_chip_at(link.destination_x,
link.destination_y)

# Don't search found chips again
if next_chip not in done_chips:
search.appendleft(next_chip)
return found_chips
102 changes: 102 additions & 0 deletions pacman/utilities/ordered_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import collections


class _Node(object):

def __init__(self, key, prev_node, next_node):
self._key = key
self._prev_node = prev_node
self._next_node = next_node

@property
def key(self):
return self._key

@property
def prev_node(self):
return self._prev_node

@prev_node.setter
def prev_node(self, prev_node):
self._prev_node = prev_node

@property
def next_node(self):
return self._next_node

@next_node.setter
def next_node(self, next_node):
self._next_node = next_node


class OrderedSet(collections.MutableSet):

def __init__(self, iterable=None):

# sentinel node for doubly linked list
# prev_node of end points to end of list (for reverse iteration)
# next_node of end points to start of list (for forward iteration)
self._end = _Node(None, None, None)
self._end.prev_node = self._end
self._end.next_node = self._end

# key --> _Node
self._map = dict()

# ior is overridden in mutable set; calls add on each element
if iterable is not None:
self |= iterable

def __len__(self):
return len(self._map)

def __contains__(self, key):
return key in self._map

def add(self, key):
if key not in self._map:
end_prev = self._end.prev_node
new_node = _Node(key, end_prev, self._end)
self._map[key] = new_node
end_prev.next_node = new_node
self._end.prev_node = new_node

def discard(self, key):
if key in self._map:
node = self._map.pop(key)
prev_node = node.prev_node
next_node = node.next_node
node.prev_node.next_node = next_node
node.next_node.prev_node = prev_node

def __iter__(self):
curr = self._end.next_node
while curr is not self._end:
yield curr.key
curr = curr.next_node

def __reversed__(self):
curr = self._end.prev_node
while curr is not self._end:
yield curr.key
curr = curr.prev_node

def pop(self, last=True):
if len(self._map) == 0:
raise KeyError('set is empty')
if last:
key = self._end.prev_node.key
else:
key = self._end.next_node.key
self.discard(key)
return key

def __repr__(self):
if not self:
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, list(self))

def __eq__(self, other):
if isinstance(other, OrderedSet):
return len(self) == len(other) and list(self) == list(other)
return set(self) == set(other)
15 changes: 7 additions & 8 deletions pacman/utilities/resource_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pacman.model.resources.resource_container import ResourceContainer
from pacman.model.resources.dtcm_resource import DTCMResource
from pacman.model.resources.sdram_resource import SDRAMResource
from spinn_machine.utilities.ordered_set import OrderedSet
from pacman.utilities.ordered_set import OrderedSet
from pacman.utilities import utility_calls
from pacman.model.resources.cpu_cycles_per_tick_resource \
import CPUCyclesPerTickResource
Expand All @@ -27,7 +27,7 @@ def __init__(self, machine, chips=None):
the set of chips used, or to re-order the chips. Note\
also that on de-allocation, the order is no longer\
guaranteed.
:type chips: iterable of chips
:type chips: iterable of (x, y) tuples of coordinates of chips
"""

# The amount of SDRAM used by each chip,
Expand Down Expand Up @@ -79,16 +79,15 @@ def __init__(self, machine, chips=None):

# Set of (x, y) tuples of coordinates of chips which have available
# processors
self._chips_available = OrderedSet()
chips_to_use = chips
self._chips_available = OrderedSet(chips)
if chips is None:
chips_to_use = machine.chips
for chip in chips_to_use:
key = (chip.x, chip.y)
self._chips_available.add(key)
for chip in machine.chips:
key = (chip.x, chip.y)
self._chips_available.add(key)

# Initialize the ethernet area codes
for (chip_x, chip_y) in self._chips_available:
chip = self._machine.get_chip_at(chip_x, chip_y)
key = (chip_x, chip_y)

# add area codes for ethernets
Expand Down

0 comments on commit a954505

Please sign in to comment.