• 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

43.75
/spinnman/model/chip_info.py
1
# Copyright (c) 2014 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 Iterable, List, Optional
1✔
17
from spinnman.messages.spinnaker_boot import SystemVariableDefinition
1✔
18

19

20
class ChipInfo(object):
1✔
21
    """
22
    Represents the system variables for a chip, received from the chip SDRAM.
23
    """
24
    __slots__ = [
1✔
25
        "_ip_address",
26
        "_led_flash_period_ms",
27
        "_leds",
28
        "_links_available",
29
        "_offset",
30
        "_physical_to_virtual_core_map",
31
        "_status_map",
32
        "_system_data",
33
        "_virtual_core_ids",
34
        "_virtual_to_physical_core_map"]
35

36
    def __init__(self, system_data: bytes, offset: int):
1✔
37
        """
38
        :param bytes system_data:
39
            A byte-string retrieved from SDRAM on the board
40
        :param int offset:
41
            The offset into the byte-string where the actual data starts
42
        :raise SpinnmanInvalidParameterException:
43
            If the data doesn't contain valid system data information
44
        """
45
        self._system_data = system_data
×
46
        self._offset = offset
×
47

48
        links_available = self._read_int("links_available")
×
49
        self._links_available: List[int] = list()
×
50
        for i in range(6):
×
51
            if ((links_available >> i) & 0x1) != 0:
×
52
                self._links_available.append(i)
×
53

54
        self._led_flash_period_ms = self._read_int(
×
55
            "led_half_period_10_ms") * 10
56
        self._leds = [self._read_int("led_0"), self._read_int("led_1")]
×
57
        self._status_map = self._read_bytes("status_map")
×
58
        self._physical_to_virtual_core_map = self._read_bytes(
×
59
            "physical_to_virtual_core_map")
60
        self._virtual_to_physical_core_map = self._read_bytes(
×
61
            "virtual_to_physical_core_map")
62

63
        self._virtual_core_ids: List[int] = list()
×
64
        for physical_core_id in range(
×
65
                0, len(self._physical_to_virtual_core_map)):
66
            virtual_core_id = self._physical_to_virtual_core_map[
×
67
                physical_core_id]
68
            if virtual_core_id != 0xFF:
×
69
                self._virtual_core_ids.append(virtual_core_id)
×
70
        self._virtual_core_ids.sort()
×
71

72
        ip = self._read_bytes("ethernet_ip_address")
×
73
        self._ip_address: Optional[str] = f"{ip[0]}.{ip[1]}.{ip[2]}.{ip[3]}"
×
74
        if self._ip_address == "0.0.0.0":
×
75
            self._ip_address = None
×
76

77
    def _read_int(self, item: str) -> int:
1✔
78
        item_def = SystemVariableDefinition[item]
×
79
        code = item_def.data_type.struct_code
×
80
        assert item_def.array_size is None
×
81
        value, = struct.unpack_from(
×
82
            code, self._system_data, self._offset + item_def.offset)
83
        return value
×
84

85
    def _read_bytes(self, item: str) -> bytes:
1✔
86
        item_def = SystemVariableDefinition[item]
×
87
        assert item_def.array_size is not None
×
88
        code = f"{item_def.array_size}{item_def.data_type.struct_code}"
×
89
        value, = struct.unpack_from(
×
90
            code, self._system_data, self._offset + item_def.offset)
91
        return value
×
92

93
    @property
1✔
94
    def x(self) -> int:
1✔
95
        """
96
        The X-coordinate of the chip.
97

98
        :rtype: int
99
        """
100
        return self._read_int("x")
×
101

102
    @property
1✔
103
    def y(self) -> int:
1✔
104
        """
105
        The Y-coordinate of the chip.
106

107
        :rtype: int
108
        """
109
        return self._read_int("y")
×
110

111
    @property
1✔
112
    def x_size(self) -> int:
1✔
113
        """
114
        The number of chips in the X-dimension.
115

116
        :rtype: int
117
        """
118
        return self._read_int("x_size")
×
119

120
    @property
1✔
121
    def y_size(self) -> int:
1✔
122
        """
123
        The number of chips in the Y-dimension.
124

125
        :rtype: int
126
        """
127
        return self._read_int("y_size")
×
128

129
    @property
1✔
130
    def nearest_ethernet_x(self) -> int:
1✔
131
        """
132
        The X-coordinate of the nearest chip with Ethernet.
133

134
        :rtype: int
135
        """
136
        return self._read_int("nearest_ethernet_x")
×
137

138
    @property
1✔
139
    def nearest_ethernet_y(self) -> int:
1✔
140
        """
141
        The Y-coordinate of the nearest chip with Ethernet.
142

143
        :rtype: int
144
        """
145
        return self._read_int("nearest_ethernet_y")
×
146

147
    @property
1✔
148
    def is_ethernet_available(self) -> bool:
1✔
149
        """
150
        Whether the Ethernet is running on this chip.
151

152
        :rtype: bool
153
        """
154
        return self._read_int("is_ethernet_available") == 1
×
155

156
    @property
1✔
157
    def links_available(self) -> Iterable[int]:
1✔
158
        """
159
        The links that are available on the chip.
160

161
        :rtype: iterable(int)
162
        """
163
        return self._links_available
×
164

165
    @property
1✔
166
    def cpu_clock_mhz(self) -> int:
1✔
167
        """
168
        The speed of the CPU clock in MHz.
169

170
        :rtype: int
171
        """
172
        return self._read_int("cpu_clock_mhz")
×
173

174
    @property
1✔
175
    def physical_to_virtual_core_map(self) -> bytes:
1✔
176
        """
177
        The physical core ID to virtual core ID map; entries with a value
178
        of 0xFF are non-operational cores.
179

180
        :rtype: bytearray
181
        """
182
        return self._physical_to_virtual_core_map
×
183

184
    @property
1✔
185
    def virtual_to_physical_core_map(self) -> bytes:
1✔
186
        """
187
        The virtual core ID to physical core ID map; entries with a value
188
        of 0xFF are non-operational cores.
189

190
        :rtype: bytearray
191
        """
192
        return self._virtual_to_physical_core_map
×
193

194
    @property
1✔
195
    def virtual_core_ids(self) -> Iterable[int]:
1✔
196
        """
197
        A list of available cores by virtual core ID (including the monitor).
198

199
        :rtype: iterable(int)
200
        """
201
        return self._virtual_core_ids
×
202

203
    @property
1✔
204
    def sdram_base_address(self) -> int:
1✔
205
        """
206
        The base address of the user region of SDRAM on the chip.
207

208
        :rtype: int
209
        """
210
        return self._read_int("sdram_base_address")
×
211

212
    @property
1✔
213
    def system_sdram_base_address(self) -> int:
1✔
214
        """
215
        The base address of the System SDRAM region on the chip.
216

217
        :rtype: int
218
        """
219
        return self._read_int("system_sdram_base_address")
×
220

221
    @property
1✔
222
    def cpu_information_base_address(self) -> int:
1✔
223
        """
224
        The base address of the CPU information structure.
225

226
        :rtype: int
227
        """
228
        return self._read_int("cpu_information_base_address")
×
229

230
    @property
1✔
231
    def first_free_router_entry(self) -> int:
1✔
232
        """
233
        The ID of the first free routing entry on the chip.
234

235
        :rtype: int
236
        """
237
        return self._read_int("first_free_router_entry")
×
238

239
    @property
1✔
240
    def ip_address(self) -> Optional[str]:
1✔
241
        """
242
        The IP address of the chip, or `None` if no Ethernet.
243

244
        :rtype: str
245
        """
246
        return self._ip_address
×
247

248
    @property
1✔
249
    def iobuf_size(self) -> int:
1✔
250
        """
251
        The size of the IOBUF buffers in bytes.
252

253
        :rtype: int
254
        """
255
        return self._read_int("iobuf_size")
×
256

257
    def router_table_copy_address(self) -> int:
1✔
258
        """
259
        The address of the copy of the router table.
260

261
        :rtype: int
262
        """
263
        return self._read_int("router_table_copy_address")
×
264

265
    @property
1✔
266
    def system_ram_heap_address(self) -> int:
1✔
267
        """
268
        The address of the base of the heap in system RAM.
269

270
        :rtype: int
271
        """
272
        return self._read_int("system_ram_heap_address")
×
273

274
    @property
1✔
275
    def sdram_heap_address(self) -> int:
1✔
276
        """
277
        The address of the base of the heap in SDRAM.
278

279
        :rtype: int
280
        """
281
        return self._read_int("sdram_heap_address")
×
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