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