• 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

44.44
/spinnman/model/chip_summary_info.py
1
# Copyright (c) 2016 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 List, Optional
1✔
17
from spinnman.model.enums import CPUState
1✔
18
from spinn_machine.machine import Machine
1✔
19

20
_THREE_WORDS = struct.Struct("<3I")
1✔
21
_TWO_BYTES = struct.Struct("<BB")
1✔
22
_FOUR_BYTES = struct.Struct("<4B")
1✔
23
_EIGHTEEN_BYTES = struct.Struct("<18B")
1✔
24
_ONE_SHORT = struct.Struct("<H")
1✔
25

26

27
class ChipSummaryInfo(object):
1✔
28
    """
29
    Represents the chip summary information read via an SCP command.
30
    """
31
    __slots__ = [
1✔
32
        "_core_states",
33
        "_ethernet_ip_address",
34
        "_is_ethernet_available",
35
        "_largest_free_sdram_block",
36
        "_largest_free_sram_block",
37
        "_n_cores",
38
        "_n_free_multicast_routing_entries",
39
        "_nearest_ethernet_x",
40
        "_nearest_ethernet_y",
41
        "_parent_link",
42
        "_working_links",
43
        "_x", "_y"]
44

45
    def __init__(self, chip_summary_data: bytes, offset: int, x: int, y: int):
1✔
46
        """
47
        :param bytes chip_summary_data: The data from the SCP response
48
        :param int offset: The offset into the data where the data starts
49
        :param int x: The x-coordinate of the chip that this data is from
50
        :param int y: The y-coordinate of the chip that this data is from
51
        """
52
        (chip_summary_flags, self._largest_free_sdram_block,
×
53
            self._largest_free_sram_block) = _THREE_WORDS.unpack_from(
54
                chip_summary_data, offset)
55
        self._n_cores = chip_summary_flags & 0x1F
×
56
        self._working_links = [
×
57
            link for link in range(0, 6)
58
            if chip_summary_flags >> (8 + link) & 1 != 0]
59
        self._n_free_multicast_routing_entries = \
×
60
            (chip_summary_flags >> 14) & 0x7FF
61
        self._is_ethernet_available = bool(chip_summary_flags & (1 << 25))
×
62

63
        data_offset = offset + 12
×
64
        self._core_states = [
×
65
            CPUState(state) for state in
66
            _EIGHTEEN_BYTES.unpack_from(chip_summary_data, data_offset)]
67
        data_offset += 18
×
68

69
        self._x = x
×
70
        self._y = y
×
71

72
        self._nearest_ethernet_x, self._nearest_ethernet_y = 0, 0
×
73
        self._ethernet_ip_address: Optional[str] = None
×
74

75
        (self._nearest_ethernet_y, self._nearest_ethernet_x) = \
×
76
            _TWO_BYTES.unpack_from(chip_summary_data, data_offset)
77
        data_offset += 2
×
78

79
        ip = _FOUR_BYTES.unpack_from(chip_summary_data, data_offset)
×
80
        ethernet_ip_address = f"{ip[0]}.{ip[1]}.{ip[2]}.{ip[3]}"
×
81
        if ethernet_ip_address != "0.0.0.0":
×
82
            self._ethernet_ip_address = ethernet_ip_address
×
83
        data_offset += 4
×
84

85
        # In case the data hasn't been added in the version of SCAMP being used
86
        self._parent_link: Optional[int] = None
×
87
        if len(chip_summary_data) > data_offset:
×
88
            (self._parent_link, ) = _ONE_SHORT.unpack_from(
×
89
                chip_summary_data, data_offset)
90
            # The root chip will use the P2P "self", which is outside the range
91
            # of valid links, so check and skip this one
92
            if self._parent_link > len(Machine.LINK_ADD_TABLE):
×
93
                self._parent_link = None
×
94
            data_offset += 2
×
95

96
    @property
1✔
97
    def x(self) -> int:
1✔
98
        """
99
        The X-coordinate of the chip that this data is from.
100

101
        :rtype: int
102
        """
103
        return self._x
×
104

105
    @property
1✔
106
    def y(self) -> int:
1✔
107
        """
108
        The Y-coordinate of the chip that this data is from.
109

110
        :rtype: int
111
        """
112
        return self._y
×
113

114
    @property
1✔
115
    def n_cores(self) -> int:
1✔
116
        """
117
        The number of cores working on the chip (including monitors).
118

119
        :rtype: int
120
        """
121
        return self._n_cores
×
122

123
    @property
1✔
124
    def core_states(self) -> List[CPUState]:
1✔
125
        """
126
        The state of the cores on the chip (list of one per core).
127

128
        :rtype: list(CPUState)
129
        """
130
        return self._core_states
×
131

132
    @property
1✔
133
    def working_links(self) -> List[int]:
1✔
134
        """
135
        The IDs of the working links outgoing from this chip.
136

137
        :rtype: list(int)
138
        """
139
        return self._working_links
×
140

141
    @property
1✔
142
    def is_ethernet_available(self) -> bool:
1✔
143
        """
144
        Whether the Ethernet connection is available on this chip.
145

146
        :rtype: bool
147
        """
148
        return self._is_ethernet_available
×
149

150
    @property
1✔
151
    def n_free_multicast_routing_entries(self) -> int:
1✔
152
        """
153
        The number of multicast routing entries free on this chip.
154

155
        :rtype: int
156
        """
157
        return self._n_free_multicast_routing_entries
×
158

159
    @property
1✔
160
    def largest_free_sdram_block(self) -> int:
1✔
161
        """
162
        The size of the largest block of free SDRAM in bytes.
163

164
        :rtype: int
165
        """
166
        return self._largest_free_sdram_block
×
167

168
    @property
1✔
169
    def largest_free_sram_block(self) -> int:
1✔
170
        """
171
        The size of the largest block of free SRAM in bytes.
172

173
        :rtype: int
174
        """
175
        return self._largest_free_sram_block
×
176

177
    @property
1✔
178
    def nearest_ethernet_x(self) -> int:
1✔
179
        """
180
        The X-coordinate of the nearest Ethernet chip.
181

182
        :rtype: int
183
        """
184
        return self._nearest_ethernet_x
×
185

186
    @property
1✔
187
    def nearest_ethernet_y(self) -> int:
1✔
188
        """
189
        The Y-coordinate of the nearest Ethernet chip.
190

191
        :rtype: int
192
        """
193
        return self._nearest_ethernet_y
×
194

195
    @property
1✔
196
    def ethernet_ip_address(self) -> Optional[str]:
1✔
197
        """
198
        The IP address of the Ethernet if up, or `None` if not.
199

200
        :rtype: str
201
        """
202
        return self._ethernet_ip_address
×
203

204
    def clear_ethernet_ip_address(self) -> None:
1✔
205
        """
206
        Forces the Ethernet IP address to `None`, in case of an errant chip.
207
        """
208
        self._ethernet_ip_address = None
×
209

210
    @property
1✔
211
    def parent_link(self) -> Optional[int]:
1✔
212
        """
213
        The link to the parent of the chip in the tree of chips from root.
214

215
        :rtype: int
216
        """
217
        return self._parent_link
×
218

219
    def __repr__(self) -> str:
1✔
220
        return f"x:{self.x} y:{self.y} n_cores:{self.n_cores}"
×
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