Skip to content

Commit

Permalink
access items directly not via state
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Oct 31, 2023
1 parent 6b24b02 commit 1bd94f4
Showing 1 changed file with 39 additions and 46 deletions.
85 changes: 39 additions & 46 deletions pacman/model/partitioner_splitters/splitter_one_to_one_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,85 +12,78 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from dataclasses import dataclass
import logging
from typing import List, Optional
from spinn_utilities.overrides import overrides
from spinn_utilities.log import FormatAdapter
from pacman.exceptions import PacmanConfigurationException
from pacman.model.graphs.common import Slice
from pacman.model.partitioner_interfaces import LegacyPartitionerAPI
from .abstract_splitter_common import AbstractSplitterCommon
from pacman.model.graphs.application import ApplicationVertex
from pacman.model.graphs.common import Slice
from pacman.model.graphs.machine import MachineVertex
from pacman.utilities.utility_objs.chip_counter import ChipCounter
from pacman.model.partitioner_interfaces import LegacyPartitionerAPI
from pacman.model.resources import AbstractSDRAM
from .abstract_splitter_common import AbstractSplitterCommon

logger = FormatAdapter(logging.getLogger(__name__))


@dataclass(frozen=True)
class _State:
vertex: MachineVertex
vertex_slice: Slice
sdram: AbstractSDRAM


class SplitterOneToOneLegacy(AbstractSplitterCommon[ApplicationVertex]):
"""
A one-to-one splitter for legacy vertices.
"""

__slots__ = ("__state", )
__slots__ = [
"_machine_vertex",
"_vertex_slice",
"_sdram"]

def __init__(self) -> None:
def __init__(self):
super().__init__()
self.__state: Optional[_State] = None

@property
def _state(self) -> _State:
assert self.__state is not None, "no app vertex set"
return self.__state
self._machine_vertex: Optional[MachineVertex] = None
self._vertex_slice: Optional[Slice] = None
self._sdram: Optional[AbstractSDRAM] = None

@overrides(AbstractSplitterCommon.set_governed_app_vertex)
def set_governed_app_vertex(self, app_vertex: ApplicationVertex):
def set_governed_app_vertex(self, app_vertex):
if not isinstance(app_vertex, LegacyPartitionerAPI):
raise PacmanConfigurationException(
f"{self} is not a LegacyPartitionerAPI")
super().set_governed_app_vertex(app_vertex)
_slice = Slice(0, app_vertex.n_atoms - 1)
sdram = app_vertex.get_sdram_used_by_atoms(_slice)
self.__state = _State(
app_vertex.create_machine_vertex(
vertex_slice=_slice, sdram=sdram, label=None),
_slice, sdram)
app_vertex.remember_machine_vertex(self._state.vertex)
self._vertex_slice = Slice(0, self.governed_app_vertex.n_atoms - 1)
self._sdram = self.governed_app_vertex.get_sdram_used_by_atoms(
self._vertex_slice)
self._machine_vertex = self.governed_app_vertex.create_machine_vertex(
vertex_slice=self._vertex_slice,
sdram=self._sdram, label=None)
self.governed_app_vertex.remember_machine_vertex(self._machine_vertex)

@overrides(AbstractSplitterCommon.create_machine_vertices)
def create_machine_vertices(self, chip_counter: ChipCounter):
chip_counter.add_core(self._state.sdram)
def create_machine_vertices(self, chip_counter):
assert self._sdram is not None
chip_counter.add_core(self._sdram)

@overrides(AbstractSplitterCommon.get_out_going_slices)
def get_out_going_slices(self) -> List[Slice]:
return [self._state.vertex_slice]
def get_out_going_slices(self):
assert self._vertex_slice is not None
return [self._vertex_slice]

@overrides(AbstractSplitterCommon.get_in_coming_slices)
def get_in_coming_slices(self) -> List[Slice]:
return [self._state.vertex_slice]
def get_in_coming_slices(self):
assert self._vertex_slice is not None
return [self._vertex_slice]

@overrides(AbstractSplitterCommon.get_out_going_vertices)
def get_out_going_vertices(self, partition_id: str) -> List[MachineVertex]:
return [self._state.vertex]
def get_out_going_vertices(self, partition_id):
assert self._machine_vertex is not None
return [self._machine_vertex]

@overrides(AbstractSplitterCommon.get_in_coming_vertices)
def get_in_coming_vertices(self, partition_id: str) -> List[MachineVertex]:
return [self._state.vertex]
def get_in_coming_vertices(self, partition_id):
assert self._machine_vertex is not None
return [self._machine_vertex]

@overrides(AbstractSplitterCommon.machine_vertices_for_recording)
def machine_vertices_for_recording(
self, variable_to_record: str) -> List[MachineVertex]:
return [self._state.vertex]
def machine_vertices_for_recording(self, variable_to_record):
assert self._machine_vertex is not None
return [self._machine_vertex]

@overrides(AbstractSplitterCommon.reset_called)
def reset_called(self) -> None:
pass
def reset_called(self):
pass

0 comments on commit 1bd94f4

Please sign in to comment.