MeshDirCorners_XY.py revision 13774
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 2913774Sandreas.sandberg@arm.comfrom __future__ import print_function 3013774Sandreas.sandberg@arm.comfrom __future__ import absolute_import 3113774Sandreas.sandberg@arm.com 3211663Stushar@ece.gatech.edufrom m5.params import * 3311663Stushar@ece.gatech.edufrom m5.objects import * 3411663Stushar@ece.gatech.edu 3513774Sandreas.sandberg@arm.comfrom .BaseTopology import SimpleTopology 3611663Stushar@ece.gatech.edu 3711663Stushar@ece.gatech.edu# Creates a Mesh topology with 4 directories, one at each corner. 3811663Stushar@ece.gatech.edu# One L1 (and L2, depending on the protocol) are connected to each router. 3911663Stushar@ece.gatech.edu# XY routing is enforced (using link weights) to guarantee deadlock freedom. 4011663Stushar@ece.gatech.edu 4111663Stushar@ece.gatech.educlass MeshDirCorners_XY(SimpleTopology): 4211663Stushar@ece.gatech.edu description='MeshDirCorners_XY' 4311663Stushar@ece.gatech.edu 4411663Stushar@ece.gatech.edu def __init__(self, controllers): 4511663Stushar@ece.gatech.edu self.nodes = controllers 4611663Stushar@ece.gatech.edu 4711663Stushar@ece.gatech.edu def makeTopology(self, options, network, IntLink, ExtLink, Router): 4811663Stushar@ece.gatech.edu nodes = self.nodes 4911663Stushar@ece.gatech.edu 5011663Stushar@ece.gatech.edu num_routers = options.num_cpus 5111663Stushar@ece.gatech.edu num_rows = options.mesh_rows 5211663Stushar@ece.gatech.edu 5311666Stushar@ece.gatech.edu # default values for link latency and router latency. 5411666Stushar@ece.gatech.edu # Can be over-ridden on a per link/router basis 5511666Stushar@ece.gatech.edu link_latency = options.link_latency # used by simple and garnet 5611666Stushar@ece.gatech.edu router_latency = options.router_latency # only used by garnet 5711666Stushar@ece.gatech.edu 5811666Stushar@ece.gatech.edu 5911663Stushar@ece.gatech.edu # First determine which nodes are cache cntrls vs. dirs vs. dma 6011663Stushar@ece.gatech.edu cache_nodes = [] 6111663Stushar@ece.gatech.edu dir_nodes = [] 6211663Stushar@ece.gatech.edu dma_nodes = [] 6311663Stushar@ece.gatech.edu for node in nodes: 6411663Stushar@ece.gatech.edu if node.type == 'L1Cache_Controller' or \ 6511663Stushar@ece.gatech.edu node.type == 'L2Cache_Controller': 6611663Stushar@ece.gatech.edu cache_nodes.append(node) 6711663Stushar@ece.gatech.edu elif node.type == 'Directory_Controller': 6811663Stushar@ece.gatech.edu dir_nodes.append(node) 6911663Stushar@ece.gatech.edu elif node.type == 'DMA_Controller': 7011663Stushar@ece.gatech.edu dma_nodes.append(node) 7111663Stushar@ece.gatech.edu 7211663Stushar@ece.gatech.edu # Obviously the number or rows must be <= the number of routers 7311663Stushar@ece.gatech.edu # and evenly divisible. Also the number of caches must be a 7411663Stushar@ece.gatech.edu # multiple of the number of routers and the number of directories 7511663Stushar@ece.gatech.edu # must be four. 7611666Stushar@ece.gatech.edu assert(num_rows > 0 and num_rows <= num_routers) 7711663Stushar@ece.gatech.edu num_columns = int(num_routers / num_rows) 7811663Stushar@ece.gatech.edu assert(num_columns * num_rows == num_routers) 7911663Stushar@ece.gatech.edu caches_per_router, remainder = divmod(len(cache_nodes), num_routers) 8011663Stushar@ece.gatech.edu assert(remainder == 0) 8111663Stushar@ece.gatech.edu assert(len(dir_nodes) == 4) 8211663Stushar@ece.gatech.edu 8311663Stushar@ece.gatech.edu # Create the routers in the mesh 8411666Stushar@ece.gatech.edu routers = [Router(router_id=i, latency = router_latency) \ 8511666Stushar@ece.gatech.edu for i in range(num_routers)] 8611663Stushar@ece.gatech.edu network.routers = routers 8711663Stushar@ece.gatech.edu 8811663Stushar@ece.gatech.edu # link counter to set unique link ids 8911663Stushar@ece.gatech.edu link_count = 0 9011663Stushar@ece.gatech.edu 9111663Stushar@ece.gatech.edu # Connect each cache controller to the appropriate router 9211663Stushar@ece.gatech.edu ext_links = [] 9311663Stushar@ece.gatech.edu for (i, n) in enumerate(cache_nodes): 9411663Stushar@ece.gatech.edu cntrl_level, router_id = divmod(i, num_routers) 9511663Stushar@ece.gatech.edu assert(cntrl_level < caches_per_router) 9611663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=n, 9711666Stushar@ece.gatech.edu int_node=routers[router_id], 9811666Stushar@ece.gatech.edu latency = link_latency)) 9911663Stushar@ece.gatech.edu link_count += 1 10011663Stushar@ece.gatech.edu 10111663Stushar@ece.gatech.edu # Connect the dir nodes to the corners. 10211663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[0], 10311666Stushar@ece.gatech.edu int_node=routers[0], 10411666Stushar@ece.gatech.edu latency = link_latency)) 10511663Stushar@ece.gatech.edu link_count += 1 10611663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[1], 10711666Stushar@ece.gatech.edu int_node=routers[num_columns - 1], 10811666Stushar@ece.gatech.edu latency = link_latency)) 10911663Stushar@ece.gatech.edu link_count += 1 11011663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[2], 11111666Stushar@ece.gatech.edu int_node=routers[num_routers - num_columns], 11211666Stushar@ece.gatech.edu latency = link_latency)) 11311663Stushar@ece.gatech.edu link_count += 1 11411663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[3], 11511666Stushar@ece.gatech.edu int_node=routers[num_routers - 1], 11611666Stushar@ece.gatech.edu latency = link_latency)) 11711663Stushar@ece.gatech.edu link_count += 1 11811663Stushar@ece.gatech.edu 11911663Stushar@ece.gatech.edu # Connect the dma nodes to router 0. These should only be DMA nodes. 12011663Stushar@ece.gatech.edu for (i, node) in enumerate(dma_nodes): 12111663Stushar@ece.gatech.edu assert(node.type == 'DMA_Controller') 12211663Stushar@ece.gatech.edu ext_links.append(ExtLink(link_id=link_count, ext_node=node, 12311666Stushar@ece.gatech.edu int_node=routers[0], 12411666Stushar@ece.gatech.edu latency = link_latency)) 12511663Stushar@ece.gatech.edu 12611663Stushar@ece.gatech.edu network.ext_links = ext_links 12711663Stushar@ece.gatech.edu 12811663Stushar@ece.gatech.edu # Create the mesh links. 12911663Stushar@ece.gatech.edu int_links = [] 13011663Stushar@ece.gatech.edu 13111663Stushar@ece.gatech.edu # East output to West input links (weight = 1) 13213731Sandreas.sandberg@arm.com for row in range(num_rows): 13313731Sandreas.sandberg@arm.com for col in range(num_columns): 13411663Stushar@ece.gatech.edu if (col + 1 < num_columns): 13511663Stushar@ece.gatech.edu east_out = col + (row * num_columns) 13611663Stushar@ece.gatech.edu west_in = (col + 1) + (row * num_columns) 13711663Stushar@ece.gatech.edu int_links.append(IntLink(link_id=link_count, 13811663Stushar@ece.gatech.edu src_node=routers[east_out], 13911663Stushar@ece.gatech.edu dst_node=routers[west_in], 14011666Stushar@ece.gatech.edu src_outport="East", 14111666Stushar@ece.gatech.edu dst_inport="West", 14211666Stushar@ece.gatech.edu latency = link_latency, 14311663Stushar@ece.gatech.edu weight=1)) 14411663Stushar@ece.gatech.edu link_count += 1 14511663Stushar@ece.gatech.edu 14611663Stushar@ece.gatech.edu # West output to East input links (weight = 1) 14713731Sandreas.sandberg@arm.com for row in range(num_rows): 14813731Sandreas.sandberg@arm.com for col in range(num_columns): 14911663Stushar@ece.gatech.edu if (col + 1 < num_columns): 15011663Stushar@ece.gatech.edu east_in = col + (row * num_columns) 15111663Stushar@ece.gatech.edu west_out = (col + 1) + (row * num_columns) 15211663Stushar@ece.gatech.edu int_links.append(IntLink(link_id=link_count, 15311663Stushar@ece.gatech.edu src_node=routers[west_out], 15411663Stushar@ece.gatech.edu dst_node=routers[east_in], 15511666Stushar@ece.gatech.edu src_outport="West", 15611666Stushar@ece.gatech.edu dst_inport="East", 15711666Stushar@ece.gatech.edu latency = link_latency, 15811663Stushar@ece.gatech.edu weight=1)) 15911663Stushar@ece.gatech.edu link_count += 1 16011663Stushar@ece.gatech.edu 16111663Stushar@ece.gatech.edu # North output to South input links (weight = 2) 16213731Sandreas.sandberg@arm.com for col in range(num_columns): 16313731Sandreas.sandberg@arm.com for row in range(num_rows): 16411663Stushar@ece.gatech.edu if (row + 1 < num_rows): 16511663Stushar@ece.gatech.edu north_out = col + (row * num_columns) 16611663Stushar@ece.gatech.edu south_in = col + ((row + 1) * num_columns) 16711663Stushar@ece.gatech.edu int_links.append(IntLink(link_id=link_count, 16811663Stushar@ece.gatech.edu src_node=routers[north_out], 16911663Stushar@ece.gatech.edu dst_node=routers[south_in], 17011666Stushar@ece.gatech.edu src_outport="North", 17111666Stushar@ece.gatech.edu dst_inport="South", 17211666Stushar@ece.gatech.edu latency = link_latency, 17311663Stushar@ece.gatech.edu weight=2)) 17411663Stushar@ece.gatech.edu link_count += 1 17511663Stushar@ece.gatech.edu 17611663Stushar@ece.gatech.edu # South output to North input links (weight = 2) 17713731Sandreas.sandberg@arm.com for col in range(num_columns): 17813731Sandreas.sandberg@arm.com for row in range(num_rows): 17911663Stushar@ece.gatech.edu if (row + 1 < num_rows): 18011663Stushar@ece.gatech.edu north_in = col + (row * num_columns) 18111663Stushar@ece.gatech.edu south_out = col + ((row + 1) * num_columns) 18211663Stushar@ece.gatech.edu int_links.append(IntLink(link_id=link_count, 18311663Stushar@ece.gatech.edu src_node=routers[south_out], 18411663Stushar@ece.gatech.edu dst_node=routers[north_in], 18511666Stushar@ece.gatech.edu src_outport="South", 18611666Stushar@ece.gatech.edu dst_inport="North", 18711666Stushar@ece.gatech.edu latency = link_latency, 18811663Stushar@ece.gatech.edu weight=2)) 18911663Stushar@ece.gatech.edu link_count += 1 19011663Stushar@ece.gatech.edu 19111663Stushar@ece.gatech.edu 19211663Stushar@ece.gatech.edu network.int_links = int_links 193