Cluster.py revision 11663:cf870cd20cfc
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 302SN/Afrom BaseTopology import BaseTopology 312SN/A 324997Sgblack@eecs.umich.educlass Cluster(BaseTopology): 331110SN/A """ A cluster is a group of nodes which are all one hop from eachother 344997Sgblack@eecs.umich.edu Clusters can also contain other clusters 358229Snate@binkert.org When creating this kind of topology, return a single cluster (usually 368229Snate@binkert.org the root cluster) from create_system in configs/ruby/<protocol>.py 372680Sktlim@umich.edu """ 387676Snate@binkert.org 394997Sgblack@eecs.umich.edu _num_int_links = 0 408229Snate@binkert.org _num_ext_links = 0 412800Ssaidi@eecs.umich.edu _num_routers = 0 422289SN/A 432SN/A # Below methods for auto counting 445569Snate@binkert.org @classmethod 452167SN/A def num_int_links(cls): 462203SN/A cls._num_int_links += 1 472203SN/A return cls._num_int_links - 1 482222SN/A @classmethod 492166SN/A def num_ext_links(cls): 502203SN/A cls._num_ext_links += 1 512203SN/A return cls._num_ext_links - 1 522222SN/A @classmethod 532166SN/A def num_routers(cls): 542147SN/A cls._num_routers += 1 552147SN/A return cls._num_routers - 1 562222SN/A 572147SN/A def __init__(self, intBW=0, extBW=0, intLatency=0, extLatency=0): 582147SN/A """ internalBandwidth is bandwidth of all links within the cluster 592147SN/A externalBandwidth is bandwidth from this cluster to any cluster 602222SN/A connecting to it. 612147SN/A internal/externalLatency are similar 622147SN/A **** When creating a cluster with sub-clusters, the sub-cluster 632147SN/A external bandwidth overrides the internal bandwidth of the 642222SN/A super cluster 652147SN/A """ 662147SN/A self.nodes = [] 672147SN/A self.router = None # created in makeTopology 682222SN/A self.intBW = intBW 692147SN/A self.extBW = extBW 702147SN/A self.intLatency = intLatency 712147SN/A self.extLatency = extLatency 722222SN/A 732147SN/A def add(self, node): 742147SN/A self.nodes.append(node) 752147SN/A 762222SN/A def makeTopology(self, options, network, IntLink, ExtLink, Router): 772147SN/A """ Recursively make all of the links and routers 782147SN/A """ 792147SN/A 802222SN/A # make a router to connect all of the nodes 812147SN/A self.router = Router(router_id=self.num_routers()) 822289SN/A network.routers.append(self.router) 832289SN/A 842289SN/A for node in self.nodes: 852289SN/A if type(node) == Cluster: 862147SN/A node.makeTopology(options, network, IntLink, ExtLink, Router) 872147SN/A 882222SN/A # connect this cluster to the router 892147SN/A link_out = IntLink(link_id=self.num_int_links(), src_node=self.router, 902147SN/A dst_node_=node.router) 912147SN/A link_in = IntLink(link_id=self.num_int_links(), src_node=node.router, 922222SN/A dst_node_=self.router) 932147SN/A 942147SN/A if node.extBW: 952147SN/A link_out.bandwidth_factor = node.extBW 962222SN/A link_in.bandwidth_factor = node.extBW 972147SN/A 982147SN/A # if there is an internal b/w for this node 992147SN/A # and no ext b/w to override 1002222SN/A elif self.intBW: 1012147SN/A link_out.bandwidth_factor = self.intBW 1022147SN/A link_in.bandwidth_factor = self.intBW 1032147SN/A 1042222SN/A if node.extLatency: 1052147SN/A link_out.latency = node.extLatency 1062147SN/A link_in.latency = node.extLatency 1072147SN/A elif self.intLatency: 1082222SN/A link_out.latency = self.intLatency 1092147SN/A link_in.latency = self.intLatency 1102174SN/A 1112174SN/A network.int_links.append(link_out) 1125569Snate@binkert.org network.int_links.append(link_in) 1137678Sgblack@eecs.umich.edu else: 1142174SN/A # node is just a controller, 1152680Sktlim@umich.edu # connect it to the router via a ext_link 1162222SN/A link = ExtLink(link_id=self.num_ext_links(), ext_node=node, 1172174SN/A int_node=self.router) 1187720Sgblack@eecs.umich.edu 1197720Sgblack@eecs.umich.edu if self.intBW: 1202196SN/A link.bandwidth_factor = self.intBW 1217720Sgblack@eecs.umich.edu if self.intLatency: 1227720Sgblack@eecs.umich.edu link.latency = self.intLatency 1232196SN/A 1242201SN/A network.ext_links.append(link) 1252196SN/A 1265568Snate@binkert.org def __len__(self): 1275568Snate@binkert.org return len([i for i in self.nodes if type(i) != Cluster]) + \ 1282196SN/A sum([len(i) for i in self.nodes if type(i) == Cluster]) 1292196SN/A