cluster.py revision 11851
1# Copyright (c) 2006-2007 The Regents of The University of Michigan 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: Ron Dreslinski 28 29# Simple test script 30# 31# "m5 test.py" 32 33import os 34import optparse 35import sys 36 37import m5 38from m5.objects import * 39 40# -------------------- 41# Define Command Line Options 42# ==================== 43 44parser = optparse.OptionParser() 45 46parser.add_option("-d", "--detailed", action="store_true") 47parser.add_option("-t", "--timing", action="store_true") 48parser.add_option("-m", "--maxtick", type="int") 49parser.add_option("-c", "--numclusters", 50 help="Number of clusters", type="int") 51parser.add_option("-n", "--numcpus", 52 help="Number of cpus in total", type="int") 53parser.add_option("-f", "--frequency", 54 default = "1GHz", 55 help="Frequency of each CPU") 56parser.add_option("--l1size", 57 default = "32kB") 58parser.add_option("--l1latency", 59 default = 1) 60parser.add_option("--l2size", 61 default = "256kB") 62parser.add_option("--l2latency", 63 default = 10) 64parser.add_option("--rootdir", 65 help="ROot directory of Splash2", 66 default="/dist/splash2/codes/") 67parser.add_option("-b", "--benchmark", 68 help="Splash 2 benchmark to run") 69 70(options, args) = parser.parse_args() 71 72if args: 73 print "Error: script doesn't take any positional arguments" 74 sys.exit(1) 75 76# -------------------- 77# Define Splash2 Benchmarks 78# ==================== 79class Cholesky(Process): 80 executable = options.rootdir + '/kernels/cholesky/CHOLESKY' 81 cmd = 'CHOLESKY -p' + str(options.numcpus) + ' '\ 82 + options.rootdir + '/kernels/cholesky/inputs/tk23.O' 83 84class FFT(Process): 85 executable = options.rootdir + 'kernels/fft/FFT' 86 cmd = 'FFT -p' + str(options.numcpus) + ' -m18' 87 88class LU_contig(Process): 89 executable = options.rootdir + 'kernels/lu/contiguous_blocks/LU' 90 cmd = 'LU -p' + str(options.numcpus) 91 92class LU_noncontig(Process): 93 executable = options.rootdir + 'kernels/lu/non_contiguous_blocks/LU' 94 cmd = 'LU -p' + str(options.numcpus) 95 96class Radix(Process): 97 executable = options.rootdir + 'kernels/radix/RADIX' 98 cmd = 'RADIX -n524288 -p' + str(options.numcpus) 99 100class Barnes(Process): 101 executable = options.rootdir + 'apps/barnes/BARNES' 102 cmd = 'BARNES' 103 input = options.rootdir + 'apps/barnes/input.p' + str(options.numcpus) 104 105class FMM(Process): 106 executable = options.rootdir + 'apps/fmm/FMM' 107 cmd = 'FMM' 108 input = options.rootdir + 'apps/fmm/inputs/input.2048.p' + str(options.numcpus) 109 110class Ocean_contig(Process): 111 executable = options.rootdir + 'apps/ocean/contiguous_partitions/OCEAN' 112 cmd = 'OCEAN -p' + str(options.numcpus) 113 114class Ocean_noncontig(Process): 115 executable = options.rootdir + 'apps/ocean/non_contiguous_partitions/OCEAN' 116 cmd = 'OCEAN -p' + str(options.numcpus) 117 118class Raytrace(Process): 119 executable = options.rootdir + 'apps/raytrace/RAYTRACE' 120 cmd = 'RAYTRACE -p' + str(options.numcpus) + ' ' \ 121 + options.rootdir + 'apps/raytrace/inputs/teapot.env' 122 123class Water_nsquared(Process): 124 executable = options.rootdir + 'apps/water-nsquared/WATER-NSQUARED' 125 cmd = 'WATER-NSQUARED' 126 input = options.rootdir + 'apps/water-nsquared/input.p' + str(options.numcpus) 127 128class Water_spatial(Process): 129 executable = options.rootdir + 'apps/water-spatial/WATER-SPATIAL' 130 cmd = 'WATER-SPATIAL' 131 input = options.rootdir + 'apps/water-spatial/input.p' + str(options.numcpus) 132 133 134# -------------------- 135# Base L1 Cache Definition 136# ==================== 137 138class L1(Cache): 139 latency = options.l1latency 140 mshrs = 12 141 tgts_per_mshr = 8 142 143# ---------------------- 144# Base L2 Cache Definition 145# ---------------------- 146 147class L2(Cache): 148 latency = options.l2latency 149 mshrs = 92 150 tgts_per_mshr = 16 151 write_buffers = 8 152 153# ---------------------- 154# Define the clusters with their cpus 155# ---------------------- 156class Cluster: 157 pass 158 159cpusPerCluster = options.numcpus/options.numclusters 160 161busFrequency = Frequency(options.frequency) 162busFrequency *= cpusPerCluster 163 164all_cpus = [] 165all_l1s = [] 166all_l1buses = [] 167if options.timing: 168 clusters = [ Cluster() for i in xrange(options.numclusters)] 169 for j in xrange(options.numclusters): 170 clusters[j].id = j 171 for cluster in clusters: 172 cluster.clusterbus = L2XBar(clock=busFrequency) 173 all_l1buses += [cluster.clusterbus] 174 cluster.cpus = [TimingSimpleCPU(cpu_id = i + cluster.id, 175 clock=options.frequency) 176 for i in xrange(cpusPerCluster)] 177 all_cpus += cluster.cpus 178 cluster.l1 = L1(size=options.l1size, assoc = 4) 179 all_l1s += [cluster.l1] 180elif options.detailed: 181 clusters = [ Cluster() for i in xrange(options.numclusters)] 182 for j in xrange(options.numclusters): 183 clusters[j].id = j 184 for cluster in clusters: 185 cluster.clusterbus = L2XBar(clock=busFrequency) 186 all_l1buses += [cluster.clusterbus] 187 cluster.cpus = [DerivO3CPU(cpu_id = i + cluster.id, 188 clock=options.frequency) 189 for i in xrange(cpusPerCluster)] 190 all_cpus += cluster.cpus 191 cluster.l1 = L1(size=options.l1size, assoc = 4) 192 all_l1s += [cluster.l1] 193else: 194 clusters = [ Cluster() for i in xrange(options.numclusters)] 195 for j in xrange(options.numclusters): 196 clusters[j].id = j 197 for cluster in clusters: 198 cluster.clusterbus = L2XBar(clock=busFrequency) 199 all_l1buses += [cluster.clusterbus] 200 cluster.cpus = [AtomicSimpleCPU(cpu_id = i + cluster.id, 201 clock=options.frequency) 202 for i in xrange(cpusPerCluster)] 203 all_cpus += cluster.cpus 204 cluster.l1 = L1(size=options.l1size, assoc = 4) 205 all_l1s += [cluster.l1] 206 207# ---------------------- 208# Create a system, and add system wide objects 209# ---------------------- 210system = System(cpu = all_cpus, l1_ = all_l1s, l1bus_ = all_l1buses, 211 physmem = SimpleMemory(), 212 membus = SystemXBar(clock = busFrequency)) 213system.clock = '1GHz' 214 215system.toL2bus = L2XBar(clock = busFrequency) 216system.l2 = L2(size = options.l2size, assoc = 8) 217 218# ---------------------- 219# Connect the L2 cache and memory together 220# ---------------------- 221 222system.physmem.port = system.membus.master 223system.l2.cpu_side = system.toL2bus.slave 224system.l2.mem_side = system.membus.master 225 226# ---------------------- 227# Connect the L2 cache and clusters together 228# ---------------------- 229for cluster in clusters: 230 cluster.l1.cpu_side = cluster.clusterbus.master 231 cluster.l1.mem_side = system.toL2bus.slave 232 for cpu in cluster.cpus: 233 cpu.icache_port = cluster.clusterbus.slave 234 cpu.dcache_port = cluster.clusterbus.slave 235 236# ---------------------- 237# Define the root 238# ---------------------- 239 240root = Root(full_system = False, system = system) 241 242# -------------------- 243# Pick the correct Splash2 Benchmarks 244# ==================== 245if options.benchmark == 'Cholesky': 246 root.workload = Cholesky() 247elif options.benchmark == 'FFT': 248 root.workload = FFT() 249elif options.benchmark == 'LUContig': 250 root.workload = LU_contig() 251elif options.benchmark == 'LUNoncontig': 252 root.workload = LU_noncontig() 253elif options.benchmark == 'Radix': 254 root.workload = Radix() 255elif options.benchmark == 'Barnes': 256 root.workload = Barnes() 257elif options.benchmark == 'FMM': 258 root.workload = FMM() 259elif options.benchmark == 'OceanContig': 260 root.workload = Ocean_contig() 261elif options.benchmark == 'OceanNoncontig': 262 root.workload = Ocean_noncontig() 263elif options.benchmark == 'Raytrace': 264 root.workload = Raytrace() 265elif options.benchmark == 'WaterNSquared': 266 root.workload = Water_nsquared() 267elif options.benchmark == 'WaterSpatial': 268 root.workload = Water_spatial() 269else: 270 m5.util.panic(""" 271The --benchmark environment variable was set to something improper. 272Use Cholesky, FFT, LUContig, LUNoncontig, Radix, Barnes, FMM, OceanContig, 273OceanNoncontig, Raytrace, WaterNSquared, or WaterSpatial 274""") 275 276# -------------------- 277# Assign the workload to the cpus 278# ==================== 279 280for cluster in clusters: 281 for cpu in cluster.cpus: 282 cpu.workload = root.workload 283 284# ---------------------- 285# Run the simulation 286# ---------------------- 287 288if options.timing or options.detailed: 289 root.system.mem_mode = 'timing' 290 291# instantiate configuration 292m5.instantiate() 293 294# simulate until program terminates 295if options.maxtick: 296 exit_event = m5.simulate(options.maxtick) 297else: 298 exit_event = m5.simulate(m5.MaxTick) 299 300print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause() 301 302