Source code for pacman.model.graphs.machine.destination_segmented_sdram_machine_partition

# Copyright (c) 2019-2020 The University of Manchester
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from spinn_utilities.overrides import overrides
from pacman.exceptions import (
    PacmanConfigurationException,  PartitionMissingEdgesException)
from pacman.model.graphs import AbstractSingleSourcePartition
from pacman.model.graphs.common import EdgeTrafficType
from pacman.model.graphs.machine import (
    AbstractSDRAMPartition, SDRAMMachineEdge)


[docs]class DestinationSegmentedSDRAMMachinePartition( AbstractSingleSourcePartition, AbstractSDRAMPartition): """ An SDRAM partition that gives each edge its own slice of memory from a\ contiguous block. The edges all have the same source vertex. """ __slots__ = [ # The sdram base address for this partition. "_sdram_base_address", ] def __init__(self, identifier, pre_vertex, label): super().__init__( pre_vertex=pre_vertex, identifier=identifier, allowed_edge_types=SDRAMMachineEdge, constraints=None, label=label, traffic_weight=1, class_name="DestinationSegmentedSDRAMMachinePartition") self._sdram_base_address = None @property @overrides(AbstractSDRAMPartition.traffic_type) def traffic_type(self): return EdgeTrafficType.SDRAM
[docs] @overrides(AbstractSDRAMPartition.total_sdram_requirements) def total_sdram_requirements(self): return sum(edge.sdram_size for edge in self.edges)
@property def sdram_base_address(self): return self._sdram_base_address @sdram_base_address.setter def sdram_base_address(self, new_value): if len(self.edges) == 0: raise PartitionMissingEdgesException( "Partition {} has no edges".format(self)) self._sdram_base_address = new_value for edge in self.edges: edge.sdram_base_address = new_value new_value += edge.sdram_size
[docs] @overrides(AbstractSingleSourcePartition.add_edge) def add_edge(self, edge, graph_code): if self._sdram_base_address is not None: raise PacmanConfigurationException( "Illegal attempt to add an edge after sdram_base_address set") super().check_edge(edge) # safety check if self._pre_vertex != edge.pre_vertex: raise PacmanConfigurationException( "The destination segmented SDRAM partition only accepts " "1 pre-vertex") # add super().add_edge(edge, graph_code)
[docs] @overrides(AbstractSDRAMPartition.get_sdram_base_address_for) def get_sdram_base_address_for(self, vertex): if self._pre_vertex == vertex: return self._sdram_base_address for edge in self._edges: if edge.post_vertex == vertex: return edge.sdram_base_address return None
[docs] @overrides(AbstractSDRAMPartition.get_sdram_size_of_region_for) def get_sdram_size_of_region_for(self, vertex): if self._pre_vertex == vertex: return self.total_sdram_requirements() for edge in self._edges: if edge.post_vertex == vertex: return edge.sdram_size return None
[docs] @overrides(AbstractSingleSourcePartition.clone_without_edges) def clone_without_edges(self): """ :rtype: DestinationSegmentedSDRAMMachinePartition """ return DestinationSegmentedSDRAMMachinePartition( self._identifier, self._pre_vertex, self._label)