CoDiPack  3.0.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-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 <stddef.h>
38#include <stdint.h>
39
40#include <limits>
41
42#include "misc/exceptions.hpp"
43#include "tools/cuda/cudaFunctionAttributes.hpp"
44
46
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_SpecializeStdComplex
261 #define CODI_SpecializeStdComplex 1
262#endif
266 // Do not undefine.
267
268#ifndef CODI_SortIndicesOnReset
270 #define CODI_SortIndicesOnReset true
271#endif
274#undef CODI_SortIndicesOnReset
275
276#ifndef CODI_VariableAdjointInterfaceInPrimalTapes
278 #define CODI_VariableAdjointInterfaceInPrimalTapes 0
279#endif
282#if CODI_VariableAdjointInterfaceInPrimalTapes
283 #define ADJOINT_VECTOR_TYPE VectorAccessInterface<Real, Identifier>
284#else
286 #define ADJOINT_VECTOR_TYPE Gradient
287#endif
288 // Do not undefine.
289
290#ifndef CODI_ReversalZeroesAdjoints
292 #define CODI_ReversalZeroesAdjoints true
293#endif
294#if CODI_VariableAdjointInterfaceInPrimalTapes && !CODI_ReversalZeroesAdjoints
295 #warning CODI_ReversalZeroesAdjoints == false is incompatible with CODI_VariableAdjointInterfaceInPrimalTapes == true.
296#endif
299#undef CODI_ReversalZeroesAdjoints
300
302 /*******************************************************************************/
306
307#ifndef CODI_ADWorkflowEvents
309 #define CODI_ADWorkflowEvents true
310#endif
313#undef CODI_ADWorkflowEvents
314
315#ifndef CODI_PreaccEvents
317 #define CODI_PreaccEvents false
318#endif
321#undef CODI_PreaccEvents
322
323#ifndef CODI_StatementEvents
325 #define CODI_StatementEvents false
326#endif
329#undef CODI_StatementEvents
330
331#ifndef CODI_IndexEvents
333 #define CODI_IndexEvents false
334#endif
337#undef CODI_IndexEvents
338
340 /*******************************************************************************/
343
344#ifndef CODI_EnableEigen
346 #define CODI_EnableEigen 0
347#endif
349 bool constexpr EnableEigen = CODI_EnableEigen;
350 // Do not undefine
351
352#ifndef CODI_EnableEnzyme
354 #define CODI_EnableEnzyme false
355#endif
358 // Do not undefine.
359
360#ifndef CODI_EnableMPI
362 #define CODI_EnableMPI false
363#endif
365 bool constexpr EnableMPI = CODI_EnableMPI;
366 // Do not undefine.
367
368#ifndef CODI_EnableOpenMP
370 #define CODI_EnableOpenMP false
371#endif
374 // Do not undefine.
375
376#ifndef CODI_EnableOpDiLib
378 #define CODI_EnableOpDiLib false
379#endif
380#if CODI_EnableOpDiLib && !CODI_EnableOpenMP
381 #error CODI_EnableOpDiLib == true is incompatible with CODI_EnableOpenMP == false.
382#endif
385 // Do not undefine.
386
388 /*******************************************************************************/
391
393#define CODI_FunctionAttributes CODI_CUDAFunctionAttributes
394
395#ifndef CODI_AnnotateBranchLikelihood
397 #define CODI_AnnotateBranchLikelihood CODI_HasCpp20
398#endif
399#if CODI_AnnotateBranchLikelihood
401 #define CODI_Likely [[likely]]
403 #define CODI_Unlikely [[unlikely]]
404#else
406 #define CODI_Likely /* empty */
408 #define CODI_Unlikely /* empty */
409#endif
412#undef CODI_AnnotateBranchLikelihood
413
414#ifndef CODI_AvoidedInlines
416 #define CODI_AvoidedInlines 1
417#endif
418#if CODI_AvoidedInlines
419 #if defined(_MSC_VER)
420 #define CODI_NO_INLINE __declspec(noinline)
421 #else
422 #define CODI_NO_INLINE __attribute__((noinline))
423 #endif
424#else
426 #define CODI_NO_INLINE /* no avoiding of inline defined */
427#endif
429 bool constexpr AvoidedInlines = CODI_AvoidedInlines;
430#undef CODI_AvoidedInlines
431
432#ifndef CODI_EnableAssert
434 #define CODI_EnableAssert false
435#endif
436#ifndef codiAssert // Can also be defined by the user before including codi.hpp.
437 #if CODI_EnableAssert
438 #define codiAssert(x) ::codi::checkAndOutputAssert(x, CODI_TO_STRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__)
439 #else
441 #define codiAssert(x) /* disabled by CODI_EnableAssert */
442 #endif
443#endif
446#undef CODI_EnableAssert
447
448#ifndef CODI_ForcedInlines
450 #define CODI_ForcedInlines 0
451#endif
452#if CODI_ForcedInlines
453 #if defined(__INTEL_COMPILER) | defined(_MSC_VER)
454 #define CODI_INLINE CODI_FunctionAttributes __forceinline
455 #define CODI_INLINE_NO_FA __forceinline
456 #define CODI_LAMBDA_INLINE CODI_FunctionAttributes /*__forceinline*/
457 #elif defined(__GNUC__)
458 #define CODI_INLINE CODI_FunctionAttributes inline __attribute__((always_inline))
459 #define CODI_INLINE_NO_FA inline __attribute__((always_inline))
460 #define CODI_LAMBDA_INLINE CODI_FunctionAttributes __attribute__((always_inline))
461 #else
462 #warning Could not determine compiler for forced inline definitions. Using inline.
463 #define CODI_INLINE CODI_FunctionAttributes inline
464 #define CODI_INLINE_NO_FA inline
465 #define CODI_LAMBDA_INLINE CODI_FunctionAttributes /*inline*/
466 #endif
467#else
469 #define CODI_INLINE CODI_FunctionAttributes inline
471 #define CODI_INLINE_NO_FA inline
473 #define CODI_LAMBDA_INLINE /* inline */
474#endif
477#undef CODI_ForcedInlines
478
479#ifndef CODI_Restrict
481 #define CODI_Restrict 1
482#endif
483#if CODI_Restrict
484 #if defined(__INTEL_COMPILER) | defined(_MSC_VER)
485 #define CODI_RESTRICT __restrict
486 #elif defined(__GNUC__)
487 #define CODI_RESTRICT __restrict__
488 #else
489 #warning Could not determine compiler for restrict definitions. Using nothing.
491 #define CODI_RESTRICT /* no restrict */
492 #endif
493#else
495 #define CODI_RESTRICT /* no restrict */
496#endif
498 bool constexpr Restrict = CODI_Restrict;
499#undef CODI_Restrict
500
502 }
503}
#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:450
#define CODI_EnableOpDiLib
See codi::Config::EnableOpDiLib.
Definition config.h:378
#define CODI_OverflowCheck
See codi::Config::OverflowCheck.
Definition config.h:245
#define CODI_PreaccEvents
See codi::Config::PreaccEvents.
Definition config.h:317
#define CODI_CheckZeroIndex
See codi::Config::CheckZeroIndex.
Definition config.h:175
#define CODI_StatementEvents
See codi::Config::StatementEvents.
Definition config.h:325
#define CODI_CheckTapeActivity
See codi::Config::CheckTapeActivity.
Definition config.h:167
#define CODI_IndexEvents
See codi::Config::IndexEvents.
Definition config.h:333
#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:434
#define CODI_EnableEnzyme
See codi::Config::EnableEnzyme.
Definition config.h:354
#define CODI_VariableAdjointInterfaceInPrimalTapes
See codi::Config::VariableAdjointInterfaceInPrimalTapes.
Definition config.h:278
#define CODI_CheckEmptyStatements
See codi::Config::CheckEmptyStatements.
Definition config.h:151
#define CODI_SortIndicesOnReset
See codi::Config::SortIndicesOnReset.
Definition config.h:270
#define CODI_CopyOptimization
See codi::Config::CopyOptimization.
Definition config.h:183
#define CODI_AnnotateBranchLikelihood
See codi::Config::AnnotateBranchLikelihood.
Definition config.h:397
#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:309
#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_SpecializeStdComplex
See codi::Config::SpecializeStdComplex.
Definition config.h:261
#define CODI_IgnoreIntelNoInlineWarning
See codi::Config::IgnoreIntelNoInlineWarning.
Definition config.h:217
#define CODI_EnableOpenMP
See codi::Config::EnableOpenMP.
Definition config.h:370
#define CODI_Restrict
See codi::Config::Restrict.
Definition config.h:481
#define CODI_ChunkSize
See codi::Config::ChunkSize.
Definition config.h:91
#define CODI_ReversalZeroesAdjoints
See codi::Config::ReversalZeroesAdjoints.
Definition config.h:292
#define CODI_EnableMPI
See codi::Config::EnableMPI.
Definition config.h:362
#define CODI_ImplicitConversionWarning
See codi::Config::ImplicitConversionWarning.
Definition config.h:201
Configuration options for CoDiPack.
Definition config.h:65
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:445
bool constexpr SpecializeStdComplex
Definition config.h:265
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:411
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:320
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:357
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:312
bool constexpr ImplicitConversion
Definition config.h:196
bool constexpr EnableOpenMP
Add OpenMP specific headers.
Definition config.h:373
bool constexpr EnableMPI
Add MPI and MeDiPack specific headers.
Definition config.h:365
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:336
bool constexpr StatementEvents
Enable statement events. Disabled by default.
Definition config.h:328
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:273
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 Restrict
Annotate pointers with the restrict keyword in order to improve the performance of CoDiPack.
Definition config.h:498
bool constexpr ReversalZeroesAdjoints
With a linear index management, control if adjoints are set to zero during reversal.
Definition config.h:298
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:349
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:281
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:429
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:384
bool constexpr ForcedInlines
Force inlining instead of using the heuristics from the compiler.
Definition config.h:476
CoDiPack - Code Differentiation Package.
Definition codi.hpp:94