Mesh_XY.py revision 11663:cf870cd20cfc
18839Sandreas.hansson@arm.com# Copyright (c) 2010 Advanced Micro Devices, Inc. 28839Sandreas.hansson@arm.com# 2016 Georgia Institute of Technology 38839Sandreas.hansson@arm.com# All rights reserved. 48839Sandreas.hansson@arm.com# 58839Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 68839Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 78839Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 88839Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 98839Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 108839Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 118839Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 128839Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 135647Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 145647Sgblack@eecs.umich.edu# this software without specific prior written permission. 155647Sgblack@eecs.umich.edu# 165647Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175647Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185647Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195647Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205647Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215647Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225647Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235647Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245647Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255647Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265647Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275647Sgblack@eecs.umich.edu# 285647Sgblack@eecs.umich.edu# Authors: Brad Beckmann 295647Sgblack@eecs.umich.edu# Tushar Krishna 305647Sgblack@eecs.umich.edu 315647Sgblack@eecs.umich.edufrom m5.params import * 325647Sgblack@eecs.umich.edufrom m5.objects import * 335647Sgblack@eecs.umich.edu 345647Sgblack@eecs.umich.edufrom BaseTopology import SimpleTopology 355647Sgblack@eecs.umich.edu 365647Sgblack@eecs.umich.edu# Creates a generic Mesh assuming an equal number of cache 375647Sgblack@eecs.umich.edu# and directory controllers. 385647Sgblack@eecs.umich.edu# XY routing is enforced (using link weights) 395647Sgblack@eecs.umich.edu# to guarantee deadlock freedom. 405647Sgblack@eecs.umich.edu 418742Sgblack@eecs.umich.educlass Mesh_XY(SimpleTopology): 425647Sgblack@eecs.umich.edu description='Mesh_XY' 438742Sgblack@eecs.umich.edu 445647Sgblack@eecs.umich.edu def __init__(self, controllers): 455647Sgblack@eecs.umich.edu self.nodes = controllers 465647Sgblack@eecs.umich.edu 475647Sgblack@eecs.umich.edu # Makes a generic mesh 485647Sgblack@eecs.umich.edu # assuming an equal number of cache and directory cntrls 499338SAndreas.Sandberg@arm.com 508839Sandreas.hansson@arm.com def makeTopology(self, options, network, IntLink, ExtLink, Router): 518839Sandreas.hansson@arm.com nodes = self.nodes 527900Shestness@cs.utexas.edu 537900Shestness@cs.utexas.edu num_routers = options.num_cpus 54 num_rows = options.mesh_rows 55 56 # There must be an evenly divisible number of cntrls to routers 57 # Also, obviously the number or rows must be <= the number of routers 58 cntrls_per_router, remainder = divmod(len(nodes), num_routers) 59 assert(num_rows <= num_routers) 60 num_columns = int(num_routers / num_rows) 61 assert(num_columns * num_rows == num_routers) 62 63 # Create the routers in the mesh 64 routers = [Router(router_id=i) for i in range(num_routers)] 65 network.routers = routers 66 67 # link counter to set unique link ids 68 link_count = 0 69 70 # Add all but the remainder nodes to the list of nodes to be uniformly 71 # distributed across the network. 72 network_nodes = [] 73 remainder_nodes = [] 74 for node_index in xrange(len(nodes)): 75 if node_index < (len(nodes) - remainder): 76 network_nodes.append(nodes[node_index]) 77 else: 78 remainder_nodes.append(nodes[node_index]) 79 80 # Connect each node to the appropriate router 81 ext_links = [] 82 for (i, n) in enumerate(network_nodes): 83 cntrl_level, router_id = divmod(i, num_routers) 84 assert(cntrl_level < cntrls_per_router) 85 ext_links.append(ExtLink(link_id=link_count, ext_node=n, 86 int_node=routers[router_id])) 87 link_count += 1 88 89 # Connect the remainding nodes to router 0. These should only be 90 # DMA nodes. 91 for (i, node) in enumerate(remainder_nodes): 92 assert(node.type == 'DMA_Controller') 93 assert(i < remainder) 94 ext_links.append(ExtLink(link_id=link_count, ext_node=node, 95 int_node=routers[0])) 96 link_count += 1 97 98 network.ext_links = ext_links 99 100 # Create the mesh links. 101 int_links = [] 102 103 # East output to West input links (weight = 1) 104 for row in xrange(num_rows): 105 for col in xrange(num_columns): 106 if (col + 1 < num_columns): 107 east_out = col + (row * num_columns) 108 west_in = (col + 1) + (row * num_columns) 109 int_links.append(IntLink(link_id=link_count, 110 src_node=routers[east_out], 111 dst_node=routers[west_in], 112 weight=1)) 113 link_count += 1 114 115 # West output to East input links (weight = 1) 116 for row in xrange(num_rows): 117 for col in xrange(num_columns): 118 if (col + 1 < num_columns): 119 east_in = col + (row * num_columns) 120 west_out = (col + 1) + (row * num_columns) 121 int_links.append(IntLink(link_id=link_count, 122 src_node=routers[west_out], 123 dst_node=routers[east_in], 124 weight=1)) 125 link_count += 1 126 127 # North output to South input links (weight = 2) 128 for col in xrange(num_columns): 129 for row in xrange(num_rows): 130 if (row + 1 < num_rows): 131 north_out = col + (row * num_columns) 132 south_in = col + ((row + 1) * num_columns) 133 int_links.append(IntLink(link_id=link_count, 134 src_node=routers[north_out], 135 dst_node=routers[south_in], 136 weight=2)) 137 link_count += 1 138 139 # South output to North input links (weight = 2) 140 for col in xrange(num_columns): 141 for row in xrange(num_rows): 142 if (row + 1 < num_rows): 143 north_in = col + (row * num_columns) 144 south_out = col + ((row + 1) * num_columns) 145 int_links.append(IntLink(link_id=link_count, 146 src_node=routers[south_out], 147 dst_node=routers[north_in], 148 weight=2)) 149 link_count += 1 150 151 152 network.int_links = int_links 153