The Sparta Modeling Framework
Loading...
Searching...
No Matches
CheckpointBase.hpp
1// <CheckpointBase> -*- C++ -*-
2
3#pragma once
4
5#include <iostream>
6#include <sstream>
7
8#include "sparta/functional/ArchData.hpp"
12
14
15namespace sparta::serialization::checkpoint
16{
26 {
27 public:
28
32
35
37 typedef uint64_t chkpt_id_t;
38
41
45 static const chkpt_id_t MIN_CHECKPOINT = 0;
46
52
53
57
60
63
66
69
70 protected:
71
76 tick_(tick),
77 chkpt_id_(id)
78 { }
79
80 CheckpointBase() = default;
81
82 public:
83
87 virtual ~CheckpointBase() = default;
88
92 template <typename Archive>
93 void serialize(Archive& ar, const unsigned int /*version*/) {
94 ar & tick_;
95 ar & chkpt_id_;
96 }
97
101 virtual std::string stringize() const {
102 std::stringstream ss;
103 ss << "<Checkpoint id=" << chkpt_id_ << " at t=" << tick_;
104 ss << ' ' << getTotalMemoryUse()/1000.0f << "kB (" << getContentMemoryUse()/1000.0f << "kB Data)";
105 ss << '>';
106 return ss.str();
107 }
108
114 virtual void dumpData(std::ostream& o) const = 0;
115
120 virtual uint64_t getTotalMemoryUse() const noexcept = 0;
121
126 virtual uint64_t getContentMemoryUse() const noexcept = 0;
127
131
136 virtual void load(const std::vector<ArchData*>& dats) = 0;
137
141 tick_t getTick() const noexcept { return tick_; }
142
148 chkpt_id_t getID() const noexcept { return chkpt_id_; }
149
154 virtual chkpt_id_t getPrevID() const = 0;
155
160 virtual std::vector<chkpt_id_t> getNextIDs() const = 0;
161
166 virtual std::string getDeletedRepr() const {
167 return "*";
168 }
169
172
173 protected:
178 chkpt_id_ = id;
179 }
180
181 private:
182 tick_t tick_;
183 chkpt_id_t chkpt_id_;
184 };
185
186} // namespace sparta::serialization::checkpoint
187
189inline std::ostream& operator<<(std::ostream& o, const sparta::serialization::checkpoint::CheckpointBase& dcp){
190 o << dcp.stringize();
191 return o;
192}
193
195inline std::ostream& operator<<(std::ostream& o, const sparta::serialization::checkpoint::CheckpointBase* dcp){
196 if(dcp == 0){
197 o << "null";
198 }else{
199 o << dcp->stringize();
200 }
201 return o;
202}
203
205#define SPARTA_CHECKPOINT_BODY \
206 namespace sparta{ namespace serialization { namespace checkpoint { \
207 const CheckpointBase::chkpt_id_t CheckpointBase::MIN_CHECKPOINT; \
208 const CheckpointBase::chkpt_id_t CheckpointBase::UNIDENTIFIED_CHECKPOINT; \
209 }}}
File that contains checkpoint exception types.
A simple time-based, event precedence based scheduler.
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
Contains a set of contiguous line of architectural data which can be referred to by any architected o...
Definition ArchData.hpp:39
uint64_t Tick
Typedef for our unit of time.
Single checkpoint object interface with a tick number and an ID unique to the owning Checkpointer ins...
virtual std::string stringize() const
Returns a string describing this object.
CheckpointBase & operator=(CheckpointBase &&)=delete
Not move assignable.
virtual std::vector< chkpt_id_t > getNextIDs() const =0
Returns next checkpoint following *this. May be an empty vector if there are no later checkpoints.
virtual uint64_t getTotalMemoryUse() const noexcept=0
Returns memory usage by this checkpoint including any framework data structures.
virtual uint64_t getContentMemoryUse() const noexcept=0
Returns memory usage by this checkpoint solely for the checkpointed content.
virtual chkpt_id_t getPrevID() const =0
Get the ID of our previous checkpoint. Returns UNIDENTIFIED_CHECKPOINT only for the head checkpoint.
CheckpointBase & operator=(const CheckpointBase &)=delete
Non-assignable.
static const chkpt_id_t MIN_CHECKPOINT
Indicates the smallest valid checkpoint id.
uint64_t chkpt_id_t
tick_t Checkpoint ID type to which checkpoints will refer
virtual std::string getDeletedRepr() const
Gets the representation of this deleted checkpoint as part of a checkpoint chain (if that checkpointe...
virtual ~CheckpointBase()=default
Destructor.
virtual void dumpData(std::ostream &o) const =0
Writes all checkpoint raw data to an ostream.
void serialize(Archive &ar, const unsigned int)
boost::serialization support
CheckpointBase(const CheckpointBase &)=delete
Not copy constructable.
void setID_(chkpt_id_t id)
Sets the checkpoint ID.
chkpt_id_t getID() const noexcept
Returns the ID of this checkpoint.
virtual void load(const std::vector< ArchData * > &dats)=0
Attempts to restore this checkpoint state to the simulation state (ArchData) objects given to this Ch...
CheckpointBase(CheckpointBase &&)=delete
Not move constructable.
tick_t getTick() const noexcept
Returns the tick number at which this checkpoint was taken.
static const chkpt_id_t UNIDENTIFIED_CHECKPOINT
Indicates unidentified checkpoint (could mean 'invalid' or 'any') depending on context.
sparta::Scheduler::Tick tick_t
tick_t Tick type to which checkpoints will refer
std::ostream & operator<<(std::ostream &o, const SimulationInfo &info)
ostream insertion operator for SimulationInfo