The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::serialization::checkpoint::PersistentFastCheckpointer Class Reference

Implements a Persistent FastCheckpointer, i.e. implements an interface to save checkpoints to disk. More...

#include <PersistentFastCheckpointer.hpp>

Inheritance diagram for sparta::serialization::checkpoint::PersistentFastCheckpointer:
Collaboration diagram for sparta::serialization::checkpoint::PersistentFastCheckpointer:

Classes

class  FileReadAdapter
 file storage adpater for ArchData More...
 
class  FileWriteAdapter
 file storage adpater for ArchData More...
 

Construction & Initialization

 PersistentFastCheckpointer (TreeNode &root, sparta::Scheduler *sched=nullptr)
 PersistentFastCheckpointer Constructor.
 
virtual ~PersistentFastCheckpointer ()
 Destructor.
 
FastCheckpointer::chkpt_id_t save (std::ostream &outf)
 
FastCheckpointer::chkpt_id_t save (std::string filename)
 
FastCheckpointer::chkpt_id_t save ()
 
void restore (std::istream &in)
 
void restore (const std::string &filename)
 

Additional Inherited Members

- Public Types inherited from sparta::serialization::checkpoint::FastCheckpointer
typedef DeltaCheckpoint< storage::VectorStoragecheckpoint_type
 
- Public Types inherited from sparta::serialization::checkpoint::Checkpointer
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 inherited from sparta::serialization::checkpoint::FastCheckpointer
 FastCheckpointer (TreeNode &root, Scheduler *sched=nullptr)
 FastCheckpointer Constructor.
 
 ~FastCheckpointer ()
 Destructor.
 
uint32_t getSnapshotThreshold () const noexcept
 Returns the next-shapshot threshold.
 
void setSnapshotThreshold (uint32_t thresh) noexcept
 Sets the snapshot threshold.
 
void deleteCheckpoint (chkpt_id_t id) override
 Deletes a checkpoint by ID.
 
void loadCheckpoint (chkpt_id_t id) override
 Loads state from a specific checkpoint by ID.
 
bool checkpointExists (chkpt_id_t id)
 Queries a specific checkpoint by ID.
 
std::vector< chkpt_id_tgetCheckpointsAt (tick_t t) const override
 Gets all checkpoints taken at tick t on any timeline.
 
std::vector< chkpt_id_tgetCheckpoints () const override
 Gets all checkpoint IDs available on any timeline sorted by tick (or equivalently checkpoint ID).
 
uint32_t getNumCheckpoints () const noexcept override
 Gets the current number of checkpoints having valid IDs.
 
uint32_t getNumSnapshots () const noexcept
 Gets the current number of snapshots with valid IDs.
 
uint32_t getNumDeltas () const noexcept
 Gets the current number of delta checkpoints with valid IDs.
 
uint32_t getNumDeadCheckpoints () const noexcept
 Gets the curent number of checkpoints (delta or snapshot) withOUT valid IDs.
 
std::deque< chkpt_id_tgetCheckpointChain (chkpt_id_t id) const override
 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_type::UNIDENTIFIED_CHECKPOINT to represent temporary deleted checkpoints in the chain.
 
checkpoint_typefindLatestCheckpointAtOrBefore (tick_t tick, chkpt_id_t from) override
 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_typefindInternalCheckpoint (chkpt_id_t id)
 Gets a checkpoint through findCheckpoint interface casted to the type of Checkpoint subclass used by this class.
 
std::string stringize () const override
 Returns a string describing this object.
 
void traceValue (std::ostream &o, chkpt_id_t id, const ArchData *container, uint32_t offset, uint32_t size) override
 Forwards debug/trace info onto checkpoint by ID.
 
- Public Member Functions inherited from sparta::serialization::checkpoint::Checkpointer
 Checkpointer (TreeNode &root, sparta::Scheduler *sched=nullptr)
 Checkpointer Constructor.
 
virtual ~Checkpointer ()
 Destructor.
 
const TreeNodegetRoot () const noexcept
 Returns the root associated with this checkpointer.
 
TreeNodegetRoot () noexcept
 Non-const variant of getRoot.
 
const SchedulergetScheduler () 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.
 
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).
 
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.
 
CheckpointfindCheckpoint (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 CheckpointgetHead () 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.
 
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.
 
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 inherited from sparta::serialization::checkpoint::FastCheckpointer
void cleanupChain_ (checkpoint_type *d)
 Delete given checkpoint and all contiguous previous checkpoints which can be deleted (See checkpoint_type::canDelete). This is the only place where checkpoint objects are actually freed (aside from destruction) and it ensures that they will not disrupt the checkpoint delta chains. All other deletion is simply flagging and re-identifying checkpoints.
 
bool recursForwardFindAlive_ (checkpoint_type *d) const
 Look forward to see if any future checkpoints depend on d.
 
checkpoint_typefindCheckpoint_ (chkpt_id_t id) noexcept override
 Attempts to find a checkpoint within this checkpointer by ID.
 
const checkpoint_typefindCheckpoint_ (chkpt_id_t id) const noexcept override
 const variant of findCheckpoint_
 
void dumpCheckpointNode_ (const Checkpoint *chkpt, std::ostream &o) const override
 Implements Checkpointer::dumpCheckpointNode_.
 
- Protected Member Functions inherited from sparta::serialization::checkpoint::Checkpointer
const std::vector< ArchData * > & getArchDatas () const
 Returns ArchDatas enumerated by this Checkpointer for iteration when saving or loading checkpoint data.
 
CheckpointgetHead_ () noexcept
 Non-const variant of getHead_.
 
const CheckpointgetHead_ () 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.
 
CheckpointgetCurrent_ () 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 inherited from sparta::serialization::checkpoint::Checkpointer
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.
 

Detailed Description

Implements a Persistent FastCheckpointer, i.e. implements an interface to save checkpoints to disk.

Used in conjunction with the fast checkpointer (which saves checkpoints to memory), this class enables user the save the checkpoints to disk for loading later.

Definition at line 27 of file PersistentFastCheckpointer.hpp.

Constructor & Destructor Documentation

◆ PersistentFastCheckpointer()

sparta::serialization::checkpoint::PersistentFastCheckpointer::PersistentFastCheckpointer ( TreeNode root,
sparta::Scheduler sched = nullptr 
)
inline

PersistentFastCheckpointer Constructor.

Parameters
rootTreeNode 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
schedScheduler whose current cycle will be read when taking checkpoints and restored when restoring checkpoints. See sparta::serialization::Checkpoint::Checkpoint for details

Definition at line 149 of file PersistentFastCheckpointer.hpp.

◆ ~PersistentFastCheckpointer()

virtual sparta::serialization::checkpoint::PersistentFastCheckpointer::~PersistentFastCheckpointer ( )
inlinevirtual

Destructor.

Definition at line 160 of file PersistentFastCheckpointer.hpp.

Member Function Documentation

◆ restore() [1/2]

void sparta::serialization::checkpoint::PersistentFastCheckpointer::restore ( const std::string &  filename)
inline

Restore checkpoint from file.

Parameters
filenameThe name of the checkpoint file

Definition at line 226 of file PersistentFastCheckpointer.hpp.

Here is the call graph for this function:

◆ restore() [2/2]

void sparta::serialization::checkpoint::PersistentFastCheckpointer::restore ( std::istream &  in)
inline

Restore checkpoint from istream.

Parameters
inInput stream from which to retrieve checkpoint data

Definition at line 214 of file PersistentFastCheckpointer.hpp.

Here is the call graph for this function:

◆ save() [1/3]

FastCheckpointer::chkpt_id_t sparta::serialization::checkpoint::PersistentFastCheckpointer::save ( )
inline

Save checkpoint to calculated filename.

Calculates the filename based on the configured prefix and suffix, as well as the checkpoint ID.

Returns
The checkpoint ID

Definition at line 197 of file PersistentFastCheckpointer.hpp.

Here is the call graph for this function:

◆ save() [2/3]

FastCheckpointer::chkpt_id_t sparta::serialization::checkpoint::PersistentFastCheckpointer::save ( std::ostream &  outf)
inline

Save checkpoint to ostream.

Parameters
outfOutput stream to save to
Returns
The checkpoint ID

Definition at line 170 of file PersistentFastCheckpointer.hpp.

Here is the call graph for this function:

◆ save() [3/3]

FastCheckpointer::chkpt_id_t sparta::serialization::checkpoint::PersistentFastCheckpointer::save ( std::string  filename)
inline

Save checkpoint to specified file.

Parameters
filenameFilename to use for checkpoint
Returns
The checkpoint ID

Definition at line 182 of file PersistentFastCheckpointer.hpp.

Here is the call graph for this function:

The documentation for this class was generated from the following file: