41#include "../expressions/lhsExpressionInterface.hpp"
42#include "../expressions/logic/compileTimeTraversalLogic.hpp"
43#include "../expressions/logic/traversalLogic.hpp"
45#include "../traits/expressionTraits.hpp"
46#include "data/chunk.hpp"
47#include "indices/linearIndexManager.hpp"
48#include "interfaces/reverseTapeInterface.hpp"
49#include "jacobianBaseTape.hpp"
61 template<
typename T_TapeTypes>
72 using Real =
typename TapeTypes::Real;
78 CODI_STATIC_ASSERT(IndexManager::IsLinear,
"This class requires an index manager with a linear scheme.");
92 using IndexPosition =
CODI_DD(
typename IndexManager::Position,
int);
93 IndexPosition startIndex = this->
llfByteData.template extractPosition<IndexPosition>(start);
94 IndexPosition endIndex = this->
llfByteData.template extractPosition<IndexPosition>(end);
96 startIndex = std::min(startIndex, (IndexPosition)this->
adjoints.size() - 1);
97 endIndex = std::min(endIndex, (IndexPosition)this->
adjoints.size() - 1);
99 for (IndexPosition curPos = endIndex + 1; curPos <= startIndex; curPos += 1) {
119 template<
typename Adjo
int>
124 size_t& curLLFByteDataPos,
size_t const& endLLFByteDataPos,
char* dataPtr,
129 size_t& curJacobianPos,
size_t const& endJacobianPos,
Real const*
const rhsJacobians,
132 size_t& curStmtPos,
size_t const& endStmtPos,
Config::ArgumentSize const*
const numberOfJacobians,
134 size_t const& startAdjointPos,
size_t const& endAdjointPos) {
135 CODI_UNUSED(endJacobianPos, endStmtPos, endLLFByteDataPos, endLLFInfoDataPos);
139 size_t curAdjointPos = startAdjointPos;
141 while (curAdjointPos < endAdjointPos)
CODI_Likely {
147 Base::template callLowLevelFunction<LowLevelFunctionEntryCallKind::Forward>(
148 tape,
true, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr, &vectorAccess);
152 Adjoint lhsAdjoint = Adjoint();
154 adjointVector[curAdjointPos] = lhsAdjoint;
165 template<
typename Adjo
int>
170 size_t& curLLFByteDataPos,
size_t const& endLLFByteDataPos,
char* dataPtr,
175 size_t& curJacobianPos,
size_t const& endJacobianPos,
Real const*
const rhsJacobians,
178 size_t& curStmtPos,
size_t const& endStmtPos,
Config::ArgumentSize const*
const numberOfJacobians,
180 size_t const& startAdjointPos,
size_t const& endAdjointPos) {
181 CODI_UNUSED(endJacobianPos, endStmtPos, endLLFByteDataPos, endLLFInfoDataPos);
185 size_t curAdjointPos = startAdjointPos;
187 while (curAdjointPos > endAdjointPos)
CODI_Likely {
192 Base::template callLowLevelFunction<LowLevelFunctionEntryCallKind::Reverse>(
193 tape,
false, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr, &vectorAccess);
199 Adjoint
const lhsAdjoint = adjointVector[curAdjointPos];
206 adjointVector[curAdjointPos] = Adjoint();
#define CODI_Unlikely
Declare unlikely evaluation of an execution path.
Definition config.h:399
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_Likely
Declare likely evaluation of an execution path.
Definition config.h:397
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_STATIC_ASSERT(cond, message)
Static assert in CoDiPack.
Definition macros.hpp:123
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:111
uint16_t LowLevelFunctionDataSize
Size store type for a low level function.
Definition config.h:98
uint16_t LowLevelFunctionToken
Token type for low level functions in the tapes.
Definition config.h:108
size_t constexpr StatementLowLevelFunctionTag
Statement tag for low level functions.
Definition config.h:126
bool constexpr ReversalZeroesAdjoints
With a linear index management, control if adjoints are set to zero during reversal.
Definition config.h:289
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
size_t constexpr StatementInputTag
Tag for statements that are inputs. Used in linear index management context.
Definition config.h:123
std::array< AtomicTraits::RemoveAtomic< typename TraitsImplementation< Gradient >::Real >, TraitsImplementation< Gradient >::dim > toArray(Gradient const &gradient)
Converts the (possibly multi-component) gradient to an array of Reals.
Definition gradientTraits.hpp:116
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
AdjointsManagement
Policies for management of the tape's interal adjoints.
Definition tapeParameters.hpp:98
@ Automatic
Manage internal adjoints automatically, including locking, bounds checking, and resizing.
Implementation of VectorAccessInterface for adjoint vectors.
Definition adjointVectorAccess.hpp:59
Data is stored chunk-wise in this DataInterface implementation. If a chunk runs out of space,...
Definition chunkedData.hpp:64
LowLevelFunctionByteData llfByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:155
static void notifyStatementEvaluateListeners(Tape &tape, Identifier const &lhsIdentifier, size_t sizeLhsAdjoint, Real const *lhsAdjoint)
Invoke callbacks for StatementEvaluate events.
Definition eventSystem.hpp:712
Indices enable the mapping of primal values to their adjoint counterparts.
Definition indexManagerInterface.hpp:78
Base class for all standard Jacobian tape implementations.
Definition jacobianBaseTape.hpp:125
typename Base::Position Position
See TapeTypesInterface.
Definition jacobianBaseTape.hpp:149
StatementData statementData
Data stream for statement specific data.
Definition jacobianBaseTape.hpp:170
Adjoints adjoints
Evaluation vector for AD.
Definition jacobianBaseTape.hpp:173
void clearAdjoints(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Clear all adjoint values, that is, set them to zero.
Definition jacobianBaseTape.hpp:468
static void incrementAdjoints(Adjoint *adjointVector, Adjoint const &lhsAdjoint, Config::ArgumentSize const &numberOfArguments, size_t &curJacobianPos, Real const *const rhsJacobians, Identifier const *const rhsIdentifiers)
Performs the AD reverse equation for a statement.
Definition jacobianBaseTape.hpp:520
static void incrementTangents(Adjoint const *const adjointVector, Adjoint &lhsAdjoint, Config::ArgumentSize const &numberOfArguments, size_t &curJacobianPos, Real const *const rhsJacobians, Identifier const *const rhsIdentifiers)
Performs the AD forward equation for a statement.
Definition jacobianBaseTape.hpp:542
Final implementation for a Jacobian tape with a linear index management.
Definition jacobianLinearTape.hpp:62
typename TapeTypes::Real Real
See TapeTypesInterface.
Definition jacobianLinearTape.hpp:72
void clearAdjoints(Position const &start, Position const &end, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Clear all adjoints that would be set in a tape evaluation from start to end. It has to hold start >= ...
Definition jacobianLinearTape.hpp:86
typename TapeTypes::IndexManager IndexManager
See TapeTypesInterface.
Definition jacobianLinearTape.hpp:74
static void internalEvaluateForward_EvalStatements(JacobianLinearTape &tape, Adjoint *adjointVector, size_t &curLLFByteDataPos, size_t const &endLLFByteDataPos, char *dataPtr, size_t &curLLFInfoDataPos, size_t const &endLLFInfoDataPos, Config::LowLevelFunctionToken *const tokenPtr, Config::LowLevelFunctionDataSize *const dataSizePtr, size_t &curJacobianPos, size_t const &endJacobianPos, Real const *const rhsJacobians, Identifier const *const rhsIdentifiers, size_t &curStmtPos, size_t const &endStmtPos, Config::ArgumentSize const *const numberOfJacobians, size_t const &startAdjointPos, size_t const &endAdjointPos)
Perform a forward evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
Definition jacobianLinearTape.hpp:120
JacobianLinearTape()
Constructor.
Definition jacobianLinearTape.hpp:81
typename TapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition jacobianLinearTape.hpp:73
T_TapeTypes TapeTypes
See JacobianLinearTape.
Definition jacobianLinearTape.hpp:65
typename TapeTypes::Identifier Identifier
See TapeTypesInterface.
Definition jacobianLinearTape.hpp:75
friend Base
Allow the base class to call protected and private methods.
Definition jacobianLinearTape.hpp:70
static void internalEvaluateReverse_EvalStatements(JacobianLinearTape &tape, Adjoint *adjointVector, size_t &curLLFByteDataPos, size_t const &endLLFByteDataPos, char *dataPtr, size_t &curLLFInfoDataPos, size_t const &endLLFInfoDataPos, Config::LowLevelFunctionToken *const tokenPtr, Config::LowLevelFunctionDataSize *const dataSizePtr, size_t &curJacobianPos, size_t const &endJacobianPos, Real const *const rhsJacobians, Identifier const *const rhsIdentifiers, size_t &curStmtPos, size_t const &endStmtPos, Config::ArgumentSize const *const numberOfJacobians, size_t const &startAdjointPos, size_t const &endAdjointPos)
Perform a reverse evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
Definition jacobianLinearTape.hpp:166
void pushStmtData(Identifier const &index, Config::ArgumentSize const &numberOfArguments)
Add statement specific data to the data streams.
Definition jacobianLinearTape.hpp:112
typename Base::Position Position
See TapeTypesInterface.
Definition jacobianLinearTape.hpp:76
Type definitions for the Jacobian tapes.
Definition jacobianBaseTape.hpp:75