Пример #1
0
class GraphBinaryGatherer(object):
    """ Extracts binaries to be executed.
    """

    __slots__ = ["_exe_finder", "_exe_targets"]

    def __init__(self):
        self._exe_finder = None
        self._exe_targets = None

    def __call__(self,
                 placements,
                 graph,
                 executable_finder,
                 graph_mapper=None):
        self._exe_finder = executable_finder
        self._exe_targets = ExecutableTargets()
        progress = ProgressBar(graph.n_vertices, "Finding binaries")
        for vertex in progress.over(graph.vertices):
            placement = placements.get_placement_of_vertex(vertex)
            self.__get_binary(placement, vertex)
            if graph_mapper is not None:
                self.__get_binary(placement,
                                  graph_mapper.get_application_vertex(vertex))

        return self._exe_targets

    def __get_binary(self, placement, vertex):
        # If we've got junk input (shouldn't happen), ignore it
        if vertex is None:
            return
        # if the vertex cannot generate a DSG, ignore it
        if not isinstance(vertex, AbstractHasAssociatedBinary):
            return

        # Get name of binary from vertex
        binary_name = vertex.get_binary_file_name()
        exec_type = vertex.get_binary_start_type()

        # Attempt to find this within search paths
        binary_path = self._exe_finder.get_executable_path(binary_name)
        if binary_path is None:
            raise ExecutableNotFoundException(binary_name)

        self._exe_targets.add_processor(binary_path, placement.x, placement.y,
                                        placement.p, exec_type)
 def test_front_end_common_load_executable_images(self):
     transceiver = _MockTransceiver(self)
     loader = LoadExecutableImages()
     targets = ExecutableTargets()
     targets.add_processor("test.aplx", 0, 0, 0, SIM)
     targets.add_processor("test.aplx", 0, 0, 1, SIM)
     targets.add_processor("test.aplx", 0, 0, 2, SIM)
     targets.add_processor("test2.aplx", 0, 1, 0, SIM)
     targets.add_processor("test2.aplx", 0, 1, 1, SIM)
     targets.add_processor("test2.aplx", 0, 1, 2, SIM)
     loader.load_app_images(targets, 30, transceiver)
Пример #3
0
def emergency_recover_state_from_failure(txrx, app_id, vertex, placement):
    """ Used to get at least *some* information out of a core when something\
    goes badly wrong. Not a replacement for what abstract spinnaker base does.

    :param txrx: The transceiver.
    :param app_id: The ID of the application.
    :param vertex: The vertex to retrieve the IOBUF from if it is suspected\
        as being dead
    :type vertex: \
        :py:class:`spinn_front_end_common.abstract_models.AbstractHasAssociatedBinary`
    :param placement: Where the vertex is located.
    """
    # pylint: disable=protected-access
    _emergency_state_check(txrx, app_id)
    target = ExecutableTargets()
    path = get_simulator()._executable_finder.get_executable_path(
        vertex.get_binary_file_name())
    target.add_processor(path, placement.x, placement.y, placement.p,
                         vertex.get_binary_start_type())
    _emergency_iobuf_extract(txrx, target)
    def test_call(self):
        executor = HostExecuteDataSpecification()
        transceiver = _MockTransceiver(user_0_addresses={0: 1000})
        machine = virtual_machine(2, 2)
        tempdir = tempfile.mkdtemp()

        dsg_targets = DataSpecificationTargets(machine, tempdir)
        with dsg_targets.create_data_spec(0, 0, 0) as spec_writer:
            spec = DataSpecificationGenerator(spec_writer)
            spec.reserve_memory_region(0, 100)
            spec.reserve_memory_region(1, 100, empty=True)
            spec.reserve_memory_region(2, 100)
            spec.switch_write_focus(0)
            spec.write_value(0)
            spec.write_value(1)
            spec.write_value(2)
            spec.switch_write_focus(2)
            spec.write_value(3)
            spec.end_specification()

        # Execute the spec
        targets = ExecutableTargets()
        targets.add_processor("text.aplx", 0, 0, 0,
                              ExecutableType.USES_SIMULATION_INTERFACE)
        infos = executor.execute_application_data_specs(
            transceiver, machine, 30, dsg_targets, False, targets,
            report_folder=tempdir)

        # Test regions - although 3 are created, only 2 should be uploaded
        # (0 and 2), and only the data written should be uploaded
        # The space between regions should be as allocated regardless of
        # how much data is written
        header_and_table_size = (MAX_MEM_REGIONS + 2) * 4
        regions = transceiver.regions_written
        self.assertEqual(len(regions), 4)

        # Base address for header and table
        self.assertEqual(regions[0][0], 0)

        # Base address for region 0 (after header and table)
        self.assertEqual(regions[1][0], header_and_table_size)

        # Base address for region 2
        self.assertEqual(regions[2][0], header_and_table_size + 200)

        # User 0 write address
        self.assertEqual(regions[3][0], 1000)

        # Size of header and table
        self.assertEqual(len(regions[0][1]), header_and_table_size)

        # Size of region 0
        self.assertEqual(len(regions[1][1]), 12)

        # Size of region 2
        self.assertEqual(len(regions[2][1]), 4)

        # Size of user 0
        self.assertEqual(len(regions[3][1]), 4)

        info = infos[(0, 0, 0)]
        self.assertEqual(info.memory_used, 372)
        self.assertEqual(info.memory_written, 88)