42#include "misc/exceptions.hpp"
43#include "tools/cuda/cudaFunctionAttributes.hpp"
72#define CODI_HasCpp20 __cplusplus >= 202002L
81#ifndef CODI_ByteDataChunkSize
83 #define CODI_ByteDataChunkSize 4194304
87#undef CODI_ByteDataChunkSize
91 #define CODI_ChunkSize 2097152
104 "Low level function data size is larger than the "
105 "maximum size of a byte data chunk. Fix: Increase 'ByteDataChunkSize'.");
128#ifndef CODI_SmallChunkSize
130 #define CODI_SmallChunkSize 32768
134#undef CODI_SmallChunkSize
141#ifndef CODI_CheckExpressionArguments
143 #define CODI_CheckExpressionArguments false
147#undef CODI_CheckExpressionArguments
149#ifndef CODI_CheckEmptyStatements
151 #define CODI_CheckEmptyStatements true
155#undef CODI_CheckEmptyStatements
157#ifndef CODI_CheckJacobianIsZero
159 #define CODI_CheckJacobianIsZero true
163#undef CODI_CheckJacobianIsZero
165#ifndef CODI_CheckTapeActivity
167 #define CODI_CheckTapeActivity true
171#undef CODI_CheckTapeActivity
173#ifndef CODI_CheckZeroIndex
175 #define CODI_CheckZeroIndex true
179#undef CODI_CheckZeroIndex
181#ifndef CODI_CopyOptimization
183 #define CODI_CopyOptimization true
187#undef CODI_CopyOptimization
189#ifndef CODI_ImplicitConversion
191 #define CODI_ImplicitConversion false
199#ifndef CODI_ImplicitConversionWarning
201 #define CODI_ImplicitConversionWarning true
205#undef CODI_ImplicitConversionWarning
207#ifndef CODI_ImplicitTagConversion
209 #define CODI_ImplicitTagConversion false
215#ifndef CODI_IgnoreIntelNoInlineWarning
217 #define CODI_IgnoreIntelNoInlineWarning false
221#if CODI_IgnoreIntelNoInlineWarning
222 #ifdef __INTEL_COMPILER
223 #pragma warning disable 2196
227#ifndef CODI_RemoveDuplicateJacobianArguments
229 #define CODI_RemoveDuplicateJacobianArguments 0
235#ifndef CODI_IgnoreInvalidJacobians
237 #define CODI_IgnoreInvalidJacobians false
241#undef CODI_IgnoreInvalidJacobians
243#ifndef CODI_OverflowCheck
245 #define CODI_OverflowCheck true
249#undef CODI_OverflowCheck
251#ifndef CODI_SkipZeroAdjointEvaluation
253 #define CODI_SkipZeroAdjointEvaluation true
257#undef CODI_SkipZeroAdjointEvaluation
259#ifndef CODI_SpecializeStdComplex
261 #define CODI_SpecializeStdComplex 1
268#ifndef CODI_SortIndicesOnReset
270 #define CODI_SortIndicesOnReset true
274#undef CODI_SortIndicesOnReset
276#ifndef CODI_VariableAdjointInterfaceInPrimalTapes
278 #define CODI_VariableAdjointInterfaceInPrimalTapes 0
282#if CODI_VariableAdjointInterfaceInPrimalTapes
283 #define ADJOINT_VECTOR_TYPE VectorAccessInterface<Real, Identifier>
286 #define ADJOINT_VECTOR_TYPE Gradient
290#ifndef CODI_ReversalZeroesAdjoints
292 #define CODI_ReversalZeroesAdjoints true
294#if CODI_VariableAdjointInterfaceInPrimalTapes && !CODI_ReversalZeroesAdjoints
295 #warning CODI_ReversalZeroesAdjoints == false is incompatible with CODI_VariableAdjointInterfaceInPrimalTapes == true.
299#undef CODI_ReversalZeroesAdjoints
307#ifndef CODI_ADWorkflowEvents
309 #define CODI_ADWorkflowEvents true
313#undef CODI_ADWorkflowEvents
315#ifndef CODI_PreaccEvents
317 #define CODI_PreaccEvents false
321#undef CODI_PreaccEvents
323#ifndef CODI_StatementEvents
325 #define CODI_StatementEvents false
329#undef CODI_StatementEvents
331#ifndef CODI_IndexEvents
333 #define CODI_IndexEvents false
337#undef CODI_IndexEvents
344#ifndef CODI_EnableEigen
346 #define CODI_EnableEigen 0
352#ifndef CODI_EnableEnzyme
354 #define CODI_EnableEnzyme false
360#ifndef CODI_EnableMPI
362 #define CODI_EnableMPI false
368#ifndef CODI_EnableOpenMP
370 #define CODI_EnableOpenMP false
376#ifndef CODI_EnableOpDiLib
378 #define CODI_EnableOpDiLib false
380#if CODI_EnableOpDiLib && !CODI_EnableOpenMP
381 #error CODI_EnableOpDiLib == true is incompatible with CODI_EnableOpenMP == false.
393#define CODI_FunctionAttributes CODI_CUDAFunctionAttributes
395#ifndef CODI_AnnotateBranchLikelihood
397 #define CODI_AnnotateBranchLikelihood CODI_HasCpp20
399#if CODI_AnnotateBranchLikelihood
401 #define CODI_Likely [[likely]]
403 #define CODI_Unlikely [[unlikely]]
408 #define CODI_Unlikely
412#undef CODI_AnnotateBranchLikelihood
414#ifndef CODI_AvoidedInlines
416 #define CODI_AvoidedInlines 1
418#if CODI_AvoidedInlines
419 #if defined(_MSC_VER)
420 #define CODI_NO_INLINE __declspec(noinline)
422 #define CODI_NO_INLINE __attribute__((noinline))
426 #define CODI_NO_INLINE
430#undef CODI_AvoidedInlines
432#ifndef CODI_EnableAssert
434 #define CODI_EnableAssert false
437 #if CODI_EnableAssert
438 #define codiAssert(x) ::codi::checkAndOutputAssert(x, CODI_TO_STRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__)
441 #define codiAssert(x)
446#undef CODI_EnableAssert
448#ifndef CODI_ForcedInlines
450 #define CODI_ForcedInlines 0
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
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))
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
469 #define CODI_INLINE CODI_FunctionAttributes inline
471 #define CODI_INLINE_NO_FA inline
473 #define CODI_LAMBDA_INLINE
477#undef CODI_ForcedInlines
481 #define CODI_Restrict 1
484 #if defined(__INTEL_COMPILER) | defined(_MSC_VER)
485 #define CODI_RESTRICT __restrict
486 #elif defined(__GNUC__)
487 #define CODI_RESTRICT __restrict__
489 #warning Could not determine compiler for restrict definitions. Using nothing.
491 #define CODI_RESTRICT
495 #define CODI_RESTRICT
#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