Helper structure for storing low level functions and their arguments on a tape. More...
#include <lowLevelFunctionCreationUtilities.hpp>
Public Types | |
template<typename T > | |
using | ActiveStoreTrait = ActiveArgumentStoreTraits<T> |
Utilities for handling an active argument. | |
using | ActivityStoreType |
Type for the activity store. Currently limited to 64 variables. | |
template<typename T , typename S = T> | |
using | PassiveStoreTrait = PassiveArgumentStoreTraits<T, S> |
Functionality for handling a passive argument. | |
Static Public Member Functions | |
Action creation | |
static RestoreActions | createRestoreActions (bool isInput, bool isOutput, bool isInputActive, bool primalRequired) |
Collect the restore actions for an argument in a RestoreActions instance. | |
static StoreActions | createStoreActions (bool tapeActive, bool isInput, bool isOutput, bool isInputActive, bool primalRequired) |
Collect the store actions for an argument in a StoreActions instance. | |
Argument activity | |
static size_t | countActivitySize () |
Return the size of the activity structure. | |
static bool | getActivity (ActivityStoreType const &activity, size_t arg) |
Check the activity structure for activity of a specific argument. | |
static void | restoreActivity (ByteDataView *fixedStore, ActivityStoreType &activity) |
Restore the activity structure from the data stream. | |
static void | setActivity (ActivityStoreType &activity, size_t arg, bool active) |
Store the activity of an argument in the activity structure. | |
static void | storeActivity (ByteDataView *fixedStore, ActivityStoreType const &activity) |
Store the activity structure in the data stream. | |
Static Public Attributes | |
static size_t constexpr | ActiveArguments |
See LowLevelFunctionCreationUtilities. | |
static size_t constexpr | TokenSize = sizeof(codi::Config::LowLevelFunctionToken) |
Token size for the low level function token. | |
Helper structure for storing low level functions and their arguments on a tape.
The process of storing the data for a low level function consists of several steps:
In the following sections, the steps are explained. For an example implementation, see codi::ExtFunc_matrixMatrixMultiplication.
If the tape is not active, then no low level function should be created. Otherwise, each active argument can be checked with ActiveStoreTrait::isActive()
. If all active arguments are passive, that is, all underlying CoDiPack types are passive, then the low level function should also not be created.
Currently the number of low-level function arguments is limited to 64. Note that the limit applies to the number of arguments passed to the low-level function, which is in general much smaller than the number of active CoDiPack values passed to the function. Matrix-matrix multiplication, for example, has two arguments (two matrices), but each matrix consists of multiple CoDiPack values.
The required size for storing all arguments can be determined with ActiveStoreTrait::countSize()
and PassiveStoreTrait::countSize()
.
The total size is then:
Depending on the activity of the arguments and if the primal values of the arguments are required for the derivative computation, the required size may vary.
A call to LowLevelFunctionTapeInterface::pushLowLevelFunction() adds the low level function to the tape and populates the codi::ByteDataView for the fixed and dynamic data.
Usually, the following needs to be done:
ActiveStoreTrait::store
and PassiveArgumentStoreTraits::store
for all arguments.There are two options.
ActiveStoreTrait::ArgumentStore::value()
and can be used to call a passive version of the low level function.After the low level function is evaluated, each active output argument needs to be registered on the tape with a call to ActiveStoreTrait::setExternalFunctionOutput()
.
The restoring process needs to read the data in the same order as it was written. The following needs to be done:
ActiveStoreTrait::restore()
or PassiveStoreTrait::restore()
.Currently, it is assumed that all data is stored in the binary data stream of the tape. This data stream is automatically reset during a tape reset, which releases the data. There is currently no mechanism to automatically delete heap allocated data in the store methods.
T_ActiveArguments | The number of active input arguments. |
using codi::LowLevelFunctionCreationUtilities< T_ActiveArguments >::ActivityStoreType |
Type for the activity store. Currently limited to 64 variables.
|
staticconstexpr |