1# Copyright (c) 2005-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# Splash2 Run Script
30#
31
32from __future__ import print_function
33from __future__ import absolute_import
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("-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 = "1ns")
60parser.add_option("--l2size",
61                  default = "256kB")
62parser.add_option("--l2latency",
63                  default = "10ns")
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
76if not options.numcpus:
77    print("Specify the number of cpus with -n")
78    sys.exit(1)
79
80# --------------------
81# Define Splash2 Benchmarks
82# ====================
83class Cholesky(Process):
84    cwd = options.rootdir + '/kernels/cholesky'
85    executable = options.rootdir + '/kernels/cholesky/CHOLESKY'
86    cmd = ['CHOLESKY', '-p' +  str(options.numcpus),
87            options.rootdir + '/kernels/cholesky/inputs/tk23.O']
88
89class FFT(Process):
90    cwd = options.rootdir + '/kernels/fft'
91    executable = options.rootdir + '/kernels/fft/FFT'
92    cmd = ['FFT', '-p', str(options.numcpus), '-m18']
93
94class LU_contig(Process):
95    executable = options.rootdir + '/kernels/lu/contiguous_blocks/LU'
96    cmd = ['LU', '-p', str(options.numcpus)]
97    cwd = options.rootdir + '/kernels/lu/contiguous_blocks'
98
99class LU_noncontig(Process):
100    executable = options.rootdir + '/kernels/lu/non_contiguous_blocks/LU'
101    cmd = ['LU', '-p', str(options.numcpus)]
102    cwd = options.rootdir + '/kernels/lu/non_contiguous_blocks'
103
104class Radix(Process):
105    executable = options.rootdir + '/kernels/radix/RADIX'
106    cmd = ['RADIX', '-n524288', '-p', str(options.numcpus)]
107    cwd = options.rootdir + '/kernels/radix'
108
109class Barnes(Process):
110    executable = options.rootdir + '/apps/barnes/BARNES'
111    cmd = ['BARNES']
112    input = options.rootdir + '/apps/barnes/input.p' + str(options.numcpus)
113    cwd = options.rootdir + '/apps/barnes'
114
115class FMM(Process):
116    executable = options.rootdir + '/apps/fmm/FMM'
117    cmd = ['FMM']
118    if str(options.numcpus) == '1':
119        input = options.rootdir + '/apps/fmm/inputs/input.2048'
120    else:
121        input = options.rootdir + '/apps/fmm/inputs/input.2048.p' + str(options.numcpus)
122    cwd = options.rootdir + '/apps/fmm'
123
124class Ocean_contig(Process):
125    executable = options.rootdir + '/apps/ocean/contiguous_partitions/OCEAN'
126    cmd = ['OCEAN', '-p', str(options.numcpus)]
127    cwd = options.rootdir + '/apps/ocean/contiguous_partitions'
128
129class Ocean_noncontig(Process):
130    executable = options.rootdir + '/apps/ocean/non_contiguous_partitions/OCEAN'
131    cmd = ['OCEAN', '-p', str(options.numcpus)]
132    cwd = options.rootdir + '/apps/ocean/non_contiguous_partitions'
133
134class Raytrace(Process):
135    executable = options.rootdir + '/apps/raytrace/RAYTRACE'
136    cmd = ['RAYTRACE', '-p' + str(options.numcpus),
137           options.rootdir + '/apps/raytrace/inputs/teapot.env']
138    cwd = options.rootdir + '/apps/raytrace'
139
140class Water_nsquared(Process):
141    executable = options.rootdir + '/apps/water-nsquared/WATER-NSQUARED'
142    cmd = ['WATER-NSQUARED']
143    if options.numcpus==1:
144        input = options.rootdir + '/apps/water-nsquared/input'
145    else:
146        input = options.rootdir + '/apps/water-nsquared/input.p' + str(options.numcpus)
147    cwd = options.rootdir + '/apps/water-nsquared'
148
149class Water_spatial(Process):
150    executable = options.rootdir + '/apps/water-spatial/WATER-SPATIAL'
151    cmd = ['WATER-SPATIAL']
152    if options.numcpus==1:
153        input = options.rootdir + '/apps/water-spatial/input'
154    else:
155        input = options.rootdir + '/apps/water-spatial/input.p' + str(options.numcpus)
156    cwd = options.rootdir + '/apps/water-spatial'
157
158# --------------------
159# Base L1 Cache Definition
160# ====================
161
162class L1(Cache):
163    latency = options.l1latency
164    mshrs = 12
165    tgts_per_mshr = 8
166
167# ----------------------
168# Base L2 Cache Definition
169# ----------------------
170
171class L2(Cache):
172    latency = options.l2latency
173    mshrs = 92
174    tgts_per_mshr = 16
175    write_buffers = 8
176
177# ----------------------
178# Define the cpus
179# ----------------------
180
181busFrequency = Frequency(options.frequency)
182
183if options.timing:
184    cpus = [TimingSimpleCPU(cpu_id = i,
185                            clock=options.frequency)
186            for i in range(options.numcpus)]
187elif options.detailed:
188    cpus = [DerivO3CPU(cpu_id = i,
189                       clock=options.frequency)
190            for i in range(options.numcpus)]
191else:
192    cpus = [AtomicSimpleCPU(cpu_id = i,
193                            clock=options.frequency)
194            for i in range(options.numcpus)]
195
196# ----------------------
197# Create a system, and add system wide objects
198# ----------------------
199system = System(cpu = cpus, physmem = SimpleMemory(),
200                membus = SystemXBar(clock = busFrequency))
201system.clock = '1GHz'
202
203system.toL2bus = L2XBar(clock = busFrequency)
204system.l2 = L2(size = options.l2size, assoc = 8)
205
206# ----------------------
207# Connect the L2 cache and memory together
208# ----------------------
209
210system.physmem.port = system.membus.master
211system.l2.cpu_side = system.toL2bus.master
212system.l2.mem_side = system.membus.slave
213system.system_port = system.membus.slave
214
215# ----------------------
216# Connect the L2 cache and clusters together
217# ----------------------
218for cpu in cpus:
219    cpu.addPrivateSplitL1Caches(L1(size = options.l1size, assoc = 1),
220                                L1(size = options.l1size, assoc = 4))
221    # connect cpu level-1 caches to shared level-2 cache
222    cpu.connectAllPorts(system.toL2bus, system.membus)
223
224
225# ----------------------
226# Define the root
227# ----------------------
228
229root = Root(full_system = False, system = system)
230
231# --------------------
232# Pick the correct Splash2 Benchmarks
233# ====================
234if options.benchmark == 'Cholesky':
235    root.workload = Cholesky()
236elif options.benchmark == 'FFT':
237    root.workload = FFT()
238elif options.benchmark == 'LUContig':
239    root.workload = LU_contig()
240elif options.benchmark == 'LUNoncontig':
241    root.workload = LU_noncontig()
242elif options.benchmark == 'Radix':
243    root.workload = Radix()
244elif options.benchmark == 'Barnes':
245    root.workload = Barnes()
246elif options.benchmark == 'FMM':
247    root.workload = FMM()
248elif options.benchmark == 'OceanContig':
249    root.workload = Ocean_contig()
250elif options.benchmark == 'OceanNoncontig':
251    root.workload = Ocean_noncontig()
252elif options.benchmark == 'Raytrace':
253    root.workload = Raytrace()
254elif options.benchmark == 'WaterNSquared':
255    root.workload = Water_nsquared()
256elif options.benchmark == 'WaterSpatial':
257    root.workload = Water_spatial()
258else:
259    print("The --benchmark environment variable was set to something "
260          "improper. Use Cholesky, FFT, LUContig, LUNoncontig, Radix, "
261          "Barnes, FMM, OceanContig, OceanNoncontig, Raytrace, WaterNSquared, "
262          "or WaterSpatial", file=sys.stderr)
263    sys.exit(1)
264
265# --------------------
266# Assign the workload to the cpus
267# ====================
268
269for cpu in cpus:
270    cpu.workload = root.workload
271
272# ----------------------
273# Run the simulation
274# ----------------------
275
276if options.timing or options.detailed:
277    root.system.mem_mode = 'timing'
278
279# instantiate configuration
280m5.instantiate()
281
282# simulate until program terminates
283if options.maxtick:
284    exit_event = m5.simulate(options.maxtick)
285else:
286    exit_event = m5.simulate(m5.MaxTick)
287
288print('Exiting @ tick', m5.curTick(), 'because', exit_event.getCause())
289
290