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/indexManagerInterface.hpp"
48#include "interfaces/editingTapeInterface.hpp"
49#include "interfaces/reverseTapeInterface.hpp"
50#include "jacobianBaseTape.hpp"
62 template<
typename T_TapeTypes>
65 public EditingTapeInterface<typename JacobianBaseTape<T_TapeTypes, JacobianReuseTape<T_TapeTypes>>::Position> {
75 using Real =
typename TapeTypes::Real;
82 CODI_STATIC_ASSERT(!IndexManager::IsLinear,
"This class requires an index manager with a reuse scheme.");
105 if (*index < adjointsSize) {
110 using StmtPosition =
typename StatementData::Position;
111 StmtPosition startStmt = this->
llfByteData.template extractPosition<StmtPosition>(start);
112 StmtPosition endStmt = this->
llfByteData.template extractPosition<StmtPosition>(end);
114 this->
statementData.forEachReverse(startStmt, endStmt, clearFunc);
136 template<
typename Adjo
int>
141 size_t& curLLFByteDataPos,
size_t const& endLLFByteDataPos,
char* dataPtr,
146 size_t& curJacobianPos,
size_t const& endJacobianPos,
Real const*
const rhsJacobians,
149 size_t& curStmtPos,
size_t const& endStmtPos,
Identifier const*
const lhsIdentifiers,
151 CODI_UNUSED(endJacobianPos, endLLFByteDataPos, endLLFInfoDataPos);
159 Base::template callLowLevelFunction<LowLevelFunctionEntryCallKind::Forward>(
160 tape,
true, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr, &vectorAccess);
162 Adjoint lhsAdjoint = Adjoint();
165 adjointVector[lhsIdentifiers[curStmtPos]] = lhsAdjoint;
168 tape, lhsIdentifiers[curStmtPos], GradientTraits::dim<Adjoint>(),
177 template<
typename Adjo
int>
182 size_t& curLLFByteDataPos,
size_t const& endLLFByteDataPos,
char* dataPtr,
187 size_t& curJacobianPos,
size_t const& endJacobianPos,
Real const*
const rhsJacobians,
190 size_t& curStmtPos,
size_t const& endStmtPos,
Identifier const*
const lhsIdentifiers,
192 CODI_UNUSED(endJacobianPos, endLLFByteDataPos, endLLFInfoDataPos);
202 Base::template callLowLevelFunction<LowLevelFunctionEntryCallKind::Reverse>(
203 tape,
false, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr, &vectorAccess);
205 Adjoint
const lhsAdjoint = adjointVector[lhsIdentifiers[curStmtPos]];
208 tape, lhsIdentifiers[curStmtPos], GradientTraits::dim<Adjoint>(),
211 adjointVector[lhsIdentifiers[curStmtPos]] = Adjoint();
230 erase(start, end, emptyTape);
248 srcTape.
llfByteData.evaluateForward(start, end, JacobianReuseTape::internalAppend,
this);
259 size_t& curLLFByteDataPos,
size_t const& endLLFByteDataPos,
char* dataPtr,
264 size_t& curJacobianPos,
size_t const& endJacobianPos,
Real const*
const rhsJacobians,
265 Identifier
const*
const rhsIdentifiers,
267 size_t& curStmtPos,
size_t const& endStmtPos, Identifier
const*
const lhsIdentifiers,
269 CODI_UNUSED(endLLFByteDataPos, endLLFInfoDataPos, endJacobianPos);
271 while (curStmtPos < endStmtPos) {
275 size_t dataSize = dataSizePtr[curLLFInfoDataPos];
282 dstDataStore.
write(&dataPtr[curLLFByteDataPos], dataSize);
284 curLLFInfoDataPos += 1;
285 curLLFByteDataPos += dataSize;
289 dstTape->
jacobianData.reserveItems(numberOfJacobians[curStmtPos]);
291 dstTape->
pushStmtData(lhsIdentifiers[curStmtPos], numberOfJacobians[curStmtPos]);
292 size_t curJacobianEnd = curJacobianPos + numberOfJacobians[curStmtPos];
294 while (curJacobianPos < curJacobianEnd) {
295 dstTape->
jacobianData.pushData(rhsJacobians[curJacobianPos], rhsIdentifiers[curJacobianPos]);
#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
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
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.
Represents a concrete lvalue in the CoDiPack expression tree.
Definition activeType.hpp:52
Implementation of VectorAccessInterface for adjoint vectors.
Definition adjointVectorAccess.hpp:59
Definition byteDataView.hpp:51
T * write(T const &data)
Write a single entry of type T.
Definition byteDataView.hpp:114
Data is stored chunk-wise in this DataInterface implementation. If a chunk runs out of space,...
Definition chunkedData.hpp:64
Position getPosition() const
Current position of the tape.
Definition commonTapeImplementation.hpp:629
Position getZeroPosition() const
Initial position of the tape.
Definition commonTapeImplementation.hpp:634
void reset(bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the initial state for a fresh recording.
Definition commonTapeImplementation.hpp:354
LowLevelFunctionByteData llfByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:155
void resetTo(Position const &pos, bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the provided position.
Definition commonTapeImplementation.hpp:668
Edit tapes after they have been recorded.
Definition editingTapeInterface.hpp:65
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
JacobianData jacobianData
Data stream for argument specific data.
Definition jacobianBaseTape.hpp:171
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
void pushLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &data)
Push a low level function to the tape.
Definition jacobianBaseTape.hpp:774
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 reuse index management.
Definition jacobianReuseTape.hpp:65
void erase(Position const &start, Position const &end)
Erase a part of the tape. It has to hold start <= end.
Definition jacobianReuseTape.hpp:228
void append(JacobianReuseTape &srcTape, Position const &start, Position const &end)
Definition jacobianReuseTape.hpp:247
typename TapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition jacobianReuseTape.hpp:76
typename TapeTypes::StatementData StatementData
See JacobianTapeTypes.
Definition jacobianReuseTape.hpp:80
void erase(Position const &start, Position const &end, JacobianReuseTape &emptyTape)
Erase a part of the tape. It has to hold start <= end. This variant of erase takes a reference to an ...
Definition jacobianReuseTape.hpp:236
T_TapeTypes TapeTypes
See JacobianReuseTape.
Definition jacobianReuseTape.hpp:68
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 jacobianReuseTape.hpp:94
JacobianReuseTape()
Constructor.
Definition jacobianReuseTape.hpp:85
typename TapeTypes::Identifier Identifier
See TapeTypesInterface.
Definition jacobianReuseTape.hpp:78
static void internalEvaluateForward_EvalStatements(JacobianReuseTape &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, Identifier const *const lhsIdentifiers, Config::ArgumentSize const *const numberOfJacobians)
Perform a forward evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
Definition jacobianReuseTape.hpp:137
friend Base
Allow the base class to call protected and private methods.
Definition jacobianReuseTape.hpp:73
static void internalEvaluateReverse_EvalStatements(JacobianReuseTape &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, Identifier const *const lhsIdentifiers, Config::ArgumentSize const *const numberOfJacobians)
Perform a reverse evaluation of the tape. Arguments are from the recursive eval methods of the DataIn...
Definition jacobianReuseTape.hpp:178
typename TapeTypes::Real Real
See TapeTypesInterface.
Definition jacobianReuseTape.hpp:75
typename TapeTypes::IndexManager IndexManager
See TapeTypesInterface.
Definition jacobianReuseTape.hpp:77
void pushStmtData(Identifier const &index, Config::ArgumentSize const &numberOfArguments)
Add statement specific data to the data streams.
Definition jacobianReuseTape.hpp:131
typename Base::Position Position
See TapeTypesInterface.
Definition jacobianReuseTape.hpp:79
Type definitions for the Jacobian tapes.
Definition jacobianBaseTape.hpp:75