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

SpiNNakerManchester / PACMAN / 6945509033

21 Nov 2023 02:51PM UTC coverage: 84.047% (+0.9%) from 83.103%
6945509033

push

github

Christian-B
remove unused import

1552 of 2025 branches covered (0.0%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

534 existing lines in 55 files now uncovered.

5065 of 5848 relevant lines covered (86.61%)

0.87 hits per line

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

45.59
/pacman/utilities/algorithm_utilities/partition_algorithm_utilities.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
"""
1✔
15
A collection of methods which support partitioning algorithms.
16
"""
17

18
import math
1✔
19
from typing import List
1✔
20
from pacman.exceptions import PacmanConfigurationException
1✔
21
from pacman.model.graphs.common import MDSlice, Slice
1✔
22
from pacman.model.graphs.application import ApplicationVertex
1✔
23

24

25
def get_multidimensional_slices(
1✔
26
        app_vertex: ApplicationVertex) -> List[Slice]:
27
    """
28
    Get the multi-dimensional slices of an application vertex
29
    such that each is sized to the maximum atoms per dimension per core
30
    except the last, which might be smaller in one or more dimensions.
31

32
    :param ApplicationVertex app_vertex: The vertex to get the slices of
33
    :return: The slices
34
    :rtype: list(~pacman.model.graphs.common.Slice)
35
    """
36
    atoms_per_core = app_vertex.get_max_atoms_per_dimension_per_core()
1✔
37
    n_atoms = app_vertex.atoms_shape
1✔
38
    if len(atoms_per_core) != len(n_atoms):
1!
UNCOV
39
        raise PacmanConfigurationException(
×
40
            "The length of atoms_per_core doesn't match the number of"
41
            " dimensions")
42

43
    if len(app_vertex.atoms_shape) == 1:
1!
44
        return get_single_dimension_slices(app_vertex)
1✔
45

46
    # Find out how many vertices we will create, keeping track of the
47
    # total atoms per core, and the numerator to divide by when working
48
    # out positions
49
    n_vertices = 1
×
50
    total_atoms_per_core = 1
×
51
    dim_numerator = [0] * len(n_atoms)
×
52
    total_n_atoms = 1
×
53
    for d in range(len(n_atoms)):
×
54
        dim_numerator[d] = n_vertices
×
55
        n_this_dim = int(math.ceil(n_atoms[d] / atoms_per_core[d]))
×
UNCOV
56
        n_vertices *= n_this_dim
×
UNCOV
57
        total_atoms_per_core *= atoms_per_core[d]
×
58
        total_n_atoms *= n_atoms[d]
×
59

60
    # Run over all the vertices and create slices for them
UNCOV
61
    slices: List[Slice] = list()
×
UNCOV
62
    hi_atom = -1
×
UNCOV
63
    for v in range(n_vertices):
×
64
        # Work out where in each of the dimensions this vertex starts by
65
        # dividing the remainder from the previous dimension by the
66
        # numerator of each dimension
67
        start = [0] * len(n_atoms)
×
68
        n_on_core = [0] * len(n_atoms)
×
69
        remainder = v
×
70
        total_on_core = 1
×
71
        for d in reversed(range(len(n_atoms))):
×
72
            start[d] = (remainder // dim_numerator[d]) * atoms_per_core[d]
×
73
            remainder = remainder % dim_numerator[d]
×
UNCOV
74
            hi_d = min(start[d] + atoms_per_core[d], n_atoms[d])
×
UNCOV
75
            n_on_core[d] = hi_d - start[d]
×
76
            total_on_core *= n_on_core[d]
×
77

78
        # Make a slice and a vertex
UNCOV
79
        lo_atom = hi_atom + 1
×
UNCOV
80
        hi_atom = (lo_atom + total_on_core) - 1
×
81
        vertex_slice = MDSlice(
×
82
            lo_atom, hi_atom, tuple(n_on_core), tuple(start),
83
            app_vertex.atoms_shape)
UNCOV
84
        slices.append(vertex_slice)
×
85

UNCOV
86
    return slices
×
87

88

89
def get_single_dimension_slices(app_vertex: ApplicationVertex) -> List[Slice]:
1✔
90
    """ Get the single dimension slices of an application vertex
91
        such that each is sized to the maximum atoms per dimension per core
92
        except the last which might be smaller in one or more dimensions
93

94
    :param ApplicationVertex app_vertex: The vertex to get the slices of
95
    """
96
    # If there is only one slice, get that
97
    if app_vertex.n_atoms < app_vertex.get_max_atoms_per_core():
1✔
98
        return [Slice(0, app_vertex.n_atoms - 1)]
1✔
99

100
    total_on_core = app_vertex.get_max_atoms_per_dimension_per_core()[0]
1✔
101

102
    n_vertices = math.ceil(app_vertex.n_atoms / total_on_core)
1✔
103

104
    # Run over all the vertices and create slices for them
105
    slices = list()
1✔
106
    hi_atom = -1
1✔
107
    for _ in range(n_vertices):
1✔
108
        # Make a slice
109
        lo_atom = hi_atom + 1
1✔
110
        hi_atom = min(app_vertex.n_atoms - 1, (lo_atom + total_on_core) - 1)
1✔
111
        vertex_slice = Slice(lo_atom, hi_atom)
1✔
112
        slices.append(vertex_slice)
1✔
113

114
    return slices
1✔
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

© 2026 Coveralls, Inc