Mesh_XY.py revision 11664:2365e9e396f7
12100SN/A# Copyright (c) 2010 Advanced Micro Devices, Inc. 22083SN/A# 2016 Georgia Institute of Technology 32089SN/A# All rights reserved. 42022SN/A# 52089SN/A# Redistribution and use in source and binary forms, with or without 62022SN/A# modification, are permitted provided that the following conditions are 72022SN/A# met: redistributions of source code must retain the above copyright 82022SN/A# notice, this list of conditions and the following disclaimer; 92083SN/A# redistributions in binary form must reproduce the above copyright 102239SN/A# notice, this list of conditions and the following disclaimer in the 112239SN/A# documentation and/or other materials provided with the distribution; 122239SN/A# neither the name of the copyright holders nor the names of its 132083SN/A# contributors may be used to endorse or promote products derived from 142083SN/A# this software without specific prior written permission. 152083SN/A# 162083SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172083SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182083SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192083SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202083SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212083SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222089SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232083SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242083SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252083SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262083SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272089SN/A# 282083SN/A# Authors: Brad Beckmann 292083SN/A# Tushar Krishna 302083SN/A 312083SN/Afrom m5.params import * 322083SN/Afrom m5.objects import * 332083SN/A 342089SN/Afrom BaseTopology import SimpleTopology 352083SN/A 362022SN/A# Creates a generic Mesh assuming an equal number of cache 372083SN/A# and directory controllers. 382022SN/A# XY routing is enforced (using link weights) 392083SN/A# to guarantee deadlock freedom. 402083SN/A 412083SN/Aclass Mesh_XY(SimpleTopology): 422022SN/A description='Mesh_XY' 432083SN/A 442083SN/A def __init__(self, controllers): 452083SN/A self.nodes = controllers 462083SN/A 472083SN/A # Makes a generic mesh 482083SN/A # assuming an equal number of cache and directory cntrls 492083SN/A 502089SN/A def makeTopology(self, options, network, IntLink, ExtLink, Router): 512104SN/A nodes = self.nodes 522083SN/A 532083SN/A num_routers = options.num_cpus 542083SN/A num_rows = options.mesh_rows 552083SN/A 562104SN/A # There must be an evenly divisible number of cntrls to routers 572089SN/A # Also, obviously the number or rows must be <= the number of routers 582239SN/A cntrls_per_router, remainder = divmod(len(nodes), num_routers) 592239SN/A assert(num_rows <= num_routers) 602239SN/A num_columns = int(num_routers / num_rows) 612239SN/A assert(num_columns * num_rows == num_routers) 622089SN/A 632089SN/A # Create the routers in the mesh 642089SN/A routers = [Router(router_id=i) for i in range(num_routers)] 652089SN/A network.routers = routers 662089SN/A 672089SN/A # link counter to set unique link ids 682089SN/A link_count = 0 692089SN/A 702089SN/A # Add all but the remainder nodes to the list of nodes to be uniformly 712083SN/A # distributed across the network. 722089SN/A network_nodes = [] 732083SN/A remainder_nodes = [] 742083SN/A for node_index in xrange(len(nodes)): 752083SN/A if node_index < (len(nodes) - remainder): 762083SN/A network_nodes.append(nodes[node_index]) 772083SN/A else: 782083SN/A remainder_nodes.append(nodes[node_index]) 792083SN/A 802083SN/A # Connect each node to the appropriate router 812239SN/A ext_links = [] 822239SN/A for (i, n) in enumerate(network_nodes): 832083SN/A cntrl_level, router_id = divmod(i, num_routers) 842083SN/A assert(cntrl_level < cntrls_per_router) 852083SN/A ext_links.append(ExtLink(link_id=link_count, ext_node=n, 862083SN/A int_node=routers[router_id])) 872239SN/A link_count += 1 882083SN/A 892083SN/A # Connect the remainding nodes to router 0. These should only be 902083SN/A # DMA nodes. 912083SN/A for (i, node) in enumerate(remainder_nodes): 922083SN/A assert(node.type == 'DMA_Controller') 932083SN/A assert(i < remainder) 942083SN/A ext_links.append(ExtLink(link_id=link_count, ext_node=node, 952083SN/A int_node=routers[0])) 962022SN/A link_count += 1 972022SN/A 982022SN/A network.ext_links = ext_links 992083SN/A 1002083SN/A # Create the mesh links. 1012083SN/A int_links = [] 1022083SN/A 1032083SN/A # East output to West input links (weight = 1) 1042083SN/A for row in xrange(num_rows): 1052083SN/A for col in xrange(num_columns): 1062083SN/A if (col + 1 < num_columns): 1072083SN/A east_out = col + (row * num_columns) 1082083SN/A west_in = (col + 1) + (row * num_columns) 1092083SN/A int_links.append(IntLink(link_id=link_count, 1102083SN/A src_node=routers[east_out], 1112083SN/A dst_node=routers[west_in], 1122083SN/A src_outport="East", 1132083SN/A dst_inport="West", 1142083SN/A weight=1)) 1152083SN/A link_count += 1 1162083SN/A 1172083SN/A # West output to East input links (weight = 1) 1182083SN/A for row in xrange(num_rows): 1192022SN/A for col in xrange(num_columns): 1202083SN/A if (col + 1 < num_columns): 1212083SN/A east_in = col + (row * num_columns) 1222083SN/A west_out = (col + 1) + (row * num_columns) 1232083SN/A int_links.append(IntLink(link_id=link_count, 1242083SN/A src_node=routers[west_out], 1252083SN/A dst_node=routers[east_in], 1262083SN/A src_outport="West", 1272022SN/A dst_inport="East", 1282083SN/A weight=1)) 1292083SN/A link_count += 1 1302083SN/A 1312083SN/A # North output to South input links (weight = 2) 1322083SN/A for col in xrange(num_columns): 1332083SN/A for row in xrange(num_rows): 1342083SN/A if (row + 1 < num_rows): 1352083SN/A north_out = col + (row * num_columns) 1362083SN/A south_in = col + ((row + 1) * num_columns) 1372083SN/A int_links.append(IntLink(link_id=link_count, 1382083SN/A src_node=routers[north_out], 1392083SN/A dst_node=routers[south_in], 1402083SN/A src_outport="North", 1412083SN/A dst_inport="South", 1422083SN/A weight=2)) 1432239SN/A link_count += 1 1442083SN/A 1452686Sksewell@umich.edu # South output to North input links (weight = 2) 1462239SN/A for col in xrange(num_columns): 1472239SN/A for row in xrange(num_rows): 1482686Sksewell@umich.edu if (row + 1 < num_rows): 1492239SN/A north_in = col + (row * num_columns) 1502686Sksewell@umich.edu south_out = col + ((row + 1) * num_columns) 1512103SN/A int_links.append(IntLink(link_id=link_count, 1522103SN/A src_node=routers[south_out], 1532103SN/A dst_node=routers[north_in], 1542103SN/A src_outport="South", 1552103SN/A dst_inport="North", 1562103SN/A weight=2)) 1572103SN/A link_count += 1 1582103SN/A 1592103SN/A 1602103SN/A network.int_links = int_links 1612103SN/A