Cluster.py revision 9148:a7a72f42919e
12SN/A# Copyright (c) 2012 Advanced Micro Devices, Inc.
21762SN/A# All rights reserved.
32SN/A#
42SN/A# Redistribution and use in source and binary forms, with or without
52SN/A# modification, are permitted provided that the following conditions are
62SN/A# met: redistributions of source code must retain the above copyright
72SN/A# notice, this list of conditions and the following disclaimer;
82SN/A# redistributions in binary form must reproduce the above copyright
92SN/A# notice, this list of conditions and the following disclaimer in the
102SN/A# documentation and/or other materials provided with the distribution;
112SN/A# neither the name of the copyright holders nor the names of its
122SN/A# contributors may be used to endorse or promote products derived from
132SN/A# this software without specific prior written permission.
142SN/A#
152SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262SN/A#
272665Ssaidi@eecs.umich.edu# Authors: Jason Power
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu
302665Ssaidi@eecs.umich.edufrom BaseTopology import BaseTopology
312SN/A
322SN/Aclass Cluster(BaseTopology):
332SN/A    """ A cluster is a group of nodes which are all one hop from eachother
342SN/A        Clusters can also contain other clusters
352SN/A        When creating this kind of topology, return a single cluster (usually
362984Sgblack@eecs.umich.edu        the root cluster) from create_system in configs/ruby/<protocol>.py
372171SN/A    """
382984Sgblack@eecs.umich.edu
39146SN/A    _num_int_links = 0
40146SN/A    _num_ext_links = 0
41146SN/A    _num_routers = 0
422680Sktlim@umich.edu
432SN/A    # Below methods for auto counting
442SN/A    @classmethod
452SN/A    def num_int_links(cls):
464088Sbinkertn@umich.edu        cls._num_int_links += 1
475569Snate@binkert.org        return cls._num_int_links - 1
483838Shsul@eecs.umich.edu    @classmethod
493838Shsul@eecs.umich.edu    def num_ext_links(cls):
503838Shsul@eecs.umich.edu        cls._num_ext_links += 1
513838Shsul@eecs.umich.edu        return cls._num_ext_links - 1
525569Snate@binkert.org    @classmethod
53860SN/A    def num_routers(cls):
543838Shsul@eecs.umich.edu        cls._num_routers += 1
553838Shsul@eecs.umich.edu        return cls._num_routers - 1
56860SN/A
57860SN/A    def __init__(self, intBW=0, extBW=0, intLatency=0, extLatency=0):
585569Snate@binkert.org        """ internalBandwidth is bandwidth of all links within the cluster
591147SN/A            externalBandwidth is bandwidth from this cluster to any cluster
605034Smilesck@eecs.umich.edu                connecting to it.
615358Sgblack@eecs.umich.edu            internal/externalLatency are similar
623838Shsul@eecs.umich.edu            **** When creating a cluster with sub-clusters, the sub-cluster
635004Sgblack@eecs.umich.edu                 external bandwidth overrides the internal bandwidth of the
645004Sgblack@eecs.umich.edu                 super cluster
654957Sacolyte@umich.edu        """
663838Shsul@eecs.umich.edu        self.nodes = []
672SN/A        self.router = None # created in makeTopology
683838Shsul@eecs.umich.edu        self.intBW = intBW
693838Shsul@eecs.umich.edu        self.extBW = extBW
703838Shsul@eecs.umich.edu        self.intLatency = intLatency
713838Shsul@eecs.umich.edu        self.extLatency = extLatency
723838Shsul@eecs.umich.edu
732SN/A    def add(self, node):
746022Sgblack@eecs.umich.edu        self.nodes.append(node)
756022Sgblack@eecs.umich.edu
766022Sgblack@eecs.umich.edu    def makeTopology(self, options, IntLink, ExtLink, Router):
776022Sgblack@eecs.umich.edu        """ Recursively make all of the links and routers
786022Sgblack@eecs.umich.edu        """
796022Sgblack@eecs.umich.edu        routers = []
806022Sgblack@eecs.umich.edu        int_links = []
816022Sgblack@eecs.umich.edu        ext_links = []
826022Sgblack@eecs.umich.edu
836022Sgblack@eecs.umich.edu        # make a router to connect all of the nodes
846022Sgblack@eecs.umich.edu        self.router = Router(router_id=self.num_routers())
856022Sgblack@eecs.umich.edu        routers.append(self.router)
866022Sgblack@eecs.umich.edu        for node in self.nodes:
876022Sgblack@eecs.umich.edu            if type(node) == Cluster:
886022Sgblack@eecs.umich.edu                subRouters, subIntLinks, subExtLinks = node.makeTopology(options, IntLink, ExtLink, Router)
896022Sgblack@eecs.umich.edu                routers += subRouters
906022Sgblack@eecs.umich.edu                int_links += subIntLinks
916022Sgblack@eecs.umich.edu                ext_links += subExtLinks
926022Sgblack@eecs.umich.edu
936022Sgblack@eecs.umich.edu                # connect this cluster to the router
946022Sgblack@eecs.umich.edu                link = IntLink(link_id=self.num_int_links(), node_a=self.router, node_b=node.router)
956022Sgblack@eecs.umich.edu                if node.extBW:
966022Sgblack@eecs.umich.edu                    link.bandwidth_factor = node.extBW
976022Sgblack@eecs.umich.edu                elif self.intBW: # if there is an interanl b/w for this node and no ext b/w to override
986022Sgblack@eecs.umich.edu                    link.bandwidth_factor = self.intBW
996022Sgblack@eecs.umich.edu
1006022Sgblack@eecs.umich.edu                if node.extLatency:
1016022Sgblack@eecs.umich.edu                    link.latency = node.extLatency
1026022Sgblack@eecs.umich.edu                elif self.intLatency:
1036022Sgblack@eecs.umich.edu                    link.latency = self.intLatency
1046022Sgblack@eecs.umich.edu
1056022Sgblack@eecs.umich.edu                int_links.append(link)
1066022Sgblack@eecs.umich.edu            else:
1076022Sgblack@eecs.umich.edu                # node is just a controller connect it to the router via a ext_link
1086022Sgblack@eecs.umich.edu                link = ExtLink(link_id=self.num_ext_links(), ext_node=node, int_node=self.router)
1096022Sgblack@eecs.umich.edu                if self.intBW:
1106022Sgblack@eecs.umich.edu                    link.bandwidth_factor = self.intBW
1116022Sgblack@eecs.umich.edu                if self.intLatency:
1126022Sgblack@eecs.umich.edu                    link.latency = self.intLatency
1136022Sgblack@eecs.umich.edu
1146022Sgblack@eecs.umich.edu                ext_links.append(link)
1156022Sgblack@eecs.umich.edu
1166022Sgblack@eecs.umich.edu        return routers, int_links, ext_links
1176022Sgblack@eecs.umich.edu
1186022Sgblack@eecs.umich.edu    def __len__(self):
1196022Sgblack@eecs.umich.edu        return len([i for i in self.nodes if type(i) != Cluster]) + \
1206022Sgblack@eecs.umich.edu               sum([len(i) for i in self.nodes if type(i) == Cluster])
1216022Sgblack@eecs.umich.edu