CoDiPack  2.3.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-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 "../../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
76
127 template<typename T_Type>
129 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
130 using Tape = typename Type::Tape;
131
132 using Identifier = typename Type::Identifier;
133 using Real = typename Type::Real;
134
135 using EvalHandle = typename Tape::EvalHandle;
136
137 virtual ~TapeWriterInterface() {};
138
143 virtual void start(Tape& tape) { CODI_UNUSED(tape); }
144
149 virtual void writeStatement(Identifier const& curLhsIdentifier, size_t& curJacobianPos,
150 Real const* const rhsJacobians, Identifier const* const rhsIdentifiers,
151 Config::ArgumentSize const& nJacobians) {
152 CODI_UNUSED(curLhsIdentifier, curJacobianPos, rhsJacobians, rhsIdentifiers, nJacobians);
153 }
154
159 virtual void writeStatement(WriteInfo const& info, Identifier const& curLhsIdentifier, Real const& primalValue,
160 Config::ArgumentSize const& nPassiveValues, size_t const& curRhsIdentifiersPos,
161 Identifier const* const rhsIdentifiers, size_t const& curPassiveValuePos,
162 Real const* const passiveValues, size_t& curConstantPos,
163 Real const* const constantValues, EvalHandle stmtEvalHandle) {
164 CODI_UNUSED(info, curLhsIdentifier, primalValue, nPassiveValues, curRhsIdentifiersPos, rhsIdentifiers,
165 passiveValues, curPassiveValuePos, curConstantPos, constantValues, stmtEvalHandle);
166 }
167
169 virtual void writeLowLevelFunction(size_t& curLLFByteDataPos, char* dataPtr, size_t& curLLFInfoDataPos,
170 Config::LowLevelFunctionToken* const tokenPtr,
171 Config::LowLevelFunctionDataSize* const dataSizePtr) {
172 CODI_UNUSED(curLLFByteDataPos, dataPtr, curLLFInfoDataPos, tokenPtr, dataSizePtr);
173 }
174
176 virtual void finish() {}
177 };
178
249 template<typename T_Type>
251 using Type = CODI_DD(T_Type, CODI_DEFAULT_LHS_EXPRESSION);
252 using Tape = typename Type::Tape;
253 using Identifier = typename Type::Identifier;
254 using Real = typename Type::Real;
255
257
259 virtual void readFile(std::string const& name) { CODI_UNUSED(name); }
260
261 virtual Tape& getTape() = 0;
262
263 virtual std::vector<Identifier> const& getInputs() const& = 0;
264
265 virtual std::vector<Identifier> const& getOutputs() const& = 0;
267 };
268}
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
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:91
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
FileType
Used to select the type of writer that should be generated.
Definition tapeReaderWriterInterface.hpp:47
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:250
virtual std::vector< Identifier > const & getOutputs() const &=0
typename Type::Tape Tape
The tape type that is to be restored.
Definition tapeReaderWriterInterface.hpp:252
virtual ~TapeReaderInterface()
Destructor.
Definition tapeReaderWriterInterface.hpp:256
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:253
typename Type::Real Real
Primal computation type, e.g. double.
Definition tapeReaderWriterInterface.hpp:254
T_Type Type
The evaluation type.
Definition tapeReaderWriterInterface.hpp:251
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:259
The interface used by all the tape writers. The tape writers are used to generate text,...
Definition tapeReaderWriterInterface.hpp:128
typename Tape::EvalHandle EvalHandle
Evaluation handle used for primal value tapes.
Definition tapeReaderWriterInterface.hpp:135
virtual void writeStatement(WriteInfo const &info, Identifier const &curLhsIdentifier, Real const &primalValue, Config::ArgumentSize const &nPassiveValues, size_t const &curRhsIdentifiersPos, Identifier const *const rhsIdentifiers, size_t const &curPassiveValuePos, Real const *const passiveValues, size_t &curConstantPos, 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:159
T_Type Type
The evaluation type.
Definition tapeReaderWriterInterface.hpp:129
virtual void start(Tape &tape)
Destructor.
Definition tapeReaderWriterInterface.hpp:143
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:169
typename Type::Identifier Identifier
Identifier for the internal management, e.g. int.
Definition tapeReaderWriterInterface.hpp:132
typename Type::Tape Tape
The tape type that is to be written out.
Definition tapeReaderWriterInterface.hpp:130
typename Type::Real Real
Primal computation type, e.g. double.
Definition tapeReaderWriterInterface.hpp:133
virtual void finish()
After all the statements have been written, the finish method finalizes the writing process.
Definition tapeReaderWriterInterface.hpp:176
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:149
This class is used during the writing process of a primal value tape. The WriteInfo is returned by co...
Definition tapeReaderWriterInterface.hpp:69
size_t numberOfActiveArguments
Number of active arguments.
Definition tapeReaderWriterInterface.hpp:70
std::string stmtExpression
Used to generate a .hpp file for reading back a primal value tape.
Definition tapeReaderWriterInterface.hpp:72
std::string mathRepresentation
Definition tapeReaderWriterInterface.hpp:73
size_t numberOfConstantArguments
Number of constant arguments.
Definition tapeReaderWriterInterface.hpp:71