MeshDirCorners_XY.py revision 13731
111663Stushar@ece.gatech.edu# Copyright (c) 2010 Advanced Micro Devices, Inc. 211663Stushar@ece.gatech.edu# All rights reserved. 311663Stushar@ece.gatech.edu# 411663Stushar@ece.gatech.edu# Redistribution and use in source and binary forms, with or without 511663Stushar@ece.gatech.edu# modification, are permitted provided that the following conditions are 611663Stushar@ece.gatech.edu# met: redistributions of source code must retain the above copyright 711663Stushar@ece.gatech.edu# notice, this list of conditions and the following disclaimer; 811663Stushar@ece.gatech.edu# redistributions in binary form must reproduce the above copyright 911663Stushar@ece.gatech.edu# notice, this list of conditions and the following disclaimer in the 1011663Stushar@ece.gatech.edu# documentation and/or other materials provided with the distribution; 1111663Stushar@ece.gatech.edu# neither the name of the copyright holders nor the names of its 1211663Stushar@ece.gatech.edu# contributors may be used to endorse or promote products derived from 1311663Stushar@ece.gatech.edu# this software without specific prior written permission. 1411663Stushar@ece.gatech.edu# 1511663Stushar@ece.gatech.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1611663Stushar@ece.gatech.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1711663Stushar@ece.gatech.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1811663Stushar@ece.gatech.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1911663Stushar@ece.gatech.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2011663Stushar@ece.gatech.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2111663Stushar@ece.gatech.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2211663Stushar@ece.gatech.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2311663Stushar@ece.gatech.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2411663Stushar@ece.gatech.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2511663Stushar@ece.gatech.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2611663Stushar@ece.gatech.edu# 2711663Stushar@ece.gatech.edu# Authors: Brad Beckmann 2811663Stushar@ece.gatech.edu 2911663Stushar@ece.gatech.edufrom m5.params import * 3011663Stushar@ece.gatech.edufrom m5.objects import * 3111663Stushar@ece.gatech.edu 3211663Stushar@ece.gatech.edufrom BaseTopology import SimpleTopology 3311663Stushar@ece.gatech.edu 3411663Stushar@ece.gatech.edu# Creates a Mesh topology with 4 directories, one at each corner. 3511663Stushar@ece.gatech.edu# One L1 (and L2, depending on the protocol) are connected to each router. 3611663Stushar@ece.gatech.edu# XY routing is enforced (using link weights) to guarantee deadlock freedom. 3711663Stushar@ece.gatech.edu 3811663Stushar@ece.gatech.educlass MeshDirCorners_XY(SimpleTopology): 3911663Stushar@ece.gatech.edu description='MeshDirCorners_XY' 4011663Stushar@ece.gatech.edu 4111663Stushar@ece.gatech.edu def __init__(self, controllers): 4211663Stushar@ece.gatech.edu self.nodes = controllers 4311663Stushar@ece.gatech.edu 4411663Stushar@ece.gatech.edu def makeTopology(self, options, network, IntLink, ExtLink, Router): 4511663Stushar@ece.gatech.edu nodes = self.nodes 4611663Stushar@ece.gatech.edu 4711663Stushar@ece.gatech.edu num_routers = options.num_cpus 4811663Stushar@ece.gatech.edu num_rows = options.mesh_rows 4911663Stushar@ece.gatech.edu 5011666Stushar@ece.gatech.edu # default values for link latency and router latency. 5111666Stushar@ece.gatech.edu # Can be over-ridden on a per link/router basis 5211666Stushar@ece.gatech.edu link_latency = options.link_latency # used by simple and garnet 5311666Stushar@ece.gatech.edu router_latency = options.router_latency # only used by garnet 5411666Stushar@ece.gatech.edu 5511666Stushar@ece.gatech.edu 5611663Stushar@ece.gatech.edu # First determine which nodes are cache cntrls vs. dirs vs. dma 5711663Stushar@ece.gatech.edu cache_nodes = [] 5811663Stushar@ece.gatech.edu dir_nodes = [] 5911663Stushar@ece.gatech.edu dma_nodes = [] 6011663Stushar@ece.gatech.edu for node in nodes: 6111663Stushar@ece.gatech.edu if node.type == 'L1Cache_Controller' or \ 6211663Stushar@ece.gatech.edu node.type == 'L2Cache_Controller': 6311663Stushar@ece.gatech.edu cache_nodes.append(node) 6411663Stushar@ece.gatech.edu elif node.type == 'Directory_Controller': 6511663Stushar@ece.gatech.edu dir_nodes.append(node) 6611663Stushar@ece.gatech.edu elif node.type == 'DMA_Controller': 6711663Stushar@ece.gatech.edu dma_nodes.append(node) 6811663Stushar@ece.gatech.edu 6911663Stushar@ece.gatech.edu # Obviously the number or rows must be <= the number of routers 7011663Stushar@ece.gatech.edu # and evenly divisible. Also the number of caches must be a 7111663Stushar@ece.gatech.edu # multiple of the number of routers and the number of directories 7211663Stushar@ece.gatech.edu # must be four. 7311666Stushar@ece.gatech.edu assert(num_rows > 0 and num_rows <= num_routers) 7411663Stushar@ece.gatech.edu num_columns = int(num_routers / num_rows) 7511663Stushar@ece.gatech.edu assert(num_columns * num_rows == num_routers) 7611663Stushar@ece.gatech.edu caches_per_router, remainder = divmod(len(cache_nodes), num_routers) 7711663Stushar@ece.gatech.edu assert(remainder == 0) 7811663Stushar@ece.gatech.edu assert(len(dir_nodes) == 4) 7911663Stushar@ece.gatech.edu 8011663Stushar@ece.gatech.edu # Create the routers in the mesh 8111666Stushar@ece.gatech.edu routers = [Router(router_id=i, latency = router_latency) \ 8211666Stushar@ece.gatech.edu for i in range(num_routers)] 8311663Stushar@ece.gatech.edu network.routers = routers 8411663Stushar@ece.gatech.edu 8511663Stushar@ece.gatech.edu # link counter to set unique link ids 8611663Stushar@ece.gatech.edu link_count = 0 8711663Stushar@ece.gatech.edu 8811663Stushar@ece.gatech.edu # Connect each cache controller to the appropriate router 8911663Stushar@ece.gatech.edu ext_links = [] 9011663Stushar@ece.gatech.edu for (i, n) in enumerate(cache_nodes): 9111663Stushar@ece.gatech.edu cntrl_level, router_id = divmod(i, num_routers) 9211663Stushar@ece.gatech.edu assert(cntrl_level < caches_per_router) 9311663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=n, 9411666Stushar@ece.gatech.edu int_node=routers[router_id], 9511666Stushar@ece.gatech.edu latency = link_latency)) 9611663Stushar@ece.gatech.edu link_count += 1 9711663Stushar@ece.gatech.edu 9811663Stushar@ece.gatech.edu # Connect the dir nodes to the corners. 9911663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[0], 10011666Stushar@ece.gatech.edu int_node=routers[0], 10111666Stushar@ece.gatech.edu latency = link_latency)) 10211663Stushar@ece.gatech.edu link_count += 1 10311663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[1], 10411666Stushar@ece.gatech.edu int_node=routers[num_columns - 1], 10511666Stushar@ece.gatech.edu latency = link_latency)) 10611663Stushar@ece.gatech.edu link_count += 1 10711663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[2], 10811666Stushar@ece.gatech.edu int_node=routers[num_routers - num_columns], 10911666Stushar@ece.gatech.edu latency = link_latency)) 11011663Stushar@ece.gatech.edu link_count += 1 11111663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[3], 11211666Stushar@ece.gatech.edu int_node=routers[num_routers - 1], 11311666Stushar@ece.gatech.edu latency = link_latency)) 11411663Stushar@ece.gatech.edu link_count += 1 11511663Stushar@ece.gatech.edu 11611663Stushar@ece.gatech.edu # Connect the dma nodes to router 0. These should only be DMA nodes. 11711663Stushar@ece.gatech.edu for (i, node) in enumerate(dma_nodes): 11811663Stushar@ece.gatech.edu assert(node.type == 'DMA_Controller') 11911663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=node, 12011666Stushar@ece.gatech.edu int_node=routers[0], 12111666Stushar@ece.gatech.edu latency = link_latency)) 12211663Stushar@ece.gatech.edu 12311663Stushar@ece.gatech.edu network.ext_links = ext_links 12411663Stushar@ece.gatech.edu 12511663Stushar@ece.gatech.edu # Create the mesh links. 12611663Stushar@ece.gatech.edu int_links = [] 12711663Stushar@ece.gatech.edu 12811663Stushar@ece.gatech.edu # East output to West input links (weight = 1) 12913731Sandreas.sandberg@arm.com for row in range(num_rows): 13013731Sandreas.sandberg@arm.com for col in range(num_columns): 13111663Stushar@ece.gatech.edu if (col + 1 < num_columns): 13211663Stushar@ece.gatech.edu east_out = col + (row * num_columns) 13311663Stushar@ece.gatech.edu west_in = (col + 1) + (row * num_columns) 13411663Stushar@ece.gatech.edu int_links.append(IntLink(link_id=link_count, 13511663Stushar@ece.gatech.edu src_node=routers[east_out], 13611663Stushar@ece.gatech.edu dst_node=routers[west_in], 13711666Stushar@ece.gatech.edu src_outport="East", 13811666Stushar@ece.gatech.edu dst_inport="West", 13911666Stushar@ece.gatech.edu latency = link_latency, 14011663Stushar@ece.gatech.edu weight=1)) 14111663Stushar@ece.gatech.edu link_count += 1 14211663Stushar@ece.gatech.edu 14311663Stushar@ece.gatech.edu # West output to East input links (weight = 1) 14413731Sandreas.sandberg@arm.com for row in range(num_rows): 14513731Sandreas.sandberg@arm.com for col in range(num_columns): 14611663Stushar@ece.gatech.edu if (col + 1 < num_columns): 14711663Stushar@ece.gatech.edu east_in = col + (row * num_columns) 14811663Stushar@ece.gatech.edu west_out = (col + 1) + (row * num_columns) 14911663Stushar@ece.gatech.edu int_links.append(IntLink(link_id=link_count, 15011663Stushar@ece.gatech.edu src_node=routers[west_out], 15111663Stushar@ece.gatech.edu dst_node=routers[east_in], 15211666Stushar@ece.gatech.edu src_outport="West", 15311666Stushar@ece.gatech.edu dst_inport="East", 15411666Stushar@ece.gatech.edu latency = link_latency, 15511663Stushar@ece.gatech.edu weight=1)) 15611663Stushar@ece.gatech.edu link_count += 1 15711663Stushar@ece.gatech.edu 15811663Stushar@ece.gatech.edu # North output to South input links (weight = 2) 15913731Sandreas.sandberg@arm.com for col in range(num_columns): 16013731Sandreas.sandberg@arm.com for row in range(num_rows): 16111663Stushar@ece.gatech.edu if (row + 1 < num_rows): 16211663Stushar@ece.gatech.edu north_out = col + (row * num_columns) 16311663Stushar@ece.gatech.edu south_in = col + ((row + 1) * num_columns) 16411663Stushar@ece.gatech.edu int_links.append(IntLink(link_id=link_count, 16511663Stushar@ece.gatech.edu src_node=routers[north_out], 16611663Stushar@ece.gatech.edu dst_node=routers[south_in], 16711666Stushar@ece.gatech.edu src_outport="North", 16811666Stushar@ece.gatech.edu dst_inport="South", 16911666Stushar@ece.gatech.edu latency = link_latency, 17011663Stushar@ece.gatech.edu weight=2)) 17111663Stushar@ece.gatech.edu link_count += 1 17211663Stushar@ece.gatech.edu 17311663Stushar@ece.gatech.edu # South output to North input links (weight = 2) 17413731Sandreas.sandberg@arm.com for col in range(num_columns): 17513731Sandreas.sandberg@arm.com for row in range(num_rows): 17611663Stushar@ece.gatech.edu if (row + 1 < num_rows): 17711663Stushar@ece.gatech.edu north_in = col + (row * num_columns) 17811663Stushar@ece.gatech.edu south_out = col + ((row + 1) * num_columns) 17911663Stushar@ece.gatech.edu int_links.append(IntLink(link_id=link_count, 18011663Stushar@ece.gatech.edu src_node=routers[south_out], 18111663Stushar@ece.gatech.edu dst_node=routers[north_in], 18211666Stushar@ece.gatech.edu src_outport="South", 18311666Stushar@ece.gatech.edu dst_inport="North", 18411666Stushar@ece.gatech.edu latency = link_latency, 18511663Stushar@ece.gatech.edu weight=2)) 18611663Stushar@ece.gatech.edu link_count += 1 18711663Stushar@ece.gatech.edu 18811663Stushar@ece.gatech.edu 18911663Stushar@ece.gatech.edu network.int_links = int_links 190