CoDiPack  3.1.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-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 <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 "io/tapeReaderWriterInterface.hpp"
51#include "misc/externalFunction.hpp"
52#include "misc/lowLevelFunctionEntry.hpp"
53#include "misc/vectorAccessInterface.hpp"
54
56namespace codi {
57
65 public:
66
67 using Real = CODI_ANY;
71
74 template<typename Chunk, typename Nested>
76
79 };
80
86 template<typename T_TapeTypes>
88 public:
89
90 using TapeTypes = CODI_DD(T_TapeTypes, TapeTypesInterface);
91
92 template<typename Chunk, typename Nested>
93 using Data = typename TapeTypes::template Data<Chunk, Nested>;
94
95 using NestedData = typename TapeTypes::NestedData;
96
101
106
107 using Position = typename LowLevelFunctionByteData::Position;
108 };
109
128 template<typename T_ImplTapeTypes, typename T_Impl>
130 : public FullTapeInterface<
131 typename T_ImplTapeTypes::Real, typename T_ImplTapeTypes::Gradient, typename T_ImplTapeTypes::Identifier,
132 typename CommonTapeTypes<T_ImplTapeTypes>::Position, typename T_ImplTapeTypes::ActiveTypeTapeData> {
133 public:
134
135 using ImplTapeTypes = CODI_DD(T_ImplTapeTypes, TapeTypesInterface);
137
138 using Real = typename ImplTapeTypes::Real;
139 using Gradient = typename ImplTapeTypes::Gradient;
140 using Identifier = typename ImplTapeTypes::Identifier;
141 using ActiveTypeTapeData = typename ImplTapeTypes::ActiveTypeTapeData;
142
148
150 using NestedPosition = typename LowLevelFunctionByteData::Position;
151
152 protected:
153
154 bool active;
155 std::set<TapeParameters> options;
156
159
164
166
168 static std::vector<LowLevelFunctionEntry<Impl, Real, Identifier>>* lowLevelFunctionLookup;
169
170 private:
171
173 static Config::LowLevelFunctionToken constexpr EXTERNAL_FUNCTION_TOKEN = 0;
174
175 CODI_INLINE Impl const& cast() const {
176 return static_cast<Impl const&>(*this);
177 }
178
179 CODI_INLINE Impl& cast() {
180 return static_cast<Impl&>(*this);
181 }
182
183 CODI_INLINE void resetInternal(bool resetAdjoints, AdjointsManagement adjointsManagement,
184 EventHints::Reset kind) {
185 EventSystem<Impl>::notifyTapeResetListeners(cast(), this->getZeroPosition(), kind, resetAdjoints);
186
187 if (resetAdjoints) {
188 cast().clearAdjoints(adjointsManagement);
189 }
190
192
193 llfByteData.reset();
194
195 // Requires extra reset since the default vector implementation forwards to resetTo
196 cast().indexManager.get().reset();
197 }
198
199 protected:
200
202 CODI_INLINE void initializeManualPushData(Real const& lhsValue, Identifier const& lhsIndex, size_t size) {
203 codiAssert(this->manualPushGoal == this->manualPushCounter);
205 this->manualPushLhsValue = lhsValue;
206 this->manualPushLhsIdentifier = lhsIndex;
207 this->manualPushCounter = 0;
208 this->manualPushGoal = size;
209 }
210 }
211
214 codiAssert(this->manualPushCounter < this->manualPushGoal);
215
217 this->manualPushCounter += 1;
218 }
219 }
220
221 protected:
222
223 /*******************************************************************************/
226
228
230
231 public:
232
235 : active(false),
236 options(),
237 llfInfoData(Config::SmallChunkSize),
238 llfByteData(Config::ByteDataChunkSize),
243 allocator() {
246
247 if (nullptr == lowLevelFunctionLookup) {
248 lowLevelFunctionLookup = new std::vector<LowLevelFunctionEntry<Impl, Real, Identifier>>();
249
250 // Add external function token. So EXTERNAL_FUNCTION_TOKEN is always zero.
253 if (token != EXTERNAL_FUNCTION_TOKEN) {
254 CODI_EXCEPTION("External function token is not zero.");
255 }
256 }
257 }
258
261
264
267
270
271 /*******************************************************************************/
274
276 void setGradient(Identifier const& identifier, Gradient const& gradient,
278 cast().gradient(identifier, adjointsManagement) = gradient;
279 }
280
282 Gradient const& getGradient(Identifier const& identifier,
283 AdjointsManagement adjointsManagement = AdjointsManagement::Automatic) const {
284 return cast().gradient(identifier, adjointsManagement);
285 }
286
287 // Gradient functions are not implemented.
288
290 /*******************************************************************************/
293
296 Impl& impl = cast();
297
298 impl.evaluate(impl.getPosition(), impl.getZeroPosition(), adjointsManagement);
299 }
300
302 template<typename Lhs>
304 cast().template store<Lhs, Lhs>(value, static_cast<ExpressionInterface<Real, Lhs> const&>(value));
306 value.cast().getIdentifier());
307 }
308
314
320
322 bool isActive() const {
323 return active;
324 }
325
327 template<typename Stream = std::ostream>
328 void printStatistics(Stream& out = std::cout) const {
329 cast().getTapeValues().formatDefault(out);
330 }
331
333 template<typename Stream = std::ostream>
334 void printTableHeader(Stream& out = std::cout) const {
335 cast().getTapeValues().formatHeader(out);
336 }
337
339 template<typename Stream = std::ostream>
340 void printTableRow(Stream& out = std::cout) const {
341 cast().getTapeValues().formatRow(out);
342 }
343
346 TapeValues values = cast().internalGetTapeValues();
347
348 values.addSection("Low level function info data entries");
349 llfInfoData.addToTapeValues(values);
350 values.addSection("Low level function byte data entries");
351 llfByteData.addToTapeValues(values);
352
353 return values;
354 }
355
357 CODI_INLINE void reset(bool resetAdjoints = true,
359 resetInternal(resetAdjoints, adjointsManagement, EventHints::Reset::Full);
360 }
361
362 // clearAdjoints and reset(Position) are not implemented.
363
365 /*******************************************************************************/
368
370 template<typename Callbacks>
371 void iterateForward(Callbacks&& callbacks) {
372 Impl& impl = cast();
373
374 impl.iterateForward(std::forward<Callbacks>(callbacks), impl.getZeroPosition(), impl.getPosition());
375 }
376
378 template<typename Callbacks>
379 void iterateReverse(Callbacks&& callbacks) {
380 Impl& impl = cast();
381
382 impl.iterateReverse(std::forward<Callbacks>(callbacks), impl.getPosition(), impl.getZeroPosition());
383 }
384
385 // iterateForward(callbacks, start, end) and iterateForward(callbacks, start, end) are not implemented.
386
388 /*******************************************************************************/
391
393 void swap(Impl& other) {
394 std::swap(active, other.active);
395
396 llfByteData.swap(other.llfByteData);
397 }
398
400 void resetHard() {
401 Impl& impl = cast();
402
403 // First perform a regular reset.
404 resetInternal(false, AdjointsManagement::Automatic, EventHints::Reset::Hard);
405
406 // Then perform the hard resets.
407 impl.deleteAdjointVector();
408
409 llfByteData.resetHard();
410 }
411
413
414 private:
415 static void writeFunction(const ChunkBase* chunk, FileIo& handle) {
416 chunk->writeData(handle);
417 }
418
419 static void readFunction(ChunkBase* chunk, FileIo& handle) {
420 chunk->readData(handle);
421 }
422
423 static void deleteFunction(ChunkBase* chunk) {
424 chunk->deleteData();
425 }
426
427 public:
428
431 void writeToFile(const std::string& filename) {
432 FileIo io(filename, true);
433
434 llfByteData.forEachChunk(writeFunction, true, io);
435 }
436
438 void readFromFile(const std::string& filename) {
439 FileIo io(filename, false);
440
441 llfByteData.forEachChunk(readFunction, true, io);
442 }
443
445 void deleteData() {
446 llfByteData.forEachChunk(deleteFunction, true);
447 }
448
450 std::set<TapeParameters> const& getAvailableParameters() const {
451 return options;
452 }
453
456 size_t getParameter(TapeParameters parameter) const {
457 switch (parameter) {
459 return llfByteData.getDataSize();
460 break;
462 return llfInfoData.getDataSize();
463 break;
465 CODI_WARNING(
466 "Tape parameter 'ExternalFunctionsSize' no longer supported. Use 'LLFInfoDataSize' and "
467 "'LLFByteDataSize' instead.");
468 return 0;
469 break;
470 default:
471 CODI_EXCEPTION("Tried to get undefined parameter for tape.");
472 return 0;
473 break;
474 }
475 }
476
478 bool hasParameter(TapeParameters parameter) const {
479 return options.cend() != options.find(parameter);
480 }
481
484 void setParameter(TapeParameters parameter, size_t value) {
485 switch (parameter) {
487 llfByteData.resize(value);
488 break;
490 llfInfoData.resize(value);
491 break;
493 CODI_WARNING(
494 "Tape parameter 'ExternalFunctionsSize' is no longer supported. Use 'LLFInfoDataSize' and "
495 "'LLFByteDataSize' instead.");
496 break;
497 default:
498 CODI_EXCEPTION("Tried to set undefined parameter for tape.");
499 break;
500 }
501 }
502
503 // createVectorAccess is not implemented.
504 // createVectorAccessCustomAdjoints is not implemented.
505 // resizeAdjointVector is not implemented.
506 // deleteAdjointVector is not implemented.
507 // beginUseAdjointVector is not implemented.
508 // endUseAdjointVector is not implemented.
509
511 /*******************************************************************************/
514
515 protected:
516
520 ByteDataView& dataView) {
521 codiAssert((size_t)token < lowLevelFunctionLookup->size());
523 CODI_EXCEPTION(
524 "Requested size for low level function is to big. Increase "
525 "codi::Config::LowLevelFunctionDataSize or perform a dynamic memory allocation.");
526 }
527
528 llfInfoData.reserveItems(1);
529 llfByteData.reserveItems(size);
530
531 llfInfoData.pushData(token, size);
532
533 char* dataPointer = nullptr;
534 llfByteData.getDataPointers(dataPointer);
535 dataView.init(dataPointer, 0, size);
536 llfByteData.addDataSize(size);
537 }
538
541 bool forward,
542 /* data from low level function byte data vector */
543 size_t& curLLFByteDataPos, char* dataPtr,
544 /* data from low level function info data vector */
545 size_t& curLLFTInfoDataPos, Config::LowLevelFunctionToken* const tokenPtr,
546 Config::LowLevelFunctionDataSize* const dataSizePtr, ByteDataView& dataView,
548 if (!forward) {
549 curLLFTInfoDataPos -= 1;
550 curLLFByteDataPos -= dataSizePtr[curLLFTInfoDataPos];
551 }
552 size_t endPos = curLLFByteDataPos + dataSizePtr[curLLFTInfoDataPos];
553 dataView.init(dataPtr, curLLFByteDataPos, endPos);
554
555 Config::LowLevelFunctionToken id = tokenPtr[curLLFTInfoDataPos];
556 func = &((*lowLevelFunctionLookup)[id]);
557
558 if (forward) {
559 curLLFByteDataPos += dataSizePtr[curLLFTInfoDataPos];
560 curLLFTInfoDataPos += 1;
561 }
562
563 return id;
564 }
565
568 template<LowLevelFunctionEntryCallKind callType, typename... Args>
569 CODI_INLINE static void callLowLevelFunction(Impl& impl, bool forward,
570 /* data from low level function byte data vector */
571 size_t& curLLFByteDataPos, char* dataPtr,
572 /* data from low level function info data vector */
573 size_t& curLLFTInfoDataPos,
574 Config::LowLevelFunctionToken* const tokenPtr,
575 Config::LowLevelFunctionDataSize* const dataSizePtr,
576 Args&&... args) {
577 ByteDataView dataView = {};
580 forward, curLLFByteDataPos, dataPtr, curLLFTInfoDataPos, tokenPtr, dataSizePtr, dataView, func);
581 if (func->template has<callType>()) CODI_Likely {
582 func->template call<callType>(&impl, dataView, std::forward<Args>(args)...);
583
584 codiAssert(dataView.getEnd() == dataView.getPosition());
585 } else CODI_Unlikely if (LowLevelFunctionEntryCallKind::Delete == callType) {
586 // No delete registered. Data is skiped by the curLLFByteDataPos update.
587 } else {
588 CODI_EXCEPTION("Requested call is not supported for low level function with token '%d'.", (int)id);
589 }
590 }
591
593 CODI_INLINE static void skipLowLevelFunction(bool forward,
594 /* data from low level function byte data vector */
595 size_t& curLLFByteDataPos, char* dataPtr,
596 /* data from low level function info data vector */
597 size_t& curLLFTInfoDataPos,
598 Config::LowLevelFunctionToken* const tokenPtr,
599 Config::LowLevelFunctionDataSize* const dataSizePtr) {
600 CODI_UNUSED(dataPtr, tokenPtr);
601
602 if (forward) {
603 curLLFByteDataPos += dataSizePtr[curLLFTInfoDataPos];
604 curLLFTInfoDataPos += 1;
605 } else {
606 curLLFTInfoDataPos -= 1;
607 curLLFByteDataPos -= dataSizePtr[curLLFTInfoDataPos];
608 }
609 }
610
611 public:
612
617
629
630 // pushLowLevelFunction is not implemented.
631
633 /*******************************************************************************/
636
640 ExternalFunctionLowLevelEntryMapper<Impl, Real, Identifier>::store(cast(), EXTERNAL_FUNCTION_TOKEN, extFunc);
641 }
642 }
643
644 // registerExternalFunctionOutput is not implemented.
645
647 /*******************************************************************************/
650
653 Impl& impl = cast();
654
655 impl.evaluateForward(impl.getZeroPosition(), impl.getPosition(), adjointsManagement);
656 }
657
659 /*******************************************************************************/
662
664 template<typename Type>
665 void writeTape(std::unique_ptr<TapeWriterInterface<Type>> writer) {
666 Impl& impl = cast();
667 impl.writeTape(writer.get(), impl.getZeroPosition(), impl.getPosition());
668 }
669
672 template<typename Type>
673 void writeTape(std::unique_ptr<TapeWriterInterface<Type>> writer, Position const& start, Position const& end) {
674 Impl& impl = cast();
675 impl.writeTape(writer.get(), start, end);
676 }
677
679 template<typename Type>
681 Impl& impl = cast();
682 impl.writeTape(&writeToFileRef, impl.getZeroPosition(), impl.getPosition());
683 }
684
687 template<typename Type>
688 void writeTape(codi::TapeWriterInterface<Type>& writeToFileRef, Position const& start, Position const& end) {
689 Impl& impl = cast();
690 impl.writeTape(&writeToFileRef, start, end);
691 }
692
694 /*******************************************************************************/
697
702
707
709 bool isIdentifierActive(Identifier const& index) const {
710 return index != cast().getPassiveIndex();
711 }
712
714 template<typename Lhs>
718
721 Impl& impl = cast();
722 return impl.getIndexManager().getIndex(data);
723 }
724
727 Impl& impl = cast();
728 return impl.getIndexManager().getIndex(data);
729 }
730
732 /*******************************************************************************/
735
738 return llfByteData.getPosition();
739 }
740
743 return llfByteData.getZeroPosition();
744 }
745
747
748 protected:
749
752 // Clear external function data.
753 auto deleteFunc = [this](
754 /* data from low level function byte data vector */
755 size_t& curLLFByteDataPos, size_t const& endLLFByteDataPos, char* dataPtr,
756 /* data from low level function info data vector */
757 size_t& curLLFInfoDataPos, size_t const& endLLFInfoDataPos,
758 Config::LowLevelFunctionToken* const tokenPtr,
759 Config::LowLevelFunctionDataSize* const dataSizePtr) {
760 CODI_UNUSED(endLLFByteDataPos);
761
762 while (curLLFInfoDataPos > endLLFInfoDataPos) {
763 callLowLevelFunction<LowLevelFunctionEntryCallKind::Delete>(cast(), false, curLLFByteDataPos, dataPtr,
764 curLLFInfoDataPos, tokenPtr, dataSizePtr);
765 }
766 };
767
768 llfByteData.template evaluateReverse<1>(cast().getPosition(), pos, deleteFunc);
769 }
770
771 public:
772
774
776 CODI_INLINE void resetTo(Position const& pos, bool resetAdjoints = true,
778 EventSystem<Impl>::notifyTapeResetListeners(cast(), pos, EventHints::Reset::To, resetAdjoints);
779
780 if (resetAdjoints) {
781 Impl& impl = cast();
782 impl.clearAdjoints(impl.getPosition(), pos, adjointsManagement);
783 }
784
786
787 llfByteData.resetTo(pos);
788 }
789
790 // clearAdjoints and evaluate are not implemented.
791
793 /*******************************************************************************/
796
799 Impl& impl = cast();
800
801 impl.evaluatePrimal(impl.getZeroPosition(), impl.getPosition());
802 }
803
805 void setPrimal(Identifier const& identifier, Real const& primal) {
806 cast().primal(identifier) = primal;
807 }
808
810 Real const& getPrimal(Identifier const& identifier) const {
811 return cast().primal(identifier);
812 }
813
815
816 protected:
817
818 /*******************************************************************************/
821
823 void init(typename ImplTapeTypes::NestedData* nested) {
824 llfInfoData.setNested(nested);
825 llfByteData.setNested(&llfInfoData);
826 }
827
829 };
830
832 template<typename ImplTapeTypes, typename Impl>
833 std::vector<LowLevelFunctionEntry<Impl, typename ImplTapeTypes::Real, typename ImplTapeTypes::Identifier>>*
835}
#define CODI_Unlikely
Declare unlikely evaluation of an execution path.
Definition config.h:408
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:469
#define CODI_Likely
Declare likely evaluation of an execution path.
Definition config.h:406
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:441
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:97
#define CODI_ENABLE_CHECK(option, condition)
Definition macros.hpp:62
#define CODI_ANY
Used in default declarations of expression templates.
Definition macros.hpp:101
Configuration options for CoDiPack.
Definition config.h:65
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:445
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:328
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:97
TapeParameters
Configuration options for a tape.
Definition tapeParameters.hpp:52
@ LLFByteDataSize
Definition tapeParameters.hpp:70
@ LLFInfoDataSize
Definition tapeParameters.hpp:68
@ ExternalFunctionsSize
Definition tapeParameters.hpp:57
LowLevelFunctionEntryCallKind
All possible call types for a low level function entry.
Definition lowLevelFunctionEntry.hpp:51
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
Definition byteDataView.hpp:51
inlinesize_t getPosition()
Get the current data position.
Definition byteDataView.hpp:77
inlinesize_t getEnd()
Get the end data position.
Definition byteDataView.hpp:72
inlinevoid init(char *pointer, size_t pos, size_t end)
Initialize the object.
Definition byteDataView.hpp:87
Definition chunk.hpp:185
Definition chunk.hpp:283
A chunk stores a contiguous block of data in CoDiPack.
Definition chunk.hpp:76
inlinevirtual void writeData(FileIo &handle) const =0
Write data to the FileIo handle.
Gradient const & getGradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic) const
Set the gradient.
Definition commonTapeImplementation.hpp:282
inlinevoid 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:519
void iterateForward(Callbacks &&callbacks)
Iterate over the tape in a generalized fashion. callbacks needs to implement codi::CallbacksInterface...
Definition commonTapeImplementation.hpp:371
void setPassive()
Stop/interrupt recording of statements.
Definition commonTapeImplementation.hpp:316
inlineIdentifier & getIdentifier(ActiveTypeTapeData &data)
Definition commonTapeImplementation.hpp:726
CommonTapeImplementation(CommonTapeImplementation &&)=delete
Do not allow move construction. Relevant use cases should be covered by swap.
inlinevoid 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:202
Real manualPushLhsValue
Definition commonTapeImplementation.hpp:160
typename ImplTapeTypes::Real Real
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:138
std::set< TapeParameters > const & getAvailableParameters() const
See Parameters functions.
Definition commonTapeImplementation.hpp:450
CommonTapeImplementation(CommonTapeImplementation const &)=delete
Do not allow copy construction.
Position getPosition() const
Current position of the tape.
Definition commonTapeImplementation.hpp:737
void writeTape(codi::TapeWriterInterface< Type > &writeToFileRef, Position const &start, Position const &end)
For partial-tape writers using a manually generated writers.
Definition commonTapeImplementation.hpp:688
void setParameter(TapeParameters parameter, size_t value)
See Parameters functions.
Definition commonTapeImplementation.hpp:484
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:652
void resetHard()
Delete everything and return to the state after construction, as far as possible.
Definition commonTapeImplementation.hpp:400
void setPrimal(Identifier const &identifier, Real const &primal)
Set primal value.
Definition commonTapeImplementation.hpp:805
void setGradient(Identifier const &identifier, Gradient const &gradient, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Set the gradient.
Definition commonTapeImplementation.hpp:276
size_t manualPushCounter
Definition commonTapeImplementation.hpp:163
typename CommonTapeTypes< ImplTapeTypes >::LowLevelFunctionByteData LowLevelFunctionByteData
See CommonTapeTypes.
Definition commonTapeImplementation.hpp:146
void printStatistics(Stream &out=std::cout) const
Default formatting of TapeValues.
Definition commonTapeImplementation.hpp:328
LowLevelFunctionInfoData llfInfoData
Definition commonTapeImplementation.hpp:157
inlinevoid resetTo(Position const &pos, bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the provided position.
Definition commonTapeImplementation.hpp:776
typename ImplTapeTypes::Gradient Gradient
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:139
void deactivateValue(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition commonTapeImplementation.hpp:715
Position getZeroPosition() const
Initial position of the tape.
Definition commonTapeImplementation.hpp:742
Identifier manualPushLhsIdentifier
Definition commonTapeImplementation.hpp:161
void deleteData()
See File IO functions.
Definition commonTapeImplementation.hpp:445
void readFromFile(const std::string &filename)
See File IO functions.
Definition commonTapeImplementation.hpp:438
typename CommonTapeTypes< ImplTapeTypes >::LowLevelFunctionInfoData LowLevelFunctionInfoData
See CommonTapeTypes.
Definition commonTapeImplementation.hpp:144
void setActive()
Start/continue recording of statements.
Definition commonTapeImplementation.hpp:310
Real const & getPrimal(Identifier const &identifier) const
Get primal value.
Definition commonTapeImplementation.hpp:810
bool hasParameter(TapeParameters parameter) const
See Parameters functions.
Definition commonTapeImplementation.hpp:478
bool isActive() const
Check if the tape is recording.
Definition commonTapeImplementation.hpp:322
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:751
inlinestatic void skipLowLevelFunction(bool forward, size_t &curLLFByteDataPos, char *dataPtr, size_t &curLLFTInfoDataPos, Config::LowLevelFunctionToken *const tokenPtr, Config::LowLevelFunctionDataSize *const dataSizePtr)
Skip the data for a low level function.
Definition commonTapeImplementation.hpp:593
size_t manualPushGoal
Definition commonTapeImplementation.hpp:162
Identifier getPassiveIndex() const
Identifier for passive values. Usually 0.
Definition commonTapeImplementation.hpp:699
inlineConfig::LowLevelFunctionToken registerLowLevelFunction(LowLevelFunctionEntry< Impl, Real, Identifier > const &entry)
Register a low level function on the tape.
Definition commonTapeImplementation.hpp:619
void init(typename ImplTapeTypes::NestedData *nested)
Initialize the base class.
Definition commonTapeImplementation.hpp:823
TemporaryMemory allocator
Definition commonTapeImplementation.hpp:165
static std::vector< LowLevelFunctionEntry< Impl, Real, Identifier > > * lowLevelFunctionLookup
Definition commonTapeImplementation.hpp:168
LowLevelFunctionByteData NestedData
Shorthand.
Definition commonTapeImplementation.hpp:149
typename LowLevelFunctionByteData::Position NestedPosition
Shorthand.
Definition commonTapeImplementation.hpp:150
bool active
Definition commonTapeImplementation.hpp:154
std::set< TapeParameters > options
Definition commonTapeImplementation.hpp:155
inlinevoid incrementManualPushCounter()
Increment the manual push counter. Check against the declared push goal.
Definition commonTapeImplementation.hpp:213
void printTableHeader(Stream &out=std::cout) const
Table header output of TapeValues.
Definition commonTapeImplementation.hpp:334
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
CommonTapeImplementation & operator=(CommonTapeImplementation const &)=delete
Do not allow copy assignment.
Identifier getInvalidIndex() const
Invalid identifier.
Definition commonTapeImplementation.hpp:704
void printTableRow(Stream &out=std::cout) const
Table row output of TapeValues.
Definition commonTapeImplementation.hpp:340
inlineTemporaryMemory & getTemporaryMemory()
Temporary memory that can be used for dynamic data both during the evaluation and the recording.
Definition commonTapeImplementation.hpp:614
bool isIdentifierActive(Identifier const &index) const
Definition commonTapeImplementation.hpp:709
TapeValues getTapeValues() const
Get current tape values.
Definition commonTapeImplementation.hpp:345
T_ImplTapeTypes ImplTapeTypes
See CommonTapeImplementation.
Definition commonTapeImplementation.hpp:135
void writeTape(std::unique_ptr< TapeWriterInterface< Type > > writer)
For full-tape writers using a smart pointer.
Definition commonTapeImplementation.hpp:665
void writeTape(codi::TapeWriterInterface< Type > &writeToFileRef)
For full-tape writers using a manually generated writers.
Definition commonTapeImplementation.hpp:680
T_Impl Impl
See CommonTapeImplementation.
Definition commonTapeImplementation.hpp:136
void evaluate(AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Perform a full reverse evaluation of the tape.
Definition commonTapeImplementation.hpp:295
void swap(Impl &other)
Swap all data with an other tape.
Definition commonTapeImplementation.hpp:393
inlinevoid reset(bool resetAdjoints=true, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
Reset the tape to the initial state for a fresh recording.
Definition commonTapeImplementation.hpp:357
typename CommonTapeTypes< ImplTapeTypes >::Position Position
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:147
void writeTape(std::unique_ptr< TapeWriterInterface< Type > > writer, Position const &start, Position const &end)
For partial-tape writers using a smart pointer.
Definition commonTapeImplementation.hpp:673
LowLevelFunctionByteData llfByteData
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 registerOutput(LhsExpressionInterface< Real, Gradient, Impl, Lhs > &value)
Definition commonTapeImplementation.hpp:303
inlineIdentifier const & getIdentifier(ActiveTypeTapeData const &data)
Definition commonTapeImplementation.hpp:720
typename ImplTapeTypes::Identifier Identifier
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:140
CommonTapeImplementation()
Constructor.
Definition commonTapeImplementation.hpp:234
void pushExternalFunction(ExternalFunction< Impl > const &extFunc)
Definition commonTapeImplementation.hpp:638
size_t getParameter(TapeParameters parameter) const
See Parameters functions.
Definition commonTapeImplementation.hpp:456
void evaluatePrimal()
Perform a full (forward) reevaluation of the primals in the tape.
Definition commonTapeImplementation.hpp:798
void writeToFile(const std::string &filename)
See File IO functions.
Definition commonTapeImplementation.hpp:431
void iterateReverse(Callbacks &&callbacks)
Iterate over the tape in a generalized fashion. callbacks needs to implement codi::CallbacksInterface...
Definition commonTapeImplementation.hpp:379
typename ImplTapeTypes::ActiveTypeTapeData ActiveTypeTapeData
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:141
Declares all types used in the CommonTapeImplementation.
Definition commonTapeImplementation.hpp:87
typename TapeTypes::template Data< Chunk, Nested > Data
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:93
typename TapeTypes::NestedData NestedData
See TapeTypesInterface.
Definition commonTapeImplementation.hpp:95
Data< LowLevelFunctionInfoChunk, NestedData > LowLevelFunctionInfoData
Token and size data for low level functions.
Definition commonTapeImplementation.hpp:100
Chunk1< char > LowLevelFunctionByteChunk
Byte data chunk.
Definition commonTapeImplementation.hpp:103
typename LowLevelFunctionByteData::Position Position
Global position of the tape.
Definition commonTapeImplementation.hpp:107
Data< LowLevelFunctionByteChunk, LowLevelFunctionInfoData > LowLevelFunctionByteData
Byte data for low level functions.
Definition commonTapeImplementation.hpp:105
T_TapeTypes TapeTypes
See CommonTapeTypes.
Definition commonTapeImplementation.hpp:90
Chunk2< Config::LowLevelFunctionToken, Config::LowLevelFunctionDataSize > LowLevelFunctionInfoChunk
Token and size data chunk.
Definition commonTapeImplementation.hpp:98
Data stream interface for tape data. Encapsulates data that is written e.g. for each statement or arg...
Definition dataInterface.hpp:149
static inlinevoid notifyTapeStartRecordingListeners(Tape &tape)
Invoke callbacks for TapeStartRecording events.
Definition eventSystem.hpp:370
static inlinevoid notifyTapeResetListeners(Tape &tape, Position const &position, EventHints::Reset kind, bool clearAdjoints)
Invoke callbacks for TapeReset events.
Definition eventSystem.hpp:521
static inlinevoid notifyTapeStopRecordingListeners(Tape &tape)
Invoke callbacks for TapeStopRecording events.
Definition eventSystem.hpp:396
static inlinevoid notifyTapeRegisterOutputListeners(Tape &tape, Real &value, Identifier &identifier)
Invoke callbacks for TapeRegisterOutput events.
Definition eventSystem.hpp:453
Base class for all CoDiPack expressions.
Definition expressionInterface.hpp:60
inlinestatic LowLevelFunctionEntry< Tape, Real, Identifier > create()
Create the function entry for the tape registration.
Definition externalFunction.hpp:285
inlinestatic void store(Tape &tape, Config::LowLevelFunctionToken token, ExtFunc const &extFunc)
Store an external function on the tape.
Definition externalFunction.hpp:277
User-defined evaluation functions for the taping process.
Definition externalFunction.hpp:118
Helper structure for writing binary data.
Definition fileIo.hpp:84
Full tape interface that supports all features of CoDiPack.
Definition fullTapeInterface.hpp:89
Gradient & gradient(Identifier const &identifier, AdjointsManagement adjointsManagement=AdjointsManagement::Automatic)
static Index constexpr InactiveIndex
Default inactive index for all index managers.
Definition indexManagerInterface.hpp:87
static Index constexpr InvalidIndex
Default invalid index for all index mangers (max value for unsigned types).
Definition indexManagerInterface.hpp:88
Base class for all CoDiPack lvalue expression.
Definition lhsExpressionInterface.hpp:63
inlineReal const & getValue() const
Get the primal value of this lvalue.
Definition lhsExpressionInterface.hpp:129
inlineImpl & cast()
Cast to the implementation.
Definition lhsExpressionInterface.hpp:103
Low level function entry on the tape. See LowLevelFunctionTapeInterface for details.
Definition lowLevelFunctionEntry.hpp:69
Interface for the definition of tape types.
Definition commonTapeImplementation.hpp:64
DataInterface< Nested > Data
Definition commonTapeImplementation.hpp:75
DataInterface<> NestedData
Definition commonTapeImplementation.hpp:77
int Gradient
Gradient computation type, e.g. double or Direction.
Definition commonTapeImplementation.hpp:68
int Real
Primal computation type, e.g. double.
Definition commonTapeImplementation.hpp:67
int Identifier
Identifier for the internal management, e.g. int.
Definition commonTapeImplementation.hpp:69
int ActiveTypeTapeData
Tape data stored in each active type. Usually the identifier data.
Definition commonTapeImplementation.hpp:70
Tape information that can be printed in a pretty print format or a table format.
Definition tapeValues.hpp:75
void addSection(std::string const &name)
Add section. All further entries are added under this section.
Definition tapeValues.hpp:158
The interface used by all the tape writers. The tape writers are used to generate text,...
Definition tapeReaderWriterInterface.hpp:129
Allocator for temporary used memory.
Definition temporaryMemory.hpp:54