Simulation.py (10159:ca6f1407f8f8) Simulation.py (10608:427f988fe6e5)
1# Copyright (c) 2012-2013 ARM Limited
2# All rights reserved
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 126 unchanged lines hidden (view full) ---

135 # assume workload 0 has the simpoint
136 if testsys.cpu[0].workload[0].simpoint == 0:
137 fatal('Unable to find simpoint')
138 inst += int(testsys.cpu[0].workload[0].simpoint)
139
140 checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % (options.bench, inst))
141 if not exists(checkpoint_dir):
142 fatal("Unable to find checkpoint directory %s", checkpoint_dir)
1# Copyright (c) 2012-2013 ARM Limited
2# All rights reserved
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 126 unchanged lines hidden (view full) ---

135 # assume workload 0 has the simpoint
136 if testsys.cpu[0].workload[0].simpoint == 0:
137 fatal('Unable to find simpoint')
138 inst += int(testsys.cpu[0].workload[0].simpoint)
139
140 checkpoint_dir = joinpath(cptdir, "cpt.%s.%s" % (options.bench, inst))
141 if not exists(checkpoint_dir):
142 fatal("Unable to find checkpoint directory %s", checkpoint_dir)
143
144 elif options.restore_simpoint_checkpoint:
145 # Restore from SimPoint checkpoints
146 # Assumes that the checkpoint dir names are formatted as follows:
147 dirs = listdir(cptdir)
148 expr = re.compile('cpt\.simpoint_(\d+)_inst_(\d+)' +
149 '_weight_([\d\.e\-]+)_interval_(\d+)_warmup_(\d+)')
150 cpts = []
151 for dir in dirs:
152 match = expr.match(dir)
153 if match:
154 cpts.append(dir)
155 cpts.sort()
156
157 cpt_num = options.checkpoint_restore
158 if cpt_num > len(cpts):
159 fatal('Checkpoint %d not found', cpt_num)
160 checkpoint_dir = joinpath(cptdir, cpts[cpt_num - 1])
161 match = expr.match(cpts[cpt_num - 1])
162 if match:
163 index = int(match.group(1))
164 start_inst = int(match.group(2))
165 weight_inst = float(match.group(3))
166 interval_length = int(match.group(4))
167 warmup_length = int(match.group(5))
168 print "Resuming from", checkpoint_dir
169 simpoint_start_insts = []
170 simpoint_start_insts.append(warmup_length)
171 simpoint_start_insts.append(warmup_length + interval_length)
172 testsys.cpu[0].simpoint_start_insts = simpoint_start_insts
173 if testsys.switch_cpus != None:
174 testsys.switch_cpus[0].simpoint_start_insts = simpoint_start_insts
175
176 print "Resuming from SimPoint",
177 print "#%d, start_inst:%d, weight:%f, interval:%d, warmup:%d" % \
178 (index, start_inst, weight_inst, interval_length, warmup_length)
179
143 else:
144 dirs = listdir(cptdir)
180 else:
181 dirs = listdir(cptdir)
145 expr = re.compile('cpt\.([0-9]*)')
182 expr = re.compile('cpt\.([0-9]+)')
146 cpts = []
147 for dir in dirs:
148 match = expr.match(dir)
149 if match:
150 cpts.append(match.group(1))
151
152 cpts.sort(lambda a,b: cmp(long(a), long(b)))
153

--- 80 unchanged lines hidden (view full) ---

234 exit_cause = "maximum %d checkpoints dropped" % max_checkpoints
235 break
236
237 exit_event = m5.simulate(maxtick - m5.curTick())
238 exit_cause = exit_event.getCause()
239
240 return exit_event
241
183 cpts = []
184 for dir in dirs:
185 match = expr.match(dir)
186 if match:
187 cpts.append(match.group(1))
188
189 cpts.sort(lambda a,b: cmp(long(a), long(b)))
190

--- 80 unchanged lines hidden (view full) ---

271 exit_cause = "maximum %d checkpoints dropped" % max_checkpoints
272 break
273
274 exit_event = m5.simulate(maxtick - m5.curTick())
275 exit_cause = exit_event.getCause()
276
277 return exit_event
278
279# Set up environment for taking SimPoint checkpoints
280# Expecting SimPoint files generated by SimPoint 3.2
281def parseSimpointAnalysisFile(options, testsys):
282 import re
283
284 simpoint_filename, weight_filename, interval_length, warmup_length = \
285 options.take_simpoint_checkpoints.split(",", 3)
286 print "simpoint analysis file:", simpoint_filename
287 print "simpoint weight file:", weight_filename
288 print "interval length:", interval_length
289 print "warmup length:", warmup_length
290
291 interval_length = int(interval_length)
292 warmup_length = int(warmup_length)
293
294 # Simpoint analysis output starts interval counts with 0.
295 simpoints = []
296 simpoint_start_insts = []
297
298 # Read in SimPoint analysis files
299 simpoint_file = open(simpoint_filename)
300 weight_file = open(weight_filename)
301 while True:
302 line = simpoint_file.readline()
303 if not line:
304 break
305 m = re.match("(\d+)\s+(\d+)", line)
306 if m:
307 interval = int(m.group(1))
308 else:
309 fatal('unrecognized line in simpoint file!')
310
311 line = weight_file.readline()
312 if not line:
313 fatal('not enough lines in simpoint weight file!')
314 m = re.match("([0-9\.e\-]+)\s+(\d+)", line)
315 if m:
316 weight = float(m.group(1))
317 else:
318 fatal('unrecognized line in simpoint weight file!')
319
320 if (interval * interval_length - warmup_length > 0):
321 starting_inst_count = \
322 interval * interval_length - warmup_length
323 actual_warmup_length = warmup_length
324 else:
325 # Not enough room for proper warmup
326 # Just starting from the beginning
327 starting_inst_count = 0
328 actual_warmup_length = interval * interval_length
329
330 simpoints.append((interval, weight, starting_inst_count,
331 actual_warmup_length))
332
333 # Sort SimPoints by starting inst count
334 simpoints.sort(key=lambda obj: obj[2])
335 for s in simpoints:
336 interval, weight, starting_inst_count, actual_warmup_length = s
337 print str(interval), str(weight), starting_inst_count, \
338 actual_warmup_length
339 simpoint_start_insts.append(starting_inst_count)
340
341 print "Total # of simpoints:", len(simpoints)
342 testsys.cpu[0].simpoint_start_insts = simpoint_start_insts
343
344 return (simpoints, interval_length)
345
346def takeSimpointCheckpoints(simpoints, interval_length, cptdir):
347 num_checkpoints = 0
348 index = 0
349 last_chkpnt_inst_count = -1
350 for simpoint in simpoints:
351 interval, weight, starting_inst_count, actual_warmup_length = simpoint
352 if starting_inst_count == last_chkpnt_inst_count:
353 # checkpoint starting point same as last time
354 # (when warmup period longer than starting point)
355 exit_cause = "simpoint starting point found"
356 code = 0
357 else:
358 exit_event = m5.simulate()
359
360 # skip checkpoint instructions should they exist
361 while exit_event.getCause() == "checkpoint":
362 print "Found 'checkpoint' exit event...ignoring..."
363 exit_event = m5.simulate()
364
365 exit_cause = exit_event.getCause()
366 code = exit_event.getCode()
367
368 if exit_cause == "simpoint starting point found":
369 m5.checkpoint(joinpath(cptdir,
370 "cpt.simpoint_%02d_inst_%d_weight_%f_interval_%d_warmup_%d"
371 % (index, starting_inst_count, weight, interval_length,
372 actual_warmup_length)))
373 print "Checkpoint #%d written. start inst:%d weight:%f" % \
374 (num_checkpoints, starting_inst_count, weight)
375 num_checkpoints += 1
376 last_chkpnt_inst_count = starting_inst_count
377 else:
378 break
379 index += 1
380
381 print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause)
382 print "%d checkpoints taken" % num_checkpoints
383 sys.exit(code)
384
385def restoreSimpointCheckpoint():
386 exit_event = m5.simulate()
387 exit_cause = exit_event.getCause()
388
389 if exit_cause == "simpoint starting point found":
390 print "Warmed up! Dumping and resetting stats!"
391 m5.stats.dump()
392 m5.stats.reset()
393
394 exit_event = m5.simulate()
395 exit_cause = exit_event.getCause()
396
397 if exit_cause == "simpoint starting point found":
398 print "Done running SimPoint!"
399 sys.exit(exit_event.getCode())
400
401 print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_cause)
402 sys.exit(exit_event.getCode())
403
242def repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, switch_freq):
243 print "starting switch loop"
244 while True:
245 exit_event = m5.simulate(switch_freq)
246 exit_cause = exit_event.getCause()
247
248 if exit_cause != "simulate() limit reached":
249 return exit_event

--- 156 unchanged lines hidden (view full) ---

406 options.take_checkpoints = checkpoint_inst
407 else:
408 options.take_checkpoints = offset
409 # Set all test cpus with the right number of instructions
410 # for the upcoming simulation
411 for i in xrange(np):
412 testsys.cpu[i].max_insts_any_thread = offset
413
404def repeatSwitch(testsys, repeat_switch_cpu_list, maxtick, switch_freq):
405 print "starting switch loop"
406 while True:
407 exit_event = m5.simulate(switch_freq)
408 exit_cause = exit_event.getCause()
409
410 if exit_cause != "simulate() limit reached":
411 return exit_event

--- 156 unchanged lines hidden (view full) ---

568 options.take_checkpoints = checkpoint_inst
569 else:
570 options.take_checkpoints = offset
571 # Set all test cpus with the right number of instructions
572 # for the upcoming simulation
573 for i in xrange(np):
574 testsys.cpu[i].max_insts_any_thread = offset
575
576 if options.take_simpoint_checkpoints != None:
577 simpoints, interval_length = parseSimpointAnalysisFile(options, testsys)
578
414 checkpoint_dir = None
415 if options.checkpoint_restore:
416 cpt_starttick, checkpoint_dir = findCptDir(options, cptdir, testsys)
417 m5.instantiate(checkpoint_dir)
418
419 # Handle the max tick settings now that tick frequency was resolved
420 # during system instantiation
421 # NOTE: the maxtick variable here is in absolute ticks, so it must

--- 58 unchanged lines hidden (view full) ---

480 print "Simulation ends instruction count:%d" % \
481 (testsys.switch_cpus_1[0].max_insts_any_thread)
482 m5.switchCpus(testsys, switch_cpu_list1)
483
484 # If we're taking and restoring checkpoints, use checkpoint_dir
485 # option only for finding the checkpoints to restore from. This
486 # lets us test checkpointing by restoring from one set of
487 # checkpoints, generating a second set, and then comparing them.
579 checkpoint_dir = None
580 if options.checkpoint_restore:
581 cpt_starttick, checkpoint_dir = findCptDir(options, cptdir, testsys)
582 m5.instantiate(checkpoint_dir)
583
584 # Handle the max tick settings now that tick frequency was resolved
585 # during system instantiation
586 # NOTE: the maxtick variable here is in absolute ticks, so it must

--- 58 unchanged lines hidden (view full) ---

645 print "Simulation ends instruction count:%d" % \
646 (testsys.switch_cpus_1[0].max_insts_any_thread)
647 m5.switchCpus(testsys, switch_cpu_list1)
648
649 # If we're taking and restoring checkpoints, use checkpoint_dir
650 # option only for finding the checkpoints to restore from. This
651 # lets us test checkpointing by restoring from one set of
652 # checkpoints, generating a second set, and then comparing them.
488 if options.take_checkpoints and options.checkpoint_restore:
653 if (options.take_checkpoints or options.take_simpoint_checkpoints) \
654 and options.checkpoint_restore:
655
489 if m5.options.outdir:
490 cptdir = m5.options.outdir
491 else:
492 cptdir = getcwd()
493
494 if options.take_checkpoints != None :
495 # Checkpoints being taken via the command line at <when> and at
496 # subsequent periods of <period>. Checkpoint instructions
497 # received from the benchmark running are ignored and skipped in
498 # favor of command line checkpoint instructions.
499 exit_event = scriptCheckpoints(options, maxtick, cptdir)
656 if m5.options.outdir:
657 cptdir = m5.options.outdir
658 else:
659 cptdir = getcwd()
660
661 if options.take_checkpoints != None :
662 # Checkpoints being taken via the command line at <when> and at
663 # subsequent periods of <period>. Checkpoint instructions
664 # received from the benchmark running are ignored and skipped in
665 # favor of command line checkpoint instructions.
666 exit_event = scriptCheckpoints(options, maxtick, cptdir)
667
668 # Take SimPoint checkpoints
669 elif options.take_simpoint_checkpoints != None:
670 takeSimpointCheckpoints(simpoints, interval_length, cptdir)
671
672 # Restore from SimPoint checkpoints
673 elif options.restore_simpoint_checkpoint != None:
674 restoreSimpointCheckpoint()
675
500 else:
501 if options.fast_forward:
502 m5.stats.reset()
503 print "**** REAL SIMULATION ****"
504
505 # If checkpoints are being taken, then the checkpoint instruction
506 # will occur in the benchmark code it self.
507 if options.repeat_switch and maxtick > options.repeat_switch:
508 exit_event = repeatSwitch(testsys, repeat_switch_cpu_list,
509 maxtick, options.repeat_switch)
510 else:
511 exit_event = benchCheckpoints(options, maxtick, cptdir)
512
513 print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause())
514 if options.checkpoint_at_end:
515 m5.checkpoint(joinpath(cptdir, "cpt.%d"))
516
517 if not m5.options.interactive:
518 sys.exit(exit_event.getCode())
676 else:
677 if options.fast_forward:
678 m5.stats.reset()
679 print "**** REAL SIMULATION ****"
680
681 # If checkpoints are being taken, then the checkpoint instruction
682 # will occur in the benchmark code it self.
683 if options.repeat_switch and maxtick > options.repeat_switch:
684 exit_event = repeatSwitch(testsys, repeat_switch_cpu_list,
685 maxtick, options.repeat_switch)
686 else:
687 exit_event = benchCheckpoints(options, maxtick, cptdir)
688
689 print 'Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause())
690 if options.checkpoint_at_end:
691 m5.checkpoint(joinpath(cptdir, "cpt.%d"))
692
693 if not m5.options.interactive:
694 sys.exit(exit_event.getCode())