Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into nengo_mods_…
Browse files Browse the repository at this point in the history
…making_graph_fleixble
  • Loading branch information
alan-stokes committed Aug 10, 2018
2 parents 0e3eaf2 + 221f1f5 commit b51f87a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pacman.utilities import constants
from spinn_machine import SDRAM, Chip, Link, Processor, Router
import sys

Expand Down Expand Up @@ -41,7 +42,7 @@ def create_virtual_chip(machine, link_data, virtual_chip_x, virtual_chip_y):

# create the processors
processors = list()
for virtual_core_id in range(0, 128):
for virtual_core_id in range(0, constants.CORES_PER_VIRTUAL_CHIP):
processors.append(Processor.factory(virtual_core_id))

# connect the real chip with the virtual one
Expand Down
2 changes: 2 additions & 0 deletions pacman/utilities/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
DEFAULT_MASK = 0xfffff800 # DEFAULT LOCATION FOR THE APP MASK
BITS_IN_KEY = 32

CORES_PER_VIRTUAL_CHIP = 128

EDGES = Enum(
value="EDGES",
names=[("EAST", 0),
Expand Down
76 changes: 74 additions & 2 deletions pacman/utilities/utility_objs/resource_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ChipAndCoreConstraint, AbstractPlacerConstraint
from pacman.model.resources import ResourceContainer, DTCMResource, \
SDRAMResource, CPUCyclesPerTickResource
from pacman.utilities import utility_calls
from pacman.utilities import utility_calls, constants
from pacman.exceptions import PacmanInvalidParameterException, \
PacmanValueError, PacmanException

Expand Down Expand Up @@ -75,7 +75,14 @@ class ResourceTracker(object):
"_n_cores_preallocated",

# counter of chips that have had processors allocated to them
"_chips_used"
"_chips_used",

# The number of chips with the n cores currently available
"_real_chips_with_n_cores_available",

# the number of virtual chips with the n cores currently available
"_virtual_chips_with_n_cores_available"

]

def __init__(self, machine, chips=None, preallocated_resources=None):
Expand Down Expand Up @@ -152,6 +159,23 @@ def __init__(self, machine, chips=None, preallocated_resources=None):
self._n_cores_preallocated = self._convert_preallocated_resources(
preallocated_resources)

# update tracker for n cores available per chip
self._real_chips_with_n_cores_available = \
[0] * (machine.MAX_CORES_PER_CHIP + 1)
self._virtual_chips_with_n_cores_available = \
[0] * (constants.CORES_PER_VIRTUAL_CHIP + 1)

for chip in machine.chips:
pre_allocated = 0
if (chip.x, chip.y) in self._n_cores_preallocated:
pre_allocated = self._n_cores_preallocated[(chip.x, chip.y)]
if chip.virtual:
self._virtual_chips_with_n_cores_available[
chip.n_user_processors - pre_allocated] += 1
else:
self._real_chips_with_n_cores_available[
chip.n_user_processors - pre_allocated] += 1

# Set of (x, y) tuples of coordinates of chips which have available
# processors
self._chips_available = OrderedSet()
Expand Down Expand Up @@ -722,6 +746,18 @@ def _allocate_core(self, chip, key, processor_id):
# TODO: Find a core that meets the resource requirements
processor_id = self._core_tracker[key].pop()

# update number tracker
if chip.virtual:
self._virtual_chips_with_n_cores_available[
len(self._core_tracker[key])] -= 1
self._virtual_chips_with_n_cores_available[
len(self._core_tracker[key]) - 1] += 1
else:
self._real_chips_with_n_cores_available[
len(self._core_tracker[key])] -= 1
self._real_chips_with_n_cores_available[
len(self._core_tracker[key]) - 1] += 1

if len(self._core_tracker[key]) == self._n_cores_preallocated[key]:
self._chips_available.remove(key)

Expand Down Expand Up @@ -1192,6 +1228,29 @@ def _available_resources(self, usable_chips):
n_tags += len(self._machine.get_chip_at(eth_x, eth_y).tag_ids)
return n_cores, n_chips, max_sdram, n_tags

def get_maximum_cores_available_on_a_chip(self):
""" returns the number of available cores of a real chip with the \
maximum number of available cores
:return: the max cores available on the best real chip
:rtype: int
"""
for n_cores_available, n_chips_with_n_cores in reversed(list(
enumerate(self._real_chips_with_n_cores_available))):
if n_chips_with_n_cores != 0:
return n_cores_available

def get_maximum_cores_available_on_a_virtual_chip(self):
""" returns the number of available cores of a virtual chip with the \
maximum number of available cores
:return: the max cores available on the best real chip
:rtype: int
"""
for n_cores_available, n_chips_with_n_cores in reversed(list(
enumerate(self._virtual_chips_with_n_cores_available))):
if n_chips_with_n_cores != 0:
return n_cores_available

def get_maximum_constrained_resources_available(
self, resources, constraints):
""" Get the maximum resources available given the constraints
Expand Down Expand Up @@ -1293,6 +1352,19 @@ def unallocate_resources(self, chip_x, chip_y, processor_id, resources,

self._chips_available.add((chip_x, chip_y))
self._sdram_tracker[chip_x, chip_y] -= resources.sdram.get_value()

# update number tracker
if self._machine.get_chip_at(chip_x, chip_y).virtual:
self._virtual_chips_with_n_cores_available[
len(self._core_tracker[chip_x, chip_y])] -= 1
self._virtual_chips_with_n_cores_available[
len(self._core_tracker[chip_x, chip_y]) + 1] += 1
else:
self._real_chips_with_n_cores_available[
len(self._core_tracker[chip_x, chip_y])] -= 1
self._real_chips_with_n_cores_available[
len(self._core_tracker[chip_x, chip_y]) + 1] += 1

self._core_tracker[chip_x, chip_y].add(processor_id)

# check if chip used needs updating
Expand Down

0 comments on commit b51f87a

Please sign in to comment.