41#include "../../misc/eventSystem.hpp"
43#include "../../misc/mathUtility.hpp"
44#include "../data/emptyData.hpp"
45#include "indexManagerInterface.hpp"
54 template<
typename T_Index,
typename T_Tag>
88 template<
typename T_Index>
93 using Tag = std::uint8_t;
100 static size_t constexpr TAG_BITS =
sizeof(std::uint8_t) * 8;
101 static Index constexpr TAG_SIZE = 1 << TAG_BITS;
102 static Index constexpr TAG_MASK = TAG_SIZE - 1;
119 Index reservedIndices;
120 Index nextNewIdentifier;
121 std::uint8_t curTag = 1;
122 std::vector<std::vector<Index>> indexUse;
129 reservedIndices(reservedIndices),
130 nextNewIdentifier(reservedIndices + 1),
131 indexUse(2, std::vector<
Index>(
Config::SmallChunkSize)) {
147 double memoryindexUseVector = 0;
148 for (std::vector<Index>
const& cur : indexUse) {
149 memoryindexUseVector += (double)indexUse.size() * (double)(
sizeof(
Index));
152 TapeValues::LocalReductionOperation
constexpr operation =
153 NeedsStaticStorage ? TapeValues::LocalReductionOperation::Max : TapeValues::LocalReductionOperation::Sum;
155 values.
addDoubleEntry(
"Memory: index use vector", memoryindexUseVector, operation,
true,
true);
159 template<
typename Tape>
165 Index index = nextNewIdentifier;
166 nextNewIdentifier += 1;
169 CODI_EXCEPTION(
"Overfow of identifiers.");
174 data = {index, curTag};
175 indexUse[curTag][index] = 1;
181 template<
typename Tape>
187 template<
typename Tape>
189 validateIdentifier(lhs);
190 validateIdentifier(rhs,
false);
200 indexUse[curTag][rhs.
id] += 1;
211 template<
typename Tape>
213 validateIdentifier(data);
216 indexUse[data.
tag][data.
id] -= 1;
218 if (indexUse[data.
tag][data.
id] == 0) {
233 nextNewIdentifier = 1 + reservedIndices;
240 validateIdentifier(data,
false);
255 return nextNewIdentifier - 1;
265 curTag = curTag % TAG_SIZE;
272 if (indexUse.size() <= curTag) {
275 indexUse[curTag].clear();
281 indexUse[curTag].resize(nextNewIdentifier);
287 if (data.tag == 0 || data.tag >= indexUse.size()) {
288 CODI_EXCEPTION(
"Invalid tag '%d' with index '%d'.", (
int)data.tag, (
int)data.id);
291 if (indexUse[data.tag][data.id] <= 0) {
292 if (data.tag == curTag) {
293 CODI_EXCEPTION(
"Index '%d(%d)' is used after it was finally deleted.", (
int)data.id, (
int)data.tag);
295 CODI_EXCEPTION(
"Deleted index '%d(%d)' from old iteration is used.", (
int)data.id, (
int)data.tag);
299 if (data.tag != curTag) {
301 CODI_EXCEPTION(
"Index '%d' from an old iteration '%d' is used, current tag is %d.", (
int)data.id,
302 (
int)data.tag, (
int)curTag);
#define CODI_NO_INLINE
See codi::Config::AvoidedInlines.
Definition config.h:426
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
Configuration options for CoDiPack.
Definition config.h:65
size_t constexpr SmallChunkSize
Default smaller size of chunks (ChunkBase) used in ChunkedData in reverse tape implementations.
Definition config.h:133
bool constexpr CopyOptimization
Do not store copy statements like a = b; if the identity handler allows it.
Definition config.h:186
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
IndexManagerInterface< T_Index > Base
Abbreviation for the base class.
Definition debugMultiUseIndexManager.hpp:96
static bool constexpr NeedsStaticStorage
See IndexManagerInterface.
Definition debugMultiUseIndexManager.hpp:112
~DebugMultiUseIndexManager()
Destructor.
Definition debugMultiUseIndexManager.hpp:136
inlinebool assignUnusedIndex(ActiveTypeIndexData &index)
Call on registering input values.
Definition debugMultiUseIndexManager.hpp:182
inlinevoid reset()
Reset for a new recording.
Definition debugMultiUseIndexManager.hpp:232
static bool constexpr CopyNeedsStatement
See IndexManagerInterface.
Definition debugMultiUseIndexManager.hpp:110
inlinebool assignIndex(ActiveTypeIndexData &data)
Call on assignment of a primal value, e.g. on w for w = a + b.
Definition debugMultiUseIndexManager.hpp:160
static bool constexpr IsLinear
See IndexManagerInterface.
Definition debugMultiUseIndexManager.hpp:111
inlineIndex getLargestCreatedIndex() const
Returns the largest created index.
Definition debugMultiUseIndexManager.hpp:254
void addToTapeValues(TapeValues &values) const
Add storage and other information to the tape values.
Definition debugMultiUseIndexManager.hpp:146
inlinevoid validateRhsIndex(ActiveTypeIndexData const &data) const
Check if the rhs index is valid.
Definition debugMultiUseIndexManager.hpp:239
inlineIndex & getIndex(ActiveTypeIndexData &data)
Extract index from data stored in active type.
Definition debugMultiUseIndexManager.hpp:249
inlinevoid initIndex(ActiveTypeIndexData &index)
Initialize the index data. Usually zero everything.
Definition debugMultiUseIndexManager.hpp:227
DebugMultiUseIndexManager(Index const &reservedIndices)
Constructor.
Definition debugMultiUseIndexManager.hpp:127
T_Index Index
See DebugMultiUseIndexManager.
Definition debugMultiUseIndexManager.hpp:92
IndexTagPair< Index, Tag > ActiveTypeIndexData
See IndexManagerInterface.
Definition debugMultiUseIndexManager.hpp:95
inlinevoid copyIndex(ActiveTypeIndexData &lhs, ActiveTypeIndexData const &rhs)
Call on copy of a primal value, e.g. w = a.
Definition debugMultiUseIndexManager.hpp:188
inlinevoid freeIndex(ActiveTypeIndexData &data)
Definition debugMultiUseIndexManager.hpp:212
std::uint8_t Tag
Tag used for the recording live time management.
Definition debugMultiUseIndexManager.hpp:93
inlineIndex const & getIndex(ActiveTypeIndexData const &data)
Extract index from data stored in active type.
Definition debugMultiUseIndexManager.hpp:244
No data is stored in this DataInterface implementation. It is used to terminate the recursive nature ...
Definition emptyData.hpp:54
static inlinevoid notifyIndexCopyListeners(Index const &index)
Invoke callbacks for IndexCopy events.
Definition eventSystem.hpp:833
static inlinevoid notifyIndexFreeListeners(Index const &index)
Invoke callbacks for IndexFree events.
Definition eventSystem.hpp:806
Indices enable the mapping of primal values to their adjoint counterparts.
Definition indexManagerInterface.hpp:78
static Index constexpr InactiveIndex
Default inactive index for all index managers.
Definition indexManagerInterface.hpp:87
Definition debugMultiUseIndexManager.hpp:55
T_Index Index
See IndexTagPair.
Definition debugMultiUseIndexManager.hpp:56
inlinebool operator!=(IndexTagPair const &o)
Not equal comparison.
Definition debugMultiUseIndexManager.hpp:68
inlinebool operator==(IndexTagPair const &o)
Equal comparison.
Definition debugMultiUseIndexManager.hpp:63
Index id
Definition debugMultiUseIndexManager.hpp:59
T_Tag Tag
See IndexTagPair.
Definition debugMultiUseIndexManager.hpp:57
Tag tag
Definition debugMultiUseIndexManager.hpp:60
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:75
void addDoubleEntry(std::string const &name, double const &value, LocalReductionOperation operation=LocalReductionOperation::Sum, bool usedMem=false, bool allocatedMem=false)
Add double entry. If it is a memory entry, it should be in bytes.
Definition tapeValues.hpp:137