0ff80d8e14e40a83e8db11df25b9374a66035855
[gem5.git] / configs / example / apu_se.py
1 # Copyright (c) 2015 Advanced Micro Devices, Inc.
2 # All rights reserved.
3 #
4 # For use for simulation and test purposes only
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright notice,
13 # this list of conditions and the following disclaimer in the documentation
14 # and/or other materials provided with the distribution.
15 #
16 # 3. Neither the name of the copyright holder nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
31
32 from __future__ import print_function
33 from __future__ import absolute_import
34
35 import optparse, os, re
36 import math
37 import glob
38 import inspect
39
40 import m5
41 from m5.objects import *
42 from m5.util import addToPath
43
44 addToPath('../')
45
46 from ruby import Ruby
47
48 from common import Options
49 from common import Simulation
50 from common import GPUTLBOptions, GPUTLBConfig
51
52 ########################## Script Options ########################
53 def setOption(parser, opt_str, value = 1):
54 # check to make sure the option actually exists
55 if not parser.has_option(opt_str):
56 raise Exception("cannot find %s in list of possible options" % opt_str)
57
58 opt = parser.get_option(opt_str)
59 # set the value
60 exec("parser.values.%s = %s" % (opt.dest, value))
61
62 def getOption(parser, opt_str):
63 # check to make sure the option actually exists
64 if not parser.has_option(opt_str):
65 raise Exception("cannot find %s in list of possible options" % opt_str)
66
67 opt = parser.get_option(opt_str)
68 # get the value
69 exec("return_value = parser.values.%s" % opt.dest)
70 return return_value
71
72 # Adding script options
73 parser = optparse.OptionParser()
74 Options.addCommonOptions(parser)
75 Options.addSEOptions(parser)
76
77 parser.add_option("--cpu-only-mode", action="store_true", default=False,
78 help="APU mode. Used to take care of problems in "\
79 "Ruby.py while running APU protocols")
80 parser.add_option("-k", "--kernel-files",
81 help="file(s) containing GPU kernel code (colon separated)")
82 parser.add_option("-u", "--num-compute-units", type="int", default=1,
83 help="number of GPU compute units"),
84 parser.add_option("--num-cp", type="int", default=0,
85 help="Number of GPU Command Processors (CP)")
86 parser.add_option("--benchmark-root", help="Root of benchmark directory tree")
87
88 # not super important now, but to avoid putting the number 4 everywhere, make
89 # it an option/knob
90 parser.add_option("--cu-per-sqc", type="int", default=4, help="number of CUs" \
91 "sharing an SQC (icache, and thus icache TLB)")
92 parser.add_option("--simds-per-cu", type="int", default=4, help="SIMD units" \
93 "per CU")
94 parser.add_option("--wf-size", type="int", default=64,
95 help="Wavefront size(in workitems)")
96 parser.add_option("--sp-bypass-path-length", type="int", default=4, \
97 help="Number of stages of bypass path in vector ALU for Single Precision ops")
98 parser.add_option("--dp-bypass-path-length", type="int", default=4, \
99 help="Number of stages of bypass path in vector ALU for Double Precision ops")
100 # issue period per SIMD unit: number of cycles before issuing another vector
101 parser.add_option("--issue-period", type="int", default=4, \
102 help="Number of cycles per vector instruction issue period")
103 parser.add_option("--glbmem-wr-bus-width", type="int", default=32, \
104 help="VGPR to Coalescer (Global Memory) data bus width in bytes")
105 parser.add_option("--glbmem-rd-bus-width", type="int", default=32, \
106 help="Coalescer to VGPR (Global Memory) data bus width in bytes")
107 # Currently we only support 1 local memory pipe
108 parser.add_option("--shr-mem-pipes-per-cu", type="int", default=1, \
109 help="Number of Shared Memory pipelines per CU")
110 # Currently we only support 1 global memory pipe
111 parser.add_option("--glb-mem-pipes-per-cu", type="int", default=1, \
112 help="Number of Global Memory pipelines per CU")
113 parser.add_option("--wfs-per-simd", type="int", default=10, help="Number of " \
114 "WF slots per SIMD")
115
116 parser.add_option("--vreg-file-size", type="int", default=2048,
117 help="number of physical vector registers per SIMD")
118 parser.add_option("--bw-scalor", type="int", default=0,
119 help="bandwidth scalor for scalability analysis")
120 parser.add_option("--CPUClock", type="string", default="2GHz",
121 help="CPU clock")
122 parser.add_option("--GPUClock", type="string", default="1GHz",
123 help="GPU clock")
124 parser.add_option("--cpu-voltage", action="store", type="string",
125 default='1.0V',
126 help = """CPU voltage domain""")
127 parser.add_option("--gpu-voltage", action="store", type="string",
128 default='1.0V',
129 help = """CPU voltage domain""")
130 parser.add_option("--CUExecPolicy", type="string", default="OLDEST-FIRST",
131 help="WF exec policy (OLDEST-FIRST, ROUND-ROBIN)")
132 parser.add_option("--xact-cas-mode", action="store_true",
133 help="enable load_compare mode (transactional CAS)")
134 parser.add_option("--SegFaultDebug",action="store_true",
135 help="checks for GPU seg fault before TLB access")
136 parser.add_option("--FunctionalTLB",action="store_true",
137 help="Assumes TLB has no latency")
138 parser.add_option("--LocalMemBarrier",action="store_true",
139 help="Barrier does not wait for writethroughs to complete")
140 parser.add_option("--countPages", action="store_true",
141 help="Count Page Accesses and output in per-CU output files")
142 parser.add_option("--TLB-prefetch", type="int", help = "prefetch depth for"\
143 "TLBs")
144 parser.add_option("--pf-type", type="string", help="type of prefetch: "\
145 "PF_CU, PF_WF, PF_PHASE, PF_STRIDE")
146 parser.add_option("--pf-stride", type="int", help="set prefetch stride")
147 parser.add_option("--numLdsBanks", type="int", default=32,
148 help="number of physical banks per LDS module")
149 parser.add_option("--ldsBankConflictPenalty", type="int", default=1,
150 help="number of cycles per LDS bank conflict")
151 parser.add_option('--fast-forward-pseudo-op', action='store_true',
152 help = 'fast forward using kvm until the m5_switchcpu'
153 ' pseudo-op is encountered, then switch cpus. subsequent'
154 ' m5_switchcpu pseudo-ops will toggle back and forth')
155 parser.add_option('--outOfOrderDataDelivery', action='store_true',
156 default=False, help='enable OoO data delivery in the GM'
157 ' pipeline')
158
159 Ruby.define_options(parser)
160
161 #add TLB options to the parser
162 GPUTLBOptions.tlb_options(parser)
163
164 (options, args) = parser.parse_args()
165
166 # The GPU cache coherence protocols only work with the backing store
167 setOption(parser, "--access-backing-store")
168
169 # if benchmark root is specified explicitly, that overrides the search path
170 if options.benchmark_root:
171 benchmark_path = [options.benchmark_root]
172 else:
173 # Set default benchmark search path to current dir
174 benchmark_path = ['.']
175
176 ########################## Sanity Check ########################
177
178 # Currently the gpu model requires ruby
179 if buildEnv['PROTOCOL'] == 'None':
180 fatal("GPU model requires ruby")
181
182 # Currently the gpu model requires only timing or detailed CPU
183 if not (options.cpu_type == "TimingSimpleCPU" or
184 options.cpu_type == "DerivO3CPU"):
185 fatal("GPU model requires TimingSimpleCPU or DerivO3CPU")
186
187 # This file can support multiple compute units
188 assert(options.num_compute_units >= 1)
189
190 # Currently, the sqc (I-Cache of GPU) is shared by
191 # multiple compute units(CUs). The protocol works just fine
192 # even if sqc is not shared. Overriding this option here
193 # so that the user need not explicitly set this (assuming
194 # sharing sqc is the common usage)
195 n_cu = options.num_compute_units
196 num_sqc = int(math.ceil(float(n_cu) / options.cu_per_sqc))
197 options.num_sqc = num_sqc # pass this to Ruby
198
199 ########################## Creating the GPU system ########################
200 # shader is the GPU
201 shader = Shader(n_wf = options.wfs_per_simd,
202 clk_domain = SrcClockDomain(
203 clock = options.GPUClock,
204 voltage_domain = VoltageDomain(
205 voltage = options.gpu_voltage)))
206
207 # GPU_RfO(Read For Ownership) implements SC/TSO memory model.
208 # Other GPU protocols implement release consistency at GPU side.
209 # So, all GPU protocols other than GPU_RfO should make their writes
210 # visible to the global memory and should read from global memory
211 # during kernal boundary. The pipeline initiates(or do not initiate)
212 # the acquire/release operation depending on these impl_kern_launch_rel
213 # and impl_kern_end_rel flags. The flag=true means pipeline initiates
214 # a acquire/release operation at kernel launch/end.
215 # VIPER protocols (GPU_VIPER, GPU_VIPER_Region and GPU_VIPER_Baseline)
216 # are write-through based, and thus only imple_kern_launch_acq needs to
217 # set.
218 if buildEnv['PROTOCOL'] == 'GPU_RfO':
219 shader.impl_kern_launch_acq = False
220 shader.impl_kern_end_rel = False
221 elif (buildEnv['PROTOCOL'] != 'GPU_VIPER' or
222 buildEnv['PROTOCOL'] != 'GPU_VIPER_Region' or
223 buildEnv['PROTOCOL'] != 'GPU_VIPER_Baseline'):
224 shader.impl_kern_launch_acq = True
225 shader.impl_kern_end_rel = False
226 else:
227 shader.impl_kern_launch_acq = True
228 shader.impl_kern_end_rel = True
229
230 # Switching off per-lane TLB by default
231 per_lane = False
232 if options.TLB_config == "perLane":
233 per_lane = True
234
235 # List of compute units; one GPU can have multiple compute units
236 compute_units = []
237 for i in range(n_cu):
238 compute_units.append(ComputeUnit(cu_id = i, perLaneTLB = per_lane,
239 num_SIMDs = options.simds_per_cu,
240 wfSize = options.wf_size,
241 spbypass_pipe_length = options.sp_bypass_path_length,
242 dpbypass_pipe_length = options.dp_bypass_path_length,
243 issue_period = options.issue_period,
244 coalescer_to_vrf_bus_width = \
245 options.glbmem_rd_bus_width,
246 vrf_to_coalescer_bus_width = \
247 options.glbmem_wr_bus_width,
248 num_global_mem_pipes = \
249 options.glb_mem_pipes_per_cu,
250 num_shared_mem_pipes = \
251 options.shr_mem_pipes_per_cu,
252 n_wf = options.wfs_per_simd,
253 execPolicy = options.CUExecPolicy,
254 xactCasMode = options.xact_cas_mode,
255 debugSegFault = options.SegFaultDebug,
256 functionalTLB = options.FunctionalTLB,
257 localMemBarrier = options.LocalMemBarrier,
258 countPages = options.countPages,
259 localDataStore = \
260 LdsState(banks = options.numLdsBanks,
261 bankConflictPenalty = \
262 options.ldsBankConflictPenalty),
263 out_of_order_data_delivery =
264 options.outOfOrderDataDelivery))
265 wavefronts = []
266 vrfs = []
267 for j in range(options.simds_per_cu):
268 for k in range(shader.n_wf):
269 wavefronts.append(Wavefront(simdId = j, wf_slot_id = k,
270 wfSize = options.wf_size))
271 vrfs.append(VectorRegisterFile(simd_id=j,
272 num_regs_per_simd=options.vreg_file_size))
273 compute_units[-1].wavefronts = wavefronts
274 compute_units[-1].vector_register_file = vrfs
275 if options.TLB_prefetch:
276 compute_units[-1].prefetch_depth = options.TLB_prefetch
277 compute_units[-1].prefetch_prev_type = options.pf_type
278
279 # attach the LDS and the CU to the bus (actually a Bridge)
280 compute_units[-1].ldsPort = compute_units[-1].ldsBus.slave
281 compute_units[-1].ldsBus.master = compute_units[-1].localDataStore.cuPort
282
283 # Attach compute units to GPU
284 shader.CUs = compute_units
285
286 ########################## Creating the CPU system ########################
287 options.num_cpus = options.num_cpus
288
289 # The shader core will be whatever is after the CPU cores are accounted for
290 shader_idx = options.num_cpus
291
292 # The command processor will be whatever is after the shader is accounted for
293 cp_idx = shader_idx + 1
294 cp_list = []
295
296 # List of CPUs
297 cpu_list = []
298
299 CpuClass, mem_mode = Simulation.getCPUClass(options.cpu_type)
300 if CpuClass == AtomicSimpleCPU:
301 fatal("AtomicSimpleCPU is not supported")
302 if mem_mode != 'timing':
303 fatal("Only the timing memory mode is supported")
304 shader.timing = True
305
306 if options.fast_forward and options.fast_forward_pseudo_op:
307 fatal("Cannot fast-forward based both on the number of instructions and"
308 " on pseudo-ops")
309 fast_forward = options.fast_forward or options.fast_forward_pseudo_op
310
311 if fast_forward:
312 FutureCpuClass, future_mem_mode = CpuClass, mem_mode
313
314 CpuClass = X86KvmCPU
315 mem_mode = 'atomic_noncaching'
316 # Leave shader.timing untouched, because its value only matters at the
317 # start of the simulation and because we require switching cpus
318 # *before* the first kernel launch.
319
320 future_cpu_list = []
321
322 # Initial CPUs to be used during fast-forwarding.
323 for i in range(options.num_cpus):
324 cpu = CpuClass(cpu_id = i,
325 clk_domain = SrcClockDomain(
326 clock = options.CPUClock,
327 voltage_domain = VoltageDomain(
328 voltage = options.cpu_voltage)))
329 cpu_list.append(cpu)
330
331 if options.fast_forward:
332 cpu.max_insts_any_thread = int(options.fast_forward)
333
334 if fast_forward:
335 MainCpuClass = FutureCpuClass
336 else:
337 MainCpuClass = CpuClass
338
339 # CPs to be used throughout the simulation.
340 for i in range(options.num_cp):
341 cp = MainCpuClass(cpu_id = options.num_cpus + i,
342 clk_domain = SrcClockDomain(
343 clock = options.CPUClock,
344 voltage_domain = VoltageDomain(
345 voltage = options.cpu_voltage)))
346 cp_list.append(cp)
347
348 # Main CPUs (to be used after fast-forwarding if fast-forwarding is specified).
349 for i in range(options.num_cpus):
350 cpu = MainCpuClass(cpu_id = i,
351 clk_domain = SrcClockDomain(
352 clock = options.CPUClock,
353 voltage_domain = VoltageDomain(
354 voltage = options.cpu_voltage)))
355 if fast_forward:
356 cpu.switched_out = True
357 future_cpu_list.append(cpu)
358 else:
359 cpu_list.append(cpu)
360
361 ########################## Creating the GPU dispatcher ########################
362 # Dispatcher dispatches work from host CPU to GPU
363 host_cpu = cpu_list[0]
364 dispatcher = GpuDispatcher()
365
366 ########################## Create and assign the workload ########################
367 # Check for rel_path in elements of base_list using test, returning
368 # the first full path that satisfies test
369 def find_path(base_list, rel_path, test):
370 for base in base_list:
371 if not base:
372 # base could be None if environment var not set
373 continue
374 full_path = os.path.join(base, rel_path)
375 if test(full_path):
376 return full_path
377 fatal("%s not found in %s" % (rel_path, base_list))
378
379 def find_file(base_list, rel_path):
380 return find_path(base_list, rel_path, os.path.isfile)
381
382 executable = find_path(benchmark_path, options.cmd, os.path.exists)
383 # it's common for a benchmark to be in a directory with the same
384 # name as the executable, so we handle that automatically
385 if os.path.isdir(executable):
386 benchmark_path = [executable]
387 executable = find_file(benchmark_path, options.cmd)
388 if options.kernel_files:
389 kernel_files = [find_file(benchmark_path, f)
390 for f in options.kernel_files.split(':')]
391 else:
392 # if kernel_files is not set, see if there's a unique .asm file
393 # in the same directory as the executable
394 kernel_path = os.path.dirname(executable)
395 kernel_files = glob.glob(os.path.join(kernel_path, '*.asm'))
396 if kernel_files:
397 print("Using GPU kernel code file(s)", ",".join(kernel_files))
398 else:
399 fatal("Can't locate kernel code (.asm) in " + kernel_path)
400
401 # OpenCL driver
402 driver = ClDriver(filename="hsa", codefile=kernel_files)
403 for cpu in cpu_list:
404 cpu.createThreads()
405 cpu.workload = Process(executable = executable,
406 cmd = [options.cmd] + options.options.split(),
407 drivers = [driver])
408 for cp in cp_list:
409 cp.workload = host_cpu.workload
410
411 if fast_forward:
412 for i in range(len(future_cpu_list)):
413 future_cpu_list[i].workload = cpu_list[i].workload
414 future_cpu_list[i].createThreads()
415
416 ########################## Create the overall system ########################
417 # List of CPUs that must be switched when moving between KVM and simulation
418 if fast_forward:
419 switch_cpu_list = \
420 [(cpu_list[i], future_cpu_list[i]) for i in range(options.num_cpus)]
421
422 # Full list of processing cores in the system. Note that
423 # dispatcher is also added to cpu_list although it is
424 # not a processing element
425 cpu_list = cpu_list + [shader] + cp_list + [dispatcher]
426
427 # creating the overall system
428 # notice the cpu list is explicitly added as a parameter to System
429 system = System(cpu = cpu_list,
430 mem_ranges = [AddrRange(options.mem_size)],
431 cache_line_size = options.cacheline_size,
432 mem_mode = mem_mode)
433 if fast_forward:
434 system.future_cpu = future_cpu_list
435 system.voltage_domain = VoltageDomain(voltage = options.sys_voltage)
436 system.clk_domain = SrcClockDomain(clock = options.sys_clock,
437 voltage_domain = system.voltage_domain)
438
439 if fast_forward:
440 have_kvm_support = 'BaseKvmCPU' in globals()
441 if have_kvm_support and buildEnv['TARGET_ISA'] == "x86":
442 system.vm = KvmVM()
443 for i in range(len(host_cpu.workload)):
444 host_cpu.workload[i].useArchPT = True
445 host_cpu.workload[i].kvmInSE = True
446 else:
447 fatal("KvmCPU can only be used in SE mode with x86")
448
449 # configure the TLB hierarchy
450 GPUTLBConfig.config_tlb_hierarchy(options, system, shader_idx)
451
452 # create Ruby system
453 system.piobus = IOXBar(width=32, response_latency=0,
454 frontend_latency=0, forward_latency=0)
455 Ruby.create_system(options, None, system)
456 system.ruby.clk_domain = SrcClockDomain(clock = options.ruby_clock,
457 voltage_domain = system.voltage_domain)
458
459 # attach the CPU ports to Ruby
460 for i in range(options.num_cpus):
461 ruby_port = system.ruby._cpu_ports[i]
462
463 # Create interrupt controller
464 system.cpu[i].createInterruptController()
465
466 # Connect cache port's to ruby
467 system.cpu[i].icache_port = ruby_port.slave
468 system.cpu[i].dcache_port = ruby_port.slave
469
470 ruby_port.mem_master_port = system.piobus.slave
471 if buildEnv['TARGET_ISA'] == "x86":
472 system.cpu[i].interrupts[0].pio = system.piobus.master
473 system.cpu[i].interrupts[0].int_master = system.piobus.slave
474 system.cpu[i].interrupts[0].int_slave = system.piobus.master
475 if fast_forward:
476 system.cpu[i].itb.walker.port = ruby_port.slave
477 system.cpu[i].dtb.walker.port = ruby_port.slave
478
479 # attach CU ports to Ruby
480 # Because of the peculiarities of the CP core, you may have 1 CPU but 2
481 # sequencers and thus 2 _cpu_ports created. Your GPUs shouldn't be
482 # hooked up until after the CP. To make this script generic, figure out
483 # the index as below, but note that this assumes there is one sequencer
484 # per compute unit and one sequencer per SQC for the math to work out
485 # correctly.
486 gpu_port_idx = len(system.ruby._cpu_ports) \
487 - options.num_compute_units - options.num_sqc
488 gpu_port_idx = gpu_port_idx - options.num_cp * 2
489
490 wavefront_size = options.wf_size
491 for i in range(n_cu):
492 # The pipeline issues wavefront_size number of uncoalesced requests
493 # in one GPU issue cycle. Hence wavefront_size mem ports.
494 for j in range(wavefront_size):
495 system.cpu[shader_idx].CUs[i].memory_port[j] = \
496 system.ruby._cpu_ports[gpu_port_idx].slave[j]
497 gpu_port_idx += 1
498
499 for i in range(n_cu):
500 if i > 0 and not i % options.cu_per_sqc:
501 print("incrementing idx on ", i)
502 gpu_port_idx += 1
503 system.cpu[shader_idx].CUs[i].sqc_port = \
504 system.ruby._cpu_ports[gpu_port_idx].slave
505 gpu_port_idx = gpu_port_idx + 1
506
507 # attach CP ports to Ruby
508 for i in range(options.num_cp):
509 system.cpu[cp_idx].createInterruptController()
510 system.cpu[cp_idx].dcache_port = \
511 system.ruby._cpu_ports[gpu_port_idx + i * 2].slave
512 system.cpu[cp_idx].icache_port = \
513 system.ruby._cpu_ports[gpu_port_idx + i * 2 + 1].slave
514 system.cpu[cp_idx].interrupts[0].pio = system.piobus.master
515 system.cpu[cp_idx].interrupts[0].int_master = system.piobus.slave
516 system.cpu[cp_idx].interrupts[0].int_slave = system.piobus.master
517 cp_idx = cp_idx + 1
518
519 # connect dispatcher to the system.piobus
520 dispatcher.pio = system.piobus.master
521 dispatcher.dma = system.piobus.slave
522
523 ################# Connect the CPU and GPU via GPU Dispatcher ###################
524 # CPU rings the GPU doorbell to notify a pending task
525 # using this interface.
526 # And GPU uses this interface to notify the CPU of task completion
527 # The communcation happens through emulated driver.
528
529 # Note this implicit setting of the cpu_pointer, shader_pointer and tlb array
530 # parameters must be after the explicit setting of the System cpu list
531 if fast_forward:
532 shader.cpu_pointer = future_cpu_list[0]
533 dispatcher.cpu = future_cpu_list[0]
534 else:
535 shader.cpu_pointer = host_cpu
536 dispatcher.cpu = host_cpu
537 dispatcher.shader_pointer = shader
538 dispatcher.cl_driver = driver
539
540 ########################## Start simulation ########################
541
542 root = Root(system=system, full_system=False)
543 m5.ticks.setGlobalFrequency('1THz')
544 if options.abs_max_tick:
545 maxtick = options.abs_max_tick
546 else:
547 maxtick = m5.MaxTick
548
549 # Benchmarks support work item annotations
550 Simulation.setWorkCountOptions(system, options)
551
552 # Checkpointing is not supported by APU model
553 if (options.checkpoint_dir != None or
554 options.checkpoint_restore != None):
555 fatal("Checkpointing not supported by apu model")
556
557 checkpoint_dir = None
558 m5.instantiate(checkpoint_dir)
559
560 # Map workload to this address space
561 host_cpu.workload[0].map(0x10000000, 0x200000000, 4096)
562
563 if options.fast_forward:
564 print("Switch at instruction count: %d" % cpu_list[0].max_insts_any_thread)
565
566 exit_event = m5.simulate(maxtick)
567
568 if options.fast_forward:
569 if exit_event.getCause() == "a thread reached the max instruction count":
570 m5.switchCpus(system, switch_cpu_list)
571 print("Switched CPUS @ tick %s" % (m5.curTick()))
572 m5.stats.reset()
573 exit_event = m5.simulate(maxtick - m5.curTick())
574 elif options.fast_forward_pseudo_op:
575 while exit_event.getCause() == "switchcpu":
576 # If we are switching *to* kvm, then the current stats are meaningful
577 # Note that we don't do any warmup by default
578 if type(switch_cpu_list[0][0]) == FutureCpuClass:
579 print("Dumping stats...")
580 m5.stats.dump()
581 m5.switchCpus(system, switch_cpu_list)
582 print("Switched CPUS @ tick %s" % (m5.curTick()))
583 m5.stats.reset()
584 # This lets us switch back and forth without keeping a counter
585 switch_cpu_list = [(x[1], x[0]) for x in switch_cpu_list]
586 exit_event = m5.simulate(maxtick - m5.curTick())
587
588 print("Ticks:", m5.curTick())
589 print('Exiting because ', exit_event.getCause())
590 sys.exit(exit_event.getCode())