stdlib: Added LoopPoint checkpoint specific generator

Added looppoint_save_checkpoint_generator to take checkpoints for
LoopPoint methodology.
Users can decide to update the relative counts storing in the LoopPoint
module and exit when all the target PC-count pairs are encountered or
not.

Change-Id: Id1cf1516f4fa838e20a67530e94b361e42ca09f3
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67197
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Zhantong Qiu
2023-01-06 17:28:00 -08:00
parent 82c587bd88
commit afbca3b6e7

View File

@@ -29,6 +29,7 @@ import m5.stats
from ..components.processors.abstract_processor import AbstractProcessor
from ..components.processors.switchable_processor import SwitchableProcessor
from ..resources.resource import SimpointResource
from gem5.utils.looppoint import LoopPoint
from m5.util import warn
from pathlib import Path
@@ -167,3 +168,46 @@ def simpoints_save_checkpoint_generator(
yield False
else:
yield True
def looppoint_save_checkpoint_generator(
checkpoint_dir: Path,
looppoint: LoopPoint,
update_relatives: bool = True,
exit_when_empty: bool = True,
):
"""
A generator for taking a checkpoint for LoopPoint. It will save the
checkpoints in the checkpoint_dir path with the Region id.
(i.e. "cpt.Region10) It only takes a checkpoint if the current PC Count
pair is a significant PC Count Pair. This is determined in the LoopPoint
module. The simulation loop continues after exiting this generator.
:param checkpoint_dir: where to save the checkpoints
:param loopoint: the looppoint object used in the configuration script
:param update_relative: if the generator should update the relative count
information in the output json file, then it should be True. It is default
as True.
:param exit_when_empty: if the generator should exit the simulation loop if
all PC paris have been discovered, then it should be True. It is default as
True.
"""
if exit_when_empty:
total_pairs = len(looppoint.get_targets())
else:
total_pairs = -1
# it will never equal to 0 if exit_when_empty is false
while total_pairs != 0:
region = looppoint.get_current_region()
# if it is a significant PC Count pair, then the get_current_region()
# will return an integer greater than 0. By significant PC Count pair,
# it means the PC Count pair that indicates where to take the
# checkpoint at. This is determined in the LoopPoint module.
if region != -1:
if update_relatives:
looppoint.update_relatives_counts()
m5.checkpoint((checkpoint_dir / f"cpt.Region{region}").as_posix())
total_pairs -= 1
yield False
yield True