CoDiPack  3.0.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
tapeReaderWriterInterface.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2025 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 "../../config.h"
38#include "../../expressions/lhsExpressionInterface.hpp"
39#include "../../traits/tapeTraits.hpp"
40#include "../data/position.hpp"
41
43namespace codi {
44 using EvalHandleKey = size_t;
45
47 enum class FileType {
48 Text,
49 Binary,
50 Graph,
51 Math,
52 Invalid
53 };
54
59 enum class IdentifierType {
60 Input,
61 Output,
62 Temp
63 };
64
77
128 template<typename T_Type>
130 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
131 using Tape = typename Type::Tape;
132
133 using Identifier = typename Type::Identifier;
134 using Real = typename Type::Real;
135
136 using EvalHandle = typename Tape::EvalHandle;
137
138 virtual ~TapeWriterInterface() {};
139
144 virtual void start(Tape& tape) {
145 CODI_UNUSED(tape);
146 }
147
152 virtual void writeStatement(Identifier const& curLhsIdentifier, size_t& curJacobianPos,
153 Real const* const rhsJacobians, Identifier const* const rhsIdentifiers,
154 Config::ArgumentSize const& nJacobians) {
155 CODI_UNUSED(curLhsIdentifier, curJacobianPos, rhsJacobians, rhsIdentifiers, nJacobians);
156 }
157
162 virtual void writeStatement(WriteInfo const& info, Identifier const* lhsIdentifiers, Real const* lhsPrimalValues,
163 Config::ArgumentSize const& nPassiveValues, Identifier const* const rhsIdentifiers,
164 Real const* const passiveValues, Real const* const constantValues,
165 EvalHandle stmtEvalHandle) {
166 CODI_UNUSED(info, lhsIdentifiers, lhsPrimalValues, nPassiveValues, rhsIdentifiers, passiveValues,
167 constantValues, stmtEvalHandle);
168 }
169
171 virtual void writeLowLevelFunction(size_t& curLLFByteDataPos, char* dataPtr, size_t& curLLFInfoDataPos,
172 Config::LowLevelFunctionToken* const tokenPtr,
173 Config::LowLevelFunctionDataSize* const dataSizePtr) {
174 CODI_UNUSED(curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr);
175 }
176
178 virtual void finish() {}
179 };
180
251 template<typename T_Type>
253 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
254 using Tape = typename Type::Tape;
255 using Identifier = typename Type::Identifier;
256 using Real = typename Type::Real;
257
259
261 virtual void readFile(std::string const& name) {
262 CODI_UNUSED(name);
263 }
264
265 virtual Tape& getTape() = 0;
266
267 virtual std::vector<Identifier> const& getInputs() const& = 0;
268
269 virtual std::vector<Identifier> const& getOutputs() const& = 0;
271 };
272}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:96
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
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94
FileType
Used to select the type of writer that should be generated.
Definition tapeReaderWriterInterface.hpp:47
inlinevoid CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:54
size_t EvalHandleKey
Key for the evalHandle lookup.
Definition tapeReaderWriterInterface.hpp:44
IdentifierType
Used by the math statements to record the type of each identifier. This information is then used in t...
Definition tapeReaderWriterInterface.hpp:59
The interface is used by all the tape readers. The tape readers are used to restore a tape from eithe...
Definition tapeReaderWriterInterface.hpp:252
virtual std::vector< Identifier > const & getOutputs() const &=0
typename Type::Tape Tape
The tape type that is to be restored.
Definition tapeReaderWriterInterface.hpp:254
virtual ~TapeReaderInterface()
Destructor.
Definition tapeReaderWriterInterface.hpp:258
virtual std::vector< Identifier > const & getInputs() const &=0
Used to get the restored inputs of the tape.
typename Type::Identifier Identifier
Identifier for the internal management, e.g. int.
Definition tapeReaderWriterInterface.hpp:255
typename Type::Real Real
Primal computation type, e.g. double.
Definition tapeReaderWriterInterface.hpp:256
T_Type Type
The evaluation type.
Definition tapeReaderWriterInterface.hpp:253
virtual Tape & getTape()=0
Used to get a reference to the restored tape.
virtual void readFile(std::string const &name)
This method uses the the fileName to reproduce a valid tape.
Definition tapeReaderWriterInterface.hpp:261
The interface used by all the tape writers. The tape writers are used to generate text,...
Definition tapeReaderWriterInterface.hpp:129
typename Tape::EvalHandle EvalHandle
Definition tapeReaderWriterInterface.hpp:136
Type Type
Definition tapeReaderWriterInterface.hpp:130
virtual void start(Tape &tape)
Destructor.
Definition tapeReaderWriterInterface.hpp:144
virtual void writeLowLevelFunction(size_t &curLLFByteDataPos, char *dataPtr, size_t &curLLFInfoDataPos, Config::LowLevelFunctionToken *const tokenPtr, Config::LowLevelFunctionDataSize *const dataSizePtr)
Used for statements that contain a low level function.
Definition tapeReaderWriterInterface.hpp:171
typename Type::Identifier Identifier
Definition tapeReaderWriterInterface.hpp:133
virtual void writeStatement(WriteInfo const &info, Identifier const *lhsIdentifiers, Real const *lhsPrimalValues, Config::ArgumentSize const &nPassiveValues, Identifier const *const rhsIdentifiers, Real const *const passiveValues, Real const *const constantValues, EvalHandle stmtEvalHandle)
Called for each statement. The method writes the current statement to the file. This overload is used...
Definition tapeReaderWriterInterface.hpp:162
typename Type::Tape Tape
Definition tapeReaderWriterInterface.hpp:131
typename Type::Real Real
Definition tapeReaderWriterInterface.hpp:134
virtual void finish()
After all the statements have been written, the finish method finalizes the writing process.
Definition tapeReaderWriterInterface.hpp:178
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
std::string stmtExpression
Used to generate a .hpp file for reading back a primal value tape.
Definition tapeReaderWriterInterface.hpp:73
size_t numberOfOutputArguments
Number of output arguments.
Definition tapeReaderWriterInterface.hpp:70
std::string mathRepresentation
Definition tapeReaderWriterInterface.hpp:74
size_t numberOfConstantArguments
Number of constant arguments.
Definition tapeReaderWriterInterface.hpp:72