The Sparta Modeling Framework
Loading...
Searching...
No Matches
Checkpointable.hpp
1// <Checkpointable> -*- C++ -*-
2
3#pragma once
4
5#include <cassert>
6#include <cstring>
7#include <list>
8#include <memory>
9#include <type_traits>
10#include <vector>
11
12#include "sparta/functional/ArchData.hpp"
14#include "sparta/utils/MathUtils.hpp"
15
16namespace sparta::serialization::checkpoint {
91 {
92 public:
93
96 Checkpointable(sparta::TreeNode *cp_node) : cp_node_(cp_node) {}
97
109 template <class CheckpointableT, typename... CpArgs>
110 CheckpointableT &allocateCheckpointable(CpArgs... cp_args)
111 {
112 static_assert(false == std::is_pointer_v<CheckpointableT>,
113 "Checkpointable object cannot be a pointer");
114 constexpr size_t checkpointable_size =
115 utils::next_power_of_2(sizeof(CheckpointableT));
116 auto &cp_component = checkpoint_components_.emplace_back(
117 new CheckpointComponent(cp_node_, checkpointable_size));
118
119 auto cp_mem = cp_component->getRawDataPtr();
120 return *(new (cp_mem) CheckpointableT(cp_args...));
121 }
122
123 private:
124 sparta::TreeNode *cp_node_ = nullptr;
125
126 struct CheckpointComponent
127 {
128 CheckpointComponent(sparta::TreeNode *cp_node,
129 ArchData::offset_type line_size)
130 : adata_(cp_node, line_size, ArchData::DEFAULT_INITIAL_FILL,
131 ArchData::DEFAULT_INITIAL_FILL_SIZE,
132 false), // Cannot delete lines
133 dview_(&adata_, 0, line_size,
134 ArchDataSegment::INVALID_ID, // subset of
135 0) // subset_offset
136 {
137 adata_.layout();
138 }
139
140 uint8_t *getRawDataPtr() { return dview_.getLine()->getRawDataPtr(0); }
141
143 ArchData adata_;
144
146 DataView dview_;
147 };
148
149 std::vector<std::unique_ptr<CheckpointComponent>> checkpoint_components_;
150 };
151} // namespace sparta
Basic Node framework in sparta device tree composite pattern.
uint8_t * getRawDataPtr(const offset_type offset)
return the raw data pointer for this line for direct read and write. No error checking is performed....
Definition ArchData.hpp:403
Contains a set of contiguous line of architectural data which can be referred to by any architected o...
Definition ArchData.hpp:39
void layout()
Organizes the Segments into overlapping regions as needed, eventually calling ArchDataSegment::place ...
Definition ArchData.hpp:603
View into a backend block of memory in an ArchData.
Definition DataView.hpp:28
ArchData::Line * getLine() const
Get already-placed line.
Definition DataView.hpp:115
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.
CheckpointableT & allocateCheckpointable(CpArgs... cp_args)
Allocate a checkpointable type.
Checkpointable(sparta::TreeNode *cp_node)
Create a Checkpointable object used to allocate components for checkpointing.