cluster.py revision 3646
11689SN/A# Copyright (c) 2006 The Regents of The University of Michigan
22326SN/A# All rights reserved.
31689SN/A#
41689SN/A# Redistribution and use in source and binary forms, with or without
51689SN/A# modification, are permitted provided that the following conditions are
61689SN/A# met: redistributions of source code must retain the above copyright
71689SN/A# notice, this list of conditions and the following disclaimer;
81689SN/A# redistributions in binary form must reproduce the above copyright
91689SN/A# notice, this list of conditions and the following disclaimer in the
101689SN/A# documentation and/or other materials provided with the distribution;
111689SN/A# neither the name of the copyright holders nor the names of its
121689SN/A# contributors may be used to endorse or promote products derived from
131689SN/A# this software without specific prior written permission.
141689SN/A#
151689SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
161689SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
171689SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
181689SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
191689SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
201689SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
211689SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
221689SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
231689SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
241689SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
251689SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261689SN/A#
272665Ssaidi@eecs.umich.edu# Authors: Ron Dreslinski
282665Ssaidi@eecs.umich.edu
292831Sksewell@umich.edu# Simple test script
301689SN/A#
311689SN/A# "m5 test.py"
322064SN/A
331060SN/Aimport m5
341060SN/Afrom m5.objects import *
351696SN/Aimport os, optparse, sys
361689SN/Am5.AddToPath('../common')
372292SN/A
381717SN/A# --------------------
391060SN/A# Define Command Line Options
401061SN/A# ====================
412292SN/A
422292SN/Aparser = optparse.OptionParser()
432292SN/A
442292SN/Aparser.add_option("-d", "--detailed", action="store_true")
452326SN/Aparser.add_option("-t", "--timing", action="store_true")
461060SN/Aparser.add_option("-m", "--maxtick", type="int")
472292SN/Aparser.add_option("-c", "--numclusters",
482292SN/A                  help="Number of clusters", type="int")
492292SN/Aparser.add_option("-n", "--numcpus",
502292SN/A                  help="Number of cpus in total", type="int")
512292SN/Aparser.add_option("-f", "--frequency",
522292SN/A                  default = "1GHz",
532292SN/A                  help="Frequency of each CPU")
542326SN/Aparser.add_option("-p", "--protocol",
552292SN/A                  default="moesi",
562292SN/A                  help="The coherence protocol to use for the L1'a (i.e. MOESI, MOSI)")
572292SN/Aparser.add_option("--l1size",
582292SN/A                  default = "32kB")
592292SN/Aparser.add_option("--l1latency",
602292SN/A                  default = 1)
612292SN/Aparser.add_option("--l2size",
622292SN/A                  default = "256kB")
632292SN/Aparser.add_option("--l2latency",
642292SN/A                  default = 10)
652292SN/Aparser.add_option("--rootdir",
662292SN/A                  help="ROot directory of Splash2",
672292SN/A                  default="/dist/splash2/codes/")
682669Sktlim@umich.eduparser.add_option("-b", "--benchmark",
692292SN/A                  help="Splash 2 benchmark to run")
702292SN/A
712292SN/A(options, args) = parser.parse_args()
722292SN/A
732292SN/Aif args:
742292SN/A    print "Error: script doesn't take any positional arguments"
752292SN/A    sys.exit(1)
762292SN/A
772307SN/A# --------------------
782307SN/A# Define Splash2 Benchmarks
792292SN/A# ====================
801060SN/Aclass Cholesky(LiveProcess):
811060SN/A        executable = options.rootdir + '/kernels/cholesky/CHOLESKY'
821060SN/A        cmd = 'CHOLESKY -p' + str(options.numcpus) + ' '\
831060SN/A             + options.rootdir + '/kernels/cholesky/inputs/tk23.O'
842292SN/A
851060SN/Aclass FFT(LiveProcess):
861060SN/A        executable = options.rootdir + 'kernels/fft/FFT'
871060SN/A        cmd = 'FFT -p' + str(options.numcpus) + ' -m18'
882326SN/A
891060SN/Aclass LU_contig(LiveProcess):
901060SN/A        executable = options.rootdir + 'kernels/lu/contiguous_blocks/LU'
911060SN/A        cmd = 'LU -p' + str(options.numcpus)
921060SN/A
932292SN/Aclass LU_noncontig(LiveProcess):
942292SN/A        executable = options.rootdir + 'kernels/lu/non_contiguous_blocks/LU'
952292SN/A        cmd = 'LU -p' + str(options.numcpus)
962292SN/A
971060SN/Aclass Radix(LiveProcess):
981060SN/A        executable = options.rootdir + 'kernels/radix/RADIX'
992307SN/A        cmd = 'RADIX -n524288 -p' + str(options.numcpus)
1002292SN/A
1012980Sgblack@eecs.umich.educlass Barnes(LiveProcess):
1022292SN/A        executable = options.rootdir + 'apps/barnes/BARNES'
1032292SN/A        cmd = 'BARNES'
1042292SN/A        input = options.rootdir + 'apps/barnes/input.p' + str(options.numcpus)
1052292SN/A
1062292SN/Aclass FMM(LiveProcess):
1072292SN/A        executable = options.rootdir + 'apps/fmm/FMM'
1082292SN/A        cmd = 'FMM'
1092292SN/A        input = options.rootdir + 'apps/fmm/inputs/input.2048.p' + str(options.numcpus)
1102292SN/A
1112292SN/Aclass Ocean_contig(LiveProcess):
1122292SN/A        executable = options.rootdir + 'apps/ocean/contiguous_partitions/OCEAN'
1132292SN/A        cmd = 'OCEAN -p' + str(options.numcpus)
1142292SN/A
1152292SN/Aclass Ocean_noncontig(LiveProcess):
1162292SN/A        executable = options.rootdir + 'apps/ocean/non_contiguous_partitions/OCEAN'
1172292SN/A        cmd = 'OCEAN -p' + str(options.numcpus)
1182292SN/A
1192292SN/Aclass Raytrace(LiveProcess):
1202292SN/A        executable = options.rootdir + 'apps/raytrace/RAYTRACE'
1212292SN/A        cmd = 'RAYTRACE -p' + str(options.numcpus) + ' ' \
1222292SN/A             + options.rootdir + 'apps/raytrace/inputs/teapot.env'
1232292SN/A
1242292SN/Aclass Water_nsquared(LiveProcess):
1252292SN/A        executable = options.rootdir + 'apps/water-nsquared/WATER-NSQUARED'
1262292SN/A        cmd = 'WATER-NSQUARED'
1272831Sksewell@umich.edu        input = options.rootdir + 'apps/water-nsquared/input.p' + str(options.numcpus)
1282292SN/A
1292292SN/Aclass Water_spatial(LiveProcess):
1302292SN/A        executable = options.rootdir + 'apps/water-spatial/WATER-SPATIAL'
1312292SN/A        cmd = 'WATER-SPATIAL'
1322292SN/A        input = options.rootdir + 'apps/water-spatial/input.p' + str(options.numcpus)
1332292SN/A
1342292SN/A
1352292SN/A# --------------------
1362292SN/A# Base L1 Cache Definition
1372292SN/A# ====================
1382292SN/A
1392292SN/Aclass L1(BaseCache):
1402292SN/A    latency = options.l1latency
1412292SN/A    block_size = 64
1422831Sksewell@umich.edu    mshrs = 12
1432292SN/A    tgts_per_mshr = 8
1442292SN/A    protocol = CoherenceProtocol(protocol=options.protocol)
1452292SN/A
1462292SN/A# ----------------------
1472292SN/A# Base L2 Cache Definition
1482292SN/A# ----------------------
1492292SN/A
1502292SN/Aclass L2(BaseCache):
1512292SN/A    block_size = 64
1522292SN/A    latency = options.l2latency
1532326SN/A    mshrs = 92
1542348SN/A    tgts_per_mshr = 16
1552326SN/A    write_buffers = 8
1562326SN/A
1572348SN/A# ----------------------
1582292SN/A# Define the clusters with their cpus
1592292SN/A# ----------------------
1602292SN/Aclass Cluster:
1612292SN/A    pass
1622292SN/A
1632292SN/AcpusPerCluster = options.numcpus/options.numclusters
1642292SN/A
1651060SN/AbusFrequency = Frequency(options.frequency)
1661060SN/AbusFrequency *= cpusPerCluster
1671061SN/A
1681060SN/Aall_cpus = []
1691062SN/Aall_l1s = []
1701062SN/Aall_l1buses = []
1712301SN/Aif options.timing:
1721062SN/A    clusters = [ Cluster() for i in xrange(options.numclusters)]
1731062SN/A    for j in xrange(options.numclusters):
1741062SN/A        clusters[j].id = j
1751062SN/A    for cluster in clusters:
1761062SN/A        cluster.clusterbus = Bus(clock=busFrequency)
1771062SN/A        all_l1buses += [cluster.clusterbus]
1781062SN/A        cluster.cpus = [TimingSimpleCPU(cpu_id = i + cluster.id,
1791062SN/A                                        clock=options.frequency)
1801062SN/A                        for i in xrange(cpusPerCluster)]
1811062SN/A        all_cpus += cluster.cpus
1822301SN/A        cluster.l1 = L1(size=options.l1size, assoc = 4)
1832301SN/A        all_l1s += [cluster.l1]
1842301SN/Aelif options.detailed:
1852301SN/A    clusters = [ Cluster() for i in xrange(options.numclusters)]
1861062SN/A    for j in xrange(options.numclusters):
1871062SN/A        clusters[j].id = j
1881062SN/A    for cluster in clusters:
1891062SN/A        cluster.clusterbus = Bus(clock=busFrequency)
1901062SN/A        all_l1buses += [cluster.clusterbus]
1911062SN/A        cluster.cpus = [DerivO3CPU(cpu_id = i + cluster.id,
1921062SN/A                                   clock=options.frequency)
1931062SN/A                        for i in xrange(cpusPerCluster)]
1941062SN/A        all_cpus += cluster.cpus
1951062SN/A        cluster.l1 = L1(size=options.l1size, assoc = 4)
1961062SN/A        all_l1s += [cluster.l1]
1971062SN/Aelse:
1981062SN/A    clusters = [ Cluster() for i in xrange(options.numclusters)]
1991062SN/A    for j in xrange(options.numclusters):
2001062SN/A        clusters[j].id = j
2011062SN/A    for cluster in clusters:
2021062SN/A        cluster.clusterbus = Bus(clock=busFrequency)
2031062SN/A        all_l1buses += [cluster.clusterbus]
2041062SN/A        cluster.cpus = [AtomicSimpleCPU(cpu_id = i + cluster.id,
2051062SN/A                                        clock=options.frequency)
2061062SN/A                        for i in xrange(cpusPerCluster)]
2071062SN/A        all_cpus += cluster.cpus
2081062SN/A        cluster.l1 = L1(size=options.l1size, assoc = 4)
2091062SN/A        all_l1s += [cluster.l1]
2101062SN/A
2111062SN/A# ----------------------
2121062SN/A# Create a system, and add system wide objects
2131062SN/A# ----------------------
2141062SN/Asystem = System(cpu = all_cpus, l1_ = all_l1s, l1bus_ = all_l1buses, physmem = PhysicalMemory(),
2151062SN/A                membus = Bus(clock = busFrequency))
2161062SN/A
2171062SN/Asystem.toL2bus = Bus(clock = busFrequency)
2181062SN/Asystem.l2 = L2(size = options.l2size, assoc = 8)
2191062SN/A
2201062SN/A# ----------------------
2211062SN/A# Connect the L2 cache and memory together
2221062SN/A# ----------------------
2231062SN/A
2241062SN/Asystem.physmem.port = system.membus.port
2251062SN/Asystem.l2.cpu_side = system.toL2bus.port
2261062SN/Asystem.l2.mem_side = system.membus.port
2271062SN/A
2281062SN/A# ----------------------
2291062SN/A# Connect the L2 cache and clusters together
2301062SN/A# ----------------------
2311062SN/Afor cluster in clusters:
2321062SN/A    cluster.l1.cpu_side = cluster.clusterbus.port
2332361SN/A    cluster.l1.mem_side = system.toL2bus.port
2342326SN/A    for cpu in cluster.cpus:
2352301SN/A        cpu.icache_port = cluster.clusterbus.port
2362301SN/A        cpu.dcache_port = cluster.clusterbus.port
2372301SN/A        cpu.mem = cluster.l1
2382301SN/A
2392301SN/A# ----------------------
2402301SN/A# Define the root
2412326SN/A# ----------------------
2422301SN/A
2432361SN/Aroot = Root(system = system)
2442326SN/A
2452307SN/A# --------------------
2462301SN/A# Pick the correct Splash2 Benchmarks
2472301SN/A# ====================
2482307SN/Aif options.benchmark == 'Cholesky':
2492301SN/A    root.workload = Cholesky()
2502301SN/Aelif options.benchmark == 'FFT':
2512301SN/A    root.workload = FFT()
2522301SN/Aelif options.benchmark == 'LUContig':
2532301SN/A    root.workload = LU_contig()
2542301SN/Aelif options.benchmark == 'LUNoncontig':
2552301SN/A    root.workload = LU_noncontig()
2562301SN/Aelif options.benchmark == 'Radix':
2572301SN/A    root.workload = Radix()
2582301SN/Aelif options.benchmark == 'Barnes':
2592301SN/A    root.workload = Barnes()
2602301SN/Aelif options.benchmark == 'FMM':
2612326SN/A    root.workload = FMM()
2622301SN/Aelif options.benchmark == 'OceanContig':
2632301SN/A    root.workload = Ocean_contig()
2642301SN/Aelif options.benchmark == 'OceanNoncontig':
2652301SN/A    root.workload = Ocean_noncontig()
2662301SN/Aelif options.benchmark == 'Raytrace':
2672326SN/A    root.workload = Raytrace()
2682301SN/Aelif options.benchmark == 'WaterNSquared':
2692301SN/A    root.workload = Water_nsquared()
2702301SN/Aelif options.benchmark == 'WaterSpatial':
2712301SN/A    root.workload = Water_spatial()
2722361SN/Aelse:
2732326SN/A    panic("The --benchmark environment variable was set to something" \
2742301SN/A          +" improper.\nUse Cholesky, FFT, LUContig, LUNoncontig, Radix" \
2752301SN/A          +", Barnes, FMM, OceanContig,\nOceanNoncontig, Raytrace," \
2762301SN/A          +" WaterNSquared, or WaterSpatial\n")
2772301SN/A
2782301SN/A# --------------------
2792301SN/A# Assign the workload to the cpus
2802301SN/A# ====================
2812980Sgblack@eecs.umich.edu
2822301SN/Afor cluster in clusters:
2832326SN/A    for cpu in cluster.cpus:
2842301SN/A        cpu.workload = root.workload
2852361SN/A
2862326SN/A# ----------------------
2872301SN/A# Run the simulation
2882301SN/A# ----------------------
2892301SN/A
2902301SN/Aif options.timing or options.detailed:
2912326SN/A    root.system.mem_mode = 'timing'
2922727Sktlim@umich.edu
2932326SN/A# instantiate configuration
2942301SN/Am5.instantiate(root)
2952301SN/A
2962301SN/A# simulate until program terminates
2972301SN/Aif options.maxtick:
2982301SN/A    exit_event = m5.simulate(options.maxtick)
2992301SN/Aelse:
3002326SN/A    exit_event = m5.simulate(m5.MaxTick)
3012301SN/A
3022301SN/Aprint 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
3032326SN/A
3042301SN/A