MeshDirCorners_XY.py revision 11663:cf870cd20cfc
1# Copyright (c) 2010 Advanced Micro Devices, Inc.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright
9# notice, this list of conditions and the following disclaimer in the
10# documentation and/or other materials provided with the distribution;
11# neither the name of the copyright holders nor the names of its
12# contributors may be used to endorse or promote products derived from
13# this software without specific prior written permission.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Brad Beckmann
28
29from m5.params import *
30from m5.objects import *
31
32from BaseTopology import SimpleTopology
33
34# Creates a Mesh topology with 4 directories, one at each corner.
35# One L1 (and L2, depending on the protocol) are connected to each router.
36# XY routing is enforced (using link weights) to guarantee deadlock freedom.
37
38class MeshDirCorners_XY(SimpleTopology):
39    description='MeshDirCorners_XY'
40
41    def __init__(self, controllers):
42        self.nodes = controllers
43
44    def makeTopology(self, options, network, IntLink, ExtLink, Router):
45        nodes = self.nodes
46
47        num_routers = options.num_cpus
48        num_rows = options.mesh_rows
49
50        # First determine which nodes are cache cntrls vs. dirs vs. dma
51        cache_nodes = []
52        dir_nodes = []
53        dma_nodes = []
54        for node in nodes:
55            if node.type == 'L1Cache_Controller' or \
56            node.type == 'L2Cache_Controller':
57                cache_nodes.append(node)
58            elif node.type == 'Directory_Controller':
59                dir_nodes.append(node)
60            elif node.type == 'DMA_Controller':
61                dma_nodes.append(node)
62
63        # Obviously the number or rows must be <= the number of routers
64        # and evenly divisible.  Also the number of caches must be a
65        # multiple of the number of routers and the number of directories
66        # must be four.
67        assert(num_rows <= num_routers)
68        num_columns = int(num_routers / num_rows)
69        assert(num_columns * num_rows == num_routers)
70        caches_per_router, remainder = divmod(len(cache_nodes), num_routers)
71        assert(remainder == 0)
72        assert(len(dir_nodes) == 4)
73
74        # Create the routers in the mesh
75        routers = [Router(router_id=i) for i in range(num_routers)]
76        network.routers = routers
77
78        # link counter to set unique link ids
79        link_count = 0
80
81        # Connect each cache controller to the appropriate router
82        ext_links = []
83        for (i, n) in enumerate(cache_nodes):
84            cntrl_level, router_id = divmod(i, num_routers)
85            assert(cntrl_level < caches_per_router)
86            ext_links.append(ExtLink(link_id=link_count, ext_node=n,
87                                    int_node=routers[router_id]))
88            link_count += 1
89
90        # Connect the dir nodes to the corners.
91        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[0],
92                                int_node=routers[0]))
93        link_count += 1
94        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[1],
95                                int_node=routers[num_columns - 1]))
96        link_count += 1
97        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[2],
98                                int_node=routers[num_routers - num_columns]))
99        link_count += 1
100        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[3],
101                                int_node=routers[num_routers - 1]))
102        link_count += 1
103
104        # Connect the dma nodes to router 0.  These should only be DMA nodes.
105        for (i, node) in enumerate(dma_nodes):
106            assert(node.type == 'DMA_Controller')
107            ext_links.append(ExtLink(link_id=link_count, ext_node=node,
108                                     int_node=routers[0]))
109
110        network.ext_links = ext_links
111
112        # Create the mesh links.
113        int_links = []
114
115        # East output to West input links (weight = 1)
116        for row in xrange(num_rows):
117            for col in xrange(num_columns):
118                if (col + 1 < num_columns):
119                    east_out = col + (row * num_columns)
120                    west_in = (col + 1) + (row * num_columns)
121                    int_links.append(IntLink(link_id=link_count,
122                                             src_node=routers[east_out],
123                                             dst_node=routers[west_in],
124                                             weight=1))
125                    link_count += 1
126
127        # West output to East input links (weight = 1)
128        for row in xrange(num_rows):
129            for col in xrange(num_columns):
130                if (col + 1 < num_columns):
131                    east_in = col + (row * num_columns)
132                    west_out = (col + 1) + (row * num_columns)
133                    int_links.append(IntLink(link_id=link_count,
134                                             src_node=routers[west_out],
135                                             dst_node=routers[east_in],
136                                             weight=1))
137                    link_count += 1
138
139        # North output to South input links (weight = 2)
140        for col in xrange(num_columns):
141            for row in xrange(num_rows):
142                if (row + 1 < num_rows):
143                    north_out = col + (row * num_columns)
144                    south_in = col + ((row + 1) * num_columns)
145                    int_links.append(IntLink(link_id=link_count,
146                                             src_node=routers[north_out],
147                                             dst_node=routers[south_in],
148                                             weight=2))
149                    link_count += 1
150
151        # South output to North input links (weight = 2)
152        for col in xrange(num_columns):
153            for row in xrange(num_rows):
154                if (row + 1 < num_rows):
155                    north_in = col + (row * num_columns)
156                    south_out = col + ((row + 1) * num_columns)
157                    int_links.append(IntLink(link_id=link_count,
158                                             src_node=routers[south_out],
159                                             dst_node=routers[north_in],
160                                             weight=2))
161                    link_count += 1
162
163
164        network.int_links = int_links
165