def _load_executables(routing_tables, compressor_app_id, txrx, machine):
        """ Loads the router compressor onto the chips.

        :param routing_tables: the router tables needed to be compressed
        :param compressor_app_id: the app ID of the compressor compressor
        :param txrx: the spinnman interface
        :param machine: the SpiNNaker machine representation
        :return:\
            the executable targets that represent all cores/chips which have\
            active routing tables
        """

        # build core subsets
        core_subsets = CoreSubsets()
        for routing_table in routing_tables:

            # get the first none monitor core
            chip = machine.get_chip_at(routing_table.x, routing_table.y)
            processor = chip.get_first_none_monitor_processor()

            # add to the core subsets
            core_subsets.add_processor(
                routing_table.x, routing_table.y, processor.processor_id)

        # build executable targets
        executable_targets = ExecutableTargets()
        executable_targets.add_subsets(_BINARY_PATH, core_subsets)

        txrx.execute_application(executable_targets, compressor_app_id)
        return executable_targets
 def test_add_processor(self):
     proc_list = [0, 1, 2, 3, 5, 8, 13]
     cs = CoreSubset(0, 0, proc_list)
     css = CoreSubsets()
     css.add_core_subset(cs)
     self.assertIn(cs, css.core_subsets)
     for core_subset in css.core_subsets:
         self.assertIn(core_subset, [cs])
def convert_string_into_chip_and_core_subset(cores):
    """ Translate a string list of cores into a core subset

    :param cores:\
        string representing down cores formatted as x,y,p[:x,y,p]*
    :type cores: str or None
    """
    ignored_cores = CoreSubsets()
    if cores is not None and cores != "None":
        for downed_core in cores.split(":"):
            x, y, processor_id = downed_core.split(",")
            ignored_cores.add_processor(int(x), int(y), int(processor_id))
    return ignored_cores
def convert_vertices_to_core_subset(vertices, placements):
    """ Converts vertices into core subsets.

    :param extra_monitor_cores_to_set:\
        the vertices to convert to core subsets
    :param placements: the placements object
    :return: the CoreSubSets of the vertices
    """
    core_subsets = CoreSubsets()
    for vertex in vertices:
        placement = placements.get_placement_of_vertex(vertex)
        core_subsets.add_processor(placement.x, placement.y, placement.p)
    return core_subsets
class ExecutableTargets(object):
    """ Encapsulate the binaries and cores on which to execute them.
    """
    __slots__ = [
        "_all_core_subsets",
        "_targets",
        "_total_processors"]

    def __init__(self):
        self._targets = dict()
        self._total_processors = 0
        self._all_core_subsets = CoreSubsets()

    def add_subsets(self, binary, subsets):
        """ Add core subsets to a binary

        :param binary: the path to the binary needed to be executed
        :param subsets: \
            the subset of cores that the binary needs to be loaded on
        :return:
        """
        for subset in subsets.core_subsets:
            for p in subset.processor_ids:
                self.add_processor(binary, subset.x, subset.y, p)

    def add_processor(self, binary, chip_x, chip_y, chip_p):
        """ Add a processor to the executable targets

        :param binary: the binary path for executable
        :param chip_x: the coordinate on the machine in terms of x for the chip
        :param chip_y: the coordinate on the machine in terms of y for the chip
        :param chip_p: the processor ID to place this executable on
        :return:
        """
        if self.known(binary, chip_x, chip_y, chip_p):
            return
        if binary not in self._targets:
            self._targets[binary] = CoreSubsets()
        self._targets[binary].add_processor(chip_x, chip_y, chip_p)
        self._all_core_subsets.add_processor(chip_x, chip_y, chip_p)
        self._total_processors += 1

    def get_cores_for_binary(self, binary):
        """ Get the cores that a binary is to run on

        :param binary: The binary to find the cores for
        """
        return self._targets.get(binary)

    @property
    def binaries(self):
        """ The binaries of the executables
        """
        return self._targets.keys()

    @property
    def total_processors(self):
        """ The total number of cores to be loaded
        """
        return self._total_processors

    @property
    def all_core_subsets(self):
        """ All the core subsets for all the binaries
        """
        return self._all_core_subsets

    def known(self, binary, chip_x, chip_y, chip_p):
        if self._all_core_subsets.is_core(chip_x, chip_y, chip_p):
            # OK if and only if the chip is in this binary already
            if binary in self._targets:
                if self._targets[binary].is_core(chip_x, chip_y, chip_p):
                    return True
            parameter = "x:{} y:{} p:{}".format(chip_x, chip_y, chip_p)
            problem = "Already associated with a different binary"
            raise SpinnmanInvalidParameterException(parameter, binary, problem)
        else:
            return False
 def __init__(self):
     self._targets = dict()
     self._total_processors = 0
     self._all_core_subsets = CoreSubsets()
class ExecutableTargets(object):
    """ Encapsulate the binaries and cores on which to execute them.
    """
    __slots__ = [
        "_all_core_subsets", "_targets", "_total_processors",
        "_binary_type_map"
    ]

    def __init__(self):
        self._targets = dict()
        self._total_processors = 0
        self._all_core_subsets = CoreSubsets()
        self._binary_type_map = defaultdict(OrderedSet)

    def add_subsets(self, binary, subsets, executable_type=None):
        """ Add core subsets to a binary

        :param str binary: the path to the binary needed to be executed
        :param ~spinn_machine.CoreSubsets subsets:
            the subset of cores that the binary needs to be loaded on
        :param ~spinn_front_end_common.utilities.utility_objs.ExecutableType \
                executable_type:
            The type of this executable.
            ``None`` means don't record it.
        """
        try:
            for subset in subsets.core_subsets:
                for p in subset.processor_ids:
                    self.add_processor(binary, subset.x, subset.y, p)
        except AttributeError:
            if subsets is not None:
                raise
        if executable_type is not None:
            self._binary_type_map[executable_type].add(binary)

    def add_processor(self,
                      binary,
                      chip_x,
                      chip_y,
                      chip_p,
                      executable_type=None):
        """ Add a processor to the executable targets

        :param str binary: the binary path for executable
        :param int chip_x:
            the coordinate on the machine in terms of x for the chip
        :param int chip_y:
            the coordinate on the machine in terms of y for the chip
        :param int chip_p: the processor ID to place this executable on
        :param ~spinn_front_end_common.utilities.utility_objs.ExecutableType \
                executable_type:
            the executable type for locating n cores of
        """
        if self.known(binary, chip_x, chip_y, chip_p):
            return
        if binary not in self._targets:
            self._targets[binary] = CoreSubsets()
        if executable_type is not None:
            self._binary_type_map[executable_type].add(binary)
        self._targets[binary].add_processor(chip_x, chip_y, chip_p)
        self._all_core_subsets.add_processor(chip_x, chip_y, chip_p)
        self._total_processors += 1

    def get_n_cores_for_executable_type(self, executable_type):
        """ get the number of cores that the executable type is using

        :param ~spinn_front_end_common.utilities.utility_objs.ExecutableType \
                executable_type:
            the executable type for locating n cores of
        :return: the number of cores using this executable type
        :rtype: int
        """
        return sum(
            len(self.get_cores_for_binary(aplx))
            for aplx in self._binary_type_map[executable_type])

    def get_binaries_of_executable_type(self, executable_type):
        """ get the binaries of a given a executable type

        :param ~spinn_front_end_common.utilities.utility_objs.ExecutableType \
                executable_type:
            the executable type enum value
        :return: iterable of binaries with that executable type
        :rtype: iterable(str)
        """
        return self._binary_type_map[executable_type]

    def executable_types_in_binary_set(self):
        """ get the executable types in the set of binaries

        :return: iterable of the executable types in this binary set.
        :rtype:
            iterable(~spinn_front_end_common.utilities.utility_objs.ExecutableType)
        """
        return self._binary_type_map.keys()

    def get_cores_for_binary(self, binary):
        """ Get the cores that a binary is to run on

        :param str binary: The binary to find the cores for
        """
        return self._targets.get(binary)

    @property
    def binaries(self):
        """ The binaries of the executables

        :rtype: iterable(str)
        """
        return self._targets.keys()

    @property
    def total_processors(self):
        """ The total number of cores to be loaded

        :rtype: int
        """
        return self._total_processors

    @property
    def all_core_subsets(self):
        """ All the core subsets for all the binaries

        :rtype: ~spinn_machine.CoreSubsets
        """
        return self._all_core_subsets

    def known(self, binary, chip_x, chip_y, chip_p):
        """
        :param str binary:
        :param int chip_x:
        :param int chip_y:
        :param int chip_p:
        :rtype: bool
        """
        if not self._all_core_subsets.is_core(chip_x, chip_y, chip_p):
            return False
        # OK if and only if the chip is in this binary already
        if binary in self._targets:
            if self._targets[binary].is_core(chip_x, chip_y, chip_p):
                return True

        parameter = "x:{} y:{} p:{}".format(chip_x, chip_y, chip_p)
        problem = "Already associated with a different binary"
        raise SpinnmanInvalidParameterException(parameter, binary, problem)
from spinnman.model.enums import (
    DiagnosticFilterDestination, DiagnosticFilterPacketType)
from spinnman.constants import ROUTER_REGISTER_REGISTERS
from board_test_configuration import BoardTestConfiguration

logging.basicConfig(level=logging.INFO)
logging.getLogger("spinnman.transceiver").setLevel(logging.DEBUG)

board_config = BoardTestConfiguration()
board_config.set_up_remote_board()

n_cores = 20
core_subsets = CoreSubsets(core_subsets=[CoreSubset(0, 0, range(1, 11)),
                                         CoreSubset(1, 1, range(1, 11))])

down_cores = CoreSubsets()
down_cores.add_processor(0, 0, 5)
down_chips = CoreSubsets(core_subsets=[CoreSubset(0, 1, [])])


def print_enums(name, enum_list):
    string = ""
    for enum_value in enum_list:
        string += enum_value.name + "; "
    print(name, string)


def print_word_as_binary(name, word, start=0, end=32, fields=None):
    start_fields = set()
    end_fields = set()
    if fields is not None:
Beispiel #9
0
    return os.path.join(path, "mock{}.aplx".format(id))


extractor = ChipIOBufExtractor()
executableFinder = ExecutableFinder([path])

transceiver = _PretendTransceiver([
    IOBuffer(0, 0, 1, text001),
    IOBuffer(0, 0, 2, text002),
    IOBuffer(1, 1, 1, text111),
    IOBuffer(1, 1, 2, text112),
    IOBuffer(0, 0, 3, text003)
])

executable_targets = ExecutableTargets()
core_subsets = CoreSubsets([CoreSubset(0, 0, [1, 2])])
fooaplx = mock_aplx("foo")
executable_targets.add_subsets(fooaplx, core_subsets)
core_subsets = CoreSubsets([CoreSubset(1, 1, [1, 2])])
baraplx = mock_aplx("bar")
executable_targets.add_subsets(baraplx, core_subsets)
core_subsets = CoreSubsets([CoreSubset(0, 0, [3])])
alphaaplx = mock_aplx("alpha")
executable_targets.add_subsets(alphaaplx, core_subsets)


class TestFrontEndCommonChipIOBufExtractor(unittest.TestCase):
    def testExectuableFinder(self):
        self.assertIn(fooaplx, executableFinder.get_executable_path(fooaplx))

    def testCallSimple(self):
def system_cores(exec_targets):
    cores = CoreSubsets()
    for binary in exec_targets.get_binaries_of_executable_type(
            ExecutableType.SYSTEM):
        cores.add_core_subsets(exec_targets.get_cores_for_binary(binary))
    return cores
Beispiel #11
0
    def _generate_core_subsets(
            self, routing_tables, executable_finder, machine, progress_bar,
            system_executable_targets):
        """ generates the core subsets for the binaries

        :param ~.MulticastRoutingTables routing_tables: the routing tables
        :param ~.ExecutableFinder executable_finder: the executable path finder
        :param ~.Machine machine: the spinn machine instance
        :param ~.ProgressBar progress_bar: progress bar
        :param ExecutableTargets system_executable_targets:
            the executables targets to cores
        :return: (targets, sorter path, and compressor path)
        :rtype: tuple(ExecutableTargets, str, str)
        """
        bit_field_sorter_cores = CoreSubsets()
        bit_field_compressor_cores = CoreSubsets()

        _, cores = LoadExecutableImages.filter_targets(
            system_executable_targets, lambda ty: ty is ExecutableType.SYSTEM)

        for routing_table in progress_bar.over(routing_tables, False):
            # add 1 core to the sorter, and the rest to compressors
            sorter = None
            for processor in machine.get_chip_at(
                    routing_table.x, routing_table.y).processors:
                if (not processor.is_monitor and
                        not cores.all_core_subsets.is_core(
                            routing_table.x, routing_table.y,
                            processor.processor_id)):
                    if sorter is None:
                        sorter = processor
                        bit_field_sorter_cores.add_processor(
                            routing_table.x, routing_table.y,
                            processor.processor_id)
                    else:
                        bit_field_compressor_cores.add_processor(
                            routing_table.x, routing_table.y,
                            processor.processor_id)

        # convert core subsets into executable targets
        executable_targets = ExecutableTargets()

        # bit field executable paths
        bit_field_sorter_executable_path = \
            executable_finder.get_executable_path(
                self._BIT_FIELD_SORTER_AND_SEARCH_EXECUTOR_APLX)

        bit_field_compressor_executable_path = \
            executable_finder.get_executable_path(self.compressor_aplx)

        # add the sets
        executable_targets.add_subsets(
            binary=bit_field_sorter_executable_path,
            subsets=bit_field_sorter_cores,
            executable_type=ExecutableType.SYSTEM)
        executable_targets.add_subsets(
            binary=bit_field_compressor_executable_path,
            subsets=bit_field_compressor_cores,
            executable_type=ExecutableType.SYSTEM)

        return (executable_targets, bit_field_sorter_executable_path,
                bit_field_compressor_executable_path)
 def test_add_core_subset_duplicate_core_subset(self):
     proc_list = [0, 1, 2, 3, 5, 8, 13]
     cs = CoreSubset(0, 0, proc_list)
     css = CoreSubsets([cs])
     css.add_core_subset(cs)
 def test_add_processor_duplicate_processor_different_chip(self):
     proc_list = [0, 1, 2, 3, 5, 8, 13]
     cs = CoreSubset(0, 0, proc_list)
     css = CoreSubsets([cs])
     css.add_processor(0, 1, 0)