Mesh_XY.py revision 11663:cf870cd20cfc
12068SN/A# Copyright (c) 2010 Advanced Micro Devices, Inc. 22068SN/A# 2016 Georgia Institute of Technology 32068SN/A# All rights reserved. 42068SN/A# 52068SN/A# Redistribution and use in source and binary forms, with or without 62068SN/A# modification, are permitted provided that the following conditions are 72068SN/A# met: redistributions of source code must retain the above copyright 82068SN/A# notice, this list of conditions and the following disclaimer; 92068SN/A# redistributions in binary form must reproduce the above copyright 102068SN/A# notice, this list of conditions and the following disclaimer in the 112068SN/A# documentation and/or other materials provided with the distribution; 122068SN/A# neither the name of the copyright holders nor the names of its 132068SN/A# contributors may be used to endorse or promote products derived from 142068SN/A# this software without specific prior written permission. 152068SN/A# 162068SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172068SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182068SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192068SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202068SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212068SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222068SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232068SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242068SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252068SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262068SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272068SN/A# 282665Ssaidi@eecs.umich.edu# Authors: Brad Beckmann 292665Ssaidi@eecs.umich.edu# Tushar Krishna 302068SN/A 312649Ssaidi@eecs.umich.edufrom m5.params import * 322649Ssaidi@eecs.umich.edufrom m5.objects import * 332649Ssaidi@eecs.umich.edu 342649Ssaidi@eecs.umich.edufrom BaseTopology import SimpleTopology 357799Sgblack@eecs.umich.edu 367799Sgblack@eecs.umich.edu# Creates a generic Mesh assuming an equal number of cache 377799Sgblack@eecs.umich.edu# and directory controllers. 382649Ssaidi@eecs.umich.edu# XY routing is enforced (using link weights) 392649Ssaidi@eecs.umich.edu# to guarantee deadlock freedom. 402068SN/A 412068SN/Aclass Mesh_XY(SimpleTopology): 422068SN/A description='Mesh_XY' 432090SN/A 442090SN/A def __init__(self, controllers): 452132SN/A self.nodes = controllers 462068SN/A 477799Sgblack@eecs.umich.edu # Makes a generic mesh 488738Sgblack@eecs.umich.edu # assuming an equal number of cache and directory cntrls 492147SN/A 502068SN/A def makeTopology(self, options, network, IntLink, ExtLink, Router): 512068SN/A nodes = self.nodes 522068SN/A 532068SN/A num_routers = options.num_cpus 542068SN/A num_rows = options.mesh_rows 552068SN/A 562068SN/A # There must be an evenly divisible number of cntrls to routers 572068SN/A # Also, obviously the number or rows must be <= the number of routers 582068SN/A cntrls_per_router, remainder = divmod(len(nodes), num_routers) 592068SN/A assert(num_rows <= num_routers) 602068SN/A num_columns = int(num_routers / num_rows) 612068SN/A assert(num_columns * num_rows == num_routers) 622068SN/A 632068SN/A # Create the routers in the mesh 642068SN/A routers = [Router(router_id=i) for i in range(num_routers)] 652068SN/A network.routers = routers 662068SN/A 677799Sgblack@eecs.umich.edu # link counter to set unique link ids 682068SN/A link_count = 0 697799Sgblack@eecs.umich.edu 707799Sgblack@eecs.umich.edu # Add all but the remainder nodes to the list of nodes to be uniformly 717799Sgblack@eecs.umich.edu # distributed across the network. 722068SN/A network_nodes = [] 732068SN/A remainder_nodes = [] 742068SN/A for node_index in xrange(len(nodes)): 752068SN/A if node_index < (len(nodes) - remainder): 762068SN/A network_nodes.append(nodes[node_index]) 772068SN/A else: 782068SN/A remainder_nodes.append(nodes[node_index]) 792068SN/A 807799Sgblack@eecs.umich.edu # Connect each node to the appropriate router 812068SN/A ext_links = [] 827799Sgblack@eecs.umich.edu for (i, n) in enumerate(network_nodes): 837799Sgblack@eecs.umich.edu cntrl_level, router_id = divmod(i, num_routers) 842068SN/A assert(cntrl_level < cntrls_per_router) 852068SN/A ext_links.append(ExtLink(link_id=link_count, ext_node=n, 862068SN/A int_node=routers[router_id])) 872068SN/A link_count += 1 882068SN/A 892068SN/A # Connect the remainding nodes to router 0. These should only be 902068SN/A # DMA nodes. 912068SN/A for (i, node) in enumerate(remainder_nodes): 922068SN/A assert(node.type == 'DMA_Controller') 932068SN/A assert(i < remainder) 942068SN/A ext_links.append(ExtLink(link_id=link_count, ext_node=node, 952068SN/A int_node=routers[0])) 962068SN/A link_count += 1 972068SN/A 982068SN/A network.ext_links = ext_links 992068SN/A 1002068SN/A # Create the mesh links. 1012068SN/A int_links = [] 1022068SN/A 1032068SN/A # East output to West input links (weight = 1) 1042068SN/A for row in xrange(num_rows): 1052068SN/A for col in xrange(num_columns): 1062068SN/A if (col + 1 < num_columns): 1072068SN/A east_out = col + (row * num_columns) 1082068SN/A west_in = (col + 1) + (row * num_columns) 1092068SN/A int_links.append(IntLink(link_id=link_count, 1102068SN/A src_node=routers[east_out], 1112068SN/A dst_node=routers[west_in], 1122068SN/A weight=1)) 1132227SN/A link_count += 1 1142068SN/A 1152068SN/A # West output to East input links (weight = 1) 1162068SN/A for row in xrange(num_rows): 1172068SN/A for col in xrange(num_columns): 1182068SN/A if (col + 1 < num_columns): 1192068SN/A east_in = col + (row * num_columns) 1202068SN/A west_out = (col + 1) + (row * num_columns) 1212068SN/A int_links.append(IntLink(link_id=link_count, 1222068SN/A src_node=routers[west_out], 1232068SN/A dst_node=routers[east_in], 1242068SN/A weight=1)) 1252068SN/A link_count += 1 1262068SN/A 1272068SN/A # North output to South input links (weight = 2) 1282068SN/A for col in xrange(num_columns): 1292068SN/A for row in xrange(num_rows): 1302068SN/A if (row + 1 < num_rows): 1312068SN/A north_out = col + (row * num_columns) 1322068SN/A south_in = col + ((row + 1) * num_columns) 1332068SN/A int_links.append(IntLink(link_id=link_count, 1342068SN/A src_node=routers[north_out], 1352068SN/A dst_node=routers[south_in], 1362068SN/A weight=2)) 1372068SN/A link_count += 1 1382068SN/A 1392068SN/A # South output to North input links (weight = 2) 1402068SN/A for col in xrange(num_columns): 1412068SN/A for row in xrange(num_rows): 1422068SN/A if (row + 1 < num_rows): 1432068SN/A north_in = col + (row * num_columns) 1442068SN/A south_out = col + ((row + 1) * num_columns) 1452068SN/A int_links.append(IntLink(link_id=link_count, 1462068SN/A src_node=routers[south_out], 1472068SN/A dst_node=routers[north_in], 1482068SN/A weight=2)) 1492068SN/A link_count += 1 1502068SN/A 1512068SN/A 1529918Ssteve.reinhardt@amd.com network.int_links = int_links 1532068SN/A