The Sparta Modeling Framework
|
Checkpointer interface. Defines an ID-based checkpointing API for tree of related checkpoints which could be stored as ordered deltas internally. More...
#include <Checkpointer.hpp>
Public Types | |
Local Types | |
typedef Checkpoint::tick_t | tick_t |
tick_t Tick type to which checkpoints will refer | |
typedef Checkpoint::chkpt_id_t | chkpt_id_t |
tick_t Tick type to which checkpoints will refer | |
Public Member Functions | |
Construction & Initialization | |
Checkpointer (TreeNode &root, sparta::Scheduler *sched=nullptr) | |
Checkpointer Constructor. | |
virtual | ~Checkpointer () |
Destructor. | |
Attributes | |
const TreeNode & | getRoot () const noexcept |
Returns the root associated with this checkpointer. | |
TreeNode & | getRoot () noexcept |
Non-const variant of getRoot. | |
const Scheduler * | getScheduler () const noexcept |
Returns the sheduler associated with this checkpointer. | |
uint64_t | getTotalMemoryUse () const noexcept |
Computes and returns the memory usage by this checkpointer at this moment including any framework overhead. | |
uint64_t | getContentMemoryUse () const noexcept |
Computes and returns the memory usage by this checkpointer at this moment purely for the checkpoint state being held. | |
uint64_t | getTotalCheckpointsCreated () const noexcept |
Returns the total number of checkpoints which have been created by this checkpointer. This is unrelated to the current number of checkpoints in existance. Includes the head checkpoint if created. | |
Checkpointing Actions & Queries | |
void | createHead () |
Creates a head without taking an identified checkpoint. Cannot already have a head. | |
chkpt_id_t | createCheckpoint (bool force_snapshot=false) |
Creates a checkpoint at the given scheduler's current tick with a new checkpoint ID some point after the current checkpoint (see getCurrentID). If the current checkpoint already has other next checkpoints, the new checkpoint will be an alternate branch of the current checkpoint. This snapshot may be stored as a full snapshot if the checkpointer requires it, or if the snapshot threshold is exceeded, or if the force_snapshot argument is true Current tick will be read from scheduler (if not null) and must be >= the head checkpoint's tick. The current tick must also be >= the current checkpoints tick (See getCurrenTick). | |
virtual void | deleteCheckpoint (chkpt_id_t id)=0 |
Deletes a checkpoint by ID. | |
virtual void | loadCheckpoint (chkpt_id_t id)=0 |
Loads state from a specific checkpoint by ID. | |
void | forgetCurrent () |
Forgets the current checkpoint and current checkpoint (resetting to the head checkpoint) so that checkpoints can be taken at a different time without assuming simulation state continutiy with this checkpointers. This is ONLY to be used by a simulator IFF another checkpointer restores state at another cycle or the simulator resets but this checkpointer's tree is still expected to exist. | |
virtual std::vector< chkpt_id_t > | getCheckpointsAt (tick_t t) const =0 |
Gets all checkpoints taken at tick t on any timeline. | |
virtual std::vector< chkpt_id_t > | getCheckpoints () const =0 |
Gets all known checkpoint IDs available on any timeline sorted by tick (or equivalently checkpoint ID). | |
virtual uint32_t | getNumCheckpoints () const noexcept=0 |
Gets the current number of checkpoints having valid IDs which a client of this interface can refer to. | |
virtual std::deque< chkpt_id_t > | getCheckpointChain (chkpt_id_t id) const =0 |
Debugging utility which gets a deque of checkpoints representing a chain starting at the checkpoint head and ending at the checkpoint specified by id. Ths results can contain Checkpoint::UNIDENTIFIED_CHECKPOINT to represent temporary deleted checkpoints in the chain. | |
virtual Checkpoint * | findLatestCheckpointAtOrBefore (tick_t tick, chkpt_id_t from)=0 |
Finds the latest checkpoint at or before the given tick starting at the from checkpoint and working backward. If no checkpoints before or at tick are found, returns nullptr. | |
Checkpoint * | findCheckpoint (chkpt_id_t id) noexcept |
Finds a checkpoint by its ID. | |
virtual bool | hasCheckpoint (chkpt_id_t id) const noexcept |
Tests whether this checkpoint manager has a checkpoint with the given id. | |
const Checkpoint * | getHead () const noexcept |
Returns the head checkpoint which is equivalent to the earliest checkpoint taken. | |
chkpt_id_t | getHeadID () const noexcept |
Returns the checkpoint ID of the head checkpoint (if it exists) which is equivalent to the earliest checkpoint taken. | |
chkpt_id_t | getCurrentID () const |
Returns the current checkpoint ID. This is mainly a debugging utility as the current ID changes when adding, deleting, and loading checkpoints based on whether the checkpoints take were deltas or snapshots. A correct integration of the checkpointer by a simulator should not depend on this method for behavior decisions. | |
tick_t | getCurrentTick () const |
Gets the tick number of the current checkpoint (see getCurrentID). This is the tick number of the latest checkpoint either saved or written through this checkpointer. The next checkpoint taken will be on the same chain as a checkpoint taken at this tick. | |
Printing Methods | |
virtual std::string | stringize () const |
Returns a string describing this object. | |
void | dumpList (std::ostream &o) const |
Dumps this checkpointer's flat list of checkpoints to an ostream with a newline following each checkpoint. | |
void | dumpData (std::ostream &o) const |
Dumps this checkpointer's data to an ostream with a newline following each checkpoint. | |
void | dumpAnnotatedData (std::ostream &o) const |
Dumps this checkpointer's data to an ostream with annotations between each ArchData and a newline following each checkpoint description and each checkpoint data dump. | |
virtual void | traceValue (std::ostream &o, chkpt_id_t id, const ArchData *container, uint32_t offset, uint32_t size)=0 |
Debugging utility which dumps values in some bytes across a chain of checkpoints. The intent is to show the values loaded when attempting to restore needed to restore the given value in the selected checkpoint. | |
void | dumpTree (std::ostream &o) const |
Dumps this checkpointer's tree to an ostream with a line for each branch. Printout timescale is not relevant. Multi-line printouts for deep branches will be difficult to read. | |
void | dumpBranch (std::ostream &o, const Checkpoint *chkpt, uint32_t indent, uint32_t pos, std::deque< uint32_t > &continues) const |
Recursively dumps one branch (and sub-branches) to an ostream with a line for each branch. | |
Protected Member Functions | |
virtual Checkpoint * | findCheckpoint_ (chkpt_id_t id) noexcept=0 |
Attempts to find a checkpoint within this checkpointer by ID. | |
virtual const Checkpoint * | findCheckpoint_ (chkpt_id_t id) const noexcept=0 |
const variant of findCheckpoint_ | |
virtual void | createHead_ ()=0 |
Create a head node. | |
virtual chkpt_id_t | createCheckpoint_ (bool force_snapshot=false)=0 |
Create a checkpoint. | |
virtual void | dumpCheckpointNode_ (const Checkpoint *chkpt, std::ostream &o) const |
const std::vector< ArchData * > & | getArchDatas () const |
Returns ArchDatas enumerated by this Checkpointer for iteration when saving or loading checkpoint data. | |
Checkpoint * | getHead_ () noexcept |
Non-const variant of getHead_. | |
const Checkpoint * | getHead_ () const noexcept |
Gets the head checkpoint. Returns nullptr if none created yet. | |
void | setHead_ (Checkpoint *head) |
Sets the head checkpointer pointer to head for the first time. | |
Checkpoint * | getCurrent_ () const noexcept |
Gets the current checkpointer pointer. Returns nullptr if there is no current checkpoint object. | |
void | setCurrent_ (Checkpoint *current) |
Sets the current checkpoint pointer. | |
Protected Attributes | |
std::map< chkpt_id_t, std::unique_ptr< Checkpoint > > | chkpts_ |
All checkpoints sorted by ascending tick number (or equivalently ascending checkpoint ID since both are monotonically increasing) | |
Scheduler *const | sched_ |
Scheduler whose tick count will be set and read. Cannnot be updated after first checkpoint without bad side effects. Keeping this const for simplicity. | |
Checkpointer interface. Defines an ID-based checkpointing API for tree of related checkpoints which could be stored as ordered deltas internally.
Internal storage and structure are to be defined by implementations of this interface
A checkpoint tree may look something like the following, where each checkpoint is shown here by its simulation tick number (not ID)
* t=0 (head) --> t=100 +-> t=300 * | * `-> t=320 --> t=400 +-> t=500 * | `-> t=430 * `-> t=300 *
The procedure for using a Checkpointer is generally:
Then:
Definition at line 56 of file Checkpointer.hpp.
tick_t Tick type to which checkpoints will refer
Definition at line 68 of file Checkpointer.hpp.
tick_t Tick type to which checkpoints will refer
Definition at line 65 of file Checkpointer.hpp.
|
inline |
Checkpointer Constructor.
root | TreeNode at which checkpoints will be taken. This cannot be changed later. This does not necessarily need to be a RootTreeNode. Before the first checkpoint is taken, this node must be finalized (see sparta::TreeNode::isFinalized). At this point, the node does not need to be finalized |
sched | Relevant scheduler. If nullptr (default), the checkpointer will not touch attempt to roll back the scheduler on checkpoint restores |
Definition at line 88 of file Checkpointer.hpp.
|
inlinevirtual |
Destructor.
Definition at line 99 of file Checkpointer.hpp.
|
inline |
Creates a checkpoint at the given scheduler's current tick with a new checkpoint ID some point after the current checkpoint (see getCurrentID). If the current checkpoint already has other next checkpoints, the new checkpoint will be an alternate branch of the current checkpoint. This snapshot may be stored as a full snapshot if the checkpointer requires it, or if the snapshot threshold is exceeded, or if the force_snapshot argument is true Current tick will be read from scheduler (if not null) and must be >= the head checkpoint's tick. The current tick must also be >= the current checkpoints tick (See getCurrenTick).
force_snapshot | Forces the newly-created checkpoint to be a full snapshot instead of allowing the checkpointer to decide based on getSnapshotThreshold. A snapshot takes more time and space to store, but this can be a performance optimization if this checkpoint will be re-loaded very frequently |
CheckpointError | if a head checkpoint exists and the current tick is less than the head checkpoint's tick, or if the root TreeNode is not finalized. Also throws if the number of checkpoint IDs has been exhausted (i.e. all values of a chkpt_id_t have been used as IDs). This is unlikely and has a special exception message. |
Definition at line 249 of file Checkpointer.hpp.
|
protectedpure virtual |
Create a checkpoint.
|
inline |
Creates a head without taking an identified checkpoint. Cannot already have a head.
CheckpointError | if root is not yet finalized or a head already exists for this checkpointer |
Generally, this is called after all simulation state is initialized (e.g. resisters set) since it makes little sense to go back to a pre-initialized state.
Test for a head if necessary with getHead(). Typically, this should be called before running the simulation.
Definition at line 187 of file Checkpointer.hpp.
|
protectedpure virtual |
|
pure virtual |
Deletes a checkpoint by ID.
id | ID of checkpoint to delete. Must not be Checkpoint::UNIDENTIFIED_CHECKPOINT and must not be equal to the ID of the head checkpoint. |
CheckpointError | if this manager has no checkpoint with given id. Test with hasCheckpoint first. If id == Checkpoint::UNIDENTIFIED_CHECKPOINT, always throws. Throws if id == getHeadID(). Head cannot be deleted |
Internally, this deletion may be effective-only and actual data may still exist in an incaccessible form as part of the checkpoint tree implementation.
If the current checkpoint is deleted, current will be updated back along the current checkpoints previous checkpoint chain until a non deleted checkpoint is found. This will become the new current checkpoint
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
inline |
Dumps this checkpointer's data to an ostream with annotations between each ArchData and a newline following each checkpoint description and each checkpoint data dump.
o | ostream to dump to |
Definition at line 532 of file Checkpointer.hpp.
|
inline |
Recursively dumps one branch (and sub-branches) to an ostream with a line for each branch.
o | ostream to dump to |
chkpt | Checkpoint to start printint at |
indent | Number of spaces to indent before printing this branch |
pos | Position on line. |
continues | Vector of continue indent points where '|' characters should be printed on lines whose indent amount is greater than each particular indent point. This creates the vertical lines expected in directory-like tree-view displays |
Definition at line 580 of file Checkpointer.hpp.
|
inlineprotectedvirtual |
Reimplemented in sparta::serialization::checkpoint::FastCheckpointer.
Definition at line 692 of file Checkpointer.hpp.
|
inline |
Dumps this checkpointer's data to an ostream with a newline following each checkpoint.
o | ostream to dump to |
Definition at line 519 of file Checkpointer.hpp.
|
inline |
Dumps this checkpointer's flat list of checkpoints to an ostream with a newline following each checkpoint.
o | ostream to dump to |
Definition at line 508 of file Checkpointer.hpp.
|
inline |
Dumps this checkpointer's tree to an ostream with a line for each branch. Printout timescale is not relevant. Multi-line printouts for deep branches will be difficult to read.
o | ostream to dump to |
Definition at line 562 of file Checkpointer.hpp.
|
inlinenoexcept |
Finds a checkpoint by its ID.
id | ID of checkpoint to find. Guaranteed not to be flagged as deleted |
Definition at line 390 of file Checkpointer.hpp.
|
protectedpure virtualnoexcept |
const variant of findCheckpoint_
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
protectedpure virtualnoexcept |
Attempts to find a checkpoint within this checkpointer by ID.
id | Checkpoint ID to search for |
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
pure virtual |
Finds the latest checkpoint at or before the given tick starting at the from checkpoint and working backward. If no checkpoints before or at tick are found, returns nullptr.
tick | Tick to search for |
from | Checkpoint at which to begin searching for a tick. Must be a valid checkpoint known by this checkpointer. See hasCheckpoint. |
CheckpointError | if from does not refer to a valid checkpoint. |
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
inline |
Forgets the current checkpoint and current checkpoint (resetting to the head checkpoint) so that checkpoints can be taken at a different time without assuming simulation state continutiy with this checkpointers. This is ONLY to be used by a simulator IFF another checkpointer restores state at another cycle or the simulator resets but this checkpointer's tree is still expected to exist.
Definition at line 312 of file Checkpointer.hpp.
|
inlineprotected |
Returns ArchDatas enumerated by this Checkpointer for iteration when saving or loading checkpoint data.
Definition at line 700 of file Checkpointer.hpp.
|
pure virtual |
Debugging utility which gets a deque of checkpoints representing a chain starting at the checkpoint head and ending at the checkpoint specified by id. Ths results can contain Checkpoint::UNIDENTIFIED_CHECKPOINT to represent temporary deleted checkpoints in the chain.
id | ID of checkpoint that terminates the chain |
CheckpointError | if id does not refer to a valid checkpoint. |
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
pure virtual |
Gets all known checkpoint IDs available on any timeline sorted by tick (or equivalently checkpoint ID).
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
pure virtual |
Gets all checkpoints taken at tick t on any timeline.
t | Tick number at which checkpoints should found. |
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
inlinenoexcept |
Computes and returns the memory usage by this checkpointer at this moment purely for the checkpoint state being held.
Definition at line 142 of file Checkpointer.hpp.
|
inlineprotectednoexcept |
Gets the current checkpointer pointer. Returns nullptr if there is no current checkpoint object.
Definition at line 735 of file Checkpointer.hpp.
|
inline |
Returns the current checkpoint ID. This is mainly a debugging utility as the current ID changes when adding, deleting, and loading checkpoints based on whether the checkpoints take were deltas or snapshots. A correct integration of the checkpointer by a simulator should not depend on this method for behavior decisions.
The current checkpoint refers to the most recent checkpoint either loaded or created. This value is used to refer to the previous-checkpoint when creating a delta checkpoint.
Loading, creating, and deleting a checkpoint updates the current checkpoint.
If the previous current checkpoint was deleted, current is updated to refer back to the most recent previous checkpoint in the same previous-checkpoint chain of one which was deleted.
Definition at line 459 of file Checkpointer.hpp.
|
inline |
Gets the tick number of the current checkpoint (see getCurrentID). This is the tick number of the latest checkpoint either saved or written through this checkpointer. The next checkpoint taken will be on the same chain as a checkpoint taken at this tick.
Definition at line 479 of file Checkpointer.hpp.
|
inlinenoexcept |
Returns the head checkpoint which is equivalent to the earliest checkpoint taken.
The head checkpoint has an ID of Checkpoint::UNIDENTIFIED_CHECKPOINT and can never be deleted.
Definition at line 415 of file Checkpointer.hpp.
|
inlineprotectednoexcept |
Gets the head checkpoint. Returns nullptr if none created yet.
Definition at line 714 of file Checkpointer.hpp.
|
inlineprotectednoexcept |
Non-const variant of getHead_.
Definition at line 707 of file Checkpointer.hpp.
|
inlinenoexcept |
Returns the checkpoint ID of the head checkpoint (if it exists) which is equivalent to the earliest checkpoint taken.
The head checkpoint can never be deleted.
Definition at line 428 of file Checkpointer.hpp.
|
pure virtualnoexcept |
Gets the current number of checkpoints having valid IDs which a client of this interface can refer to.
Ignores any internal temporary or deleted checkpoints without visible IDs
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
inlinenoexcept |
Returns the root associated with this checkpointer.
Definition at line 112 of file Checkpointer.hpp.
|
inlinenoexcept |
Non-const variant of getRoot.
Definition at line 117 of file Checkpointer.hpp.
|
inlinenoexcept |
Returns the sheduler associated with this checkpointer.
Definition at line 122 of file Checkpointer.hpp.
|
inlinenoexcept |
Returns the total number of checkpoints which have been created by this checkpointer. This is unrelated to the current number of checkpoints in existance. Includes the head checkpoint if created.
Definition at line 155 of file Checkpointer.hpp.
|
inlinenoexcept |
Computes and returns the memory usage by this checkpointer at this moment including any framework overhead.
Definition at line 130 of file Checkpointer.hpp.
|
inlinevirtualnoexcept |
Tests whether this checkpoint manager has a checkpoint with the given id.
Definition at line 401 of file Checkpointer.hpp.
|
pure virtual |
Loads state from a specific checkpoint by ID.
CheckpointError | if id does not refer to checkpoint that exists or if checkpoint could not be load. |
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
inlineprotected |
Sets the current checkpoint pointer.
current | Pointer to set as current checkpoint. The next checkpoint created will follow the current checkpoint set here. Cannot be nullptr |
Definition at line 745 of file Checkpointer.hpp.
|
inlineprotected |
Sets the head checkpointer pointer to head for the first time.
head | New head checkpoint pointer. Must not be nullptr |
Definition at line 725 of file Checkpointer.hpp.
|
inlinevirtual |
Returns a string describing this object.
Reimplemented in sparta::serialization::checkpoint::FastCheckpointer.
Definition at line 497 of file Checkpointer.hpp.
|
pure virtual |
Debugging utility which dumps values in some bytes across a chain of checkpoints. The intent is to show the values loaded when attempting to restore needed to restore the given value in the selected checkpoint.
o | ostream with each value and checkpoint ID will be printed |
id | ID of checkpoint to "restore" value from |
container | ArchData in which the data being traced lives |
offset | Offset into container |
size | Bytes to read at offset |
Implemented in sparta::serialization::checkpoint::FastCheckpointer.
|
protected |
All checkpoints sorted by ascending tick number (or equivalently ascending checkpoint ID since both are monotonically increasing)
This map must still be explicitly torn down in reverse order by a subclass of Checkpointer
Definition at line 759 of file Checkpointer.hpp.
|
protected |
Scheduler whose tick count will be set and read. Cannnot be updated after first checkpoint without bad side effects. Keeping this const for simplicity.
Definition at line 766 of file Checkpointer.hpp.