CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
commonTapeImplementation.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 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 <type_traits>
39
40#include "../config.h"
41#include "../misc/byteDataView.hpp"
42#include "../misc/eventSystem.hpp"
43#include "../misc/fileIo.hpp"
44#include "../misc/macros.hpp"
45#include "../misc/temporaryMemory.hpp"
46#include "data/dataInterface.hpp"
47#include "data/position.hpp"
48#include "indices/indexManagerInterface.hpp"
49#include "interfaces/fullTapeInterface.hpp"
50#include "misc/externalFunction.hpp"
51#include "misc/lowLevelFunctionEntry.hpp"
52#include "misc/vectorAccessInterface.hpp"
53
55namespace codi {
56
64 public:
65
66 using Real = CODI_ANY;
69
72 template<typename Chunk, typename Nested>
74
77 };
78
84 template<typename T_TapeTypes>
86 public:
87
88 using TapeTypes = CODI_DD(T_TapeTypes, TapeTypesInterface);
89
90 template<typename Chunk, typename Nested>
91 using Data = typename TapeTypes::template Data<Chunk, Nested>;
92
93 using NestedData = typename TapeTypes::NestedData;
94
99
104
105 using Position = typename LowLevelFunctionByteData::Position;
106 };
107
126 template<typename T_ImplTapeTypes, typename T_Impl>
128 : public FullTapeInterface<typename T_ImplTapeTypes::Real, typename T_ImplTapeTypes::Gradient,
129 typename T_ImplTapeTypes::Identifier,
130 typename CommonTapeTypes<T_ImplTapeTypes>::Position> {
131 public:
132
133 using ImplTapeTypes = CODI_DD(T_ImplTapeTypes, TapeTypesInterface);
135
136 using Real = typename ImplTapeTypes::Real;
137 using Gradient = typename ImplTapeTypes::Gradient;
138 using Identifier = typename ImplTapeTypes::Identifier;
139
145
147 using NestedPosition = typename LowLevelFunctionByteData::Position;
148
149 protected:
150
151 bool active;
152 std::set<TapeParameters> options;
153
156
161
163
165 static std::vector<LowLevelFunctionEntry<Impl, Real, Identifier>>* lowLevelFunctionLookup;
166
167 private:
168
170 static Config::LowLevelFunctionToken constexpr EXTERNAL_FUNCTION_TOKEN = 0;
171
172 CODI_INLINE Impl const& cast() const {
173 return static_cast<Impl const&>(*this);
174 }
175
176 CODI_INLINE Impl& cast() {
177 return static_cast<Impl&>(*this);
178 }
179
180 CODI_INLINE void resetInternal(bool resetAdjoints, AdjointsManagement adjointsManagement,
181 EventHints::Reset kind) {
182 EventSystem<Impl>::notifyTapeResetListeners(cast(), this->getZeroPosition(), kind, resetAdjoints);
183
184 if (resetAdjoints) {
185 cast().clearAdjoints(adjointsManagement);
186 }
187
189
190 llfByteData.reset();
191
192 // Requires extra reset since the default vector implementation forwards to resetTo
193 cast().indexManager.get().reset();
194 }
195
196 protected:
197
199 CODI_INLINE void initializeManualPushData(Real const& lhsValue, Identifier const& lhsIndex, size_t size) {
200 codiAssert(this->manualPushGoal == this->manualPushCounter);
202 this->manualPushLhsValue = lhsValue;
203 this->manualPushLhsIdentifier = lhsIndex;
204 this->manualPushCounter = 0;
205 this->manualPushGoal = size;
206 }
207 }
208
211 codiAssert(this->manualPushCounter < this->manualPushGoal);
212
214 this->manualPushCounter += 1;
215 }
216 }
217
218 protected:
219
220 /*******************************************************************************/
223
225
227
228 public:
229
232 : active(false),
233 options(),
234 llfInfoData(Config::SmallChunkSize),
235 llfByteData(Config::ByteDataChunkSize),
240 allocator() {
243
244 if (nullptr == lowLevelFunctionLookup) {
245 lowLevelFunctionLookup = new std::vector<LowLevelFunctionEntry<Impl, Real, Identifier>>();
246
247 // Add external function token. So EXTERNAL_FUNCTION_TOKEN is always zero.
250 if (token != EXTERNAL_FUNCTION_TOKEN) {
251 CODI_EXCEPTION("External function token is not zero.");
252 }
253 }
254 }
255
258
261
264
267
268 /*******************************************************************************/
271
273 void setGradient(Identifier const& identifier, Gradient const& gradient,
275 cast().gradient(identifier, adjointsManagement) = gradient;
276 }
277
279 Gradient const& getGradient(Identifier const& identifier,
280 AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
281 return cast().gradient(identifier, adjointsManagement);
282 }
283
284 // Gradient functions are not implemented.
285
287 /*******************************************************************************/
290
293 Impl& impl = cast();
294
295 impl.evaluate(impl.getPosition(), impl.getZeroPosition(), adjointsManagement);
296 }
297
299 template<typename Lhs>
301 cast().template store<Lhs, Lhs>(value, static_cast<ExpressionInterface<Real, Lhs> const&>(value));
303 value.cast().getIdentifier());
304 }
305
311
317
319 bool isActive() const {
320 return active;
321 }
322
324 template<typename Stream = std::ostream>
325 void printStatistics(Stream& out = std::cout) const {
326 cast().getTapeValues().formatDefault(out);
327 }
328
330 template<typename Stream = std::ostream>
331 void printTableHeader(Stream& out = std::cout) const {
332 cast().getTapeValues().formatHeader(out);
333 }
334
336 template<typename Stream = std::ostream>
337 void printTableRow(Stream& out = std::cout) const {
338 cast().getTapeValues().formatRow(out);
339 }
340
343 TapeValues values = cast().internalGetTapeValues();
344
345 values.addSection("Low level function info data entries");
346 llfInfoData.addToTapeValues(values);
347 values.addSection("Low level function byte data entries");
348 llfByteData.addToTapeValues(values);
349
350 return values;
351 }
352
354 CODI_INLINE void reset(bool resetAdjoints = true,
356 resetInternal(resetAdjoints, adjointsManagement, EventHints::Reset::Full);
357 }
358
359 // clearAdjoints and reset(Position) are not implemented.
360
362 /*******************************************************************************/
365
367 void swap(Impl& other) {
368 std::swap(active, other.active);
369
370 llfByteData.swap(other.llfByteData);
371 }
372
374 void resetHard() {
375 Impl& impl = cast();
376
377 // First perform a regular reset.
378 resetInternal(false, AdjointsManagement::Automatic, EventHints::Reset::Hard);
379
380 // Then perform the hard resets.
381 impl.deleteAdjointVector();
382
383 llfByteData.resetHard();
384 }
385
387
388 private:
389 static void writeFunction(const ChunkBase* chunk, FileIo& handle) {
390 chunk->writeData(handle);
391 }
392
393 static void readFunction(ChunkBase* chunk, FileIo& handle) {
394 chunk->readData(handle);
395 }
396
397 static void deleteFunction(ChunkBase* chunk) {
398 chunk->deleteData();
399 }
400
401 public:
402
405 void writeToFile(const std::string& filename) {
406 FileIo io(filename, true);
407
408 llfByteData.forEachChunk(writeFunction, true, io);
409 }
410
412 void readFromFile(const std::string& filename) {
413 FileIo io(filename, false);
414
415 llfByteData.forEachChunk(readFunction, true, io);
416 }
417
419 void deleteData() {
420 llfByteData.forEachChunk(deleteFunction, true);
421 }
422
424 std::set<TapeParameters> const& getAvailableParameters() const {
425 return options;
426 }
427
430 size_t getParameter(TapeParameters parameter) const {
431 switch (parameter) {
433 return llfByteData.getDataSize();
434 break;
436 return llfInfoData.getDataSize();
437 break;
439 CODI_WARNING(
440 "Tape parameter 'ExternalFunctionsSize' no longer supported. Use 'LLFInfoDataSize' and "
441 "'LLFByteDataSize' instead.");
442 return 0;
443 break;
444 default:
445 CODI_EXCEPTION("Tried to get undefined parameter for tape.");
446 return 0;
447 break;
448 }
449 }
450
452 bool hasParameter(TapeParameters parameter) const {
453 return options.cend() != options.find(parameter);
454 }
455
458 void setParameter(TapeParameters parameter, size_t value) {
459 switch (parameter) {
461 llfByteData.resize(value);
462 break;
464 llfInfoData.resize(value);
465 break;
467 CODI_WARNING(
468 "Tape parameter 'ExternalFunctionsSize' is no longer supported. Use 'LLFInfoDataSize' and "
469 "'LLFByteDataSize' instead.");
470 break;
471 default:
472 CODI_EXCEPTION("Tried to set undefined parameter for tape.");
473 break;
474 }
475 }
476
477 // createVectorAccess is not implemented.
478 // createVectorAccessCustomAdjoints is not implemented.
479 // resizeAdjointVector is not implemented.
480 // deleteAdjointVector is not implemented.
481 // beginUseAdjointVector is not implemented.
482 // endUseAdjointVector is not implemented.
483
485 /*******************************************************************************/
488
489 protected:
490
494 ByteDataView& dataView) {
495 codiAssert((size_t)token < lowLevelFunctionLookup->size());
497 CODI_EXCEPTION(
498 "Requested size for low level function is to big. Increase "
499 "codi::Config::LowLevelFunctionDataSize or perform a dynamic memory allocation.");
500 }
501
502 llfInfoData.reserveItems(1);
503 llfByteData.reserveItems(size);
504
505 llfInfoData.pushData(token, size);
506
507 char* dataPointer = nullptr;
508 llfByteData.getDataPointers(dataPointer);
509 dataView.init(dataPointer, 0, size);
510 llfByteData.addDataSize(size);
511 }
512
515 template<LowLevelFunctionEntryCallKind callType, typename... Args>
516 CODI_INLINE static void callLowLevelFunction(Impl& impl, bool forward,
517 /* data from low level function byte data vector */
518 size_t& curLLFByteDataPos, char* dataPtr,
519 /* data from low level function info data vector */
520 size_t& curLLFTInfoDataPos,
521 Config::LowLevelFunctionToken* const tokenPtr,
522 Config::LowLevelFunctionDataSize* const dataSizePtr,
523 Args&&... args) {
524 if (!forward) {
525 curLLFTInfoDataPos -= 1;
526 curLLFByteDataPos -= dataSizePtr[curLLFTInfoDataPos];
527 }
528
529 size_t endPos = curLLFByteDataPos + dataSizePtr[curLLFTInfoDataPos];
530 ByteDataView dataView(dataPtr, curLLFByteDataPos, endPos);
531
532 Config::LowLevelFunctionToken id = tokenPtr[curLLFTInfoDataPos];
533 LowLevelFunctionEntry<Impl, Real, Identifier> const& func = (*lowLevelFunctionLookup)[id];
534 if (func.template has<callType>()) CODI_Likely {
535 func.template call<callType>(&impl, dataView, std::forward<Args>(args)...);
536
537 codiAssert(endPos == dataView.getPosition());
538 } else CODI_Unlikely if (LowLevelFunctionEntryCallKind::Delete == callType) {
539 // No delete registered. Data is skiped by the curLLFByteDataPos update.
540 } else {
541 CODI_EXCEPTION("Requested call is not supported for low level function with token '%d'.", (int)id);
542 }
543
544 if (forward) {
545 curLLFByteDataPos += dataSizePtr[curLLFTInfoDataPos];
546 curLLFTInfoDataPos += 1;
547 }
548 }
549
550 public:
551
556
568
569 // pushLowLevelFunction is not implemented.
570
572 /*******************************************************************************/
575
579 ExternalFunctionLowLevelEntryMapper<Impl, Real, Identifier>::store(cast(), EXTERNAL_FUNCTION_TOKEN, extFunc);
580 }
581 }
582
583 // registerExternalFunctionOutput is not implemented.
584
586 /*******************************************************************************/
589
592 Impl& impl = cast();
593
594 impl.evaluateForward(impl.getZeroPosition(), impl.getPosition(), adjointsManagement);
595 }
596
598 /*******************************************************************************/
601
606
611
613 bool isIdentifierActive(Identifier const& index) const {
614 return index != cast().getPassiveIndex();
615 }
616
618 template<typename Lhs>
622
624 /*******************************************************************************/
627
630 return llfByteData.getPosition();
631 }
632
635 return llfByteData.getZeroPosition();
636 }
637
639
640 protected:
641
644 // Clear external function data.
645 auto deleteFunc = [this](
646 /* data from low level function byte data vector */
647 size_t& curLLFByteDataPos, size_t const& endLLFByteDataPos, char* dataPtr,
648 /* data from low level function info data vector */
649 size_t& curLLFInfoDataPos, size_t const& endLLFInfoDataPos,
650 Config::LowLevelFunctionToken* const tokenPtr,
651 Config::LowLevelFunctionDataSize* const dataSizePtr) {
652 CODI_UNUSED(endLLFByteDataPos);
653
654 while (curLLFInfoDataPos > endLLFInfoDataPos) {
655 callLowLevelFunction<LowLevelFunctionEntryCallKind::Delete>(cast(), false, curLLFByteDataPos, dataPtr,
656 curLLFInfoDataPos, tokenPtr, dataSizePtr);
657 }
658 };
659
660 llfByteData.template evaluateReverse<1>(cast().getPosition(), pos, deleteFunc);
661 }
662
663 public:
664
666
668 CODI_INLINE void resetTo(Position const& pos, bool resetAdjoints = true,
670 EventSystem<Impl>::notifyTapeResetListeners(cast(), pos, EventHints::Reset::To, resetAdjoints);
671
672 if (resetAdjoints) {
673 Impl& impl = cast();
674 impl.clearAdjoints(impl.getPosition(), pos, adjointsManagement);
675 }
676
678
679 llfByteData.resetTo(pos);
680 }
681
682 // clearAdjoints and evaluate are not implemented.
683
685 /*******************************************************************************/
688
691 Impl& impl = cast();
692
693 impl.evaluatePrimal(impl.getZeroPosition(), impl.getPosition());
694 }
695
697 void setPrimal(Identifier const& identifier, Real const& primal) {
698 cast().primal(identifier) = primal;
699 }
700
702 Real const& getPrimal(Identifier const& identifier) const {
703 return cast().primal(identifier);
704 }
705
707
708 protected:
709
710 /*******************************************************************************/
713
715 void init(typename ImplTapeTypes::NestedData* nested) {
716 llfInfoData.setNested(nested);
717 llfByteData.setNested(&llfInfoData);
718 }
719
721 };
722
723 template<typename ImplTapeTypes, typename Impl>
724 std::vector<LowLevelFunctionEntry<Impl, typename ImplTapeTypes::Real, typename ImplTapeTypes::Identifier>>*
726}
#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 codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:432
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_ENABLE_CHECK(option, condition)
Definition macros.hpp:53
#define CODI_ANY
Used in default declarations of expression templates.
Definition macros.hpp:98
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
bool constexpr EnableAssert
Enables asserts in CoDiPack for consistency checking.
Definition config.h:436
size_t constexpr LowLevelFunctionDataSizeMax
Maximum data size of a low level function.
Definition config.h:101
bool constexpr CheckTapeActivity
Makes it possible to ignore certain code parts. If turned of everything will be recorded.
Definition config.h:170
bool constexpr StatementEvents
Enable statement events. Disabled by default.
Definition config.h:319
size_t constexpr LowLevelFunctionTokenMaxSize
Maximum number of low level functions.
Definition config.h:111
Reset
Characterize a tape reset.
Definition eventSystem.hpp:72
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
TapeParameters
Configuration options for a tape.
Definition tapeParameters.hpp:52
LowLevelFunctionEntryCallKind
All possible call types for a low level function entry.
Definition lowLevelFunctionEntry.hpp:51
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.
Definition byteDataView.hpp:51
size_t getPosition()
Get the current data position.
Definition byteDataView.hpp:70
void init(char *pointer, size_t pos, size_t end)
Initialize the object.
Definition byteDataView.hpp:75
Definition chunk.hpp:185
Definition chunk.hpp:283
A chunk stores a contiguous block of data in CoDiPack.
Definition chunk.hpp:76
virtual void writeData(FileIo &handle) const =0
Write data to the FileIo handle.
Implementation of all common tape functionality.
Definition commonTapeImplementation.hpp:130
Gradient const & getGradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
Set the gradient.
Definition commonTapeImplementation.hpp:279
void setPassive()
Stop/interrupt recording of statements.
Definition commonTapeImplementation.hpp:313
CommonTapeImplementation(CommonTapeImplementation &&)=delete
Do not allow move construction. Relevant use cases should be covered by swap.
static 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:516
Real manualPushLhsValue
For storeManual, remember the value assigned to the lhs.
Definition commonTapeImplementation.hpp:157
typename ImplTapeTypes::Real Real
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:136
static std::vector< LowLevelFunctionEntry< Impl, Real, Identifier > > * lowLevelFunctionLookup
Lookup table for low level function.
Definition commonTapeImplementation.hpp:165
std::set< TapeParameters > const & getAvailableParameters() const
See Parameters functions.
Definition commonTapeImplementation.hpp:424
CommonTapeImplementation(CommonTapeImplementation const &)=delete
Do not allow copy construction.
Position getPosition() const
Current position of the tape.
Definition commonTapeImplementation.hpp:629
void setParameter(TapeParameters parameter, size_t value)
See Parameters functions.
Definition commonTapeImplementation.hpp:458
void evaluateForward(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a forward evaluation of a part of the tape. It has to hold start <= end.
Definition commonTapeImplementation.hpp:591
void resetHard()
Delete everything and return to the state after construction, as far as possible.
Definition commonTapeImplementation.hpp:374
void setPrimal(Identifier const &identifier, Real const &primal)
Set primal value.
Definition commonTapeImplementation.hpp:697
void setGradient(Identifier const &identifier, Gradient const &gradient, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Set the gradient.
Definition commonTapeImplementation.hpp:273
size_t manualPushCounter
Count the pushes after storeManual, to identify the last push.
Definition commonTapeImplementation.hpp:160
typename CommonTapeTypes< ImplTapeTypes >::LowLevelFunctionByteData LowLevelFunctionByteData
See CommonTapeTypes.
Definition commonTapeImplementation.hpp:143
void printStatistics(Stream &out=std::cout) const
Default formatting of TapeValues.
Definition commonTapeImplementation.hpp:325
LowLevelFunctionInfoData llfInfoData
Token and size data for low level functions.
Definition commonTapeImplementation.hpp:154
typename ImplTapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:137
void deactivateValue(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition commonTapeImplementation.hpp:619
Position getZeroPosition() const
Initial position of the tape.
Definition commonTapeImplementation.hpp:634
Identifier manualPushLhsIdentifier
For storeManual, remember the identifier assigned to the lhs.
Definition commonTapeImplementation.hpp:158
void deleteData()
See File IO functions.
Definition commonTapeImplementation.hpp:419
void readFromFile(const std::string &filename)
See File IO functions.
Definition commonTapeImplementation.hpp:412
typename CommonTapeTypes< ImplTapeTypes >::LowLevelFunctionInfoData LowLevelFunctionInfoData
See CommonTapeTypes.
Definition commonTapeImplementation.hpp:141
void setActive()
Start/continue recording of statements.
Definition commonTapeImplementation.hpp:307
Real const & getPrimal(Identifier const &identifier) const
Get primal value.
Definition commonTapeImplementation.hpp:702
TemporaryMemory & getTemporaryMemory()
Temporary memory that can be used for dynamic data both during the evaluation and the recording.
Definition commonTapeImplementation.hpp:553
bool hasParameter(TapeParameters parameter) const
See Parameters functions.
Definition commonTapeImplementation.hpp:452
bool isActive() const
Check if the tape is recording.
Definition commonTapeImplementation.hpp:319
TapeValues internalGetTapeValues() const
Create tape values.
CommonTapeImplementation & operator=(CommonTapeImplementation &&)=delete
Do not allow move assignment. Relevant use cases should be covered by swap.
void deleteLowLevelFunctionData(Position const &pos)
Delete all external function data up to pos.
Definition commonTapeImplementation.hpp:643
size_t manualPushGoal
Store the number of expected pushes after a storeManual call.
Definition commonTapeImplementation.hpp:159
Identifier getPassiveIndex() const
Identifier for passive values. Usually 0.
Definition commonTapeImplementation.hpp:603
void init(typename ImplTapeTypes::NestedData *nested)
Initialize the base class.
Definition commonTapeImplementation.hpp:715
void reset(bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the initial state for a fresh recording.
Definition commonTapeImplementation.hpp:354
TemporaryMemory allocator
Allocator for temporary memory.
Definition commonTapeImplementation.hpp:162
LowLevelFunctionByteData NestedData
Shorthand.
Definition commonTapeImplementation.hpp:146
typename LowLevelFunctionByteData::Position NestedPosition
Shorthand.
Definition commonTapeImplementation.hpp:147
bool active
Whether or not the tape is in recording mode.
Definition commonTapeImplementation.hpp:151
std::set< TapeParameters > options
All options.
Definition commonTapeImplementation.hpp:152
void printTableHeader(Stream &out=std::cout) const
Table header output of TapeValues.
Definition commonTapeImplementation.hpp:331
CommonTapeImplementation & operator=(CommonTapeImplementation const &)=delete
Do not allow copy assignment.
Identifier getInvalidIndex() const
Invalid identifier.
Definition commonTapeImplementation.hpp:608
void printTableRow(Stream &out=std::cout) const
Table row output of TapeValues.
Definition commonTapeImplementation.hpp:337
bool isIdentifierActive(Identifier const &index) const
Definition commonTapeImplementation.hpp:613
TapeValues getTapeValues() const
Get current tape values.
Definition commonTapeImplementation.hpp:342
T_ImplTapeTypes ImplTapeTypes
See CommonTapeImplementation.
Definition commonTapeImplementation.hpp:133
T_Impl Impl
See CommonTapeImplementation.
Definition commonTapeImplementation.hpp:134
void evaluate(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a full reverse evaluation of the tape.
Definition commonTapeImplementation.hpp:292
void swap(Impl &other)
Swap all data with an other tape.
Definition commonTapeImplementation.hpp:367
typename CommonTapeTypes< ImplTapeTypes >::Position Position
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:144
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
void incrementManualPushCounter()
Increment the manual push counter. Check against the declared push goal.
Definition commonTapeImplementation.hpp:210
Config::LowLevelFunctionToken registerLowLevelFunction(LowLevelFunctionEntry< Impl, Real, Identifier > const &entry)
Register a low level function on the tape.
Definition commonTapeImplementation.hpp:558
void registerOutput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition commonTapeImplementation.hpp:300
typename ImplTapeTypes::Identifier Identifier
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:138
CommonTapeImplementation()
Constructor.
Definition commonTapeImplementation.hpp:231
void initializeManualPushData(Real const &lhsValue, Identifier const &lhsIndex, size_t size)
Initialize all manual push data, including the counter. Check that a previous manual store is complet...
Definition commonTapeImplementation.hpp:199
void pushExternalFunction(ExternalFunction< Impl > const &extFunc)
Definition commonTapeImplementation.hpp:577
size_t getParameter(TapeParameters parameter) const
See Parameters functions.
Definition commonTapeImplementation.hpp:430
void evaluatePrimal()
Perform a full (forward) reevaluation of the primals in the tape.
Definition commonTapeImplementation.hpp:690
void writeToFile(const std::string &filename)
See File IO functions.
Definition commonTapeImplementation.hpp:405
void internalStoreLowLevelFunction(Config::LowLevelFunctionToken token, size_t size, ByteDataView &dataView)
Called by the implementing tapes to store a low level function. The size is reserved and allocated....
Definition commonTapeImplementation.hpp:493
Declares all types used in the CommonTapeImplementation.
Definition commonTapeImplementation.hpp:85
typename TapeTypes::template Data< Chunk, Nested > Data
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:91
typename TapeTypes::NestedData NestedData
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:93
Data< LowLevelFunctionInfoChunk, NestedData > LowLevelFunctionInfoData
Token and size data for low level functions.
Definition commonTapeImplementation.hpp:98
typename LowLevelFunctionByteData::Position Position
Global position of the tape.
Definition commonTapeImplementation.hpp:105
Data< LowLevelFunctionByteChunk, LowLevelFunctionInfoData > LowLevelFunctionByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:103
T_TapeTypes TapeTypes
See CommonTapeTypes.
Definition commonTapeImplementation.hpp:88
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
static void notifyTapeRegisterOutputListeners(Tape &tape, Real &value, Identifier &identifier)
Invoke callbacks for TapeRegisterOutput events.
Definition eventSystem.hpp:453
static void notifyTapeResetListeners(Tape &tape, Position const &position, EventHints::Reset kind, bool clearAdjoints)
Invoke callbacks for TapeReset events.
Definition eventSystem.hpp:521
static void notifyTapeStopRecordingListeners(Tape &tape)
Invoke callbacks for TapeStopRecording events.
Definition eventSystem.hpp:396
static void notifyTapeStartRecordingListeners(Tape &tape)
Invoke callbacks for TapeStartRecording events.
Definition eventSystem.hpp:370
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:59
Low level function entry implementation for external functions.
Definition externalFunction.hpp:178
static void store(Tape &tape, Config::LowLevelFunctionToken token, ExtFunc const &extFunc)
Store an external function on the tape.
Definition externalFunction.hpp:212
User-defined evaluation functions for the taping process.
Definition externalFunction.hpp:102
Helper structure for writing binary data.
Definition fileIo.hpp:84
Full tape interface that supports all features of CoDiPack.
Definition fullTapeInterface.hpp:82
Gradient & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reference access to gradient.
Indices enable the mapping of primal values to their adjoint counterparts.
Definition indexManagerInterface.hpp:78
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
Real const & getValue() const
Get the primal value of this lvalue.
Definition lhsExpressionInterface.hpp:125
Impl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:99
Low level function entry on the tape. See LowLevelFunctionTapeInterface for details.
Definition lowLevelFunctionEntry.hpp:67
Real & primal(Identifier const &identifier)
Writable reference to primal value.
Interface for the definition of tape types.
Definition commonTapeImplementation.hpp:63
int Real
Primal computation type, e.g. double.
Definition commonTapeImplementation.hpp:66
int Gradient
Gradient computation type, e.g. double or Direction.
Definition commonTapeImplementation.hpp:67
int Identifier
Identifier for the internal management, e.g. int.
Definition commonTapeImplementation.hpp:68
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:73
void addSection(std::string const &name)
Add section. All further entries are added under this section.
Definition tapeValues.hpp:145
Allocator for temporary used memory.
Definition temporaryMemory.hpp:54