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 # 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.
38 class MeshDirCorners_XY(SimpleTopology
):
39 description
='MeshDirCorners_XY'
41 def __init__(self
, controllers
):
42 self
.nodes
= controllers
44 def makeTopology(self
, options
, network
, IntLink
, ExtLink
, Router
):
47 num_routers
= options
.num_cpus
48 num_rows
= options
.mesh_rows
50 # default values for link latency and router latency.
51 # Can be over-ridden on a per link/router basis
52 link_latency
= options
.link_latency
# used by simple and garnet
53 router_latency
= options
.router_latency
# only used by garnet
56 # First determine which nodes are cache cntrls vs. dirs vs. dma
61 if node
.type == 'L1Cache_Controller' or \
62 node
.type == 'L2Cache_Controller':
63 cache_nodes
.append(node
)
64 elif node
.type == 'Directory_Controller':
65 dir_nodes
.append(node
)
66 elif node
.type == 'DMA_Controller':
67 dma_nodes
.append(node
)
69 # Obviously the number or rows must be <= the number of routers
70 # and evenly divisible. Also the number of caches must be a
71 # multiple of the number of routers and the number of directories
73 assert(num_rows
> 0 and num_rows
<= num_routers
)
74 num_columns
= int(num_routers
/ num_rows
)
75 assert(num_columns
* num_rows
== num_routers
)
76 caches_per_router
, remainder
= divmod(len(cache_nodes
), num_routers
)
77 assert(remainder
== 0)
78 assert(len(dir_nodes
) == 4)
80 # Create the routers in the mesh
81 routers
= [Router(router_id
=i
, latency
= router_latency
) \
82 for i
in range(num_routers
)]
83 network
.routers
= routers
85 # link counter to set unique link ids
88 # Connect each cache controller to the appropriate router
90 for (i
, n
) in enumerate(cache_nodes
):
91 cntrl_level
, router_id
= divmod(i
, num_routers
)
92 assert(cntrl_level
< caches_per_router
)
93 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=n
,
94 int_node
=routers
[router_id
],
95 latency
= link_latency
))
98 # Connect the dir nodes to the corners.
99 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=dir_nodes
[0],
101 latency
= link_latency
))
103 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=dir_nodes
[1],
104 int_node
=routers
[num_columns
- 1],
105 latency
= link_latency
))
107 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=dir_nodes
[2],
108 int_node
=routers
[num_routers
- num_columns
],
109 latency
= link_latency
))
111 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=dir_nodes
[3],
112 int_node
=routers
[num_routers
- 1],
113 latency
= link_latency
))
116 # Connect the dma nodes to router 0. These should only be DMA nodes.
117 for (i
, node
) in enumerate(dma_nodes
):
118 assert(node
.type == 'DMA_Controller')
119 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=node
,
121 latency
= link_latency
))
123 network
.ext_links
= ext_links
125 # Create the mesh links.
128 # East output to West input links (weight = 1)
129 for row
in range(num_rows
):
130 for col
in range(num_columns
):
131 if (col
+ 1 < num_columns
):
132 east_out
= col
+ (row
* num_columns
)
133 west_in
= (col
+ 1) + (row
* num_columns
)
134 int_links
.append(IntLink(link_id
=link_count
,
135 src_node
=routers
[east_out
],
136 dst_node
=routers
[west_in
],
139 latency
= link_latency
,
143 # West output to East input links (weight = 1)
144 for row
in range(num_rows
):
145 for col
in range(num_columns
):
146 if (col
+ 1 < num_columns
):
147 east_in
= col
+ (row
* num_columns
)
148 west_out
= (col
+ 1) + (row
* num_columns
)
149 int_links
.append(IntLink(link_id
=link_count
,
150 src_node
=routers
[west_out
],
151 dst_node
=routers
[east_in
],
154 latency
= link_latency
,
158 # North output to South input links (weight = 2)
159 for col
in range(num_columns
):
160 for row
in range(num_rows
):
161 if (row
+ 1 < num_rows
):
162 north_out
= col
+ (row
* num_columns
)
163 south_in
= col
+ ((row
+ 1) * num_columns
)
164 int_links
.append(IntLink(link_id
=link_count
,
165 src_node
=routers
[north_out
],
166 dst_node
=routers
[south_in
],
169 latency
= link_latency
,
173 # South output to North input links (weight = 2)
174 for col
in range(num_columns
):
175 for row
in range(num_rows
):
176 if (row
+ 1 < num_rows
):
177 north_in
= col
+ (row
* num_columns
)
178 south_out
= col
+ ((row
+ 1) * num_columns
)
179 int_links
.append(IntLink(link_id
=link_count
,
180 src_node
=routers
[south_out
],
181 dst_node
=routers
[north_in
],
184 latency
= link_latency
,
189 network
.int_links
= int_links