MeshDirCorners_XY.py revision 11663:cf870cd20cfc
19243SN/A# Copyright (c) 2010 Advanced Micro Devices, Inc.
210206Sandreas.hansson@arm.com# All rights reserved.
39243SN/A#
49243SN/A# Redistribution and use in source and binary forms, with or without
59243SN/A# modification, are permitted provided that the following conditions are
69243SN/A# met: redistributions of source code must retain the above copyright
79243SN/A# notice, this list of conditions and the following disclaimer;
89243SN/A# redistributions in binary form must reproduce the above copyright
99243SN/A# notice, this list of conditions and the following disclaimer in the
109243SN/A# documentation and/or other materials provided with the distribution;
119243SN/A# neither the name of the copyright holders nor the names of its
129243SN/A# contributors may be used to endorse or promote products derived from
139243SN/A# this software without specific prior written permission.
149831SN/A#
159831SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
169831SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
179243SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
189243SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
199243SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
209243SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
219243SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
229243SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
239243SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
249243SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
259243SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
269243SN/A#
279243SN/A# Authors: Brad Beckmann
289243SN/A
299243SN/Afrom m5.params import *
309243SN/Afrom m5.objects import *
319243SN/A
329243SN/Afrom BaseTopology import SimpleTopology
339243SN/A
349243SN/A# Creates a Mesh topology with 4 directories, one at each corner.
359243SN/A# One L1 (and L2, depending on the protocol) are connected to each router.
369243SN/A# XY routing is enforced (using link weights) to guarantee deadlock freedom.
379243SN/A
389243SN/Aclass MeshDirCorners_XY(SimpleTopology):
399243SN/A    description='MeshDirCorners_XY'
409243SN/A
419243SN/A    def __init__(self, controllers):
429967SN/A        self.nodes = controllers
4310618SOmar.Naji@arm.com
449243SN/A    def makeTopology(self, options, network, IntLink, ExtLink, Router):
459243SN/A        nodes = self.nodes
4610146Sandreas.hansson@arm.com
479356SN/A        num_routers = options.num_cpus
4810146Sandreas.hansson@arm.com        num_rows = options.mesh_rows
4910247Sandreas.hansson@arm.com
5010208Sandreas.hansson@arm.com        # First determine which nodes are cache cntrls vs. dirs vs. dma
519352SN/A        cache_nodes = []
5210146Sandreas.hansson@arm.com        dir_nodes = []
539814SN/A        dma_nodes = []
549243SN/A        for node in nodes:
559243SN/A            if node.type == 'L1Cache_Controller' or \
5610432SOmar.Naji@arm.com            node.type == 'L2Cache_Controller':
579243SN/A                cache_nodes.append(node)
5810146Sandreas.hansson@arm.com            elif node.type == 'Directory_Controller':
599243SN/A                dir_nodes.append(node)
6010619Sandreas.hansson@arm.com            elif node.type == 'DMA_Controller':
619243SN/A                dma_nodes.append(node)
6210211Sandreas.hansson@arm.com
6310618SOmar.Naji@arm.com        # Obviously the number or rows must be <= the number of routers
6410208Sandreas.hansson@arm.com        # and evenly divisible.  Also the number of caches must be a
6510489SOmar.Naji@arm.com        # multiple of the number of routers and the number of directories
669831SN/A        # must be four.
679831SN/A        assert(num_rows <= num_routers)
689831SN/A        num_columns = int(num_routers / num_rows)
699831SN/A        assert(num_columns * num_rows == num_routers)
709831SN/A        caches_per_router, remainder = divmod(len(cache_nodes), num_routers)
7110140SN/A        assert(remainder == 0)
7210646Sandreas.hansson@arm.com        assert(len(dir_nodes) == 4)
739243SN/A
7410394Swendy.elsasser@arm.com        # Create the routers in the mesh
7510394Swendy.elsasser@arm.com        routers = [Router(router_id=i) for i in range(num_routers)]
769566SN/A        network.routers = routers
779243SN/A
789243SN/A        # link counter to set unique link ids
7910140SN/A        link_count = 0
8010140SN/A
8110147Sandreas.hansson@arm.com        # Connect each cache controller to the appropriate router
8210147Sandreas.hansson@arm.com        ext_links = []
8310393Swendy.elsasser@arm.com        for (i, n) in enumerate(cache_nodes):
8410394Swendy.elsasser@arm.com            cntrl_level, router_id = divmod(i, num_routers)
8510394Swendy.elsasser@arm.com            assert(cntrl_level < caches_per_router)
8610394Swendy.elsasser@arm.com            ext_links.append(ExtLink(link_id=link_count, ext_node=n,
879243SN/A                                    int_node=routers[router_id]))
889243SN/A            link_count += 1
8910141SN/A
909726SN/A        # Connect the dir nodes to the corners.
919726SN/A        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[0],
9210618SOmar.Naji@arm.com                                int_node=routers[0]))
9310618SOmar.Naji@arm.com        link_count += 1
949243SN/A        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[1],
9510620Sandreas.hansson@arm.com                                int_node=routers[num_columns - 1]))
9610620Sandreas.hansson@arm.com        link_count += 1
9710620Sandreas.hansson@arm.com        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[2],
9810620Sandreas.hansson@arm.com                                int_node=routers[num_routers - num_columns]))
9910620Sandreas.hansson@arm.com        link_count += 1
10010618SOmar.Naji@arm.com        ext_links.append(ExtLink(link_id=link_count, ext_node=dir_nodes[3],
10110618SOmar.Naji@arm.com                                int_node=routers[num_routers - 1]))
10210618SOmar.Naji@arm.com        link_count += 1
10310432SOmar.Naji@arm.com
10410618SOmar.Naji@arm.com        # Connect the dma nodes to router 0.  These should only be DMA nodes.
10510618SOmar.Naji@arm.com        for (i, node) in enumerate(dma_nodes):
10610618SOmar.Naji@arm.com            assert(node.type == 'DMA_Controller')
10710432SOmar.Naji@arm.com            ext_links.append(ExtLink(link_id=link_count, ext_node=node,
10810246Sandreas.hansson@arm.com                                     int_node=routers[0]))
10910618SOmar.Naji@arm.com
11010561SOmar.Naji@arm.com        network.ext_links = ext_links
11110561SOmar.Naji@arm.com
11210561SOmar.Naji@arm.com        # Create the mesh links.
11310394Swendy.elsasser@arm.com        int_links = []
11410394Swendy.elsasser@arm.com
11510394Swendy.elsasser@arm.com        # East output to West input links (weight = 1)
11610394Swendy.elsasser@arm.com        for row in xrange(num_rows):
11710394Swendy.elsasser@arm.com            for col in xrange(num_columns):
11810394Swendy.elsasser@arm.com                if (col + 1 < num_columns):
11910394Swendy.elsasser@arm.com                    east_out = col + (row * num_columns)
12010394Swendy.elsasser@arm.com                    west_in = (col + 1) + (row * num_columns)
12110618SOmar.Naji@arm.com                    int_links.append(IntLink(link_id=link_count,
12210394Swendy.elsasser@arm.com                                             src_node=routers[east_out],
12310394Swendy.elsasser@arm.com                                             dst_node=routers[west_in],
12410618SOmar.Naji@arm.com                                             weight=1))
12510394Swendy.elsasser@arm.com                    link_count += 1
12610246Sandreas.hansson@arm.com
12710246Sandreas.hansson@arm.com        # West output to East input links (weight = 1)
12810246Sandreas.hansson@arm.com        for row in xrange(num_rows):
12910140SN/A            for col in xrange(num_columns):
13010140SN/A                if (col + 1 < num_columns):
13110140SN/A                    east_in = col + (row * num_columns)
13210140SN/A                    west_out = (col + 1) + (row * num_columns)
13310140SN/A                    int_links.append(IntLink(link_id=link_count,
1349243SN/A                                             src_node=routers[west_out],
1359243SN/A                                             dst_node=routers[east_in],
1369567SN/A                                             weight=1))
1379243SN/A                    link_count += 1
13810489SOmar.Naji@arm.com
13910489SOmar.Naji@arm.com        # North output to South input links (weight = 2)
14010489SOmar.Naji@arm.com        for col in xrange(num_columns):
14110489SOmar.Naji@arm.com            for row in xrange(num_rows):
14210489SOmar.Naji@arm.com                if (row + 1 < num_rows):
14310489SOmar.Naji@arm.com                    north_out = col + (row * num_columns)
14410489SOmar.Naji@arm.com                    south_in = col + ((row + 1) * num_columns)
14510489SOmar.Naji@arm.com                    int_links.append(IntLink(link_id=link_count,
14610489SOmar.Naji@arm.com                                             src_node=routers[north_out],
14710489SOmar.Naji@arm.com                                             dst_node=routers[south_in],
1489243SN/A                                             weight=2))
1499243SN/A                    link_count += 1
1509831SN/A
1519831SN/A        # South output to North input links (weight = 2)
1529831SN/A        for col in xrange(num_columns):
1539831SN/A            for row in xrange(num_rows):
1549831SN/A                if (row + 1 < num_rows):
1559243SN/A                    north_in = col + (row * num_columns)
15610207Sandreas.hansson@arm.com                    south_out = col + ((row + 1) * num_columns)
15710207Sandreas.hansson@arm.com                    int_links.append(IntLink(link_id=link_count,
15810207Sandreas.hansson@arm.com                                             src_node=routers[south_out],
15910207Sandreas.hansson@arm.com                                             dst_node=routers[north_in],
16010207Sandreas.hansson@arm.com                                             weight=2))
16110394Swendy.elsasser@arm.com                    link_count += 1
16210394Swendy.elsasser@arm.com
16310394Swendy.elsasser@arm.com
16410394Swendy.elsasser@arm.com        network.int_links = int_links
16510394Swendy.elsasser@arm.com