Full EventSystem implementation for reverse tapes. More...
#include <eventSystem.hpp>
Public Types | |
using | Base = EventSystemBase<Tape> |
Base class abbreviation. | |
using | Event = typename Base::Event |
See EventSystemBase. | |
using | Gradient = typename Tape::Gradient |
Gradient type used by the tape. | |
using | Handle = typename Base::Handle |
See EventSystemBase. | |
using | Identifier = typename Tape::Identifier |
Identifier type used by the tape. | |
using | Index = typename Tape::Identifier |
Index type used by the tape. | |
using | Position = typename Tape::Position |
using | Real = typename Tape::Real |
Floating point type the tape is based on. | |
using | Tape = T_Tape |
See EventSystem. | |
using | VectorAccess = VectorAccessInterface<Real, Identifier> |
Vector access interface that is compatible with the Tape. | |
Public Types inherited from codi::EventSystemBase< T_Tape > | |
using | Handle = size_t |
Handle that identifies a registered callback. | |
using | Identifier = typename Tape::Identifier |
Identifier type used by the tape. | |
using | Real = typename Tape::Real |
Floating point type the tape is based on. | |
using | Tape = T_Tape |
See EventSystemBase. | |
Static Public Member Functions | |
AD workflow events | |
static Handle | registerTapeStartRecordingListener (void(*callback)(Tape &, void *), void *customData=nullptr) |
Register callbacks for TapeStartRecording events. | |
static void | notifyTapeStartRecordingListeners (Tape &tape) |
Invoke callbacks for TapeStartRecording events. | |
static Handle | registerTapeStopRecordingListener (void(*callback)(Tape &, void *), void *customData=nullptr) |
Register callbacks for TapeStopRecording events. | |
static void | notifyTapeStopRecordingListeners (Tape &tape) |
Invoke callbacks for TapeStopRecording events. | |
static Handle | registerTapeRegisterInputListener (void(*callback)(Tape &, Real &, Identifier &, void *), void *customData=nullptr) |
Register callbacks for TapeRegisterInput events. | |
static void | notifyTapeRegisterInputListeners (Tape &tape, Real &value, Identifier &identifier) |
Invoke callbacks for TapeRegisterInput events. | |
static Handle | registerTapeRegisterOutputListener (void(*callback)(Tape &, Real &, Identifier &, void *), void *customData=nullptr) |
Register callbacks for TapeRegisterOutput events. | |
static void | notifyTapeRegisterOutputListeners (Tape &tape, Real &value, Identifier &identifier) |
Invoke callbacks for TapeRegisterOutput events. | |
static Handle | registerTapeEvaluateListener (void(*callback)(Tape &, Position const &, Position const &, VectorAccess *, EventHints::EvaluationKind, EventHints::Endpoint, void *), void *customData=nullptr) |
Register callbacks for TapeEvaluate events. | |
static void | notifyTapeEvaluateListeners (Tape &tape, Position const &start, Position const &end, VectorAccess *adjoint, EventHints::EvaluationKind evalKind, EventHints::Endpoint endpoint) |
Invoke callbacks for TapeEvaluate events. | |
static Handle | registerTapeResetListener (void(*callback)(Tape &, Position const &, EventHints::Reset, bool, void *), void *customData=nullptr) |
Register callbacks for TapeReset events. | |
static void | notifyTapeResetListeners (Tape &tape, Position const &position, EventHints::Reset kind, bool clearAdjoints) |
Invoke callbacks for TapeReset events. | |
Preaccumulation events | |
static Handle | registerPreaccStartListener (void(*callback)(Tape &, void *), void *customData=nullptr) |
Register callbacks for PreaccStart events. | |
static void | notifyPreaccStartListeners (Tape &tape) |
Invoke callbacks for PreaccStart events. | |
static Handle | registerPreaccFinishListener (void(*callback)(Tape &, void *), void *customData=nullptr) |
Register callbacks for PreaccFinish events. | |
static void | notifyPreaccFinishListeners (Tape &tape) |
Invoke callbacks for PreaccFinish events. | |
static Handle | registerPreaccAddInputListener (void(*callback)(Tape &, Real const &, Identifier const &, void *), void *customData=nullptr) |
Register callbacks for PreaccAddInput events. | |
static void | notifyPreaccAddInputListeners (Tape &tape, Real const &value, Identifier const &identifier) |
Invoke callbacks for PreaccAddInput events. | |
static Handle | registerPreaccAddOutputListener (void(*callback)(Tape &, Real &, Identifier &, void *), void *customData=nullptr) |
Register callbacks for PreaccAddOutput events. | |
static void | notifyPreaccAddOutputListeners (Tape &tape, Real &value, Identifier &identifier) |
Invoke callbacks for PreaccAddOutput events. | |
Statement events | |
static Handle | registerStatementStoreOnTapeListener (void(*callback)(Tape &, Identifier const &, Real const &, size_t, Identifier const *, Real const *, void *), void *customData=nullptr) |
Register callbacks for StatementStoreOnTape events. | |
static void | notifyStatementStoreOnTapeListeners (Tape &tape, Identifier const &lhsIdentifier, Real const &newValue, size_t numActiveVariables, Identifier const *rhsIdentifiers, Real const *jacobians) |
Invoke callbacks for StatementStoreOnTape events. | |
static Handle | registerStatementEvaluateListener (void(*callback)(Tape &, Identifier const &, size_t, Real const *, void *), void *customData=nullptr) |
Register callbacks for StatementEvaluate events. | |
static void | notifyStatementEvaluateListeners (Tape &tape, Identifier const &lhsIdentifier, size_t sizeLhsAdjoint, Real const *lhsAdjoint) |
Invoke callbacks for StatementEvaluate events. | |
static Handle | registerStatementEvaluatePrimalListener (void(*callback)(Tape &, Identifier const &, Real const &, void *), void *customData=nullptr) |
Register callbacks for StatementEvaluatePrimal events. | |
static void | notifyStatementEvaluatePrimalListeners (Tape &tape, Identifier const &lhsIdentifier, Real const &lhsValue) |
Invoke callbacks for StatementEvaluatePrimal events. | |
Index handling events | |
static Handle | registerIndexAssignListener (void(*callback)(Index const &, void *), void *customData=nullptr) |
Register callbacks for IndexAssign events. | |
static void | notifyIndexAssignListeners (Index const &index) |
Invoke callbacks for IndexAssign events. | |
static Handle | registerIndexFreeListener (void(*callback)(Index const &, void *), void *customData=nullptr) |
Register callbacks for IndexFree events. | |
static void | notifyIndexFreeListeners (Index const &index) |
Invoke callbacks for IndexFree events. | |
static Handle | registerIndexCopyListener (void(*callback)(Index const &, void *), void *customData=nullptr) |
Register callbacks for IndexCopy events. | |
static void | notifyIndexCopyListeners (Index const &index) |
Invoke callbacks for IndexCopy events. | |
Static Public Member Functions inherited from codi::EventSystemBase< T_Tape > | |
static Handle | registerStatementPrimalListener (void(*callback)(Tape &, Real const &, Identifier const &, Real const &, EventHints::Statement, void *), void *customData=nullptr) |
Register callbacks for StatementPrimal events. | |
static void | notifyStatementPrimalListeners (Tape &tape, Real const &lhsValue, Identifier const &lhsIdentifier, Real const &newValue, EventHints::Statement statement) |
Invoke callbacks for StatementPrimal events. | |
static void | notifyStatementPrimalListeners (Tape &&tape, Real const &lhsValue, Identifier const &lhsIdentifier, Real const &newValue, EventHints::Statement statement) |
Invoke callbacks for StatementPrimal events. | |
static void | deregisterListener (Handle const &handle) |
Deregister a listener. | |
Additional Inherited Members | |
Protected Types inherited from codi::EventSystemBase< T_Tape > | |
using | Callback = void* |
enum class | Event { TapeStartRecording , TapeStopRecording , TapeRegisterInput , TapeRegisterOutput , TapeEvaluate , TapeReset , PreaccStart , PreaccFinish , PreaccAddInput , PreaccAddOutput , StatementPrimal , StatementStoreOnTape , StatementEvaluate , StatementEvaluatePrimal , IndexCreate , IndexAssign , IndexFree , IndexCopy , Count } |
Full set of events. | |
using | EventListenerMap = std::map<Event, std::list<std::pair<Handle, std::pair<Callback, void*>>>> |
Map that links events to registered callbacks and their associated custom data. | |
Static Protected Member Functions inherited from codi::EventSystemBase< T_Tape > | |
static EventListenerMap & | getListeners () |
Access the static EventListenerMap. | |
template<typename TypedCallback , typename... Args> | |
static void | internalNotifyListeners (bool const enabled, Event event, Args &&... args) |
Internal method for callback invocation. | |
template<typename TypedCallback > | |
static Handle | internalRegisterListener (bool const enabled, Event event, TypedCallback callback, void *customData) |
Internal method for callback registration. | |
Full EventSystem implementation for reverse tapes.
See EventSystemBase for a general description of the event system.
This class implements methods for all of the remaining events.
T_Tape | Tape type associated with the event system. |
using codi::EventSystem< T_Tape >::Position = typename Tape::Position |
Position used by the tape.
|
inlinestatic |
Invoke callbacks for IndexAssign events.
IndexAssign events occur when an index management assigns an index to a left hand side variable. This includes cases where an index is left in place, in the sense that it is freed and immediately assigned again. It is unspecified whether the event occurs before or after the actual index assignment.
index | The assigned index. |
|
inlinestatic |
Invoke callbacks for IndexCopy events.
IndexCopy events occur when an index management assigns an index to a left hand side variable by copying it from the right hand side variable. It is unspecified whether the event occurs before or after the actual index copy operation.
index | The copied index. |
|
inlinestatic |
Invoke callbacks for IndexFree events.
IndexFree events occur when an index management frees an index of a left hand side variable. This includes cases where an existing index is overwritten by a new one, and cases where an index is left in place (in the sense that it is freed and immediately assigned again). It is unspecified whether the event occurs before or after the actual index free operation.
index | The freed index. |
|
inlinestatic |
Invoke callbacks for PreaccAddInput events.
A PreaccAddInput event occurs when an input is added via a PreaccumulationHelper, e.g., by passing them to start or by calling addInput. The event occurs before the internal registration.
tape | Reference to the tape. |
value | The value of the input that is registered. |
identifier | The identifier of the input that is registered. |
|
inlinestatic |
Invoke callbacks for PreaccAddOutput events.
A PreaccAddOutput event occurs when an output is added via a PreaccumulationHelper, e.g., by passing them to finish or by calling addOutput. The event occurs before the internal registration.
tape | Reference to the tape. |
value | The value of the output that is registered. |
identifier | The identifier of the output that is registered. |
|
inlinestatic |
Invoke callbacks for PreaccFinish events.
A PreaccFinish event occurs whenever a preaccumulation is finished via a PreaccumulationHelper, after everything related to the preaccumulation is completed. Note that there may be TapeEvaluate, TapeReset, and StatementStore events due to preaccumulation after the call to finish but before this event.
tape | Reference to the tape. |
|
inlinestatic |
Invoke callbacks for PreaccStart events.
A PreaccStart event occurs whenever a preaccumulation is started via a PreaccumulationHelper, prior to internal preparations for the preaccumulation.
tape | Reference to the tape. |
|
inlinestatic |
Invoke callbacks for StatementEvaluate events.
A StatementEvaluate occurs whenever a tape evaluates a statement. For forward evaluations, the event occurs after the statement evaluation. For reverse evaluations, the event occurs before statement evaluation and before the left hand side adjoint is zeroed, if applicable.
tape | Reference to the tape. |
lhsIdentifier | Left hand side identifier. |
sizeLhsAdjoint | Number of left hand side adjoint components. |
lhsAdjoint | Pointer to the left hand side adjoint components. |
|
inlinestatic |
Invoke callbacks for StatementEvaluatePrimal events.
A StatementEvaluatePrimal occurs whenever a primal value tape evaluates a statement. For forward and reverse evaluations, it occurs in addition to StatementEvaluate events. Primal tape evaluations produce only StatementEvaluatePrimal events. StatementEvaluatePrimal events occur after StatementEvaluate events. For primal evaluations, they occur after the evaluation of the primal statement.
tape | Reference to the tape. |
lhsIdentifier | Identifier of the left hand side variable. |
lhsValue | Value of the left hand side variable. |
|
inlinestatic |
Invoke callbacks for StatementStoreOnTape events.
A StatementStoreOnTape event occurs whenever a statement is stored on an associated tape. Note that all statements emit StatementPrimal events, but might not be stored on the tape, for example because nothing is active. The event is emitted after storing all data on the tape, after the left hand side has been assigned an identifier, but before the left hand side updates its primal value.
tape | Reference to the tape. |
lhsIdentifier | Identifier assigned to the left hand side. |
newValue | Value that is assigned to the left hand side. |
numActiveVariables | Number of active variables on the right hand side. |
rhsIdentifiers | Pointer to numActiveVariables identifiers. |
jacobians | Pointer to numActiveVariables Jacobian values. |
|
inlinestatic |
Invoke callbacks for TapeEvaluate events.
TapeEvaluate events occur both prior to and after the evaluation process, with correspondingly different endpoint parameter. The tape evaluation is classified by the evalKind parameter.
tape | Reference to the tape. |
start | Starting position of the evaluation. |
end | End position of the evaluation. |
adjoint | Vector access interface that provides access to adjoint variables. |
evalKind | Indicates whether the evaluation is primal, forward, or reverse. |
endpoint | Indicates whether this is the event before or after the tape evaluation. |
|
inlinestatic |
Invoke callbacks for TapeRegisterInput events.
A TapeRegisterInput event occurs whenever registerInput calls are made to an associated tape, after the internal input registration is completed.
tape | Reference to the tape. |
value | The value of the input that has been registered. |
identifier | The new identifier of the input that has been registered. |
|
inlinestatic |
Invoke callbacks for TapeRegisterOutput events.
A TapeRegisterOutput event occurs whenever registerOutput calls are made to the tape, after the internal output registration is completed.
tape | Reference to the tape. |
value | The value of the output that has been registered. |
identifier | The new identifier of the output that has been registered. |
|
inlinestatic |
Invoke callbacks for TapeReset events.
A TapeReset event occurs in the course of reset, resetTo, and resetHard calls made to an associated tape, the respective origin is indicated by kind. For Jacobian tapes, the event occurs before any internal reset takes place. For primal value tapes, some internal reset operations have already been performed when the event occurs.
tape | Reference to the tape. |
position | Position to which we reset, zero position for full and hard resets. |
kind | Reset kind, see codi::EventHints::Reset. |
clearAdjoints | Indicates whether adjoints are zeroed. |
|
inlinestatic |
Invoke callbacks for TapeStartRecording events.
A TapeStartRecording event is triggered whenever an associated tape is set active. The event occurs before the internal tape status change.
tape | Reference to the tape. |
|
inlinestatic |
Invoke callbacks for TapeStopRecording events.
A TapeStopRecording event is triggered whenever an associated type is set passive. The event occurs before the internal tape status change.
tape | Reference to the tape. |
|
inlinestatic |
Register callbacks for IndexAssign events.
See notifyIndexAssignListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for IndexCopy events.
See notifyIndexCopyListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for IndexFree events.
See notifyIndexFreeListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for PreaccAddInput events.
See notifyPreaccAddInputListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for PreaccAddOutput events.
See notifyPreaccAddOutputListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for PreaccFinish events.
See notifyPreaccFinishListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for PreaccStart events.
See notifyPreaccStartListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for StatementEvaluate events.
See notifyStatementEvaluateListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for StatementEvaluatePrimal events.
See notifyStatementEvaluatePrimalListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for StatementStoreOnTape events.
See notifyStatementStoreOnTapeListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for TapeEvaluate events.
See notifyTapeEvaluateListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for TapeRegisterInput events.
See notifyTapeRegisterInputListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for TapeRegisterOutput events.
See notifyTapeRegisterOutputListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for TapeReset events.
See notifyTapeResetListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for TapeStartRecording events.
See notifyTapeStartRecordingListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |
|
inlinestatic |
Register callbacks for TapeStopRecording events.
See notifyTapeStopRecordingListeners for the callback parameters and event order.
callback | Callback to be invoked. |
customData | Optional. Custom data that should be linked with the callback, otherwise nullptr. |