MeshDirCorners_XY.py revision 11663
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
5011663Stushar@ece.gatech.edu        # First determine which nodes are cache cntrls vs. dirs vs. dma
5111663Stushar@ece.gatech.edu        cache_nodes = []
5211663Stushar@ece.gatech.edu        dir_nodes = []
5311663Stushar@ece.gatech.edu        dma_nodes = []
5411663Stushar@ece.gatech.edu        for node in nodes:
5511663Stushar@ece.gatech.edu            if node.type == 'L1Cache_Controller' or \
5611663Stushar@ece.gatech.edu            node.type == 'L2Cache_Controller':
5711663Stushar@ece.gatech.edu                cache_nodes.append(node)
5811663Stushar@ece.gatech.edu            elif node.type == 'Directory_Controller':
5911663Stushar@ece.gatech.edu                dir_nodes.append(node)
6011663Stushar@ece.gatech.edu            elif node.type == 'DMA_Controller':
6111663Stushar@ece.gatech.edu                dma_nodes.append(node)
6211663Stushar@ece.gatech.edu
6311663Stushar@ece.gatech.edu        # Obviously the number or rows must be <= the number of routers
6411663Stushar@ece.gatech.edu        # and evenly divisible.  Also the number of caches must be a
6511663Stushar@ece.gatech.edu        # multiple of the number of routers and the number of directories
6611663Stushar@ece.gatech.edu        # must be four.
6711663Stushar@ece.gatech.edu        assert(num_rows <= num_routers)
6811663Stushar@ece.gatech.edu        num_columns = int(num_routers / num_rows)
6911663Stushar@ece.gatech.edu        assert(num_columns * num_rows == num_routers)
7011663Stushar@ece.gatech.edu        caches_per_router, remainder = divmod(len(cache_nodes), num_routers)
7111663Stushar@ece.gatech.edu        assert(remainder == 0)
7211663Stushar@ece.gatech.edu        assert(len(dir_nodes) == 4)
7311663Stushar@ece.gatech.edu
7411663Stushar@ece.gatech.edu        # Create the routers in the mesh
7511663Stushar@ece.gatech.edu        routers = [Router(router_id=i) for i in range(num_routers)]
7611663Stushar@ece.gatech.edu        network.routers = routers
7711663Stushar@ece.gatech.edu
7811663Stushar@ece.gatech.edu        # link counter to set unique link ids
7911663Stushar@ece.gatech.edu        link_count = 0
8011663Stushar@ece.gatech.edu
8111663Stushar@ece.gatech.edu        # Connect each cache controller to the appropriate router
8211663Stushar@ece.gatech.edu        ext_links = []
8311663Stushar@ece.gatech.edu        for (i, n) in enumerate(cache_nodes):
8411663Stushar@ece.gatech.edu            cntrl_level, router_id = divmod(i, num_routers)
8511663Stushar@ece.gatech.edu            assert(cntrl_level < caches_per_router)
8611663Stushar@ece.gatech.edu            ext_links.append(ExtLink(link_id=link_count, ext_node=n,
8711663Stushar@ece.gatech.edu                                    int_node=routers[router_id]))
8811663Stushar@ece.gatech.edu            link_count += 1
8911663Stushar@ece.gatech.edu
9011663Stushar@ece.gatech.edu        # Connect the dir nodes to the corners.
9111663Stushar@ece.gatech.edu        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[0],
9211663Stushar@ece.gatech.edu                                int_node=routers[0]))
9311663Stushar@ece.gatech.edu        link_count += 1
9411663Stushar@ece.gatech.edu        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[1],
9511663Stushar@ece.gatech.edu                                int_node=routers[num_columns - 1]))
9611663Stushar@ece.gatech.edu        link_count += 1
9711663Stushar@ece.gatech.edu        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[2],
9811663Stushar@ece.gatech.edu                                int_node=routers[num_routers - num_columns]))
9911663Stushar@ece.gatech.edu        link_count += 1
10011663Stushar@ece.gatech.edu        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[3],
10111663Stushar@ece.gatech.edu                                int_node=routers[num_routers - 1]))
10211663Stushar@ece.gatech.edu        link_count += 1
10311663Stushar@ece.gatech.edu
10411663Stushar@ece.gatech.edu        # Connect the dma nodes to router 0.  These should only be DMA nodes.
10511663Stushar@ece.gatech.edu        for (i, node) in enumerate(dma_nodes):
10611663Stushar@ece.gatech.edu            assert(node.type == 'DMA_Controller')
10711663Stushar@ece.gatech.edu            ext_links.append(ExtLink(link_id=link_count, ext_node=node,
10811663Stushar@ece.gatech.edu                                     int_node=routers[0]))
10911663Stushar@ece.gatech.edu
11011663Stushar@ece.gatech.edu        network.ext_links = ext_links
11111663Stushar@ece.gatech.edu
11211663Stushar@ece.gatech.edu        # Create the mesh links.
11311663Stushar@ece.gatech.edu        int_links = []
11411663Stushar@ece.gatech.edu
11511663Stushar@ece.gatech.edu        # East output to West input links (weight = 1)
11611663Stushar@ece.gatech.edu        for row in xrange(num_rows):
11711663Stushar@ece.gatech.edu            for col in xrange(num_columns):
11811663Stushar@ece.gatech.edu                if (col + 1 < num_columns):
11911663Stushar@ece.gatech.edu                    east_out = col + (row * num_columns)
12011663Stushar@ece.gatech.edu                    west_in = (col + 1) + (row * num_columns)
12111663Stushar@ece.gatech.edu                    int_links.append(IntLink(link_id=link_count,
12211663Stushar@ece.gatech.edu                                             src_node=routers[east_out],
12311663Stushar@ece.gatech.edu                                             dst_node=routers[west_in],
12411663Stushar@ece.gatech.edu                                             weight=1))
12511663Stushar@ece.gatech.edu                    link_count += 1
12611663Stushar@ece.gatech.edu
12711663Stushar@ece.gatech.edu        # West output to East input links (weight = 1)
12811663Stushar@ece.gatech.edu        for row in xrange(num_rows):
12911663Stushar@ece.gatech.edu            for col in xrange(num_columns):
13011663Stushar@ece.gatech.edu                if (col + 1 < num_columns):
13111663Stushar@ece.gatech.edu                    east_in = col + (row * num_columns)
13211663Stushar@ece.gatech.edu                    west_out = (col + 1) + (row * num_columns)
13311663Stushar@ece.gatech.edu                    int_links.append(IntLink(link_id=link_count,
13411663Stushar@ece.gatech.edu                                             src_node=routers[west_out],
13511663Stushar@ece.gatech.edu                                             dst_node=routers[east_in],
13611663Stushar@ece.gatech.edu                                             weight=1))
13711663Stushar@ece.gatech.edu                    link_count += 1
13811663Stushar@ece.gatech.edu
13911663Stushar@ece.gatech.edu        # North output to South input links (weight = 2)
14011663Stushar@ece.gatech.edu        for col in xrange(num_columns):
14111663Stushar@ece.gatech.edu            for row in xrange(num_rows):
14211663Stushar@ece.gatech.edu                if (row + 1 < num_rows):
14311663Stushar@ece.gatech.edu                    north_out = col + (row * num_columns)
14411663Stushar@ece.gatech.edu                    south_in = col + ((row + 1) * num_columns)
14511663Stushar@ece.gatech.edu                    int_links.append(IntLink(link_id=link_count,
14611663Stushar@ece.gatech.edu                                             src_node=routers[north_out],
14711663Stushar@ece.gatech.edu                                             dst_node=routers[south_in],
14811663Stushar@ece.gatech.edu                                             weight=2))
14911663Stushar@ece.gatech.edu                    link_count += 1
15011663Stushar@ece.gatech.edu
15111663Stushar@ece.gatech.edu        # South output to North input links (weight = 2)
15211663Stushar@ece.gatech.edu        for col in xrange(num_columns):
15311663Stushar@ece.gatech.edu            for row in xrange(num_rows):
15411663Stushar@ece.gatech.edu                if (row + 1 < num_rows):
15511663Stushar@ece.gatech.edu                    north_in = col + (row * num_columns)
15611663Stushar@ece.gatech.edu                    south_out = col + ((row + 1) * num_columns)
15711663Stushar@ece.gatech.edu                    int_links.append(IntLink(link_id=link_count,
15811663Stushar@ece.gatech.edu                                             src_node=routers[south_out],
15911663Stushar@ece.gatech.edu                                             dst_node=routers[north_in],
16011663Stushar@ece.gatech.edu                                             weight=2))
16111663Stushar@ece.gatech.edu                    link_count += 1
16211663Stushar@ece.gatech.edu
16311663Stushar@ece.gatech.edu
16411663Stushar@ece.gatech.edu        network.int_links = int_links
165