Skip to content

Commit

Permalink
Merge 6df6f7e into a03dc61
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-stokes committed Jul 25, 2018
2 parents a03dc61 + 6df6f7e commit 5212d3a
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion pacman/utilities/utility_objs/resource_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ 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
"_chips_with_n_cores_available"
]

def __init__(self, machine, chips=None, preallocated_resources=None):
Expand Down Expand Up @@ -152,6 +155,16 @@ 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._chips_with_n_cores_available = \
[0] * (machine.MAX_CORES_PER_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)]
self._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 +735,11 @@ 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
self._chips_with_n_cores_available[len(self._core_tracker[key])] -= 1
self._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 +1210,18 @@ 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 the chip with the maximum\
number of available cores
:return: the max cores available on the best chip
:rtype: int
"""
for n_cores_available, n_chips_with_n_cores in reversed(list(
enumerate(self._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 +1323,13 @@ 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
self._chips_with_n_cores_available[
len(self._core_tracker[chip_x, chip_y])] -= 1
self._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 5212d3a

Please sign in to comment.