cluster.py revision 10720
11689SN/A# Copyright (c) 2006-2007 The Regents of The University of Michigan
27598Sminkyu.jeong@arm.com# All rights reserved.
37598Sminkyu.jeong@arm.com#
47598Sminkyu.jeong@arm.com# Redistribution and use in source and binary forms, with or without
57598Sminkyu.jeong@arm.com# modification, are permitted provided that the following conditions are
67598Sminkyu.jeong@arm.com# met: redistributions of source code must retain the above copyright
77598Sminkyu.jeong@arm.com# notice, this list of conditions and the following disclaimer;
87598Sminkyu.jeong@arm.com# redistributions in binary form must reproduce the above copyright
97598Sminkyu.jeong@arm.com# notice, this list of conditions and the following disclaimer in the
107598Sminkyu.jeong@arm.com# documentation and/or other materials provided with the distribution;
117598Sminkyu.jeong@arm.com# neither the name of the copyright holders nor the names of its
127598Sminkyu.jeong@arm.com# contributors may be used to endorse or promote products derived from
137598Sminkyu.jeong@arm.com# this software without specific prior written permission.
142326SN/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#
271689SN/A# Authors: Ron Dreslinski
281689SN/A
291689SN/A# Simple test script
301689SN/A#
311689SN/A# "m5 test.py"
321689SN/A
331689SN/Aimport os
341689SN/Aimport optparse
351689SN/Aimport sys
361689SN/A
371689SN/Aimport m5
381689SN/Afrom m5.objects import *
392665Ssaidi@eecs.umich.edu
402665Ssaidi@eecs.umich.edum5.util.addToPath('../common')
411689SN/A
421689SN/A# --------------------
431060SN/A# Define Command Line Options
441060SN/A# ====================
451689SN/A
461060SN/Aparser = optparse.OptionParser()
471060SN/A
481060SN/Aparser.add_option("-d", "--detailed", action="store_true")
498230Snate@binkert.orgparser.add_option("-t", "--timing", action="store_true")
506658Snate@binkert.orgparser.add_option("-m", "--maxtick", type="int")
512292SN/Aparser.add_option("-c", "--numclusters",
521717SN/A                  help="Number of clusters", type="int")
538229Snate@binkert.orgparser.add_option("-n", "--numcpus",
545529Snate@binkert.org                  help="Number of cpus in total", type="int")
551060SN/Aparser.add_option("-f", "--frequency",
566221Snate@binkert.org                  default = "1GHz",
576221Snate@binkert.org                  help="Frequency of each CPU")
581681SN/Aparser.add_option("--l1size",
595529Snate@binkert.org                  default = "32kB")
602873Sktlim@umich.eduparser.add_option("--l1latency",
614329Sktlim@umich.edu                  default = 1)
624329Sktlim@umich.eduparser.add_option("--l2size",
634329Sktlim@umich.edu                  default = "256kB")
642292SN/Aparser.add_option("--l2latency",
652292SN/A                  default = 10)
662292SN/Aparser.add_option("--rootdir",
672292SN/A                  help="ROot directory of Splash2",
682820Sktlim@umich.edu                  default="/dist/splash2/codes/")
692292SN/Aparser.add_option("-b", "--benchmark",
702820Sktlim@umich.edu                  help="Splash 2 benchmark to run")
712820Sktlim@umich.edu
725529Snate@binkert.org(options, args) = parser.parse_args()
732307SN/A
741060SN/Aif args:
752292SN/A    print "Error: script doesn't take any positional arguments"
762292SN/A    sys.exit(1)
772292SN/A
781060SN/A# --------------------
791060SN/A# Define Splash2 Benchmarks
801060SN/A# ====================
811060SN/Aclass Cholesky(LiveProcess):
821060SN/A        executable = options.rootdir + '/kernels/cholesky/CHOLESKY'
831060SN/A        cmd = 'CHOLESKY -p' + str(options.numcpus) + ' '\
841681SN/A             + options.rootdir + '/kernels/cholesky/inputs/tk23.O'
856221Snate@binkert.org
866221Snate@binkert.orgclass FFT(LiveProcess):
876221Snate@binkert.org        executable = options.rootdir + 'kernels/fft/FFT'
886221Snate@binkert.org        cmd = 'FFT -p' + str(options.numcpus) + ' -m18'
892292SN/A
902292SN/Aclass LU_contig(LiveProcess):
912820Sktlim@umich.edu        executable = options.rootdir + 'kernels/lu/contiguous_blocks/LU'
922820Sktlim@umich.edu        cmd = 'LU -p' + str(options.numcpus)
932292SN/A
942292SN/Aclass LU_noncontig(LiveProcess):
952820Sktlim@umich.edu        executable = options.rootdir + 'kernels/lu/non_contiguous_blocks/LU'
962820Sktlim@umich.edu        cmd = 'LU -p' + str(options.numcpus)
972292SN/A
982292SN/Aclass Radix(LiveProcess):
992292SN/A        executable = options.rootdir + 'kernels/radix/RADIX'
1002292SN/A        cmd = 'RADIX -n524288 -p' + str(options.numcpus)
1012292SN/A
1022292SN/Aclass Barnes(LiveProcess):
1032292SN/A        executable = options.rootdir + 'apps/barnes/BARNES'
1042292SN/A        cmd = 'BARNES'
1051060SN/A        input = options.rootdir + 'apps/barnes/input.p' + str(options.numcpus)
1061060SN/A
1071681SN/Aclass FMM(LiveProcess):
1081062SN/A        executable = options.rootdir + 'apps/fmm/FMM'
1092292SN/A        cmd = 'FMM'
1101062SN/A        input = options.rootdir + 'apps/fmm/inputs/input.2048.p' + str(options.numcpus)
1112301SN/A
1122301SN/Aclass Ocean_contig(LiveProcess):
1131062SN/A        executable = options.rootdir + 'apps/ocean/contiguous_partitions/OCEAN'
1142727Sktlim@umich.edu        cmd = 'OCEAN -p' + str(options.numcpus)
1151062SN/A
1161062SN/Aclass Ocean_noncontig(LiveProcess):
1171062SN/A        executable = options.rootdir + 'apps/ocean/non_contiguous_partitions/OCEAN'
1181062SN/A        cmd = 'OCEAN -p' + str(options.numcpus)
1191062SN/A
1201062SN/Aclass Raytrace(LiveProcess):
1211062SN/A        executable = options.rootdir + 'apps/raytrace/RAYTRACE'
1221062SN/A        cmd = 'RAYTRACE -p' + str(options.numcpus) + ' ' \
1231062SN/A             + options.rootdir + 'apps/raytrace/inputs/teapot.env'
1241062SN/A
1251062SN/Aclass Water_nsquared(LiveProcess):
1261062SN/A        executable = options.rootdir + 'apps/water-nsquared/WATER-NSQUARED'
1271062SN/A        cmd = 'WATER-NSQUARED'
1281062SN/A        input = options.rootdir + 'apps/water-nsquared/input.p' + str(options.numcpus)
1291062SN/A
1301062SN/Aclass Water_spatial(LiveProcess):
1311062SN/A        executable = options.rootdir + 'apps/water-spatial/WATER-SPATIAL'
1321062SN/A        cmd = 'WATER-SPATIAL'
1331062SN/A        input = options.rootdir + 'apps/water-spatial/input.p' + str(options.numcpus)
1341062SN/A
1351062SN/A
1361062SN/A# --------------------
1371062SN/A# Base L1 Cache Definition
1381062SN/A# ====================
1391062SN/A
1401062SN/Aclass L1(BaseCache):
1411062SN/A    latency = options.l1latency
1421062SN/A    mshrs = 12
1431062SN/A    tgts_per_mshr = 8
1441062SN/A
1451062SN/A# ----------------------
1461062SN/A# Base L2 Cache Definition
1471062SN/A# ----------------------
1481062SN/A
1491062SN/Aclass L2(BaseCache):
1501062SN/A    latency = options.l2latency
1511062SN/A    mshrs = 92
1521062SN/A    tgts_per_mshr = 16
1531062SN/A    write_buffers = 8
1541062SN/A
1551062SN/A# ----------------------
1562292SN/A# Define the clusters with their cpus
1572292SN/A# ----------------------
1582292SN/Aclass Cluster:
1592292SN/A    pass
1601062SN/A
1611062SN/AcpusPerCluster = options.numcpus/options.numclusters
1621062SN/A
1631062SN/AbusFrequency = Frequency(options.frequency)
1641062SN/AbusFrequency *= cpusPerCluster
1651062SN/A
1661062SN/Aall_cpus = []
1672292SN/Aall_l1s = []
1682292SN/Aall_l1buses = []
1692292SN/Aif options.timing:
1702292SN/A    clusters = [ Cluster() for i in xrange(options.numclusters)]
1712292SN/A    for j in xrange(options.numclusters):
1722292SN/A        clusters[j].id = j
1732292SN/A    for cluster in clusters:
1742292SN/A        cluster.clusterbus = L2XBar(clock=busFrequency)
1752292SN/A        all_l1buses += [cluster.clusterbus]
1762292SN/A        cluster.cpus = [TimingSimpleCPU(cpu_id = i + cluster.id,
1772301SN/A                                        clock=options.frequency)
1782727Sktlim@umich.edu                        for i in xrange(cpusPerCluster)]
1792353SN/A        all_cpus += cluster.cpus
1802727Sktlim@umich.edu        cluster.l1 = L1(size=options.l1size, assoc = 4)
1812727Sktlim@umich.edu        all_l1s += [cluster.l1]
1822727Sktlim@umich.eduelif options.detailed:
1836221Snate@binkert.org    clusters = [ Cluster() for i in xrange(options.numclusters)]
1842353SN/A    for j in xrange(options.numclusters):
1852727Sktlim@umich.edu        clusters[j].id = j
1862727Sktlim@umich.edu    for cluster in clusters:
1872727Sktlim@umich.edu        cluster.clusterbus = L2XBar(clock=busFrequency)
1882727Sktlim@umich.edu        all_l1buses += [cluster.clusterbus]
1892353SN/A        cluster.cpus = [DerivO3CPU(cpu_id = i + cluster.id,
1902727Sktlim@umich.edu                                   clock=options.frequency)
1912727Sktlim@umich.edu                        for i in xrange(cpusPerCluster)]
1922727Sktlim@umich.edu        all_cpus += cluster.cpus
1936221Snate@binkert.org        cluster.l1 = L1(size=options.l1size, assoc = 4)
1942301SN/A        all_l1s += [cluster.l1]
1952301SN/Aelse:
1962727Sktlim@umich.edu    clusters = [ Cluster() for i in xrange(options.numclusters)]
1972301SN/A    for j in xrange(options.numclusters):
1982727Sktlim@umich.edu        clusters[j].id = j
1996221Snate@binkert.org    for cluster in clusters:
2002301SN/A        cluster.clusterbus = L2XBar(clock=busFrequency)
2012301SN/A        all_l1buses += [cluster.clusterbus]
2022727Sktlim@umich.edu        cluster.cpus = [AtomicSimpleCPU(cpu_id = i + cluster.id,
2032301SN/A                                        clock=options.frequency)
2042727Sktlim@umich.edu                        for i in xrange(cpusPerCluster)]
2056221Snate@binkert.org        all_cpus += cluster.cpus
2062301SN/A        cluster.l1 = L1(size=options.l1size, assoc = 4)
2072301SN/A        all_l1s += [cluster.l1]
2082727Sktlim@umich.edu
2092301SN/A# ----------------------
2102727Sktlim@umich.edu# Create a system, and add system wide objects
2116221Snate@binkert.org# ----------------------
2122301SN/Asystem = System(cpu = all_cpus, l1_ = all_l1s, l1bus_ = all_l1buses,
2132301SN/A                physmem = SimpleMemory(),
2142727Sktlim@umich.edu                membus = SystemXBar(clock = busFrequency))
2152301SN/Asystem.clock = '1GHz'
2162301SN/A
2172301SN/Asystem.toL2bus = L2XBar(clock = busFrequency)
2182301SN/Asystem.l2 = L2(size = options.l2size, assoc = 8)
2192727Sktlim@umich.edu
2202727Sktlim@umich.edu# ----------------------
2212727Sktlim@umich.edu# Connect the L2 cache and memory together
2222727Sktlim@umich.edu# ----------------------
2232727Sktlim@umich.edu
2242727Sktlim@umich.edusystem.physmem.port = system.membus.master
2252727Sktlim@umich.edusystem.l2.cpu_side = system.toL2bus.slave
2262727Sktlim@umich.edusystem.l2.mem_side = system.membus.master
2272727Sktlim@umich.edu
2282301SN/A# ----------------------
2292301SN/A# Connect the L2 cache and clusters together
2306221Snate@binkert.org# ----------------------
2312301SN/Afor cluster in clusters:
2322301SN/A    cluster.l1.cpu_side = cluster.clusterbus.master
2332727Sktlim@umich.edu    cluster.l1.mem_side = system.toL2bus.slave
2342301SN/A    for cpu in cluster.cpus:
2352326SN/A        cpu.icache_port = cluster.clusterbus.slave
2366221Snate@binkert.org        cpu.dcache_port = cluster.clusterbus.slave
2372301SN/A
2382301SN/A# ----------------------
2392727Sktlim@umich.edu# Define the root
2402301SN/A# ----------------------
2412326SN/A
2426221Snate@binkert.orgroot = Root(full_system = False, system = system)
2432301SN/A
2442301SN/A# --------------------
2452727Sktlim@umich.edu# Pick the correct Splash2 Benchmarks
2462301SN/A# ====================
2472326SN/Aif options.benchmark == 'Cholesky':
2486221Snate@binkert.org    root.workload = Cholesky()
2492301SN/Aelif options.benchmark == 'FFT':
2502301SN/A    root.workload = FFT()
2512727Sktlim@umich.eduelif options.benchmark == 'LUContig':
2522301SN/A    root.workload = LU_contig()
2532326SN/Aelif options.benchmark == 'LUNoncontig':
2546221Snate@binkert.org    root.workload = LU_noncontig()
2552301SN/Aelif options.benchmark == 'Radix':
2562301SN/A    root.workload = Radix()
2572727Sktlim@umich.eduelif options.benchmark == 'Barnes':
2582301SN/A    root.workload = Barnes()
2592326SN/Aelif options.benchmark == 'FMM':
2602301SN/A    root.workload = FMM()
2612301SN/Aelif options.benchmark == 'OceanContig':
2622727Sktlim@umich.edu    root.workload = Ocean_contig()
2632301SN/Aelif options.benchmark == 'OceanNoncontig':
2642326SN/A    root.workload = Ocean_noncontig()
2652301SN/Aelif options.benchmark == 'Raytrace':
2662326SN/A    root.workload = Raytrace()
2672301SN/Aelif options.benchmark == 'WaterNSquared':
2682301SN/A    root.workload = Water_nsquared()
2692727Sktlim@umich.eduelif options.benchmark == 'WaterSpatial':
2702301SN/A    root.workload = Water_spatial()
2712326SN/Aelse:
2722301SN/A    m5.util.panic("""
2732326SN/AThe --benchmark environment variable was set to something improper.
2742301SN/AUse Cholesky, FFT, LUContig, LUNoncontig, Radix, Barnes, FMM, OceanContig,
2752301SN/AOceanNoncontig, Raytrace, WaterNSquared, or WaterSpatial
2762727Sktlim@umich.edu""")
2772326SN/A
2781062SN/A# --------------------
2791062SN/A# Assign the workload to the cpus
2801681SN/A# ====================
2811060SN/A
2822292SN/Afor cluster in clusters:
2831060SN/A    for cpu in cluster.cpus:
2846221Snate@binkert.org        cpu.workload = root.workload
2852292SN/A
2862292SN/A# ----------------------
2872292SN/A# Run the simulation
2882292SN/A# ----------------------
2892292SN/A
2902292SN/Aif options.timing or options.detailed:
2912292SN/A    root.system.mem_mode = 'timing'
2922292SN/A
2932292SN/A# instantiate configuration
2942733Sktlim@umich.edum5.instantiate()
2951060SN/A
2961060SN/A# simulate until program terminates
2971681SN/Aif options.maxtick:
2981060SN/A    exit_event = m5.simulate(options.maxtick)
2992292SN/Aelse:
3001060SN/A    exit_event = m5.simulate(m5.MaxTick)
3011060SN/A
3021060SN/Aprint 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
3031060SN/A
3041060SN/A