1 # Copyright (c) 2010 Advanced Micro Devices, Inc.
2 # 2016 Georgia Institute of Technology
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 from m5
.params
import *
29 from m5
.objects
import *
31 from topologies
.BaseTopology
import SimpleTopology
33 # Creates a generic Mesh assuming an equal number of cache
34 # and directory controllers.
35 # West-first routing is enforced (using link weights)
36 # to guarantee deadlock freedom.
37 # The network randomly chooses between links with the same
38 # weight for messages within unordered virtual networks.
39 # Within ordered virtual networks, a fixed link direction
40 # is always chosen based on which appears first inside the
43 class Mesh_westfirst(SimpleTopology
):
44 description
='Mesh_westfirst'
46 def __init__(self
, controllers
):
47 self
.nodes
= controllers
49 # Makes a generic mesh
50 # assuming an equal number of cache and directory cntrls
52 def makeTopology(self
, options
, network
, IntLink
, ExtLink
, Router
):
55 num_routers
= options
.num_cpus
56 num_rows
= options
.mesh_rows
58 # default values for link latency and router latency.
59 # Can be over-ridden on a per link/router basis
60 link_latency
= options
.link_latency
# used by simple and garnet
61 router_latency
= options
.router_latency
# only used by garnet
63 # There must be an evenly divisible number of cntrls to routers
64 # Also, obviously the number or rows must be <= the number of routers
65 cntrls_per_router
, remainder
= divmod(len(nodes
), num_routers
)
66 assert(num_rows
> 0 and num_rows
<= num_routers
)
67 num_columns
= int(num_routers
/ num_rows
)
68 assert(num_columns
* num_rows
== num_routers
)
70 # Create the routers in the mesh
71 routers
= [Router(router_id
=i
, latency
=router_latency
) \
72 for i
in range(num_routers
)]
73 network
.routers
= routers
75 # link counter to set unique link ids
78 # Add all but the remainder nodes to the list of nodes to be uniformly
79 # distributed across the network.
82 for node_index
in range(len(nodes
)):
83 if node_index
< (len(nodes
) - remainder
):
84 network_nodes
.append(nodes
[node_index
])
86 remainder_nodes
.append(nodes
[node_index
])
88 # Connect each node to the appropriate router
90 for (i
, n
) in enumerate(network_nodes
):
91 cntrl_level
, router_id
= divmod(i
, num_routers
)
92 assert(cntrl_level
< cntrls_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 remainding nodes to router 0. These should only be
100 for (i
, node
) in enumerate(remainder_nodes
):
101 assert(node
.type == 'DMA_Controller')
102 assert(i
< remainder
)
103 ext_links
.append(ExtLink(link_id
=link_count
, ext_node
=node
,
105 latency
= link_latency
))
108 network
.ext_links
= ext_links
110 # Create the mesh links.
113 # East output to West input links (weight = 2)
114 for row
in range(num_rows
):
115 for col
in range(num_columns
):
116 if (col
+ 1 < num_columns
):
117 east_out
= col
+ (row
* num_columns
)
118 west_in
= (col
+ 1) + (row
* num_columns
)
119 int_links
.append(IntLink(link_id
=link_count
,
120 src_node
=routers
[east_out
],
121 dst_node
=routers
[west_in
],
122 latency
= link_latency
,
126 # West output to East input links (weight = 1)
127 for row
in range(num_rows
):
128 for col
in range(num_columns
):
129 if (col
+ 1 < num_columns
):
130 east_in
= col
+ (row
* num_columns
)
131 west_out
= (col
+ 1) + (row
* num_columns
)
132 int_links
.append(IntLink(link_id
=link_count
,
133 src_node
=routers
[west_out
],
134 dst_node
=routers
[east_in
],
135 latency
= link_latency
,
140 # North output to South input links (weight = 2)
141 for col
in range(num_columns
):
142 for row
in range(num_rows
):
143 if (row
+ 1 < num_rows
):
144 north_out
= col
+ (row
* num_columns
)
145 south_in
= col
+ ((row
+ 1) * num_columns
)
146 int_links
.append(IntLink(link_id
=link_count
,
147 src_node
=routers
[north_out
],
148 dst_node
=routers
[south_in
],
149 latency
= link_latency
,
153 # South output to North input links (weight = 2)
154 for col
in range(num_columns
):
155 for row
in range(num_rows
):
156 if (row
+ 1 < num_rows
):
157 north_in
= col
+ (row
* num_columns
)
158 south_out
= col
+ ((row
+ 1) * num_columns
)
159 int_links
.append(IntLink(link_id
=link_count
,
160 src_node
=routers
[south_out
],
161 dst_node
=routers
[north_in
],
162 latency
= link_latency
,
167 network
.int_links
= int_links