Exemple #1
0
def test_sizeof_regions(vertex_slice, include_app_ptr):
    """Test getting the total memory usage of some regions."""
    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
        MyRegion(32),  # 8 words
    ]

    # Now query their size
    assert (utils.sizeof_regions(regions, vertex_slice, include_app_ptr) ==
            37*4 + (len(regions)*4 + 4 if include_app_ptr else 0))
    assert all(r.called for r in regions if r is not None)
    def make_vertices(self, model, *args, **kwargs):
        """Create vertices that will simulate the SDPTransmitter."""
        # Build the system region
        self._sys_region = SystemRegion(model.machine_timestep, self.size_in,
                                        1)

        # Build the filter regions
        in_sigs = model.get_signals_to_object(self)[InputPort.standard]
        self._filter_region, self._routing_region = make_filter_regions(
            in_sigs, model.dt, True, model.keyspaces.filter_routing_tag)

        # Get the resources
        resources = {
            Cores:
            1,
            SDRAM:
            region_utils.sizeof_regions(
                [self._sys_region, self._filter_region, self._routing_region],
                None)
        }

        # Create the vertex
        self._vertex = Vertex(self._label, get_application("tx"), resources)

        # Return the netlist specification
        return netlistspec(
            (self._vertex, ),  # Tuple is required
            load_function=self.load_to_machine)
    def make_vertices(self, model, *args, **kwargs):
        """Create vertices that will simulate the SDPTransmitter."""
        # Build the system region
        self._sys_region = SystemRegion(model.machine_timestep,
                                        self.size_in, 1)

        # Build the filter regions
        in_sigs = model.get_signals_connections_to_object(self)
        self._filter_region, self._routing_region = make_filter_regions(
            in_sigs[InputPort.standard], model.dt, True,
            model.keyspaces.filter_routing_tag
        )

        # Get the resources
        resources = {
            Cores: 1,
            SDRAM: region_utils.sizeof_regions(
                [self._sys_region, self._filter_region, self._routing_region],
                None
            )
        }

        # Create the vertex
        self._vertex = Vertex(get_application("tx"), resources)

        # Return the netlist specification
        return netlistspec(self._vertex,
                           load_function=self.load_to_machine)
    def make_vertices(self, model, *args, **kwargs):
        """Create vertices that will simulate the SDPReceiver."""
        # NOTE This approach will result in more routes being created than are
        # actually necessary; the way to avoid this is to modify how the
        # builder deals with signals when creating netlists.

        # Get all outgoing signals and their associated connections (this
        # SHOULD be a 1:1 mapping)
        out = model.get_signals_connections_from_object(self)
        for signal, connections in six.iteritems(out[OutputPort.standard]):
            assert len(connections) == 1, "Expecting a 1:1 mapping"
            conn = connections[0]

            # Get the transform, and from this the keys
            transform = model.params[conn].transform
            keys = [signal.keyspace(index=i) for i in
                    range(transform.shape[0])]

            # Create a vertex for this connection (assuming its size out <= 64)
            if len(keys) > 64:
                raise NotImplementedError(
                    "Connection {!s} is too wide to transmit to SpiNNaker. "
                    "Consider breaking the connection up or making the "
                    "originating node a function of time Node.".format(conn)
                )

            # Create the regions for the system
            sys_region = SystemRegion(model.machine_timestep, len(keys))
            keys_region = KeyspacesRegion(keys,
                                          [KeyField({"cluster": "cluster"})])

            # Get the resources
            resources = {
                Cores: 1,
                SDRAM: region_utils.sizeof_regions([sys_region, keys_region],
                                                   None)
            }

            # Create the vertex
            v = self.connection_vertices[conn] = Vertex(get_application("rx"),
                                                        resources)
            self._sys_regions[v] = sys_region
            self._key_regions[v] = keys_region

        # Return the netlist specification
        return netlistspec(list(self.connection_vertices.values()),
                           load_function=self.load_to_machine)
Exemple #5
0
    def make_vertices(self, model, *args, **kwargs):
        """Create vertices that will simulate the SDPReceiver."""
        # NOTE This approach will result in more routes being created than are
        # actually necessary; the way to avoid this is to modify how the
        # builder deals with signals when creating netlists.

        # Get all outgoing signals and their associated transmission parameters
        for signal, transmission_params in \
                model.get_signals_from_object(self)[OutputPort.standard]:
            # Get the transform, and from this the keys
            transform = transmission_params.full_transform(slice_out=False)
            keys = [(signal, {"index": i}) for i in
                    range(transform.shape[0])]

            # Create a vertex for this connection (assuming its size out <= 64)
            if len(keys) > 64:
                raise NotImplementedError(
                    "Connection is too wide to transmit to SpiNNaker. "
                    "Consider breaking the connection up or making the "
                    "originating node a function of time Node."
                )

            # Create the regions for the system
            sys_region = SystemRegion(model.machine_timestep, len(keys))
            keys_region = KeyspacesRegion(keys,
                                          [KeyField({"cluster": "cluster"})])

            # Get the resources
            resources = {
                Cores: 1,
                SDRAM: region_utils.sizeof_regions([sys_region, keys_region],
                                                   None)
            }

            # Create the vertex
            v = self.connection_vertices[transmission_params] = \
                Vertex(self._label, get_application("rx"), resources)
            self._sys_regions[v] = sys_region
            self._key_regions[v] = keys_region

        # Return the netlist specification
        return netlistspec(list(self.connection_vertices.values()),
                           load_function=self.load_to_machine)