Skip to content

Commit

Permalink
Merge branch 'sdram_per_timestep' into extractorJ
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jan 22, 2019
2 parents a1929da + aeba026 commit d2ea662
Show file tree
Hide file tree
Showing 44 changed files with 702 additions and 240 deletions.
4 changes: 2 additions & 2 deletions pacman/executor/pacman_algorithm_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ def _determine_algorithm_order(
" Algorithm by outputs: {}\n"
" Algorithm by tokens: {}\n"
" Inputs required per function: \n{}\n".format(
input_types,
fake_inputs,
sorted(input_types),
sorted(fake_inputs),
outputs_to_find,
token_states.get_completed_tokens(),
fake_tokens.get_completed_tokens(),
Expand Down
11 changes: 7 additions & 4 deletions pacman/model/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .abstract_sdram import AbstractSDRAM
from .constant_sdram import ConstantSDRAM
from .core_resource import CoreResource
from .cpu_cycles_per_tick_resource import CPUCyclesPerTickResource
from .dtcm_resource import DTCMResource
Expand All @@ -6,7 +8,6 @@
from .pre_allocated_resource_container import PreAllocatedResourceContainer
from .resource_container import ResourceContainer
from .reverse_iptag_resource import ReverseIPtagResource
from .sdram_resource import SDRAMResource
from .specific_board_iptag_resource import (
SpecificBoardTagResource as
SpecificBoardIPtagResource)
Expand All @@ -15,10 +16,12 @@
SpecificBoardReverseIPtagResource)
from .specific_chip_sdram_resource import SpecificChipSDRAMResource
from .specific_core_resource import SpecificCoreResource
from .variable_sdram import VariableSDRAM

__all__ = ["CPUCyclesPerTickResource", "DTCMResource",
__all__ = ["AbstractSDRAM", "ConstantSDRAM", "CoreResource",
"CPUCyclesPerTickResource", "DTCMResource",
"ElementFreeSpace", "IPtagResource", "ResourceContainer",
"ReverseIPtagResource", "SDRAMResource", "CoreResource",
"ReverseIPtagResource", "SDRAMAvaiable",
"PreAllocatedResourceContainer", "SpecificChipSDRAMResource",
"SpecificCoreResource", "SpecificBoardIPtagResource",
"SpecificBoardReverseIPtagResource"]
"SpecificBoardReverseIPtagResource", "VariableSDRAM"]
63 changes: 63 additions & 0 deletions pacman/model/resources/abstract_sdram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from six import add_metaclass

from spinn_utilities.abstract_base import (
AbstractBase, abstractmethod, abstractproperty)


@add_metaclass(AbstractBase)
class AbstractSDRAM(object):
""" Represents an amount of SDRAM used on a chip in the\
machine.
"""

@abstractmethod
def get_total_sdram(self, n_timesteps):
"""
The total sdram.
:param n_timesteps: number of timesteps to cost for
:type n_timesteps: int
:return:
"""

@abstractmethod
def __add__(self, other):
""" Combines this SDRAM resource with the other one and creates a new one
:param other: another SDRAM resource
:type other: AbstractSDRAM
:return: a New AbstractSDRAM
:rtype AbstractSDRAM
"""

@abstractmethod
def __sub__(self, other):
""" Creates a new SDRAM which is this one less the other
:param other: another SDRAM resource
:type other: AbstractSDRAM
:return: a New AbstractSDRAM
:rtype AbstractSDRAM
"""

@abstractmethod
def sub_from(self, other):
""" Creates a new SDRAM which is the other less this one
:param other: another SDRAM resource
:type other: AbstractSDRAM
:return: a New AbstractSDRAM
:rtype AbstractSDRAM
"""

@abstractproperty
def fixed(self):
""" Returns the fixed sdram cost
"""

@abstractproperty
def per_timestep(self):
""" Returns extra sdram cost for each additional timestep
Warning may well be zero
"""
56 changes: 56 additions & 0 deletions pacman/model/resources/constant_sdram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from .abstract_sdram import AbstractSDRAM


class ConstantSDRAM(AbstractSDRAM):
""" Represents an amount of SDRAM used on a chip in the machine.
This is used when the amount of SDRAM needed is not effected by runtime
"""

__slots__ = [
# The amount of SDRAM in bytes
"_sdram"
]

def __init__(self, sdram):
"""
:param sdram: The amount of SDRAM in bytes
:type sdram: int
:raise None: No known exceptions are raised
"""
self._sdram = sdram

def get_total_sdram(self, n_timesteps):
return self._sdram

@property
def fixed(self):
return self._sdram

@property
def per_timestep(self):
return 0

def __add__(self, other):
if isinstance(other, ConstantSDRAM):
return ConstantSDRAM(
self._sdram + other._sdram)
else:
# The other is more complex so delegate to it
return other.__add__(self)

def __sub__(self, other):
if isinstance(other, ConstantSDRAM):
return ConstantSDRAM(
self._sdram - other._sdram)
else:
# The other is more complex so delegate to it
return other.sub_from(self)

def sub_from(self, other):
if isinstance(other, ConstantSDRAM):
return ConstantSDRAM(
other._sdram - self._sdram)
else:
# The other is more complex so delegate to it
return other - self
3 changes: 2 additions & 1 deletion pacman/model/resources/pre_allocated_resource_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(
iterable of SpecificSDRAMResource which states that specific chips\
have missing SDRAM
:type specific_sdram_usage: \
iterable(:py:class:`pacman.model.resources.SpecificSDRAMResource`)
iterable( \
:py:class:`pacman.model.resources.SpecificChipSDRAMResource`)
:param specific_core_resources:\
states which cores have been preallocated
:type specific_core_resources: \
Expand Down
7 changes: 3 additions & 4 deletions pacman/model/resources/resource_container.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .constant_sdram import ConstantSDRAM
from .cpu_cycles_per_tick_resource import CPUCyclesPerTickResource
from .dtcm_resource import DTCMResource
from .sdram_resource import SDRAMResource


class ResourceContainer(object):
Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(
if self._dtcm_usage is None:
self._dtcm_usage = DTCMResource(0)
if self._sdram_usage is None:
self._sdram_usage = SDRAMResource(0)
self._sdram_usage = ConstantSDRAM(0)
if self._cpu_cycles is None:
self._cpu_cycles = CPUCyclesPerTickResource(0)
if self._reverse_iptags is None:
Expand Down Expand Up @@ -110,8 +110,7 @@ def extend(self, other):
self._dtcm_usage.get_value() + other.dtcm.get_value())

# add SDRAM usage
self._sdram_usage = SDRAMResource(
self._sdram_usage.get_value() + other.sdram.get_value())
self._sdram_usage = self._sdram_usage + other._sdram_usage

# add IPtags
self._iptags.extend(other.iptags)
Expand Down
23 changes: 0 additions & 23 deletions pacman/model/resources/sdram_resource.py

This file was deleted.

12 changes: 9 additions & 3 deletions pacman/model/resources/specific_chip_sdram_resource.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
from pacman.model.resources import AbstractSDRAM


class SpecificChipSDRAMResource(object):
""" Represents the the allocation of memory on a specific chip.
""" Represents the SDRAM required for this Chip
"""

__slots__ = [

# The number of cores that need to be allocated on a give chip
"_sdram_usage",

# the chip that has these cores allocated
# the chip that has this SDRAM usage
"_chip"
]

def __init__(self, chip, sdram_usage):
"""
:param sdram_usage:\
The amount of SDRAM in bytes needed to be pre-allocated
:type sdram_usage: AbstractSDRAM
The amount of SDRAM in bytes needed to be preallocated
:type sdram_usage: int
:param chip: chip of where the SDRAM is to be allocated
:type chip: :py:class:`spinn_machine.Chip`
:raise None: No known exceptions are raised
"""
assert isinstance(sdram_usage, AbstractSDRAM)
self._sdram_usage = sdram_usage
self._chip = chip

Expand Down
76 changes: 76 additions & 0 deletions pacman/model/resources/variable_sdram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from .abstract_sdram import AbstractSDRAM
from .constant_sdram import ConstantSDRAM
from pacman.exceptions import PacmanConfigurationException


class VariableSDRAM(AbstractSDRAM):
""" Represents an amount of SDRAM used on a chip in the machine.
This is where the usage increase as the run time increases
"""

__slots__ = [
# The amount of SDRAM in bytes used no matter what
"_fixed_sdram"
# The amount of extra SDRAm used for each timestep
"_per_timestep_sdram"
]

def __init__(
self, fixed_sdram, per_timestep_sdram):
"""
:param sdram: The amount of SDRAM in bytes
:type sdram: int
:raise None: No known exceptions are raised
"""
self._fixed_sdram = fixed_sdram
self._per_timestep_sdram = per_timestep_sdram

def get_total_sdram(self, n_timesteps):
if n_timesteps:
return self._fixed_sdram + \
(self._per_timestep_sdram * n_timesteps)
else:
if self._per_timestep_sdram == 0:
return self._fixed_sdram
else:
raise PacmanConfigurationException(
"Unable to run forever with a variable SDRAM cost")

@property
def fixed(self):
return self._fixed_sdram

@property
def per_timestep(self):
return self._per_timestep_sdram

def __add__(self, other):
if isinstance(other, ConstantSDRAM):
return VariableSDRAM(
self._fixed_sdram + other.fixed,
self._per_timestep_sdram)
else:
return VariableSDRAM(
self._fixed_sdram + other._fixed_sdram,
self._per_timestep_sdram + other._per_timestep_sdram)

def __sub__(self, other):
if isinstance(other, ConstantSDRAM):
return VariableSDRAM(
self._fixed_sdram - other.fixed,
self._per_timestep_sdram)
else:
return VariableSDRAM(
self._fixed_sdram - other._fixed_sdram,
self._per_timestep_sdram - other._per_timestep_sdram)

def sub_from(self, other):
if isinstance(other, ConstantSDRAM):
return VariableSDRAM(
other.fixed - self._fixed_sdram,
0 - self._per_timestep_sdram)
else:
return VariableSDRAM(
other._fixed_sdram - self._fixed_sdram,
other._per_timestep_sdram - self._per_timestep_sdram)

0 comments on commit d2ea662

Please sign in to comment.