garnet_synth_traffic.py revision 13774
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# Author: Tushar Krishna 28 29from __future__ import print_function 30from __future__ import absolute_import 31 32import m5 33from m5.objects import * 34from m5.defines import buildEnv 35from m5.util import addToPath 36import os, optparse, sys 37 38addToPath('../') 39 40from common import Options 41from ruby import Ruby 42 43# Get paths we might need. It's expected this file is in m5/configs/example. 44config_path = os.path.dirname(os.path.abspath(__file__)) 45config_root = os.path.dirname(config_path) 46m5_root = os.path.dirname(config_root) 47 48parser = optparse.OptionParser() 49Options.addNoISAOptions(parser) 50 51parser.add_option("--synthetic", type="choice", default="uniform_random", 52 choices=['uniform_random', 'tornado', 'bit_complement', \ 53 'bit_reverse', 'bit_rotation', 'neighbor', \ 54 'shuffle', 'transpose']) 55 56parser.add_option("-i", "--injectionrate", type="float", default=0.1, 57 metavar="I", 58 help="Injection rate in packets per cycle per node. \ 59 Takes decimal value between 0 to 1 (eg. 0.225). \ 60 Number of digits after 0 depends upon --precision.") 61 62parser.add_option("--precision", type="int", default=3, 63 help="Number of digits of precision after decimal point\ 64 for injection rate") 65 66parser.add_option("--sim-cycles", type="int", default=1000, 67 help="Number of simulation cycles") 68 69parser.add_option("--num-packets-max", type="int", default=-1, 70 help="Stop injecting after --num-packets-max.\ 71 Set to -1 to disable.") 72 73parser.add_option("--single-sender-id", type="int", default=-1, 74 help="Only inject from this sender.\ 75 Set to -1 to disable.") 76 77parser.add_option("--single-dest-id", type="int", default=-1, 78 help="Only send to this destination.\ 79 Set to -1 to disable.") 80 81parser.add_option("--inj-vnet", type="int", default=-1, 82 help="Only inject in this vnet (0, 1 or 2).\ 83 0 and 1 are 1-flit, 2 is 5-flit.\ 84 Set to -1 to inject randomly in all vnets.") 85 86# 87# Add the ruby specific and protocol specific options 88# 89Ruby.define_options(parser) 90 91exec(compile(open(os.path.join(config_root, "common", "Options.py")).read(), 92 os.path.join(config_root, "common", "Options.py"), 'exec')) 93 94(options, args) = parser.parse_args() 95 96if args: 97 print("Error: script doesn't take any positional arguments") 98 sys.exit(1) 99 100 101if options.inj_vnet > 2: 102 print("Error: Injection vnet %d should be 0 (1-flit), 1 (1-flit) " 103 "or 2 (5-flit) or -1 (random)" % (options.inj_vnet)) 104 sys.exit(1) 105 106 107cpus = [ GarnetSyntheticTraffic( 108 num_packets_max=options.num_packets_max, 109 single_sender=options.single_sender_id, 110 single_dest=options.single_dest_id, 111 sim_cycles=options.sim_cycles, 112 traffic_type=options.synthetic, 113 inj_rate=options.injectionrate, 114 inj_vnet=options.inj_vnet, 115 precision=options.precision, 116 num_dest=options.num_dirs) \ 117 for i in range(options.num_cpus) ] 118 119# create the desired simulated system 120system = System(cpu = cpus, mem_ranges = [AddrRange(options.mem_size)]) 121 122 123# Create a top-level voltage domain and clock domain 124system.voltage_domain = VoltageDomain(voltage = options.sys_voltage) 125 126system.clk_domain = SrcClockDomain(clock = options.sys_clock, 127 voltage_domain = system.voltage_domain) 128 129Ruby.create_system(options, False, system) 130 131# Create a seperate clock domain for Ruby 132system.ruby.clk_domain = SrcClockDomain(clock = options.ruby_clock, 133 voltage_domain = system.voltage_domain) 134 135i = 0 136for ruby_port in system.ruby._cpu_ports: 137 # 138 # Tie the cpu test ports to the ruby cpu port 139 # 140 cpus[i].test = ruby_port.slave 141 i += 1 142 143# ----------------------- 144# run simulation 145# ----------------------- 146 147root = Root(full_system = False, system = system) 148root.system.mem_mode = 'timing' 149 150# Not much point in this being higher than the L1 latency 151m5.ticks.setGlobalFrequency('1ns') 152 153# instantiate configuration 154m5.instantiate() 155 156# simulate until program terminates 157exit_event = m5.simulate(options.abs_max_tick) 158 159print('Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()) 160