Mesh_XY.py revision 11663
111663Stushar@ece.gatech.edu# Copyright (c) 2010 Advanced Micro Devices, Inc.
211663Stushar@ece.gatech.edu#               2016 Georgia Institute of Technology
311663Stushar@ece.gatech.edu# All rights reserved.
411663Stushar@ece.gatech.edu#
511663Stushar@ece.gatech.edu# Redistribution and use in source and binary forms, with or without
611663Stushar@ece.gatech.edu# modification, are permitted provided that the following conditions are
711663Stushar@ece.gatech.edu# met: redistributions of source code must retain the above copyright
811663Stushar@ece.gatech.edu# notice, this list of conditions and the following disclaimer;
911663Stushar@ece.gatech.edu# redistributions in binary form must reproduce the above copyright
1011663Stushar@ece.gatech.edu# notice, this list of conditions and the following disclaimer in the
1111663Stushar@ece.gatech.edu# documentation and/or other materials provided with the distribution;
1211663Stushar@ece.gatech.edu# neither the name of the copyright holders nor the names of its
1311663Stushar@ece.gatech.edu# contributors may be used to endorse or promote products derived from
1411663Stushar@ece.gatech.edu# this software without specific prior written permission.
1511663Stushar@ece.gatech.edu#
1611663Stushar@ece.gatech.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1711663Stushar@ece.gatech.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1811663Stushar@ece.gatech.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1911663Stushar@ece.gatech.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2011663Stushar@ece.gatech.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2111663Stushar@ece.gatech.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2211663Stushar@ece.gatech.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2311663Stushar@ece.gatech.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2411663Stushar@ece.gatech.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2511663Stushar@ece.gatech.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2611663Stushar@ece.gatech.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2711663Stushar@ece.gatech.edu#
2811663Stushar@ece.gatech.edu# Authors: Brad Beckmann
2911663Stushar@ece.gatech.edu#          Tushar Krishna
3011663Stushar@ece.gatech.edu
3111663Stushar@ece.gatech.edufrom m5.params import *
3211663Stushar@ece.gatech.edufrom m5.objects import *
3311663Stushar@ece.gatech.edu
3411663Stushar@ece.gatech.edufrom BaseTopology import SimpleTopology
3511663Stushar@ece.gatech.edu
3611663Stushar@ece.gatech.edu# Creates a generic Mesh assuming an equal number of cache
3711663Stushar@ece.gatech.edu# and directory controllers.
3811663Stushar@ece.gatech.edu# XY routing is enforced (using link weights)
3911663Stushar@ece.gatech.edu# to guarantee deadlock freedom.
4011663Stushar@ece.gatech.edu
4111663Stushar@ece.gatech.educlass Mesh_XY(SimpleTopology):
4211663Stushar@ece.gatech.edu    description='Mesh_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    # Makes a generic mesh
4811663Stushar@ece.gatech.edu    # assuming an equal number of cache and directory cntrls
4911663Stushar@ece.gatech.edu
5011663Stushar@ece.gatech.edu    def makeTopology(self, options, network, IntLink, ExtLink, Router):
5111663Stushar@ece.gatech.edu        nodes = self.nodes
5211663Stushar@ece.gatech.edu
5311663Stushar@ece.gatech.edu        num_routers = options.num_cpus
5411663Stushar@ece.gatech.edu        num_rows = options.mesh_rows
5511663Stushar@ece.gatech.edu
5611663Stushar@ece.gatech.edu        # There must be an evenly divisible number of cntrls to routers
5711663Stushar@ece.gatech.edu        # Also, obviously the number or rows must be <= the number of routers
5811663Stushar@ece.gatech.edu        cntrls_per_router, remainder = divmod(len(nodes), num_routers)
5911663Stushar@ece.gatech.edu        assert(num_rows <= num_routers)
6011663Stushar@ece.gatech.edu        num_columns = int(num_routers / num_rows)
6111663Stushar@ece.gatech.edu        assert(num_columns * num_rows == num_routers)
6211663Stushar@ece.gatech.edu
6311663Stushar@ece.gatech.edu        # Create the routers in the mesh
6411663Stushar@ece.gatech.edu        routers = [Router(router_id=i) for i in range(num_routers)]
6511663Stushar@ece.gatech.edu        network.routers = routers
6611663Stushar@ece.gatech.edu
6711663Stushar@ece.gatech.edu        # link counter to set unique link ids
6811663Stushar@ece.gatech.edu        link_count = 0
6911663Stushar@ece.gatech.edu
7011663Stushar@ece.gatech.edu        # Add all but the remainder nodes to the list of nodes to be uniformly
7111663Stushar@ece.gatech.edu        # distributed across the network.
7211663Stushar@ece.gatech.edu        network_nodes = []
7311663Stushar@ece.gatech.edu        remainder_nodes = []
7411663Stushar@ece.gatech.edu        for node_index in xrange(len(nodes)):
7511663Stushar@ece.gatech.edu            if node_index < (len(nodes) - remainder):
7611663Stushar@ece.gatech.edu                network_nodes.append(nodes[node_index])
7711663Stushar@ece.gatech.edu            else:
7811663Stushar@ece.gatech.edu                remainder_nodes.append(nodes[node_index])
7911663Stushar@ece.gatech.edu
8011663Stushar@ece.gatech.edu        # Connect each node to the appropriate router
8111663Stushar@ece.gatech.edu        ext_links = []
8211663Stushar@ece.gatech.edu        for (i, n) in enumerate(network_nodes):
8311663Stushar@ece.gatech.edu            cntrl_level, router_id = divmod(i, num_routers)
8411663Stushar@ece.gatech.edu            assert(cntrl_level < cntrls_per_router)
8511663Stushar@ece.gatech.edu            ext_links.append(ExtLink(link_id=link_count, ext_node=n,
8611663Stushar@ece.gatech.edu                                    int_node=routers[router_id]))
8711663Stushar@ece.gatech.edu            link_count += 1
8811663Stushar@ece.gatech.edu
8911663Stushar@ece.gatech.edu        # Connect the remainding nodes to router 0.  These should only be
9011663Stushar@ece.gatech.edu        # DMA nodes.
9111663Stushar@ece.gatech.edu        for (i, node) in enumerate(remainder_nodes):
9211663Stushar@ece.gatech.edu            assert(node.type == 'DMA_Controller')
9311663Stushar@ece.gatech.edu            assert(i < remainder)
9411663Stushar@ece.gatech.edu            ext_links.append(ExtLink(link_id=link_count, ext_node=node,
9511663Stushar@ece.gatech.edu                                    int_node=routers[0]))
9611663Stushar@ece.gatech.edu            link_count += 1
9711663Stushar@ece.gatech.edu
9811663Stushar@ece.gatech.edu        network.ext_links = ext_links
9911663Stushar@ece.gatech.edu
10011663Stushar@ece.gatech.edu        # Create the mesh links.
10111663Stushar@ece.gatech.edu        int_links = []
10211663Stushar@ece.gatech.edu
10311663Stushar@ece.gatech.edu        # East output to West input links (weight = 1)
10411663Stushar@ece.gatech.edu        for row in xrange(num_rows):
10511663Stushar@ece.gatech.edu            for col in xrange(num_columns):
10611663Stushar@ece.gatech.edu                if (col + 1 < num_columns):
10711663Stushar@ece.gatech.edu                    east_out = col + (row * num_columns)
10811663Stushar@ece.gatech.edu                    west_in = (col + 1) + (row * num_columns)
10911663Stushar@ece.gatech.edu                    int_links.append(IntLink(link_id=link_count,
11011663Stushar@ece.gatech.edu                                             src_node=routers[east_out],
11111663Stushar@ece.gatech.edu                                             dst_node=routers[west_in],
11211663Stushar@ece.gatech.edu                                             weight=1))
11311663Stushar@ece.gatech.edu                    link_count += 1
11411663Stushar@ece.gatech.edu
11511663Stushar@ece.gatech.edu        # West output to East 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_in = col + (row * num_columns)
12011663Stushar@ece.gatech.edu                    west_out = (col + 1) + (row * num_columns)
12111663Stushar@ece.gatech.edu                    int_links.append(IntLink(link_id=link_count,
12211663Stushar@ece.gatech.edu                                             src_node=routers[west_out],
12311663Stushar@ece.gatech.edu                                             dst_node=routers[east_in],
12411663Stushar@ece.gatech.edu                                             weight=1))
12511663Stushar@ece.gatech.edu                    link_count += 1
12611663Stushar@ece.gatech.edu
12711663Stushar@ece.gatech.edu        # North output to South input links (weight = 2)
12811663Stushar@ece.gatech.edu        for col in xrange(num_columns):
12911663Stushar@ece.gatech.edu            for row in xrange(num_rows):
13011663Stushar@ece.gatech.edu                if (row + 1 < num_rows):
13111663Stushar@ece.gatech.edu                    north_out = col + (row * num_columns)
13211663Stushar@ece.gatech.edu                    south_in = col + ((row + 1) * num_columns)
13311663Stushar@ece.gatech.edu                    int_links.append(IntLink(link_id=link_count,
13411663Stushar@ece.gatech.edu                                             src_node=routers[north_out],
13511663Stushar@ece.gatech.edu                                             dst_node=routers[south_in],
13611663Stushar@ece.gatech.edu                                             weight=2))
13711663Stushar@ece.gatech.edu                    link_count += 1
13811663Stushar@ece.gatech.edu
13911663Stushar@ece.gatech.edu        # South output to North 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_in = col + (row * num_columns)
14411663Stushar@ece.gatech.edu                    south_out = col + ((row + 1) * num_columns)
14511663Stushar@ece.gatech.edu                    int_links.append(IntLink(link_id=link_count,
14611663Stushar@ece.gatech.edu                                             src_node=routers[south_out],
14711663Stushar@ece.gatech.edu                                             dst_node=routers[north_in],
14811663Stushar@ece.gatech.edu                                             weight=2))
14911663Stushar@ece.gatech.edu                    link_count += 1
15011663Stushar@ece.gatech.edu
15111663Stushar@ece.gatech.edu
15211663Stushar@ece.gatech.edu        network.int_links = int_links
153