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_SortIndicesOnReset
261 #define CODI_SortIndicesOnReset true
265#undef CODI_SortIndicesOnReset
267#ifndef CODI_VariableAdjointInterfaceInPrimalTapes
269 #define CODI_VariableAdjointInterfaceInPrimalTapes 0
273#if CODI_VariableAdjointInterfaceInPrimalTapes
274 #define ADJOINT_VECTOR_TYPE VectorAccessInterface<Real, Identifier>
277 #define ADJOINT_VECTOR_TYPE Gradient
281#ifndef CODI_ReversalZeroesAdjoints
283 #define CODI_ReversalZeroesAdjoints true
285#if CODI_VariableAdjointInterfaceInPrimalTapes && !CODI_ReversalZeroesAdjoints
286 #warning CODI_ReversalZeroesAdjoints == false is incompatible with CODI_VariableAdjointInterfaceInPrimalTapes == true.
290#undef CODI_ReversalZeroesAdjoints
298#ifndef CODI_ADWorkflowEvents
300 #define CODI_ADWorkflowEvents true
304#undef CODI_ADWorkflowEvents
306#ifndef CODI_PreaccEvents
308 #define CODI_PreaccEvents false
312#undef CODI_PreaccEvents
314#ifndef CODI_StatementEvents
316 #define CODI_StatementEvents false
320#undef CODI_StatementEvents
322#ifndef CODI_IndexEvents
324 #define CODI_IndexEvents false
328#undef CODI_IndexEvents
335#ifndef CODI_EnableEigen
337 #define CODI_EnableEigen 0
343#ifndef CODI_EnableEnzyme
345 #define CODI_EnableEnzyme false
351#ifndef CODI_EnableMPI
353 #define CODI_EnableMPI false
359#ifndef CODI_EnableOpenMP
361 #define CODI_EnableOpenMP false
367#ifndef CODI_EnableOpDiLib
369 #define CODI_EnableOpDiLib false
371#if CODI_EnableOpDiLib && !CODI_EnableOpenMP
372 #error CODI_EnableOpDiLib == true is incompatible with CODI_EnableOpenMP == false.
384#define CODI_FunctionAttributes CODI_CUDAFunctionAttributes
386#ifndef CODI_AnnotateBranchLikelihood
388 #define CODI_AnnotateBranchLikelihood CODI_HasCpp20
390#if CODI_AnnotateBranchLikelihood
392 #define CODI_Likely [[likely]]
394 #define CODI_Unlikely [[unlikely]]
399 #define CODI_Unlikely
403#undef CODI_AnnotateBranchLikelihood
405#ifndef CODI_AvoidedInlines
407 #define CODI_AvoidedInlines 1
409#if CODI_AvoidedInlines
410 #if defined(_MSC_VER)
411 #define CODI_NO_INLINE __declspec(noinline)
413 #define CODI_NO_INLINE __attribute__((noinline))
417 #define CODI_NO_INLINE
421#undef CODI_AvoidedInlines
423#ifndef CODI_EnableAssert
425 #define CODI_EnableAssert false
428 #if CODI_EnableAssert
429 #define codiAssert(x) ::codi::checkAndOutputAssert(x, CODI_TO_STRING(x), __PRETTY_FUNCTION__, __FILE__, __LINE__)
432 #define codiAssert(x)
437#undef CODI_EnableAssert
439#ifndef CODI_ForcedInlines
441 #define CODI_ForcedInlines 0
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))
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
457 #define CODI_INLINE CODI_FunctionAttributes inline
459 #define CODI_INLINE_NO_FA inline
463#undef CODI_ForcedInlines
#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