1 # Copyright (c) 2010 Advanced Micro Devices, Inc.
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.
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.
27 # Authors: Brad Beckmann
29 from m5
.params
import *
30 from m5
.objects
import *
32 from BaseTopology
import SimpleTopology
34 class MeshDirCorners(SimpleTopology
):
35 description
='MeshDirCorners'
37 def __init__(self
, controllers
):
38 self
.nodes
= controllers
40 # This file contains a special network creation function. This
41 # networks is not general and will only work with specific system
42 # configurations. The network specified is similar to GEMS old file
45 def makeTopology(self
, options
, network
, IntLink
, ExtLink
, Router
):
48 num_routers
= options
.num_cpus
49 num_rows
= options
.mesh_rows
51 # First determine which nodes are cache cntrls vs. dirs vs. dma
56 if node
.type == 'L1Cache_Controller' or \
57 node
.type == 'L2Cache_Controller':
58 cache_nodes
.append(node
)
59 elif node
.type == 'Directory_Controller':
60 dir_nodes
.append(node
)
61 elif node
.type == 'DMA_Controller':
62 dma_nodes
.append(node
)
64 # Obviously the number or rows must be <= the number of routers
65 # and evenly divisible. Also the number of caches must be a
66 # multiple of the number of routers and the number of directories
68 assert(num_rows
<= num_routers
)
69 num_columns
= int(num_routers
/ num_rows
)
70 assert(num_columns
* num_rows
== num_routers
)
71 caches_per_router
, remainder
= divmod(len(cache_nodes
), num_routers
)
72 assert(remainder
== 0)
73 assert(len(dir_nodes
) == 4)
75 # Create the routers in the mesh
76 routers
= [Router(router_id
=i
) for i
in range(num_routers
)]
77 network
.routers
= routers
79 # link counter to set unique link ids
82 # Connect each cache controller to the appropriate router
84 for (i
, n
) in enumerate(cache_nodes
):
85 cntrl_level
, router_id
= divmod(i
, num_routers
)
86 assert(cntrl_level
< caches_per_router
)
87 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=n
,
88 int_node
=routers
[router_id
]))
91 # Connect the dir nodes to the corners.
92 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=dir_nodes
[0],
95 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=dir_nodes
[1],
96 int_node
=routers
[num_columns
- 1]))
98 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=dir_nodes
[2],
99 int_node
=routers
[num_routers
- num_columns
]))
101 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=dir_nodes
[3],
102 int_node
=routers
[num_routers
- 1]))
105 # Connect the dma nodes to router 0. These should only be DMA nodes.
106 for (i
, node
) in enumerate(dma_nodes
):
107 assert(node
.type == 'DMA_Controller')
108 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=node
,
109 int_node
=routers
[0]))
111 network
.ext_links
= ext_links
113 # Create the mesh links. First row (east-west) links then column
114 # (north-south) links
116 for row
in xrange(num_rows
):
117 for col
in xrange(num_columns
):
118 if (col
+ 1 < num_columns
):
119 east_id
= col
+ (row
* num_columns
)
120 west_id
= (col
+ 1) + (row
* num_columns
)
121 int_links
.append(IntLink(link_id
=link_count
,
122 node_a
=routers
[east_id
],
123 node_b
=routers
[west_id
],
127 for col
in xrange(num_columns
):
128 for row
in xrange(num_rows
):
129 if (row
+ 1 < num_rows
):
130 north_id
= col
+ (row
* num_columns
)
131 south_id
= col
+ ((row
+ 1) * num_columns
)
132 int_links
.append(IntLink(link_id
=link_count
,
133 node_a
=routers
[north_id
],
134 node_b
=routers
[south_id
],
138 network
.int_links
= int_links