Helper class for the implementation of an external function with Enzyme in CoDiPack. More...
#include <enzymeExternalFunctionHelper.hpp>
Public Types | |
using | Base = ExternalFunctionHelper<Type> |
Base class abbreviation. | |
using | Identifier = typename Type::Identifier |
See LhsExpressionInterface. | |
using | PrimalFunc = typename Base::PrimalFunc |
See ExternalFunctionHelper. | |
using | Real = typename Type::Real |
See LhsExpressionInterface. | |
using | Tape = typename Type::Tape |
See LhsExpressionInterface. | |
using | Type = T_Type |
See ExternalFunctionHelper. | |
Public Types inherited from codi::ExternalFunctionHelper< T_Type, T_Synchronization, T_ThreadInformation > | |
using | ForwardFunc |
Function interface for the forward AD call of an external function. | |
using | Identifier = typename Type::Identifier |
See LhsExpressionInterface. | |
using | PrimalFunc = void (*)(Real const* x, size_t m, Real* y, size_t n, ExternalFunctionUserData* d) |
Function interface for the primal call of an external function. | |
using | Real = typename Type::Real |
See LhsExpressionInterface. | |
using | ReverseFunc |
Function interface for the reverse AD call of an external function. | |
using | Synchronization = T_Synchronization |
See ExternalFunctionHelper. | |
using | Tape = typename Type::Tape |
See LhsExpressionInterface. | |
using | ThreadInformation = T_ThreadInformation |
See ExternalFunctionHelper. | |
using | Type = T_Type |
See ExternalFunctionHelper. | |
Public Member Functions | |
template<PrimalFunc func> | |
void | callAndAddToTape () |
template<PrimalFunc func> | |
void | callAndAddToTape (Type const *x, size_t m, Type *y, size_t n) |
Adds all inputs in x and outputs in y to the external function and then calls callAndAddToTape(). | |
EnzymeExternalFunctionHelper () | |
Constructor. | |
Public Member Functions inherited from codi::ExternalFunctionHelper< T_Type, T_Synchronization, T_ThreadInformation > | |
void | addInput (Type const &input) |
Add an input value. | |
void | addOutput (Type &output) |
Add an output value. | |
void | addToTape (ReverseFunc reverseFunc, ForwardFunc forwardFunc=nullptr, PrimalFunc primalFunc=nullptr) |
Add the external function to the tape. | |
template<typename Data > | |
void | addUserData (Data const &data) |
Add user data. See ExternalFunctionUserData for details. | |
void | callPrimalFunc (PrimalFunc func) |
template<typename FuncObj , typename... Args> | |
void | callPrimalFuncWithADType (FuncObj &func, Args &&... args) |
void | disableInputPrimalStore () |
Do not store primal input values. In function calls, pointers to primal inputs will be null. | |
void | disableOutputPrimalStore () |
Do not store primal output values. In function calls, pointers to primal outputs will be null. | |
void | disableRenewOfPrimalValues () |
Do not update the inputs and outputs from the primal values of the tape. Has no effect on Jacobian tapes. | |
void | enableReallocationOfPrimalValueVectors () |
ExternalFunctionHelper (bool primalFuncUsesADType=false) | |
Constructor. | |
ExternalFunctionUserData & | getExternalFunctionUserData () |
~ExternalFunctionHelper () | |
Destructor. | |
Additional Inherited Members | |
Protected Attributes inherited from codi::ExternalFunctionHelper< T_Type, T_Synchronization, T_ThreadInformation > | |
EvalData * | data |
External function data. | |
bool | getPrimalValuesFromPrimalValueVector |
std::vector< Type * > | outputValues |
References to output values. | |
bool | reallocatePrimalVectors |
bool | storeInputOutputForPrimalEval |
If a primal call with a self-implemented function will be done. | |
bool | storeInputPrimals |
If input primals are stored. Can be disabled by the user. | |
bool | storeOutputPrimals |
If output primals are stored. Can be disabled by the user. | |
std::vector< Real > | y |
Shared vector of output variables. | |
Helper class for the implementation of an external function with Enzyme in CoDiPack.
The class helps the user to create derivative functions with Enzyme and add them to the tape. See ExternalFunctionHelper for the general configuration options and procedures. This class only supports the operation mode 1 "Implemented primal function". In this implementation, this mode requires just one call to callAndAddToTape() which calls the primal function and adds it to the tape.
The procedure of pushing a differentiated function with Enzyme is as follows.
An example is:
This helper provides an additional overload where the inputs and outputs can be directly added:
The full example can be found at Example 24 - Enzyme external function helper.
T_Type | The CoDiPack type that is used outside of the external function. |
|
inline |
Calls the primal function and adds the Enzyme generated functions to the tape.
Is a combination of ExternalFunctionHelper::callPrimalFunc and ExternalFunctionHelper::addToTape.