CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::ReverseTapeInterface< T_Real, T_Gradient, T_Identifier > Struct Template Reference

Minimum tape interface for a working reverse tape implementation. More...

#include <reverseTapeInterface.hpp>

Inheritance diagram for codi::ReverseTapeInterface< T_Real, T_Gradient, T_Identifier >:

Public Types

using Gradient = T_Gradient
 See ReverseTapeInterface.
 
using Identifier = T_Identifier
 See ReverseTapeInterface.
 
using PassiveReal = RealTraits::PassiveReal< Real >
 Basic computation type.
 
using Real = T_Real
 See ReverseTapeInterface.
 
- Public Types inherited from codi::InternalStatementRecordingTapeInterface< T_Identifier >
using Identifier = T_Identifier
 See InternalStatementRecordingTapeInterface.
 
- Public Types inherited from codi::GradientAccessTapeInterface< T_Gradient, T_Identifier >
using Gradient = T_Gradient
 See GradientAccessTapeInterface.
 
using Identifier = T_Identifier
 See GradientAccessTapeInterface.
 

Public Member Functions

Recording
template<typename Lhs , typename Tape >
void registerInput (LhsExpressionInterface< Real, Gradient, Tape, Lhs > &value)
 
template<typename Lhs , typename Tape >
void registerOutput (LhsExpressionInterface< Real, Gradient, Tape, Lhs > &value)
 
void setActive ()
 Start/continue recording of statements.
 
void setPassive ()
 Stop/interrupt recording of statements.
 
bool isActive () const
 Check if the tape is recording.
 
Reversal
void evaluate (AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Perform a full reverse evaluation of the tape.
 
Reset
void clearAdjoints (AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Clear all adjoint values, that is, set them to zero.
 
void reset (bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Reset the tape to the initial state for a fresh recording.
 
Tape information
template<typename Stream = std::ostream>
void printStatistics (Stream &out=std::cout) const
 Default formatting of TapeValues.
 
template<typename Stream = std::ostream>
void printTableHeader (Stream &out=std::cout) const
 Table header output of TapeValues.
 
template<typename Stream = std::ostream>
void printTableRow (Stream &out=std::cout) const
 Table row output of TapeValues.
 
TapeValues getTapeValues () const
 Get current tape values.
 
- Public Member Functions inherited from codi::InternalStatementRecordingTapeInterface< T_Identifier >
template<typename Real >
void initIdentifier (Real &value, Identifier &identifier)
 
template<typename Real >
void destroyIdentifier (Real &value, Identifier &identifier)
 Has to be called for each identifier, before it is deallocated.
 
template<typename Lhs , typename Rhs >
void store (Lhs &lhs, Rhs const &rhs)
 Has to be called by an AD variable every time it is assigned.
 
- Public Member Functions inherited from codi::GradientAccessTapeInterface< T_Gradient, T_Identifier >
void setGradient (Identifier const &identifier, Gradient const &gradient, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Set the gradient.
 
Gradient const & getGradient (Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
 Set the gradient.
 
Gradientgradient (Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
 Reference access to gradient.
 
Gradient const & gradient (Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
 Constant reference access to gradient.
 

Additional Inherited Members

- Static Public Attributes inherited from codi::InternalStatementRecordingTapeInterface< T_Identifier >
static bool constexpr AllowJacobianOptimization
 If certain operations can be hidden from the tape.
 

Detailed Description

template<typename T_Real, typename T_Gradient, typename T_Identifier>
struct codi::ReverseTapeInterface< T_Real, T_Gradient, T_Identifier >

Minimum tape interface for a working reverse tape implementation.

See Tape Interface Design for a general overview of the tape interface design in CoDiPack.

For an example on how to uses this interface to perform an AD reverse mode recording and evaluation of a program, please see tutorials Tutorial 2 - Reverse mode AD and Tutorial 5 - Repeated tape recordings).

Implementation hints: A tape should only record information if it is active, that is, everything between a call to setActive() and setPassive(). A call to setActive() does not reset the tape in CoDiPack. A reset can only be performed by a call to reset(). Hence, the user may skip unnecessarys parts of the recording by setting the tape passive for these regions.

Here is an example for using a tape (documentation/examples/reverseModeAD.cpp):

using Tape = typename Real::Tape;
Tape& tape = Real::getTape();
// Recording
Real x = 10.0;
tape.setActive();
tape.registerInput(x);
Real y = 42.0 * x * x;
tape.registerOutput(y);
tape.setPassive();
// Reverse evaluation
y.setGradient(1.0);
tape.evaluate();
std::cout << "Gradient of dy/dx: " << x.getGradient() << std::endl;
RealReverseGen< double > RealReverse
Definition: codi.hpp:120
static Tape & getTape()
Get a reference to the tape which manages this expression.
Definition: activeType.hpp:99
T_Tape Tape
See ActiveType.
Definition: activeType.hpp:55
T_Real Real
See ReverseTapeInterface.
Definition: reverseTapeInterface.hpp:80
Template Parameters
T_RealThe computation type of a tape, usually chosen as ActiveType::Real.
T_GradientThe gradient type of a tape, usually chosen as ActiveType::Gradient.
T_IdentifierThe adjoint/tangent identification of a tape, usually chosen as ActiveType::Identifier.

Member Function Documentation

◆ clearAdjoints()

template<typename T_Real , typename T_Gradient , typename T_Identifier >
void codi::ReverseTapeInterface< T_Real, T_Gradient, T_Identifier >::clearAdjoints ( AdjointsManagement  adjointsManagement = AdjointsManagement::Automatic)

Clear all adjoint values, that is, set them to zero.

Automatic adjoints management involves locking, see AdjointsManagement for details.

◆ evaluate()

template<typename T_Real , typename T_Gradient , typename T_Identifier >
void codi::ReverseTapeInterface< T_Real, T_Gradient, T_Identifier >::evaluate ( AdjointsManagement  adjointsManagement = AdjointsManagement::Automatic)

Perform a full reverse evaluation of the tape.

Automatic adjoints management involves bounds checking, resizing, and locking, see AdjointsManagement for details.

◆ registerInput()

template<typename T_Real , typename T_Gradient , typename T_Identifier >
template<typename Lhs , typename Tape >
void codi::ReverseTapeInterface< T_Real, T_Gradient, T_Identifier >::registerInput ( LhsExpressionInterface< Real, Gradient, Tape, Lhs > &  value)

Mark a value as input (independent) and make it active.

Template Parameters
LhsClass that implements the LhsExpressionInterface. See also LhsExpressionInterface.
TapeTape implementation used in the LhsExpressionInterface. See also LhsExpressionInterface.

◆ registerOutput()

template<typename T_Real , typename T_Gradient , typename T_Identifier >
template<typename Lhs , typename Tape >
void codi::ReverseTapeInterface< T_Real, T_Gradient, T_Identifier >::registerOutput ( LhsExpressionInterface< Real, Gradient, Tape, Lhs > &  value)

Mark a value as output (dependent).

Template Parameters
LhsClass that implements the LhsExpressionInterface. See also LhsExpressionInterface.
TapeTape implementation used in the LhsExpressionInterface. See also LhsExpressionInterface.

◆ reset()

template<typename T_Real , typename T_Gradient , typename T_Identifier >
void codi::ReverseTapeInterface< T_Real, T_Gradient, T_Identifier >::reset ( bool  resetAdjoints = true,
AdjointsManagement  adjointsManagement = AdjointsManagement::Automatic 
)

Reset the tape to the initial state for a fresh recording.

See Tutorial 5 - Repeated tape recordings for remarks on repeated tape recording in CoDiPack.

Automatic adjoints management involves locking, see AdjointsManagement for details.


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