def load_to_machine(self, netlist, controller):
        """Load data to the machine."""
        # Write each vertex region to memory
        for vx in six.itervalues(self.connection_vertices):
            sys_mem, key_mem = region_utils.create_app_ptr_and_region_files(
                netlist.vertices_memory[vx],
                [self._sys_regions[vx], self._key_regions[vx]], None)

            self._sys_regions[vx].write_region_to_file(sys_mem)
            self._key_regions[vx].write_subregion_to_file(key_mem,
                                                          cluster=vx.cluster)
Ejemplo n.º 2
0
    def load_to_machine(self, netlist, controller):
        """Load data to the machine."""
        # Write each vertex region to memory
        for vx in six.itervalues(self.connection_vertices):
            sys_mem, key_mem = region_utils.create_app_ptr_and_region_files(
                netlist.vertices_memory[vx],
                [self._sys_regions[vx], self._key_regions[vx]],
                None
            )

            self._sys_regions[vx].write_region_to_file(sys_mem)
            self._key_regions[vx].write_subregion_to_file(
                key_mem, cluster=vx.cluster)
    def load_to_machine(self, netlist, controller):
        """Load data to the machine."""
        # Get the memory
        sys_mem, filter_mem, routing_mem = \
            region_utils.create_app_ptr_and_region_files(
                netlist.vertices_memory[self._vertex],
                [self._sys_region,
                 self._filter_region,
                 self._routing_region],
                None
            )

        # Write the regions into memory
        self._sys_region.write_region_to_file(sys_mem)
        self._filter_region.write_subregion_to_file(filter_mem)
        self._routing_region.write_subregion_to_file(routing_mem)
Ejemplo n.º 4
0
    def load_to_machine(self, netlist, controller):
        """Load data to the machine."""
        # Get the memory
        sys_mem, filter_mem, routing_mem = \
            region_utils.create_app_ptr_and_region_files(
                netlist.vertices_memory[self._vertex],
                [self._sys_region,
                 self._filter_region,
                 self._routing_region],
                None
            )

        # Write the regions into memory
        self._sys_region.write_region_to_file(sys_mem)
        self._filter_region.write_subregion_to_file(filter_mem)
        self._routing_region.write_subregion_to_file(routing_mem)
Ejemplo n.º 5
0
def test_create_app_ptr_and_filelikes(vertex_slice):
    """Test creation of an application pointer table and a series of smaller
    file-like objects which can be used with existing region objects.
    """
    # Create a file-like object which can be the initial file that we pass in,
    # and wrap it so that creating slices of it creates objects that we can
    # interpret.
    actual_fp = tempfile.TemporaryFile()

    class Subfilelike(object):
        def __init__(self, sl):
            self.slice = sl

        def __repr__(self):
            return "Subfilelike({!r})".format(self.slice)

        def __eq__(self, other):
            return self.slice == other.slice

    def _getitem_(self, sl):
        return Subfilelike(sl)

    fp = mock.Mock(wraps=actual_fp)
    fp.__getitem__ = _getitem_

    # Now create a series of regions with different sizes.
    class MyRegion(Region):
        def __init__(self, size):
            self.size = size
            self.called = False

        def sizeof(self, sl):
            assert sl == vertex_slice
            self.called = True
            return self.size

    # Create all the regions
    regions = [
        MyRegion(4),  # 1 word
        MyRegion(3),  # < 1 word
        MyRegion(5),  # < 2 words
        MyRegion(100),  # 25 words
        None,  # No region
        None,
        MyRegion(32),  # 8 words
    ]

    # Now create the application pointer table and all the sub-filelikes
    fps = utils.create_app_ptr_and_region_files(fp, regions, vertex_slice)
    assert all(r.called for r in regions if r is not None)

    expected_slices = [
        slice(32, 36),  # 8 words for the pointer table : +1 word
        slice(36, 40),  # : +1 word
        slice(40, 48),  # : +2 words
        slice(48, 148),  # : +25 words
        None,
        None,
        slice(148, 180),  # : +8 words
    ]
    expected_filelikes = [None if sl is None else Subfilelike(sl) for sl in
                          expected_slices]
    assert expected_filelikes == fps

    # Assert that the data written into the application pointer table is
    # correct.
    actual_fp.seek(0)
    assert actual_fp.read() == struct.pack(
        "<8I",
        0, *[0 if s is None else s.slice.start for s in expected_filelikes]
    )