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

Class to enable a modeler to register checkpointable objects in simulation. More...

#include <Checkpointable.hpp>

Public Member Functions

 Checkpointable (sparta::TreeNode *cp_node)
 Create a Checkpointable object used to allocate components for checkpointing.
 
template<class CheckpointableT , typename... CpArgs>
CheckpointableT & allocateCheckpointable (CpArgs... cp_args)
 Allocate a checkpointable type.
 

Detailed Description

Class to enable a modeler to register checkpointable objects in simulation.

Sparta's checkpointing mechanism use sparta::ArchData backend (for memory, registers) to save/restore checkpoints, but some classes store their data in member variables and not ArchData backends.

This class provides a simple interface that allows a user to register those member variables with Sparta's checkpointing mechanism.

Inside the Checkpointable, for each object registed/allocated, a block of memory is created to completely contain that object (for memory copy) and a reference to that memory is returned. If the checkpointed object is not self-contained, behavior will be indeterministic on checkpoint restores.

To guarantee the save/restore of a checkpointed object, the checkpointed object's types must be serializabtle, meaning they must be trivial/fundamental and direct. For example, the checkpointable object must not be nor contain any pointers to untracked memory. However, the checkpointed object is not required to be trivially constructable.

Examples of checkpointable types:

  • POD types (int, float, etc)
  • Static array types
  • Structual components comprised of POD types or nested structs, also of POD types

This class will not ensure the checkpointable object falls within the bound of the above contraints. In other words, the modeler is responsible for making sure the checkpointable object is self-contained within singluar storage capacity.

Example usecase:

class MyCheckpointable
{
public:
MyCheckpointable(sparta:TreeNode * my_node) :
my_checkpointable_integer_(allocateCheckpointable<uint64_t)>()),
my_checkpointable_struct_(allocateCheckpointable<MyCheckpointStructure)>(0,
"Hello World"))
{}
private:
// Checkpointable class
// Objects to be checkpointed
struct MyCheckpointStructure {
MyCheckpointStructure(uint32_t initial_int_val,
const char * initial_str_val) :
my_struct_int_(initial_int_val)
{
::strcpy(my_struct_ary_, initial_int_val);
}
uint32_t my_struct_int_;
char my_struct_ary_[128];
};
uint32_t & my_checkpointable_integer_;
MyCheckpointStructure & my_checkpointable_struct_;
};
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
Class to enable a modeler to register checkpointable objects in simulation.
Macros for handling exponential backoff.

Definition at line 90 of file Checkpointable.hpp.

Constructor & Destructor Documentation

◆ Checkpointable()

sparta::serialization::checkpoint::Checkpointable::Checkpointable ( sparta::TreeNode * cp_node)
inline

Create a Checkpointable object used to allocate components for checkpointing.

Definition at line 96 of file Checkpointable.hpp.

Member Function Documentation

◆ allocateCheckpointable()

template<class CheckpointableT , typename... CpArgs>
CheckpointableT & sparta::serialization::checkpoint::Checkpointable::allocateCheckpointable ( CpArgs... cp_args)
inline

Allocate a checkpointable type.

Parameters
cp_argsArguments to pass to the object during construction
Template Parameters
CheckpointableTThe object type – must not be a pointer
CpArgsThe object construction args (if required)

A trival, copyable type can be POD, a simple structure containing POD types, structures with embedded POD types, and array types of PODs.

Definition at line 110 of file Checkpointable.hpp.


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