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