The Sparta Modeling Framework
Loading...
Searching...
No Matches
CherryPickFastCheckpointer.hpp
1// <CherryPickFastCheckpointer> -*- C++ -*-
2
3#pragma once
4
5#include "sparta/serialization/checkpoint/FastCheckpointer.hpp"
7#include "simdb/apps/App.hpp"
8#include "simdb/utils/ConcurrentQueue.hpp"
9#include <map>
10
11namespace sparta
12{
13 class TreeNode;
14 class Scheduler;
15}
16
17namespace simdb::pipeline
18{
19 class Flusher;
20}
21
22namespace sparta::serialization::checkpoint
23{
24
25class CherryPickFastCheckpointer final : public simdb::App
26{
27public:
28 using checkpoint_type = typename FastCheckpointer::checkpoint_type;
29 using checkpoint_ptr = typename FastCheckpointer::checkpoint_ptr;
30 using checkpoint_ptrs = typename FastCheckpointer::checkpoint_ptrs;
31 using chkpt_id_t = typename Checkpointer::chkpt_id_t;
32 using arch_id_t = uint64_t;
33 using tick_t = typename Checkpointer::tick_t;
34
35 static constexpr auto NAME = "cherry-pick-fast-checkpointer";
36
53 CherryPickFastCheckpointer(simdb::DatabaseManager* db_mgr, const std::vector<TreeNode*> & roots,
54 Scheduler* sched = nullptr);
55
61 class AppFactory : public simdb::AppFactoryBase
62 {
63 public:
65
70 void parameterize(const std::vector<TreeNode*>& roots, Scheduler* sched = nullptr)
71 {
72 roots_ = roots;
73 scheduler_ = sched;
74 }
75
76 AppT* createApp(simdb::DatabaseManager* db_mgr) override
77 {
78 // Make the ctor call that the default AppFactory cannot make.
79 return new AppT(db_mgr, roots_, scheduler_);
80 }
81
82 void defineSchema(simdb::Schema& schema) const override
83 {
84 AppT::defineSchema(schema);
85 }
86
87 private:
88 std::vector<TreeNode*> roots_;
89 Scheduler* scheduler_ = nullptr;
90 };
91
95 static void defineSchema(simdb::Schema& schema);
96
100 void createPipeline(simdb::pipeline::PipelineManager* pipeline_mgr) override;
101
106 return checkpointer_;
107 }
108
123 void commitCurrentBranch(bool force_new_head_chkpt = false);
124
128 void saveCheckpoints(checkpoint_ptrs&& checkpoints);
129
135 size_t getNumCheckpoints() const;
136
140 std::string stringize() const;
141
142 struct ChkptWindow {
143 arch_id_t start_arch_id = UINT64_MAX;
144 arch_id_t end_arch_id = UINT64_MAX;
145 tick_t start_tick = UINT64_MAX;
146 tick_t end_tick = UINT64_MAX;
147 checkpoint_ptrs checkpoints;
148
149 template <typename Archive>
150 void serialize(Archive & ar, const unsigned int /*version*/) {
151 ar & start_arch_id;
152 ar & end_arch_id;
153 ar & start_tick;
154 ar & end_tick;
155
156 if (checkpoints.empty()) {
157 // We are loading a checkpoint window from disk
158 const auto num_chkpts = end_arch_id - start_arch_id + 1;
159 for (size_t i = 0; i < num_chkpts; ++i) {
160 checkpoints.emplace_back(new checkpoint_type);
161 ar & *checkpoints.back();
162 }
163 } else {
164 // We are saving a checkpoint window to disk
165 for (auto& chkpt : checkpoints) {
166 ar & *chkpt;
167 }
168 }
169 }
170 };
171
173 arch_id_t start_arch_id = UINT64_MAX;
174 arch_id_t end_arch_id = UINT64_MAX;
175 tick_t start_tick = UINT64_MAX;
176 tick_t end_tick = UINT64_MAX;
177 size_t num_chkpts = 0;
178 std::vector<char> chkpt_bytes;
179 };
180
181private:
182 FastCheckpointer checkpointer_;
183 simdb::DatabaseManager* db_mgr_ = nullptr;
184 simdb::ConcurrentQueue<ChkptWindow>* pipeline_head_ = nullptr;
185 std::unique_ptr<simdb::pipeline::Flusher> pipeline_flusher_;
186};
187
188} // namespace sparta::serialization::checkpoint
Exception class for all of Sparta.
A class that lets you schedule events now and in the future.
Checkpoint::chkpt_id_t chkpt_id_t
tick_t Tick type to which checkpoints will refer
Checkpoint::tick_t tick_t
tick_t Tick type to which checkpoints will refer
This AppFactory specialization is provided since we have to initialize the FastCheckpointer which tak...
void parameterize(const std::vector< TreeNode * > &roots, Scheduler *sched=nullptr)
Sets the ArchData root(s) and Scheduler for a given instance of the checkpointer.
static void defineSchema(simdb::Schema &schema)
Define the SimDB schema for this checkpointer.
std::string stringize() const
Returns a string describing this object.
void saveCheckpoints(checkpoint_ptrs &&checkpoints)
Send the committed checkpoints down the pipeline to the database.
void createPipeline(simdb::pipeline::PipelineManager *pipeline_mgr) override
Instantiate the async processing pipeline to save checkpoints to the DB.
CherryPickFastCheckpointer(simdb::DatabaseManager *db_mgr, const std::vector< TreeNode * > &roots, Scheduler *sched=nullptr)
CherryPickFastCheckpointer constructor.
FastCheckpointer & getFastCheckpointer() noexcept
Use the FastCheckpointer to create checkpoints / checkpoint branches.
void commitCurrentBranch(bool force_new_head_chkpt=false)
When satisfied with the outstanding/uncommitted checkpoints, call this method to commit them to the d...
size_t getNumCheckpoints() const
Get the total number of checkpoints sent to the database thus far.
Single delta checkpoint object containing all simulator state which changed since some previous Delta...
Implements quick checkpointing through delta-checkpoint trees which store state-deltas in a compact f...
Macros for handling exponential backoff.