CoDiPack  3.1.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
primalValueLinearTape.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2026 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include <algorithm>
38#include <functional>
39#include <type_traits>
40
41#include "../config.h"
42#include "../expressions/lhsExpressionInterface.hpp"
43#include "../expressions/logic/compileTimeTraversalLogic.hpp"
44#include "../expressions/logic/constructStaticContext.hpp"
45#include "../expressions/logic/traversalLogic.hpp"
46#include "../misc/macros.hpp"
47#include "../misc/memberStore.hpp"
48#include "../traits/expressionTraits.hpp"
49#include "data/chunk.hpp"
50#include "indices/indexManagerInterface.hpp"
51#include "primalValueBaseTape.hpp"
52
54namespace codi {
55
63 template<typename T_TapeTypes>
64 struct PrimalValueLinearTape : public PrimalValueBaseTape<T_TapeTypes, PrimalValueLinearTape<T_TapeTypes>> {
65 public:
66
67 using TapeTypes =
68 CODI_DD(T_TapeTypes,
71
73 friend Base;
74
75 using Real = typename TapeTypes::Real;
76 using Gradient = typename TapeTypes::Gradient;
77 using IndexManager = typename TapeTypes::IndexManager;
78 using Identifier = typename TapeTypes::Identifier;
80 using StatementEvaluator = typename TapeTypes::StatementEvaluator;
81 using EvalHandle = typename TapeTypes::EvalHandle;
82 using Position = typename Base::Position;
83
84 using StatementDataPointers = typename Base::StatementDataPointers;
85
86 template<typename T>
87 using StackArray = typename Base::template StackArray<T>;
88
91
93
97 void clearAdjoints(Position const& start, Position const& end,
99 CODI_UNUSED(adjointsManagement);
100
101 using IndexPosition = CODI_DD(typename IndexManager::Position, int);
102 IndexPosition startIndex = this->llfByteData.template extractPosition<IndexPosition>(start);
103 IndexPosition endIndex = this->llfByteData.template extractPosition<IndexPosition>(end);
104
105 startIndex = std::min(startIndex, (IndexPosition)this->adjoints.size() - 1);
106 endIndex = std::min(endIndex, (IndexPosition)this->adjoints.size() - 1);
107
108 for (IndexPosition curPos = endIndex + 1; curPos <= startIndex; curPos += 1) {
109 this->adjoints[curPos] = Gradient();
110 }
111 }
112
114 template<typename AdjointVector>
115 void clearCustomAdjoints(Position const& start, Position const& end, AdjointVector data) {
116 using IndexPosition = CODI_DD(typename IndexManager::Position, int);
117 IndexPosition startIndex = this->llfByteData.template extractPosition<IndexPosition>(start);
118 IndexPosition endIndex = this->llfByteData.template extractPosition<IndexPosition>(end);
119
120 for (IndexPosition curPos = endIndex + 1; curPos <= startIndex; curPos += 1) {
122 }
123 }
124
125 protected:
126
129 /* data from call */
130 PrimalValueLinearTape& tape, Real* primalVector, ADJOINT_VECTOR_TYPE* adjointVector,
131 /* data from low level function byte data vector */
132 size_t& curLLFByteDataPos, size_t const& endLLFByteDataPos, char* dataPtr,
133 /* data from low level function info data vector */
134 size_t& curLLFInfoDataPos, size_t const& endLLFInfoDataPos, Config::LowLevelFunctionToken* const tokenPtr,
135 Config::LowLevelFunctionDataSize* const dataSizePtr,
136 /* data from statementByteData */
137 size_t& curStatementBytePos, size_t const& endStatementBytePos, char* stmtDataPtr,
138 /* data from statementData */
139 size_t& curStatementPos, size_t const& endStatementPos,
140 Config::ArgumentSize const* const numberOfPassiveArguments, EvalHandle const* const stmtEvalHandle,
141 Config::LowLevelFunctionDataSize* const stmtByteSize,
142 /* data from index handler */
143 size_t const& startAdjointPos, size_t const& endAdjointPos) {
144 CODI_UNUSED(endLLFByteDataPos, endLLFInfoDataPos, endStatementBytePos, endAdjointPos);
145
146 size_t curAdjointPos = startAdjointPos;
147 StackArray<Real> lhsPrimals = {};
148 StackArray<Gradient> lhsTangents = {};
149
150#if !CODI_VariableAdjointInterfaceInPrimalTapes
151 typename Base::template VectorAccess<Gradient*> vectorAccess(adjointVector, primalVector);
152#endif
153
154 while (curStatementPos < endStatementPos) CODI_Likely {
155 Config::ArgumentSize nPassiveValues = numberOfPassiveArguments[curStatementPos];
156
159 tape, true, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr,
161 adjointVector
162#else
163 &vectorAccess
164#endif
165 );
166 } else if (Config::StatementInputTag == nPassiveValues) CODI_Unlikely {
167 curAdjointPos += 1;
168 } else CODI_Likely {
169 StatementEvaluator::template call<StatementCall::Forward, PrimalValueLinearTape>(
170 stmtEvalHandle[curStatementPos], tape, lhsPrimals.data(), lhsTangents.data(), primalVector,
171 adjointVector, curAdjointPos, nPassiveValues, &stmtDataPtr[curStatementBytePos]);
172
173 curStatementBytePos += stmtByteSize[curStatementPos];
174 }
175
176 curStatementPos += 1;
177 }
178 }
179
182 /* data from call */
183 PrimalValueLinearTape& tape, Real* primalVector,
184 /* data from low level function byte data vector */
185 size_t& curLLFByteDataPos, size_t const& endLLFByteDataPos, char* dataPtr,
186 /* data from low level function info data vector */
187 size_t& curLLFInfoDataPos, size_t const& endLLFInfoDataPos, Config::LowLevelFunctionToken* const tokenPtr,
188 Config::LowLevelFunctionDataSize* const dataSizePtr,
189 /* data from statementByteData */
190 size_t& curStatementBytePos, size_t const& endStatementBytePos, char* stmtDataPtr,
191 /* data from statementData */
192 size_t& curStatementPos, size_t const& endStatementPos,
193 Config::ArgumentSize const* const numberOfPassiveArguments, EvalHandle const* const stmtEvalHandle,
194 Config::LowLevelFunctionDataSize* const stmtByteSize,
195 /* data from index handler */
196 size_t const& startAdjointPos, size_t const& endAdjointPos) {
197 CODI_UNUSED(endLLFByteDataPos, endLLFInfoDataPos, endStatementBytePos, endAdjointPos);
198
199 size_t curAdjointPos = startAdjointPos;
200 StackArray<Real> lhsPrimals = {};
201
202 typename Base::template VectorAccess<Gradient*> vectorAccess(nullptr, primalVector);
203
204 while (curStatementPos < endStatementPos) CODI_Likely {
205 Config::ArgumentSize nPassiveValues = numberOfPassiveArguments[curStatementPos];
206
209 tape, true, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr, &vectorAccess);
210 } else if (Config::StatementInputTag == nPassiveValues) CODI_Unlikely {
211 curAdjointPos += 1;
212 } else CODI_Likely {
213 StatementEvaluator::template call<StatementCall::Primal, PrimalValueLinearTape>(
214 stmtEvalHandle[curStatementPos], tape, lhsPrimals.data(), primalVector, curAdjointPos, nPassiveValues,
215 &stmtDataPtr[curStatementBytePos]);
216
217 curStatementBytePos += stmtByteSize[curStatementPos];
218 }
219
220 curStatementPos += 1;
221 }
222 }
223
226 /* data from call */
227 PrimalValueLinearTape& tape, Real* primalVector, ADJOINT_VECTOR_TYPE* adjointVector,
228 /* data from low level function byte data vector */
229 size_t& curLLFByteDataPos, size_t const& endLLFByteDataPos, char* dataPtr,
230 /* data from low level function info data vector */
231 size_t& curLLFInfoDataPos, size_t const& endLLFInfoDataPos, Config::LowLevelFunctionToken* const tokenPtr,
232 Config::LowLevelFunctionDataSize* const dataSizePtr,
233 /* data from statementByteData */
234 size_t& curStatementBytePos, size_t const& endStatementBytePos, char* stmtDataPtr,
235 /* data from statementData */
236 size_t& curStatementPos, size_t const& endStatementPos,
237 Config::ArgumentSize const* const numberOfPassiveArguments, EvalHandle const* const stmtEvalHandle,
238 Config::LowLevelFunctionDataSize* const stmtByteSize,
239 /* data from index handler */
240 size_t const& startAdjointPos, size_t const& endAdjointPos) {
241 CODI_UNUSED(endLLFByteDataPos, endLLFInfoDataPos, endStatementBytePos, endAdjointPos);
242
243 size_t curAdjointPos = startAdjointPos;
244 StackArray<Gradient> lhsAdjoints = {};
245
246#if !CODI_VariableAdjointInterfaceInPrimalTapes
247 typename Base::template VectorAccess<Gradient*> vectorAccess(adjointVector, primalVector);
248#endif
249
250 while (curStatementPos > endStatementPos) CODI_Likely {
251 curStatementPos -= 1;
252
253 Config::ArgumentSize nPassiveValues = numberOfPassiveArguments[curStatementPos];
254
257 tape, false, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr,
259 adjointVector
260#else
261 &vectorAccess
262#endif
263 );
264 } else if (Config::StatementInputTag == nPassiveValues) CODI_Unlikely {
265 curAdjointPos -= 1;
266 } else CODI_Likely {
267 curStatementBytePos -= stmtByteSize[curStatementPos];
268
269 StatementEvaluator::template call<StatementCall::Reverse, PrimalValueLinearTape>(
270 stmtEvalHandle[curStatementPos], tape, lhsAdjoints.data(), primalVector, adjointVector, curAdjointPos,
271 nPassiveValues, &stmtDataPtr[curStatementBytePos]);
272 }
273 }
274 }
275
277 template<typename TapeTypes>
279 /* data from call */
280 Real* primalVector,
281 /* file interface pointer*/
283 /* data from low level function byte data vector */
284 size_t& curLLFByteDataPos, size_t const& endLLFByteDataPos, char* dataPtr,
285 /* data from low level function info data vector */
286 size_t& curLLFInfoDataPos, size_t const& endLLFInfoDataPos, Config::LowLevelFunctionToken* const tokenPtr,
287 Config::LowLevelFunctionDataSize* const dataSizePtr,
288 /* data from statementByteData */
289 size_t& curStatementBytePos, size_t const& endStatementBytePos, char* stmtDataPtr,
290 /* data from statementData */
291 size_t& curStatementPos, size_t const& endStatementPos,
292 Config::ArgumentSize const* const numberOfPassiveArguments, EvalHandle const* const stmtEvalHandle,
293 Config::LowLevelFunctionDataSize* const stmtByteSize,
294 /* data from index handler */
295 size_t const& startAdjointPos, size_t const& endAdjointPos) {
296 CODI_UNUSED(endLLFByteDataPos, endLLFInfoDataPos, endStatementBytePos, endAdjointPos);
297
298 size_t curAdjointPos = startAdjointPos;
299 StackArray<Identifier> lhsIdentifiers;
300
301 ByteDataView dataView = {};
303
304 while (curStatementPos < endStatementPos) {
305 Config::ArgumentSize nPassiveValues = numberOfPassiveArguments[curStatementPos];
306
308 Base::prepareLowLevelFunction(true, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr,
309 dataView, func);
310 writer->writeLowLevelFunction(func, dataView);
311 } else CODI_Likely {
312 WriteInfo writeInfo;
313 StatementEvaluator::template call<StatementCall::WriteInformation, PrimalValueLinearTape>(
314 stmtEvalHandle[curStatementPos], writeInfo, primalVector, nPassiveValues,
315 &stmtDataPtr[curStatementBytePos]);
316
317 StatementDataPointers pointers = {};
318 pointers.populate(writeInfo.numberOfOutputArguments, writeInfo.numberOfActiveArguments, nPassiveValues,
319 writeInfo.numberOfConstantArguments, &stmtDataPtr[curStatementBytePos]);
320
321 Real const* lhsPrimalValues = &primalVector[curAdjointPos + 1];
322 for (size_t i = 0; i < writeInfo.numberOfOutputArguments; i += 1) {
323 curAdjointPos += 1;
324 lhsIdentifiers[i] = curAdjointPos;
325 }
326
327 writer->writeStatement(writeInfo, lhsIdentifiers.data(), lhsPrimalValues, nPassiveValues,
328 pointers.rhsIdentifiers, pointers.passiveValues, pointers.constantValues,
329 stmtEvalHandle[curStatementPos]);
330
331 curStatementBytePos += stmtByteSize[curStatementPos];
332 }
333
334 curStatementPos += 1;
335 }
336 }
337
341 CODI_UNUSED(pos);
342
343 // Nothing to do.
344 }
345
346 public:
349 void revertPrimals(Position const& pos) {
350 CODI_UNUSED(pos);
351
352 // Primal values do not need to be reset.
353 }
354
355 /*******************************************************************************/
358
361 template<typename Callbacks>
362 CODI_INLINE void iterateForward(Callbacks&& callbacks, Position start, Position end) {
363 auto evalFunc =
364 [&callbacks](
365 /* data from call */
367 /* data from low level function byte data vector */
368 size_t& curLLFByteDataPos, size_t const& endLLFByteDataPos, char* dataPtr,
369 /* data from low level function info data vector */
370 size_t& curLLFInfoDataPos, size_t const& endLLFInfoDataPos,
371 Config::LowLevelFunctionToken* const tokenPtr, Config::LowLevelFunctionDataSize* const dataSizePtr,
372 /* data from statementByteData */
373 size_t& curStatementBytePos, size_t const& endStatementBytePos, char* stmtDataPtr,
374 /* data from statementData */
375 size_t& curStatementPos, size_t const& endStatementPos,
376 Config::ArgumentSize const* const numberOfPassiveArguments, EvalHandle const* const stmtEvalHandle,
377 Config::LowLevelFunctionDataSize* const stmtByteSize,
378 /* data from index handler */
379 size_t const& startAdjointPos, size_t const& endAdjointPos) CODI_LAMBDA_INLINE {
380 CODI_UNUSED(tape, endLLFByteDataPos, endLLFInfoDataPos, endStatementBytePos, endAdjointPos);
381
382 size_t curAdjointPos = startAdjointPos;
383 ByteDataView dataView = {};
385
386 while (curStatementPos < endStatementPos) CODI_Likely {
387 Config::ArgumentSize nPassiveValues = numberOfPassiveArguments[curStatementPos];
388
390 Base::prepareLowLevelFunction(true, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr,
391 dataSizePtr, dataView, func);
392 callbacks.handleLowLevelFunction(*func, dataView);
393 } else CODI_Likely {
394 if (Config::StatementInputTag == nPassiveValues) CODI_Unlikely {
395 nPassiveValues = 0;
396 }
397 callbacks.handleStatement(stmtEvalHandle[curStatementPos], nPassiveValues, curAdjointPos,
398 &stmtDataPtr[curStatementBytePos]);
399
400 curStatementBytePos += stmtByteSize[curStatementPos];
401 }
402
403 curStatementPos += 1;
404 }
405 };
406
407 Base::llfByteData.evaluateForward(start, end, evalFunc, *this);
408 }
409
412 template<typename Callbacks>
413 CODI_INLINE void iterateReverse(Callbacks&& callbacks, Position start, Position end) {
414 auto evalFunc =
415 [&callbacks](
416 /* data from call */
418 /* data from low level function byte data vector */
419 size_t& curLLFByteDataPos, size_t const& endLLFByteDataPos, char* dataPtr,
420 /* data from low level function info data vector */
421 size_t& curLLFInfoDataPos, size_t const& endLLFInfoDataPos,
422 Config::LowLevelFunctionToken* const tokenPtr, Config::LowLevelFunctionDataSize* const dataSizePtr,
423 /* data from statementByteData */
424 size_t& curStatementBytePos, size_t const& endStatementBytePos, char* stmtDataPtr,
425 /* data from statementData */
426 size_t& curStatementPos, size_t const& endStatementPos,
427 Config::ArgumentSize const* const numberOfPassiveArguments, EvalHandle const* const stmtEvalHandle,
428 Config::LowLevelFunctionDataSize* const stmtByteSize,
429 /* data from index handler */
430 size_t const& startAdjointPos, size_t const& endAdjointPos) CODI_LAMBDA_INLINE {
431 CODI_UNUSED(tape, endLLFByteDataPos, endLLFInfoDataPos, endStatementBytePos, endAdjointPos);
432
433 size_t curAdjointPos = startAdjointPos;
434 ByteDataView dataView = {};
436
437 while (curStatementPos > endStatementPos) CODI_Likely {
438 curStatementPos -= 1;
439
440 Config::ArgumentSize nPassiveValues = numberOfPassiveArguments[curStatementPos];
441
443 Base::prepareLowLevelFunction(false, curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr,
444 dataSizePtr, dataView, func);
445 callbacks.handleLowLevelFunction(*func, dataView);
446 } else CODI_Likely {
447 curStatementBytePos -= stmtByteSize[curStatementPos];
448
449 if (Config::StatementInputTag == nPassiveValues) CODI_Unlikely {
450 nPassiveValues = 0;
451 }
452 callbacks.handleStatement(stmtEvalHandle[curStatementPos], nPassiveValues, curAdjointPos,
453 &stmtDataPtr[curStatementBytePos]);
454 }
455 }
456 };
457
458 Base::llfByteData.evaluateReverse(start, end, evalFunc, *this);
459 }
460 };
461}
#define CODI_Unlikely
Declare unlikely evaluation of an execution path.
Definition config.h:408
#define CODI_LAMBDA_INLINE
See codi::Config::ForcedInlines.
Definition config.h:473
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_VariableAdjointInterfaceInPrimalTapes
See codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition config.h:278
#define ADJOINT_VECTOR_TYPE
See codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition config.h:286
#define CODI_Likely
Declare likely evaluation of an execution path.
Definition config.h:406
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
#define CODI_T(...)
Abbreviation for CODI_TEMPLATE.
Definition macros.hpp:117
typename GradientImplementation< AdjointVector >::Gradient Gradient
Deduce the entry type from an adjoint vector type, usually identical to the gradient type of a tape.
Definition adjointVectorTraits.hpp:92
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
size_t constexpr StatementInputTag
Tag for statements that are inputs. Used in linear index management context.
Definition config.h:123
typename TraitsImplementation< Type >::PassiveReal PassiveReal
The original computation type that was used in the application.
Definition realTraits.hpp:123
CoDiPack - Code Differentiation Package.
Definition codi.hpp:97
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:55
AdjointsManagement
Policies for management of the tape's interal adjoints.
Definition tapeParameters.hpp:100
@ Automatic
Manage internal adjoints automatically, including locking, bounds checking, and resizing.
Definition tapeParameters.hpp:102
ChunkedData< Chunk, NestedData > DefaultChunkedData
ChunkData DataInterface used in all regular tapes.
Definition chunkedData.hpp:520
Definition byteDataView.hpp:51
void iterateForward(Callbacks &&callbacks)
Iterate over the tape in a generalized fashion. callbacks needs to implement codi::CallbacksInterface...
Definition commonTapeImplementation.hpp:371
inlinestatic void callLowLevelFunction(Impl &impl, bool forward, size_t &curLLFByteDataPos, char *dataPtr, size_t &curLLFTInfoDataPos, Config::LowLevelFunctionToken *const tokenPtr, Config::LowLevelFunctionDataSize *const dataSizePtr, Args &&... args)
Called by the implementing tapes during a tape evaluation when a low level function statement has bee...
Definition commonTapeImplementation.hpp:569
LowLevelFunctionByteData llfByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:158
inlinestatic Config::LowLevelFunctionToken prepareLowLevelFunction(bool forward, size_t &curLLFByteDataPos, char *dataPtr, size_t &curLLFTInfoDataPos, Config::LowLevelFunctionToken *const tokenPtr, Config::LowLevelFunctionDataSize *const dataSizePtr, ByteDataView &dataView, LowLevelFunctionEntry< Impl, Real, Identifier > const *&func)
Prepare the call of a low level function.
Definition commonTapeImplementation.hpp:540
void iterateReverse(Callbacks &&callbacks)
Iterate over the tape in a generalized fashion. callbacks needs to implement codi::CallbacksInterface...
Definition commonTapeImplementation.hpp:379
Indices enable the mapping of primal values to their adjoint counterparts.
Definition indexManagerInterface.hpp:78
Low level function entry on the tape. See LowLevelFunctionTapeInterface for details.
Definition lowLevelFunctionEntry.hpp:69
std::vector< Gradient > adjoints
Definition primalValueBaseTape.hpp:188
inlinevoid clearAdjoints(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Definition primalValueBaseTape.hpp:713
typename Base::Position Position
Definition primalValueBaseTape.hpp:162
PrimalAdjointVectorAccess< Real, Identifier, AdjointVector > VectorAccess
Definition primalValueBaseTape.hpp:166
typename TapeTypes::StatementEvaluator StatementEvaluator
See PrimalValueTapeTypes.
Definition primalValueLinearTape.hpp:80
T_TapeTypes TapeTypes
See PrimalValueLinearTape.
Definition primalValueLinearTape.hpp:67
inlinevoid iterateReverse(Callbacks &&callbacks, Position start, Position end)
Iterate over the tape in a generalized fashion. callbacks needs to implement codi::CallbacksInterface...
Definition primalValueLinearTape.hpp:413
void clearCustomAdjoints(Position const &start, Position const &end, AdjointVector data)
Clear all adjoint values, that is, set them to zero.
Definition primalValueLinearTape.hpp:115
typename Base::Position Position
See TapeTypesInterface.
Definition primalValueLinearTape.hpp:82
typename TapeTypes::Identifier Identifier
See TapeTypesInterface.
Definition primalValueLinearTape.hpp:78
PrimalValueLinearTape()
Constructor.
Definition primalValueLinearTape.hpp:90
inlinestatic void internalEvaluateReverse_EvalStatements(PrimalValueLinearTape &tape, Real *primalVector, Gradient *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 &curStatementBytePos, size_t const &endStatementBytePos, char *stmtDataPtr, size_t &curStatementPos, size_t const &endStatementPos, Config::ArgumentSize const *const numberOfPassiveArguments, EvalHandle const *const stmtEvalHandle, Config::LowLevelFunctionDataSize *const stmtByteSize, 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 primalValueLinearTape.hpp:225
typename TapeTypes::IndexManager IndexManager
See PrimalValueTapeTypes.
Definition primalValueLinearTape.hpp:77
typename TapeTypes::EvalHandle EvalHandle
See PrimalValueTapeTypes.
Definition primalValueLinearTape.hpp:81
void revertPrimals(Position const &pos)
Revert the primals to the state indicated by pos.
Definition primalValueLinearTape.hpp:349
typename Base::template StackArray< T > StackArray
See PrimalValueBaseTape.
Definition primalValueLinearTape.hpp:87
typename TapeTypes::Real Real
See TapeTypesInterface.
Definition primalValueLinearTape.hpp:75
typename TapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition primalValueLinearTape.hpp:76
inlinevoid internalResetPrimalValues(Position const &pos)
Reset the primal values to the given position.
Definition primalValueLinearTape.hpp:340
inlinestatic void internalEvaluatePrimal_EvalStatements(PrimalValueLinearTape &tape, Real *primalVector, 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 &curStatementBytePos, size_t const &endStatementBytePos, char *stmtDataPtr, size_t &curStatementPos, size_t const &endStatementPos, Config::ArgumentSize const *const numberOfPassiveArguments, EvalHandle const *const stmtEvalHandle, Config::LowLevelFunctionDataSize *const stmtByteSize, size_t const &startAdjointPos, size_t const &endAdjointPos)
Perform a primal evaluation of the tape. Arguments are from the recursive eval methods of the DataInt...
Definition primalValueLinearTape.hpp:181
PrimalValueBaseTape< T_TapeTypes, PrimalValueLinearTape< T_TapeTypes > > Base
Base class abbreviation.
Definition primalValueLinearTape.hpp:72
inlinestatic void internalWriteTape(Real *primalVector, codi::TapeWriterInterface< TapeTypes > *writer, 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 &curStatementBytePos, size_t const &endStatementBytePos, char *stmtDataPtr, size_t &curStatementPos, size_t const &endStatementPos, Config::ArgumentSize const *const numberOfPassiveArguments, EvalHandle const *const stmtEvalHandle, Config::LowLevelFunctionDataSize *const stmtByteSize, size_t const &startAdjointPos, size_t const &endAdjointPos)
Passes the statement information and the stmtEvalHandle to the writer.
Definition primalValueLinearTape.hpp:278
inlinevoid iterateForward(Callbacks &&callbacks, Position start, Position end)
Iterate over the tape in a generalized fashion. callbacks needs to implement codi::CallbacksInterface...
Definition primalValueLinearTape.hpp:362
inlinestatic void internalEvaluateForward_EvalStatements(PrimalValueLinearTape &tape, Real *primalVector, Gradient *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 &curStatementBytePos, size_t const &endStatementBytePos, char *stmtDataPtr, size_t &curStatementPos, size_t const &endStatementPos, Config::ArgumentSize const *const numberOfPassiveArguments, EvalHandle const *const stmtEvalHandle, Config::LowLevelFunctionDataSize *const stmtByteSize, 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 primalValueLinearTape.hpp:128
RealTraits::PassiveReal< Real > PassiveReal
Basic computation type.
Definition primalValueLinearTape.hpp:79
typename Base::StatementDataPointers StatementDataPointers
Defined in PrimalValueBaseTape.
Definition primalValueLinearTape.hpp:84
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 primalValueLinearTape.hpp:97
Type definitions for the primal value tapes.
Definition primalValueBaseTape.hpp:82
Creation of handles for the evaluation of expressions in a context where the expression type is not a...
Definition statementEvaluatorInterface.hpp:103
The interface used by all the tape writers. The tape writers are used to generate text,...
Definition tapeReaderWriterInterface.hpp:129
virtual void writeLowLevelFunction(LowLevelFunctionEntry< Tape, Real, Identifier > const *func, ByteDataView &data)
Used for statements that contain a low level function.
Definition tapeReaderWriterInterface.hpp:171
virtual void writeStatement(Identifier const &curLhsIdentifier, size_t &curJacobianPos, Real const *const rhsJacobians, Identifier const *const rhsIdentifiers, Config::ArgumentSize const &nJacobians)
Called for each statement. The method writes the current statement to the file. This overload is used...
Definition tapeReaderWriterInterface.hpp:152
This class is used during the writing process of a primal value tape. The WriteInfo is returned by St...
Definition tapeReaderWriterInterface.hpp:69
size_t numberOfActiveArguments
Number of active arguments.
Definition tapeReaderWriterInterface.hpp:71
size_t numberOfOutputArguments
Number of output arguments.
Definition tapeReaderWriterInterface.hpp:70
size_t numberOfConstantArguments
Number of constant arguments.
Definition tapeReaderWriterInterface.hpp:72