• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / SpiNNMan / 6574804013

19 Oct 2023 12:47PM UTC coverage: 51.937% (+1.2%) from 50.777%
6574804013

Pull #327

github

Christian-B
typing changes
Pull Request #327: Type Annotations and Checking

105 of 1288 branches covered (0.0%)

Branch coverage included in aggregate %.

2375 of 2375 new or added lines in 180 files covered. (100.0%)

4775 of 8108 relevant lines covered (58.89%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.0
/spinnman/processes/load_routes_process.py
1
# Copyright (c) 2015 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
import struct
1✔
16
from typing import Collection
1✔
17
from spinn_machine import Router
1✔
18
from spinnman.exceptions import SpinnmanInvalidParameterException
1✔
19
from spinnman.messages.scp.impl import RouterInit, RouterAlloc
1✔
20
from .abstract_multi_connection_process import AbstractMultiConnectionProcess
1✔
21
from spinn_machine.multicast_routing_entry import MulticastRoutingEntry
1✔
22
from spinnman.messages.scp.impl.router_alloc import RouterAllocResponse
1✔
23
from .write_memory_process import WriteMemoryProcess
1✔
24
from .abstract_multi_connection_process_connection_selector import (
1✔
25
    ConnectionSelector)
26

27
_ROUTE_PATTERN = struct.Struct("<H2xIII")
1✔
28
_END_PATTERN = struct.Struct("<IIII")
1✔
29
_TABLE_ADDRESS = 0x67800000
1✔
30

31

32
class LoadMultiCastRoutesProcess(AbstractMultiConnectionProcess):
1✔
33
    """
34
    A process for loading the multicast routing table on a SpiNNaker chip.
35
    """
36
    __slots__ = ("_base_address", )
1✔
37

38
    def __init__(self, connection_selector: ConnectionSelector):
1✔
39
        """
40
        :param ConnectionSelector connection_selector:
41
        """
42
        super().__init__(connection_selector)
×
43
        self._base_address = 0
×
44

45
    def __handle_router_alloc_response(self, response: RouterAllocResponse):
1✔
46
        self._base_address = response.base_address
×
47

48
    def load_routes(
1✔
49
            self, x: int, y: int, routes: Collection[MulticastRoutingEntry],
50
            app_id: int):
51
        """
52
        :param int x:
53
        :param int y:
54
        :param list(~spinn_machine.MulticastRoutingEntry) routes:
55
        :param int app_id:
56
        """
57
        # Create the routing data - 16 bytes per entry plus one for the end
58
        # entry
59
        routing_data = bytearray(16 * (len(routes) + 1))
×
60
        n_entries = 0
×
61
        for route in routes:
×
62
            route_entry = \
×
63
                Router.convert_routing_table_entry_to_spinnaker_route(route)
64

65
            _ROUTE_PATTERN.pack_into(
×
66
                routing_data, n_entries * 16, n_entries,
67
                route_entry, route.routing_entry_key, route.mask)
68
            n_entries += 1
×
69

70
        # Add an entry to mark the end
71
        _END_PATTERN.pack_into(
×
72
            routing_data, n_entries * 16,
73
            0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)
74

75
        # Upload the data
76
        process = WriteMemoryProcess(self._conn_selector)
×
77
        process.write_memory_from_bytearray(
×
78
            (x, y, 0), _TABLE_ADDRESS, routing_data, 0, len(routing_data))
79

80
        # Allocate space in the router table
81
        with self._collect_responses():
×
82
            self._send_request(RouterAlloc(x, y, app_id, n_entries),
×
83
                               self.__handle_router_alloc_response)
84
        if self._base_address == 0:
×
85
            raise SpinnmanInvalidParameterException(
×
86
                "Allocation base address", str(self._base_address),
87
                "Not enough space to allocate the entries")
88

89
        # Load the entries
90
        with self._collect_responses():
×
91
            self._send_request(RouterInit(
×
92
                x, y, n_entries, _TABLE_ADDRESS, self._base_address, app_id))
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc