Indices enable the mapping of primal values to their adjoint counterparts. More...
#include <indexManagerInterface.hpp>
Public Types | |
using | Index = T_Index |
See IndexManagerInterface. | |
Public Member Functions | |
Misc functions | |
void | addToTapeValues (TapeValues &values) const |
Add storage and other information to the tape values. | |
Index | getLargestCreatedIndex () const |
Returns the largest created index. | |
Static Public Attributes | |
Global constants | |
static Index constexpr | InactiveIndex = Index(0) |
Default inactive index for all index managers. | |
static Index constexpr | InvalidIndex |
Default invalid index for all index mangers (max value for unsigned types). | |
Identifier handling | |
static bool constexpr | CopyNeedsStatement |
True if no copy optimization is implemented. See IndexManagerInterface. | |
static bool constexpr | IsLinear |
True if identifiers are coupled to the statements. See IndexManagerInterface. | |
static bool constexpr | NeedsStaticStorage = false |
True if the index manager is specific to a tape type (and not a tape instance). See IndexManagerInterface. | |
template<typename Tape > | |
bool | assignIndex (Index &index) |
Call on assignment of a primal value, e.g. on w for w = a + b . | |
template<typename Tape > | |
bool | assignUnusedIndex (Index &index) |
Call on registering input values. | |
template<typename Tape > | |
void | copyIndex (Index &lhs, Index const &rhs) |
Call on copy of a primal value, e.g. w = a . | |
template<typename Tape > | |
void | freeIndex (Index &index) |
Call on destruction of a primal value. Usually called from the destructor. | |
void | reset () |
Reset for a new recording. | |
Indices enable the mapping of primal values to their adjoint counterparts.
In operator overloading AD, each primal variable (e.g. ) needs to be mapped to the adjoint counterpart (e.g. . Since the adjoint cannot be stored in the primal, an identifier (usually an index) is associated with each primal. This identifier is then used to access the adjoint variable.
The interface defines the three basic operations which can be applied to a variable: assign, copy and free. For each of these operations on the primal variable, the corresponding function on the identifier needs to be called.
freeIndex() only needs to be called in destructors. If a variable is overwritten, only assign needs to be called on the left hand side identifier. The index manager has to decide how the old identifier is handled.
assignUnusedIndex() provides identifiers that have not been used after the last reset. These identifiers can be used for input values of the program because the adjoint will not be overwritten by intermediate variables.
CopyNeedsStatement is a static check if the index manager implements a copy optimization, that is, if it creates a new identifier for the left hand side or copies the right hand side identifier instead. Not all index management approaches admit a copy optimization.
IsLinear indicates whether the indices are coupled to the statements of a program. The tape needs to be managed accordingly.
NeedsStaticStorage indicates whether the index manager is specific to a tape type (as opposed to a specific tape instance). Depending on this setting, it is stored statically or non-statically in the tape.
Mathematical and implementational details are explained in SBG2021Index.
T_Index | Type for the identifier, usually an integer type. |
void codi::IndexManagerInterface< T_Index >::addToTapeValues | ( | TapeValues & | values | ) | const |
Add storage and other information to the tape values.
[in,out] | values | Will only create new data entries and no new section. |
bool codi::IndexManagerInterface< T_Index >::assignIndex | ( | Index & | index | ) |
Call on assignment of a primal value, e.g. on w
for w = a + b
.
bool codi::IndexManagerInterface< T_Index >::assignUnusedIndex | ( | Index & | index | ) |
Call on registering input values.
Index codi::IndexManagerInterface< T_Index >::getLargestCreatedIndex | ( | ) | const |
Returns the largest created index.
This is the largest entry in the adjoint vectors created by the tapes.
|
staticconstexpr |
True if no copy optimization is implemented. See IndexManagerInterface.
|
staticconstexpr |
Default invalid index for all index mangers (max value for unsigned types).
|
staticconstexpr |
True if identifiers are coupled to the statements. See IndexManagerInterface.