CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
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 <stddef.h>
38#include <stdint.h>
39
40#include <limits>
41
42#include "misc/exceptions.hpp"
43#include "tools/cuda/cudaFunctionAttributes.hpp"
44
48namespace codi {
49
50#ifndef CODI_IDE
52 #define CODI_IDE 0
53#endif
54
62 struct Namespace {};
63
65 namespace Config {
66
67 /*******************************************************************************/
70
72#define CODI_HasCpp20 __cplusplus >= 202002L
74 bool constexpr HasCpp20 = CODI_HasCpp20;
75
77 /*******************************************************************************/
80
81#ifndef CODI_ByteDataChunkSize
83 #define CODI_ByteDataChunkSize 4194304
84#endif
87#undef CODI_ByteDataChunkSize
88
89#ifndef CODI_ChunkSize
91 #define CODI_ChunkSize 2097152
92#endif
94 size_t constexpr ChunkSize = CODI_ChunkSize;
95#undef CODI_ChunkSize
96
98 using LowLevelFunctionDataSize = uint16_t;
99
101 size_t constexpr LowLevelFunctionDataSizeMax = std::numeric_limits<LowLevelFunctionDataSize>::max();
102
104 "Low level function data size is larger than the "
105 "maximum size of a byte data chunk. Fix: Increase 'ByteDataChunkSize'.");
106
108 using LowLevelFunctionToken = uint16_t;
109
111 size_t constexpr LowLevelFunctionTokenMaxSize = std::numeric_limits<LowLevelFunctionToken>::max();
112
114 size_t constexpr LowLevelFunctionTokenInvalid = std::numeric_limits<LowLevelFunctionToken>::max();
115
117 using ArgumentSize = uint8_t;
118
120 size_t constexpr MaxArgumentSize = 253;
121
123 size_t constexpr StatementInputTag = 255;
124
126 size_t constexpr StatementLowLevelFunctionTag = 254;
127
128#ifndef CODI_SmallChunkSize
130 #define CODI_SmallChunkSize 32768
131#endif
134#undef CODI_SmallChunkSize
135
137 /*******************************************************************************/
140
141#ifndef CODI_CheckExpressionArguments
143 #define CODI_CheckExpressionArguments false
144#endif
147#undef CODI_CheckExpressionArguments
148
149#ifndef CODI_CheckEmptyStatements
151 #define CODI_CheckEmptyStatements true
152#endif
155#undef CODI_CheckEmptyStatements
156
157#ifndef CODI_CheckJacobianIsZero
159 #define CODI_CheckJacobianIsZero true
160#endif
163#undef CODI_CheckJacobianIsZero
164
165#ifndef CODI_CheckTapeActivity
167 #define CODI_CheckTapeActivity true
168#endif
171#undef CODI_CheckTapeActivity
172
173#ifndef CODI_CheckZeroIndex
175 #define CODI_CheckZeroIndex true
176#endif
179#undef CODI_CheckZeroIndex
180
181#ifndef CODI_CopyOptimization
183 #define CODI_CopyOptimization true
184#endif
187#undef CODI_CopyOptimization
188
189#ifndef CODI_ImplicitConversion
191 #define CODI_ImplicitConversion false
192#endif
197 // Do not undefine.
198
199#ifndef CODI_ImplicitConversionWarning
201 #define CODI_ImplicitConversionWarning true
202#endif
205#undef CODI_ImplicitConversionWarning
206
207#ifndef CODI_ImplicitTagConversion
209 #define CODI_ImplicitTagConversion false
210#endif
213 // Do not undefine.
214
215#ifndef CODI_IgnoreIntelNoInlineWarning
217 #define CODI_IgnoreIntelNoInlineWarning false
218#endif
221#if CODI_IgnoreIntelNoInlineWarning
222 #ifdef __INTEL_COMPILER
223 #pragma warning disable 2196
224 #endif
225#endif
226
227#ifndef CODI_RemoveDuplicateJacobianArguments
229 #define CODI_RemoveDuplicateJacobianArguments 0
230#endif
233 // Do not undefine.
234
235#ifndef CODI_IgnoreInvalidJacobians
237 #define CODI_IgnoreInvalidJacobians false
238#endif
241#undef CODI_IgnoreInvalidJacobians
242
243#ifndef CODI_OverflowCheck
245 #define CODI_OverflowCheck true
246#endif
249#undef CODI_OverflowCheck
250
251#ifndef CODI_SkipZeroAdjointEvaluation
253 #define CODI_SkipZeroAdjointEvaluation true
254#endif
257#undef CODI_SkipZeroAdjointEvaluation
258
259#ifndef CODI_SortIndicesOnReset
261 #define CODI_SortIndicesOnReset true
262#endif
265#undef CODI_SortIndicesOnReset
266
267#ifndef CODI_VariableAdjointInterfaceInPrimalTapes
269 #define CODI_VariableAdjointInterfaceInPrimalTapes 0
270#endif
273#if CODI_VariableAdjointInterfaceInPrimalTapes
274 #define ADJOINT_VECTOR_TYPE VectorAccessInterface<Real, Identifier>
275#else
277 #define ADJOINT_VECTOR_TYPE Gradient
278#endif
279 // Do not undefine.
280
281#ifndef CODI_ReversalZeroesAdjoints
283 #define CODI_ReversalZeroesAdjoints true
284#endif
285#if CODI_VariableAdjointInterfaceInPrimalTapes && !CODI_ReversalZeroesAdjoints
286 #warning CODI_ReversalZeroesAdjoints == false is incompatible with CODI_VariableAdjointInterfaceInPrimalTapes == true.
287#endif
290#undef CODI_ReversalZeroesAdjoints
291
293 /*******************************************************************************/
297
298#ifndef CODI_ADWorkflowEvents
300 #define CODI_ADWorkflowEvents true
301#endif
304#undef CODI_ADWorkflowEvents
305
306#ifndef CODI_PreaccEvents
308 #define CODI_PreaccEvents false
309#endif
312#undef CODI_PreaccEvents
313
314#ifndef CODI_StatementEvents
316 #define CODI_StatementEvents false
317#endif
320#undef CODI_StatementEvents
321
322#ifndef CODI_IndexEvents
324 #define CODI_IndexEvents false
325#endif
328#undef CODI_IndexEvents
329
331 /*******************************************************************************/
334
335#ifndef CODI_EnableEigen
337 #define CODI_EnableEigen 0
338#endif
340 bool constexpr EnableEigen = CODI_EnableEigen;
341 // Do not undefine
342
343#ifndef CODI_EnableEnzyme
345 #define CODI_EnableEnzyme false
346#endif
349 // Do not undefine.
350
351#ifndef CODI_EnableMPI
353 #define CODI_EnableMPI false
354#endif
356 bool constexpr EnableMPI = CODI_EnableMPI;
357 // Do not undefine.
358
359#ifndef CODI_EnableOpenMP
361 #define CODI_EnableOpenMP false
362#endif
365 // Do not undefine.
366
367#ifndef CODI_EnableOpDiLib
369 #define CODI_EnableOpDiLib false
370#endif
371#if CODI_EnableOpDiLib && !CODI_EnableOpenMP
372 #error CODI_EnableOpDiLib == true is incompatible with CODI_EnableOpenMP == false.
373#endif
376 // Do not undefine.
377
379 /*******************************************************************************/
382
384#define CODI_FunctionAttributes CODI_CUDAFunctionAttributes
385
386#ifndef CODI_AnnotateBranchLikelihood
388 #define CODI_AnnotateBranchLikelihood CODI_HasCpp20
389#endif
390#if CODI_AnnotateBranchLikelihood
392 #define CODI_Likely [[likely]]
394 #define CODI_Unlikely [[unlikely]]
395#else
397 #define CODI_Likely /* empty */
399 #define CODI_Unlikely /* empty */
400#endif
403#undef CODI_AnnotateBranchLikelihood
404
405#ifndef CODI_AvoidedInlines
407 #define CODI_AvoidedInlines 1
408#endif
409#if CODI_AvoidedInlines
410 #if defined(_MSC_VER)
411 #define CODI_NO_INLINE __declspec(noinline)
412 #else
413 #define CODI_NO_INLINE __attribute__((noinline))
414 #endif
415#else
417 #define CODI_NO_INLINE /* no avoiding of inline defined */
418#endif
420 bool constexpr AvoidedInlines = CODI_AvoidedInlines;
421#undef CODI_AvoidedInlines
422
423#ifndef CODI_EnableAssert
425 #define CODI_EnableAssert false
426#endif
427#ifndef codiAssert // Can also be defined by the user before including codi.hpp.
428 #if CODI_EnableAssert
429 #define codiAssert(x) ::codi::checkAndOutputAssert(x, CODI_TO_STRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__)
430 #else
432 #define codiAssert(x) /* disabled by CODI_EnableAssert */
433 #endif
434#endif
437#undef CODI_EnableAssert
438
439#ifndef CODI_ForcedInlines
441 #define CODI_ForcedInlines 0
442#endif
443#if CODI_ForcedInlines
444 #if defined(__INTEL_COMPILER) | defined(_MSC_VER)
445 #define CODI_INLINE CODI_FunctionAttributes __forceinline
446 #define CODI_INLINE_NO_FA __forceinline
447 #elif defined(__GNUC__)
448 #define CODI_INLINE CODI_FunctionAttributes inline __attribute__((always_inline))
449 #define CODI_INLINE_NO_FA inline __attribute__((always_inline))
450 #else
451 #warning Could not determine compiler for forced inline definitions. Using inline.
452 #define CODI_INLINE CODI_FunctionAttributes inline
453 #define CODI_INLINE_NO_FA inline
454 #endif
455#else
457 #define CODI_INLINE CODI_FunctionAttributes inline
459 #define CODI_INLINE_NO_FA inline
460#endif
463#undef CODI_ForcedInlines
464
466 }
467}
#define CODI_ByteDataChunkSize
See codi::Config::ByteDataChunkSize.
Definition config.h:83
#define CODI_SmallChunkSize
See codi::Config::SmallChunkSize.
Definition config.h:130
#define CODI_ForcedInlines
See codi::Config::ForcedInlines.
Definition config.h:441
#define CODI_EnableOpDiLib
See codi::Config::EnableOpDiLib.
Definition config.h:369
#define CODI_OverflowCheck
See codi::Config::OverflowCheck.
Definition config.h:245
#define CODI_PreaccEvents
See codi::Config::PreaccEvents.
Definition config.h:308
#define CODI_CheckZeroIndex
See codi::Config::CheckZeroIndex.
Definition config.h:175
#define CODI_StatementEvents
See codi::Config::StatementEvents.
Definition config.h:316
#define CODI_CheckTapeActivity
See codi::Config::CheckTapeActivity.
Definition config.h:167
#define CODI_IndexEvents
See codi::Config::IndexEvents.
Definition config.h:324
#define CODI_ImplicitConversion
See codi::Config::ImplicitConversion.
Definition config.h:191
#define CODI_ImplicitTagConversion
See codi::Config::ImplicitTagConversion.
Definition config.h:209
#define CODI_HasCpp20
See codi::Config::HasCpp20.
Definition config.h:72
#define CODI_EnableAssert
See codi::Config::EnableAssert.
Definition config.h:425
#define CODI_EnableEnzyme
See codi::Config::EnableEnzyme.
Definition config.h:345
#define CODI_VariableAdjointInterfaceInPrimalTapes
See codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition config.h:269
#define CODI_CheckEmptyStatements
See codi::Config::CheckEmptyStatements.
Definition config.h:151
#define CODI_SortIndicesOnReset
See codi::Config::SortIndicesOnReset.
Definition config.h:261
#define CODI_CopyOptimization
See codi::Config::CopyOptimization.
Definition config.h:183
#define CODI_AnnotateBranchLikelihood
See codi::Config::AnnotateBranchLikelihood.
Definition config.h:388
#define CODI_IgnoreInvalidJacobians
See codi::Config::IgnoreInvalidJacobians.
Definition config.h:237
#define CODI_RemoveDuplicateJacobianArguments
See codi::Config::RemoveDuplicateJacobianArguments.
Definition config.h:229
#define CODI_ADWorkflowEvents
See codi::Config::ADWorkflowEvents.
Definition config.h:300
#define CODI_CheckJacobianIsZero
See codi::Config::CheckJacobianIsZero.
Definition config.h:159
#define CODI_CheckExpressionArguments
See codi::Config::CheckExpressionArguments.
Definition config.h:143
#define CODI_SkipZeroAdjointEvaluation
See codi::Config::SkipZeroAdjointEvaluation.
Definition config.h:253
#define CODI_IgnoreIntelNoInlineWarning
See codi::Config::IgnoreIntelNoInlineWarning.
Definition config.h:217
#define CODI_EnableOpenMP
See codi::Config::EnableOpenMP.
Definition config.h:361
#define CODI_ChunkSize
See codi::Config::ChunkSize.
Definition config.h:91
#define CODI_ReversalZeroesAdjoints
See codi::Config::ReversalZeroesAdjoints.
Definition config.h:283
#define CODI_EnableMPI
See codi::Config::EnableMPI.
Definition config.h:353
#define CODI_ImplicitConversionWarning
See codi::Config::ImplicitConversionWarning.
Definition config.h:201
uint16_t LowLevelFunctionDataSize
Size store type for a low level function.
Definition config.h:98
bool constexpr RemoveDuplicateJacobianArguments
Extra pass in Jacobian tapes that combines arguments with the same identifier.
Definition config.h:232
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
bool constexpr HasCpp20
If CoDiPack is compiled with C++20.
Definition config.h:74
bool constexpr AnnotateBranchLikelihood
Annotate branches with likely or unlikely, e.g., for if and else.
Definition config.h:402
const bool CheckEmptyStatements
Tapes push statements only if at least one Jacobian was pushed.
Definition config.h:154
size_t constexpr SmallChunkSize
Default smaller size of chunks (ChunkBase) used in ChunkedData in reverse tape implementations.
Definition config.h:133
size_t constexpr ChunkSize
Default size of chunks (ChunkBase) used in ChunkedData in reverse tape implementations.
Definition config.h:94
bool constexpr CheckZeroIndex
Ignore active types that are not dependent on any input value in Jacobian tapes.
Definition config.h:178
bool constexpr PreaccEvents
Enable preaccumulation events. Disabled by default.
Definition config.h:311
size_t constexpr LowLevelFunctionDataSizeMax
Maximum data size of a low level function.
Definition config.h:101
bool constexpr IgnoreInvalidJacobians
Ignore invalid Jacobians like NaN or Inf.
Definition config.h:240
size_t constexpr LowLevelFunctionTokenInvalid
Invalid low level function token.
Definition config.h:114
bool constexpr CheckTapeActivity
Makes it possible to ignore certain code parts. If turned of everything will be recorded.
Definition config.h:170
size_t constexpr StatementLowLevelFunctionTag
Statement tag for low level functions.
Definition config.h:126
bool constexpr CheckJacobianIsZero
Ignore Jacobians that are zero in Jacobian based tapes.
Definition config.h:162
bool constexpr EnableEnzyme
Add Enzyme specific functionality.
Definition config.h:348
bool constexpr ImplicitTagConversion
Enables the implicit conversion of tag data to its tag.
Definition config.h:212
bool constexpr ADWorkflowEvents
Enable AD workflow events, also known as Tape* events. Enabled by default.
Definition config.h:303
bool constexpr ImplicitConversion
Definition config.h:196
bool constexpr EnableOpenMP
Add OpenMP specific headers.
Definition config.h:364
bool constexpr EnableMPI
Add MPI and MeDiPack specific headers.
Definition config.h:356
size_t constexpr MaxArgumentSize
Maximum number of arguments in a statement.
Definition config.h:120
bool constexpr IndexEvents
Enable index management events. Disabled by default.
Definition config.h:327
bool constexpr StatementEvents
Enable statement events. Disabled by default.
Definition config.h:319
bool constexpr CheckExpressionArguments
Check for invalid arguments to expressions like division by zero.
Definition config.h:146
size_t constexpr LowLevelFunctionTokenMaxSize
Maximum number of low level functions.
Definition config.h:111
bool constexpr SortIndicesOnReset
Reuse index tapes will sort their indices on a reset.
Definition config.h:264
bool constexpr OverflowCheck
Check in the index manager if an overflow occurred.
Definition config.h:248
bool constexpr IgnoreIntelNoInlineWarning
Disables warnings of the sort: warning #2196: routine is both "inline" and "noinline".
Definition config.h:220
bool constexpr ReversalZeroesAdjoints
With a linear index management, control if adjoints are set to zero during reversal.
Definition config.h:289
size_t constexpr ByteDataChunkSize
Default size of byte chunks used in ChunkedData in reverse tape implementations.
Definition config.h:86
bool constexpr CopyOptimization
Do not store copy statements like a = b; if the identity handler allows it.
Definition config.h:186
bool constexpr EnableEigen
Enable Eigen specific implementations.
Definition config.h:340
bool constexpr ImplicitConversionWarning
Warn about implicit conversions in the code.
Definition config.h:204
bool constexpr VariableAdjointInterfaceInPrimalTapes
Allow custom adjoint vector in primal values tapes.
Definition config.h:272
uint8_t ArgumentSize
Type for the number of arguments in statements.
Definition config.h:117
bool constexpr AvoidedInlines
Do not inline functions like evaluate().
Definition config.h:420
size_t constexpr StatementInputTag
Tag for statements that are inputs. Used in linear index management context.
Definition config.h:123
bool constexpr SkipZeroAdjointEvaluation
Do not perform a reverse evaluation of a statement if the seeding adjoint is zero.
Definition config.h:256
bool constexpr EnableOpDiLib
Add OpDiLib specific headers. Requires codi::Config::EnableOpenMP == true.
Definition config.h:375
bool constexpr ForcedInlines
Force inlining instead of using the heuristics from the compiler.
Definition config.h:462
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90