CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::IndexManagerInterface< T_Index > Struct Template Reference

Indices enable the mapping of primal values to their adjoint counterparts. More...

#include <indexManagerInterface.hpp>

Inheritance diagram for codi::IndexManagerInterface< T_Index >:

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.
 

Detailed Description

template<typename T_Index>
struct codi::IndexManagerInterface< T_Index >

Indices enable the mapping of primal values to their adjoint counterparts.

In operator overloading AD, each primal variable (e.g. $ w $) needs to be mapped to the adjoint counterpart (e.g. $ \bar w $. 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.

Template Parameters
T_IndexType for the identifier, usually an integer type.

Member Function Documentation

◆ addToTapeValues()

template<typename T_Index >
void codi::IndexManagerInterface< T_Index >::addToTapeValues ( TapeValues & values) const

Add storage and other information to the tape values.

Parameters
[in,out]valuesWill only create new data entries and no new section.

◆ assignIndex()

template<typename T_Index >
template<typename Tape >
bool codi::IndexManagerInterface< T_Index >::assignIndex ( Index & index)

Call on assignment of a primal value, e.g. on w for w = a + b.

Returns
true if new indices have been generated internally.

◆ assignUnusedIndex()

template<typename T_Index >
template<typename Tape >
bool codi::IndexManagerInterface< T_Index >::assignUnusedIndex ( Index & index)

Call on registering input values.

Returns
true if new indices have been generated internally.

◆ getLargestCreatedIndex()

template<typename T_Index >
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.

Member Data Documentation

◆ CopyNeedsStatement

template<typename T_Index >
bool constexpr codi::IndexManagerInterface< T_Index >::CopyNeedsStatement
staticconstexpr
Initial value:
=
false

True if no copy optimization is implemented. See IndexManagerInterface.

◆ InvalidIndex

template<typename Index >
Index constexpr codi::IndexManagerInterface< Index >::InvalidIndex
staticconstexpr
Initial value:
=
Index(-1)
T_Index Index
See IndexManagerInterface.
Definition indexManagerInterface.hpp:81

Default invalid index for all index mangers (max value for unsigned types).

◆ IsLinear

template<typename T_Index >
bool constexpr codi::IndexManagerInterface< T_Index >::IsLinear
staticconstexpr
Initial value:
=
false

True if identifiers are coupled to the statements. See IndexManagerInterface.


The documentation for this struct was generated from the following file: