Network.py revision 12014
12SN/A# Copyright (c) 2016 Georgia Institute of Technology
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: Tushar Krishna
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.eduimport math
302SN/Aimport m5
312SN/Afrom m5.objects import *
321388SN/Afrom m5.defines import buildEnv
332SN/Afrom m5.util import addToPath, fatal
342SN/A
352SN/Adef define_options(parser):
361191SN/A    # By default, ruby uses the simple timing cpu
371191SN/A    parser.set_defaults(cpu_type="TimingSimpleCPU")
381191SN/A
391388SN/A    parser.add_option("--topology", type="string", default="Crossbar",
401717SN/A                      help="check configs/topologies for complete set")
412651Ssaidi@eecs.umich.edu    parser.add_option("--mesh-rows", type="int", default=0,
422680Sktlim@umich.edu                      help="the number of rows in the mesh topology")
431977SN/A    parser.add_option("--network", type="choice", default="simple",
443144Shsul@eecs.umich.edu                      choices=['simple', 'garnet2.0'],
45161SN/A                      help="'simple'|'garnet2.0'")
462190SN/A    parser.add_option("--router-latency", action="store", type="int",
4756SN/A                      default=1,
482190SN/A                      help="""number of pipeline stages in the garnet router.
492SN/A                            Has to be >= 1.
501062SN/A                            Can be over-ridden on a per router basis
511062SN/A                            in the topology file.""")
522359SN/A    parser.add_option("--link-latency", action="store", type="int", default=1,
532359SN/A                      help="""latency of each link the simple/garnet networks.
542359SN/A                            Has to be >= 1.
552SN/A                            Can be over-ridden on a per link basis
562SN/A                            in the topology file.""")
572SN/A    parser.add_option("--link-width-bits", action="store", type="int",
582SN/A                      default=128,
592SN/A                      help="width in bits for all links inside garnet.")
602SN/A    parser.add_option("--vcs-per-vnet", action="store", type="int", default=4,
612SN/A                      help="""number of virtual channels per virtual network
622SN/A                            inside garnet network.""")
632SN/A    parser.add_option("--routing-algorithm", action="store", type="int",
643126Sktlim@umich.edu                      default=0,
653126Sktlim@umich.edu                      help="""routing algorithm in network.
663126Sktlim@umich.edu                            0: weight-based table
673126Sktlim@umich.edu                            1: XY (for Mesh. see garnet2.0/RoutingUnit.cc)
683126Sktlim@umich.edu                            2: Custom (see garnet2.0/RoutingUnit.cc""")
693126Sktlim@umich.edu    parser.add_option("--network-fault-model", action="store_true",
703126Sktlim@umich.edu                      default=False,
713126Sktlim@umich.edu                      help="""enable network fault model:
723126Sktlim@umich.edu                            see src/mem/ruby/network/fault_model/""")
732356SN/A    parser.add_option("--garnet-deadlock-threshold", action="store",
742356SN/A                      type="int", default=50000,
752356SN/A                      help="network-level deadlock threshold.")
762367SN/A
772356SN/A
782356SN/Adef create_network(options, ruby):
792367SN/A
802356SN/A    # Set the network classes based on the command line options
812356SN/A    if options.network == "garnet2.0":
822356SN/A        NetworkClass = GarnetNetwork
832367SN/A        IntLinkClass = GarnetIntLink
842367SN/A        ExtLinkClass = GarnetExtLink
852367SN/A        RouterClass = GarnetRouter
862367SN/A        InterfaceClass = GarnetNetworkInterface
872356SN/A
882356SN/A    else:
892356SN/A        NetworkClass = SimpleNetwork
902356SN/A        IntLinkClass = SimpleIntLink
912356SN/A        ExtLinkClass = SimpleExtLink
922356SN/A        RouterClass = Switch
932356SN/A        InterfaceClass = None
942356SN/A
952356SN/A    # Instantiate the network object
962356SN/A    # so that the controllers can connect to it.
971858SN/A    network = NetworkClass(ruby_system = ruby, topology = options.topology,
981400SN/A            routers = [], ext_links = [], int_links = [], netifs = [])
992881Srdreslin@umich.edu
1001400SN/A    return (network, IntLinkClass, ExtLinkClass, RouterClass, InterfaceClass)
1012SN/A
1021400SN/Adef init_network(options, network, InterfaceClass):
1032856Srdreslin@umich.edu
1042378SN/A    if options.network == "garnet2.0":
1052SN/A        network.num_rows = options.mesh_rows
1062SN/A        network.vcs_per_vnet = options.vcs_per_vnet
1072359SN/A        network.ni_flit_size = options.link_width_bits / 8
1082831Sksewell@umich.edu        network.routing_algorithm = options.routing_algorithm
1091062SN/A        network.garnet_deadlock_threshold = options.garnet_deadlock_threshold
1102SN/A
1112SN/A    if options.network == "simple":
1122SN/A        network.setup_buffers()
1132831Sksewell@umich.edu
1141062SN/A    if InterfaceClass != None:
1151062SN/A        netifs = [InterfaceClass(id=i) \
1162SN/A                  for (i,n) in enumerate(network.ext_links)]
1172SN/A        network.netifs = netifs
1182SN/A
1192SN/A    if options.network_fault_model:
1201354SN/A        assert(options.network == "garnet2.0")
1212SN/A        network.enable_fault_model = True
122503SN/A        network.fault_model = FaultModel()
1232SN/A