Network.py revision 11762
1# Copyright (c) 2016 Georgia Institute of Technology 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution; 11# neither the name of the copyright holders nor the names of its 12# contributors may be used to endorse or promote products derived from 13# this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Tushar Krishna 28 29import math 30import m5 31from m5.objects import * 32from m5.defines import buildEnv 33from m5.util import addToPath, fatal 34 35def define_options(parser): 36 # By default, ruby uses the simple timing cpu 37 parser.set_defaults(cpu_type="timing") 38 39 parser.add_option("--topology", type="string", default="Crossbar", 40 help="check configs/topologies for complete set") 41 parser.add_option("--mesh-rows", type="int", default=0, 42 help="the number of rows in the mesh topology") 43 parser.add_option("--network", type="choice", default="simple", 44 choices=['simple', 'garnet2.0'], 45 help="'simple'|'garnet2.0'") 46 parser.add_option("--router-latency", action="store", type="int", 47 default=1, 48 help="""number of pipeline stages in the garnet router. 49 Has to be >= 1. 50 Can be over-ridden on a per router basis 51 in the topology file.""") 52 parser.add_option("--link-latency", action="store", type="int", default=1, 53 help="""latency of each link the simple/garnet networks. 54 Has to be >= 1. 55 Can be over-ridden on a per link basis 56 in the topology file.""") 57 parser.add_option("--link-width-bits", action="store", type="int", 58 default=128, 59 help="width in bits for all links inside garnet.") 60 parser.add_option("--vcs-per-vnet", action="store", type="int", default=4, 61 help="""number of virtual channels per virtual network 62 inside garnet network.""") 63 parser.add_option("--routing-algorithm", action="store", type="int", 64 default=0, 65 help="""routing algorithm in network. 66 0: weight-based table 67 1: XY (for Mesh. see garnet2.0/RoutingUnit.cc) 68 2: Custom (see garnet2.0/RoutingUnit.cc""") 69 parser.add_option("--network-fault-model", action="store_true", 70 default=False, 71 help="""enable network fault model: 72 see src/mem/ruby/network/fault_model/""") 73 parser.add_option("--garnet-deadlock-threshold", action="store", 74 type="int", default=50000, 75 help="network-level deadlock threshold.") 76 77 78def create_network(options, ruby): 79 80 # Set the network classes based on the command line options 81 if options.network == "garnet2.0": 82 NetworkClass = GarnetNetwork 83 IntLinkClass = GarnetIntLink 84 ExtLinkClass = GarnetExtLink 85 RouterClass = GarnetRouter 86 InterfaceClass = GarnetNetworkInterface 87 88 else: 89 NetworkClass = SimpleNetwork 90 IntLinkClass = SimpleIntLink 91 ExtLinkClass = SimpleExtLink 92 RouterClass = Switch 93 InterfaceClass = None 94 95 # Instantiate the network object 96 # so that the controllers can connect to it. 97 network = NetworkClass(ruby_system = ruby, topology = options.topology, 98 routers = [], ext_links = [], int_links = [], netifs = []) 99 100 return (network, IntLinkClass, ExtLinkClass, RouterClass, InterfaceClass) 101 102def init_network(options, network, InterfaceClass): 103 104 if options.network == "garnet2.0": 105 network.num_rows = options.mesh_rows 106 network.vcs_per_vnet = options.vcs_per_vnet 107 network.ni_flit_size = options.link_width_bits / 8 108 network.routing_algorithm = options.routing_algorithm 109 network.garnet_deadlock_threshold = options.garnet_deadlock_threshold 110 111 if options.network == "simple": 112 network.setup_buffers() 113 114 if InterfaceClass != None: 115 netifs = [InterfaceClass(id=i) \ 116 for (i,n) in enumerate(network.ext_links)] 117 network.netifs = netifs 118 119 if options.network_fault_model: 120 assert(options.network == "garnet2.0") 121 network.enable_fault_model = True 122 network.fault_model = FaultModel() 123