CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::LowLevelFunctionTapeInterface< T_Real, T_Gradient, T_Identifier > Struct Template Reference

Add functions with custom derivatives to the tape. Can, e.g, be used to optimize small recurring functions like matrix matrix multiplication. More...

#include <lowLevelFunctionTapeInterface.hpp>

Inheritance diagram for codi::LowLevelFunctionTapeInterface< T_Real, T_Gradient, T_Identifier >:

Public Types

using Gradient = T_Gradient
 See LowLevelFunctionTapeInterface.
 
using Identifier = T_Identifier
 See LowLevelFunctionTapeInterface.
 
using Real = T_Real
 See LowLevelFunctionTapeInterface.
 

Interface definition

TemporaryMemorygetTemporaryMemory ()
 Temporary memory that can be used for dynamic data both during the evaluation and the recording.
 
void pushLowLevelFunction (Config::LowLevelFunctionToken token, size_t size, ByteDataView &data)
 Push a low level function to the tape.
 
Config::LowLevelFunctionToken registerLowLevelFunction (LowLevelFunctionEntry< LowLevelFunctionTapeInterface, Real, Identifier > const &entry)
 Register a low level function on the tape.
 
template<LowLevelFunctionEntryCallKind callType, typename... Args>
static void callLowLevelFunction (LowLevelFunctionTapeInterface &tape, bool forward, size_t &curLLFByteDataPos, char *dataPtr, size_t &curLLFInfoDataPos, Config::LowLevelFunctionToken *const tokenPtr, Config::LowLevelFunctionDataSize *const dataSizePtr, Args &&... args)
 Internal function for evaluating a low level function entry.
 

Detailed Description

template<typename T_Real, typename T_Gradient, typename T_Identifier>
struct codi::LowLevelFunctionTapeInterface< T_Real, T_Gradient, T_Identifier >

Add functions with custom derivatives to the tape. Can, e.g, be used to optimize small recurring functions like matrix matrix multiplication.

A low level function like the matrix matrix multiplication can be added with this interface. First, the function needs to be registered with registerLowLevelFunction. This needs to be done only once, after this, the function is generally available. It can then be pushed as often as required with pushLowLevelFunction. Each push can be accompanied by different data, e.g., the specific matrices used by individual matrix matrix multiplications.

The user can write arbitrary data into the byte data stream. There is no requirement on the layout.

Template Parameters
T_RealThe computation type of a tape, usually chosen as ActiveType::Real.
T_GradientThe gradient type of a tape, usually chosen as ActiveType::Gradient.
T_IdentifierThe adjoint/tangent identification type of a tape, usually chosen as ActiveType::Identifier.

Member Function Documentation

◆ callLowLevelFunction()

template<typename T_Real , typename T_Gradient , typename T_Identifier >
template<LowLevelFunctionEntryCallKind callType, typename... Args>
static void codi::LowLevelFunctionTapeInterface< T_Real, T_Gradient, T_Identifier >::callLowLevelFunction ( LowLevelFunctionTapeInterface< T_Real, T_Gradient, T_Identifier > & tape,
bool forward,
size_t & curLLFByteDataPos,
char * dataPtr,
size_t & curLLFInfoDataPos,
Config::LowLevelFunctionToken *const tokenPtr,
Config::LowLevelFunctionDataSize *const dataSizePtr,
Args &&... args )
static

Internal function for evaluating a low level function entry.

The positions curLLFByteDataPos, and curLLFInfoDataPos are advanced according to forward. If forward is true, they are increment otherwise they are decremented.

Parameters
tapeThe tape that is evaluated.
forwardIf the tape is forward evaluated.
curLLFByteDataPosPosition of dynamic data.
dataPtrPointer for dynamic data.
curLLFInfoDataPosPosition of info data.
tokenPtrPointer for token data.
dataSizePtrPointer for data size data.
argsAdditional arguments for the function call.
Template Parameters
callTypeThe function type that is called.

◆ pushLowLevelFunction()

template<typename T_Real , typename T_Gradient , typename T_Identifier >
void codi::LowLevelFunctionTapeInterface< T_Real, T_Gradient, T_Identifier >::pushLowLevelFunction ( Config::LowLevelFunctionToken token,
size_t size,
ByteDataView & data )

Push a low level function to the tape.

Allocates memory with the requested size on the byte data stream. data is initialized for accessing this allocated memory. After the call, it can be used to write data to the data stream. token is the token from registerLowLevelFunction.

See LowLevelFunctionTapeInterface for the expected data layout.


The documentation for this struct was generated from the following file: