Documentation 6b54b78464
Loading...
Searching...
No Matches
AD Namespace Reference

Contains routines for the reverse mode of AD. In case there is no reverse type configured, they have no effect at all, and so the real versions of the routined are after #else. More...

Classes

struct  DebugControl
 Struct to store information about errors during a tag debug run. More...
 

Typedefs

using Identifier = int
 

Enumerations

enum class  TAPE_DEBUG_OPTION {
  ALLOW_PREACC , ACTIVATE_PREACC , ALLOW_ZONE , ALLOW_ALL_ZONES ,
  ACTIVATE_ALL_ZONES , ACTIVATE_ALL_ERRORS , MULTIZONE_TAGS , INIT_RUN ,
  CHECK_RUN
}
 

Functions

void StartRecording ()
 Start the recording of the operations and involved variables. If called, the computational graph of all operations occuring after the call will be stored, starting with the variables registered with RegisterInput.
 
bool PauseRecording ()
 Pause the recording of the operations and involved variables. If called, all operations occuring after the call will not be stored on the computational graph.
 
void ResumeRecording (bool wasActive)
 Resume the recording of the operations and variables after the recording had been paused.
 
void StopRecording ()
 Stops the recording of the operations and variables.
 
bool TapeActive ()
 Check if the tape is active.
 
template<typename Comm >
void PrintStatistics (Comm communicator, bool printingRank)
 Prints out tape statistics.
 
void RegisterInput (su2double &data)
 Registers the variable as an input. I.e. as a leaf of the computational graph.
 
void RegisterOutput (su2double &data)
 Registers the variable as an output. I.e. as the root of the computational graph.
 
void ResizeAdjoints ()
 Resize the adjoint vector, for subsequent access without bounds checking.
 
void BeginUseAdjoints ()
 Declare that the adjoints are being used, to protect against resizing.
 
void EndUseAdjoints ()
 Declare that the adjoints are no longer being used.
 
void SetDerivative (Identifier index, const double val)
 Sets the adjoint value at index to val.
 
double GetDerivative (Identifier index)
 Extracts the adjoint value at index.
 
Identifier GetPassiveIndex ()
 Returns the identifier that represents an inactive variable.
 
void ClearAdjoints ()
 Clears the currently stored adjoints but keeps the computational graph.
 
void ComputeAdjoint ()
 Computes the adjoints, i.e. the derivatives of the output with respect to the input variables.
 
void ComputeAdjoint (unsigned short enter, unsigned short leave)
 Computes the adjoints, i.e. the derivatives of the output with respect to the input variables.
 
void ComputeAdjointForward ()
 Computes the adjoints, i.e., the derivatives of the output with respect to the input variables, using forward tape evaluation.
 
void Reset ()
 Reset the tape structure to be ready for a new recording.
 
void ResetInput (su2double &data)
 Reset the variable (set index to zero).
 
template<class... Ts>
void SetPreaccIn (Ts &&... data)
 Sets the scalar inputs of a preaccumulation section.
 
template<class T >
void SetPreaccIn (const T &data, const int size)
 Sets the input variables of a preaccumulation section using a 1D array.
 
template<class T >
void SetPreaccIn (const T &data, const int size_x, const int size_y)
 Sets the input variables of a preaccumulation section using a 2D array.
 
void StartPreacc ()
 Starts a new preaccumulation section and sets the input variables.
 
template<class... Ts>
void SetPreaccOut (Ts &&... data)
 Sets the scalar outputs of a preaccumulation section.
 
template<class T >
void SetPreaccOut (T &&data, const int size)
 Sets the output variables of a preaccumulation section using a 1D array.
 
template<class T >
void SetPreaccOut (T &&data, const int size_x, const int size_y)
 Sets the input variables of a preaccumulation section using a 2D array.
 
void EndPreacc ()
 Ends a preaccumulation section and computes the local Jacobi matrix of a code section using the variables set with SetLocalInput(), SetLocalOutput() and pushes a statement for each output variable to the AD tape.
 
void SetExtFuncIn (su2double &data)
 Sets the scalar input of a externally differentiated function.
 
template<class T >
void SetExtFuncIn (const T &data, const int size)
 Sets the input variables of a externally differentiated function using a 1D array.
 
template<class T >
void SetExtFuncIn (const T &data, const int size_x, const int size_y)
 Sets the input variables of a externally differentiated function using a 2D array.
 
void SetExtFuncOut (su2double &data)
 Sets the scalar output of a externally differentiated function.
 
template<class T >
void SetExtFuncOut (T &&data, const int size)
 Sets the output variables of a externally differentiated function using a 1D array.
 
template<class T >
void SetExtFuncOut (T &&data, const int size_x, const int size_y)
 Sets the output variables of a externally differentiated function using a 2D array.
 
void SetIndex (Identifier &index, const su2double &data)
 Evaluates and saves gradient data from a variable.
 
void SetTag (int tag)
 Sets the tag tape to a specific tag.
 
int GetTag ()
 Gets the current tag.
 
int ComputeTag (unsigned short iZone)
 Compute the zone-specific tag.
 
void ClearTagOnVariable (su2double &v)
 Sets the tag of a variable to 0.
 
void SetTagOnVariable (su2double &v, int zone_tag=0, int run_tag=0)
 Sets the tag of a variable to a specified value.
 
void SetDebugControl (DebugControl *control)
 Set a pointer to the current DebugControl.
 
void SetTapeDebugOption (TAPE_DEBUG_OPTION option, unsigned short izone=0)
 Set options which kind of tag mismatches are considered errors and written to file.
 
void ActivateTagErrorCallback ()
 Activate the error callback by letting the tape call tagErrorCallback whenever a tag mismatch arises.
 
void SetDebugReportFile (DebugControl &control, std::ostream *output_file)
 Set a pointer to the output file of a DebugControl.
 
void ResetErrorCounter (DebugControl &control)
 Reset the error counter in a DebugControl.
 
unsigned long GetErrorCount (const DebugControl &control)
 Get the error count of a DebugControl.
 
void Push_TapePosition ()
 Pushes back the current tape position to the tape position's vector.
 
bool BeginPassive ()
 Start a passive region, i.e. stop recording.
 
void EndPassive (bool wasActive)
 End a passive region, i.e. start recording if we were recording before.
 
bool PausePreaccumulation ()
 Pause the use of preaccumulation.
 
void ResumePreaccumulation (bool wasActive)
 Resume the use of preaccumulation.
 
void StartNoSharedReading ()
 Begin a hybrid parallel adjoint evaluation mode that assumes an inherently safe reverse path.
 
void EndNoSharedReading ()
 End the "no shared reading" adjoint evaluation mode.
 
void Initialize ()
 
void Finalize ()
 

Detailed Description

Contains routines for the reverse mode of AD. In case there is no reverse type configured, they have no effect at all, and so the real versions of the routined are after #else.

Typedef Documentation

◆ Identifier

using AD::Identifier = typedef int

Enumeration Type Documentation

◆ TAPE_DEBUG_OPTION

enum class AD::TAPE_DEBUG_OPTION
strong
Enumerator
ALLOW_PREACC 
ACTIVATE_PREACC 
ALLOW_ZONE 
ALLOW_ALL_ZONES 
ACTIVATE_ALL_ZONES 
ACTIVATE_ALL_ERRORS 
MULTIZONE_TAGS 
INIT_RUN 
CHECK_RUN 

Function Documentation

◆ ActivateTagErrorCallback()

void AD::ActivateTagErrorCallback ( )
inline

Activate the error callback by letting the tape call tagErrorCallback whenever a tag mismatch arises.

◆ BeginPassive()

bool AD::BeginPassive ( )
inline

Start a passive region, i.e. stop recording.

Returns
True if tape was active.

◆ BeginUseAdjoints()

void AD::BeginUseAdjoints ( )
inline

Declare that the adjoints are being used, to protect against resizing.

Should be used together with AD::EndUseAdjoints() to protect AD::SetDerivative() and AD::GetDerivative() calls, multiple at once if possible.

◆ ClearAdjoints()

void AD::ClearAdjoints ( )
inline

Clears the currently stored adjoints but keeps the computational graph.

◆ ClearTagOnVariable()

void AD::ClearTagOnVariable ( su2double &  v)
inline

Sets the tag of a variable to 0.

Parameters
[in]v- the variable whose tag is cleared.

◆ ComputeAdjoint() [1/2]

void AD::ComputeAdjoint ( )
inline

Computes the adjoints, i.e. the derivatives of the output with respect to the input variables.

◆ ComputeAdjoint() [2/2]

void AD::ComputeAdjoint ( unsigned short  enter,
unsigned short  leave 
)
inline

Computes the adjoints, i.e. the derivatives of the output with respect to the input variables.

Parameters
[in]enter- Position where we start evaluating the tape.
[in]leave- Position where we stop evaluating the tape.

◆ ComputeAdjointForward()

void AD::ComputeAdjointForward ( )
inline

Computes the adjoints, i.e., the derivatives of the output with respect to the input variables, using forward tape evaluation.

◆ ComputeTag()

int AD::ComputeTag ( unsigned short  iZone)
inline

Compute the zone-specific tag.

Parameters
[in]iZone- Zone index from which the zone-specific tag is formed.
Returns
The zone-specific tag.

◆ EndNoSharedReading()

void AD::EndNoSharedReading ( )
inline

End the "no shared reading" adjoint evaluation mode.

◆ EndPassive()

void AD::EndPassive ( bool  wasActive)
inline

End a passive region, i.e. start recording if we were recording before.

Parameters
[in]wasActive- Whether we were recording before entering the passive region.

◆ EndPreacc()

void AD::EndPreacc ( )
inline

Ends a preaccumulation section and computes the local Jacobi matrix of a code section using the variables set with SetLocalInput(), SetLocalOutput() and pushes a statement for each output variable to the AD tape.

◆ EndUseAdjoints()

void AD::EndUseAdjoints ( )
inline

Declare that the adjoints are no longer being used.

◆ Finalize()

void AD::Finalize ( )

◆ GetDerivative()

double AD::GetDerivative ( Identifier  index)
inline

Extracts the adjoint value at index.

Parameters
[in]index- position in the adjoint vector where the derivative will be extracted.
Returns
Derivative value.

◆ GetErrorCount()

unsigned long AD::GetErrorCount ( const DebugControl &  control)
inline

Get the error count of a DebugControl.

Parameters
[in]control- the DebugControl whose error count is reported.
Returns
Value of the error counter.

◆ GetPassiveIndex()

Identifier AD::GetPassiveIndex ( )
inline

Returns the identifier that represents an inactive variable.

Returns
Passive index.

◆ GetTag()

int AD::GetTag ( )
inline

Gets the current tag.

Parameters
[in]tag- the number to which the tag is set.

◆ Initialize()

void AD::Initialize ( )

◆ PausePreaccumulation()

bool AD::PausePreaccumulation ( )
inline

Pause the use of preaccumulation.

Returns
True if preaccumulation was active.

◆ PauseRecording()

bool AD::PauseRecording ( )
inline

Pause the recording of the operations and involved variables. If called, all operations occuring after the call will not be stored on the computational graph.

◆ PrintStatistics()

template<typename Comm >
void AD::PrintStatistics ( Comm  communicator,
bool  printingRank 
)
inline

Prints out tape statistics.

Tape statistics are aggregated across OpenMP threads and MPI processes, if applicable. With MPI, the given communicator is used to reduce data across MPI processes, and the printing behaviour can be set per rank (usually, only the master rank prints).

◆ Push_TapePosition()

void AD::Push_TapePosition ( )
inline

Pushes back the current tape position to the tape position's vector.

◆ RegisterInput()

void AD::RegisterInput ( su2double &  data)
inline

Registers the variable as an input. I.e. as a leaf of the computational graph.

Parameters
[in]data- The variable to be registered as input.

◆ RegisterOutput()

void AD::RegisterOutput ( su2double &  data)
inline

Registers the variable as an output. I.e. as the root of the computational graph.

Parameters
[in]data- The variable to be registered as output.

◆ Reset()

void AD::Reset ( )
inline

Reset the tape structure to be ready for a new recording.

◆ ResetErrorCounter()

void AD::ResetErrorCounter ( DebugControl &  control)
inline

Reset the error counter in a DebugControl.

Parameters
[in]control- the DebugControl whose error counter is resetted.

◆ ResetInput()

void AD::ResetInput ( su2double &  data)
inline

Reset the variable (set index to zero).

Parameters
[in]data- the variable to be unregistered from the tape.

◆ ResizeAdjoints()

void AD::ResizeAdjoints ( )
inline

Resize the adjoint vector, for subsequent access without bounds checking.

◆ ResumePreaccumulation()

void AD::ResumePreaccumulation ( bool  wasActive)
inline

Resume the use of preaccumulation.

Parameters
[in]wasActive- Whether preaccumulation was active before pausing.

◆ ResumeRecording()

void AD::ResumeRecording ( bool  wasActive)
inline

Resume the recording of the operations and variables after the recording had been paused.

◆ SetDebugControl()

void AD::SetDebugControl ( DebugControl *  control)
inline

Set a pointer to the current DebugControl.

Parameters
[in]control- pointer to the current debug control.

◆ SetDebugReportFile()

void AD::SetDebugReportFile ( DebugControl &  control,
std::ostream *  output_file 
)
inline

Set a pointer to the output file of a DebugControl.

Parameters
[in]control- the DebugControl whose output file is set.
[in]output_file- pointer to the output file.

◆ SetDerivative()

void AD::SetDerivative ( Identifier  index,
const double  val 
)
inline

Sets the adjoint value at index to val.

Parameters
[in]index- Position in the adjoint vector.
[in]val- adjoint value to be set.

◆ SetExtFuncIn() [1/3]

template<class T >
void AD::SetExtFuncIn ( const T &  data,
const int  size 
)
inline

Sets the input variables of a externally differentiated function using a 1D array.

Parameters
[in]data- the input 1D array.
[in]size- number of rows.

◆ SetExtFuncIn() [2/3]

template<class T >
void AD::SetExtFuncIn ( const T &  data,
const int  size_x,
const int  size_y 
)
inline

Sets the input variables of a externally differentiated function using a 2D array.

Parameters
[in]data- the input 2D array.
[in]size_x- number of rows.
[in]size_y- number of columns.

◆ SetExtFuncIn() [3/3]

void AD::SetExtFuncIn ( su2double &  data)
inline

Sets the scalar input of a externally differentiated function.

Parameters
[in]data- the scalar input variable.

◆ SetExtFuncOut() [1/3]

void AD::SetExtFuncOut ( su2double &  data)
inline

Sets the scalar output of a externally differentiated function.

Parameters
[in]data- the scalar output variable.

◆ SetExtFuncOut() [2/3]

template<class T >
void AD::SetExtFuncOut ( T &&  data,
const int  size 
)
inline

Sets the output variables of a externally differentiated function using a 1D array.

Parameters
[in]data- the output 1D array.
[in]size- number of rows.

◆ SetExtFuncOut() [3/3]

template<class T >
void AD::SetExtFuncOut ( T &&  data,
const int  size_x,
const int  size_y 
)
inline

Sets the output variables of a externally differentiated function using a 2D array.

Parameters
[in]data- the output 2D array.
[in]size_x- number of rows.
[in]size_y- number of columns.

◆ SetIndex()

void AD::SetIndex ( Identifier &  index,
const su2double &  data 
)
inline

Evaluates and saves gradient data from a variable.

Parameters
[in]data- variable whose gradient information will be extracted.
[in]index- where obtained gradient information will be stored.

◆ SetPreaccIn() [1/3]

template<class T >
void AD::SetPreaccIn ( const T &  data,
const int  size 
)
inline

Sets the input variables of a preaccumulation section using a 1D array.

Parameters
[in]data- the input 1D array.
[in]size- size of the array.

◆ SetPreaccIn() [2/3]

template<class T >
void AD::SetPreaccIn ( const T &  data,
const int  size_x,
const int  size_y 
)
inline

Sets the input variables of a preaccumulation section using a 2D array.

Parameters
[in]data- the input 2D array.
[in]size_x- size of the array in x dimension.
[in]size_y- size of the array in y dimension.

◆ SetPreaccIn() [3/3]

template<class... Ts>
void AD::SetPreaccIn ( Ts &&...  data)
inline

Sets the scalar inputs of a preaccumulation section.

Parameters
[in]data- the scalar input variables.

◆ SetPreaccOut() [1/3]

template<class T >
void AD::SetPreaccOut ( T &&  data,
const int  size 
)
inline

Sets the output variables of a preaccumulation section using a 1D array.

Parameters
[in]data- the output 1D array.

◆ SetPreaccOut() [2/3]

template<class T >
void AD::SetPreaccOut ( T &&  data,
const int  size_x,
const int  size_y 
)
inline

Sets the input variables of a preaccumulation section using a 2D array.

Parameters
[in]data- the output 1D array.

◆ SetPreaccOut() [3/3]

template<class... Ts>
void AD::SetPreaccOut ( Ts &&...  data)
inline

Sets the scalar outputs of a preaccumulation section.

Parameters
[in]data- the scalar output variables.

◆ SetTag()

void AD::SetTag ( int  tag)
inline

Sets the tag tape to a specific tag.

Parameters
[in]tag- the number to which the tag is set.

◆ SetTagOnVariable()

void AD::SetTagOnVariable ( su2double &  v,
int  zone_tag = 0,
int  run_tag = 0 
)
inline

Sets the tag of a variable to a specified value.

Parameters
[in]v- the variable whose tag is set manually.

◆ SetTapeDebugOption()

void AD::SetTapeDebugOption ( TAPE_DEBUG_OPTION  option,
unsigned short  izone = 0 
)
inline

Set options which kind of tag mismatches are considered errors and written to file.

Parameters
[in]option- specification which kind of tag mismatches are considered.
[in]izone- the zone w.r.t. which a tag mismatch is allowed.

◆ StartNoSharedReading()

void AD::StartNoSharedReading ( )
inline

Begin a hybrid parallel adjoint evaluation mode that assumes an inherently safe reverse path.

◆ StartPreacc()

void AD::StartPreacc ( )
inline

Starts a new preaccumulation section and sets the input variables.

The idea of preaccumulation is to store only the Jacobi matrix of a code section during the taping process instead of all operations. This decreases the tape size and reduces runtime.

Input/Output of the section are set with several calls to SetPreaccIn()/SetPreaccOut().

Note: the call of this routine must be followed by a call of EndPreacc() and the end of the code section.

◆ StartRecording()

void AD::StartRecording ( )
inline

Start the recording of the operations and involved variables. If called, the computational graph of all operations occuring after the call will be stored, starting with the variables registered with RegisterInput.

◆ StopRecording()

void AD::StopRecording ( )
inline

Stops the recording of the operations and variables.

◆ TapeActive()

bool AD::TapeActive ( )
inline

Check if the tape is active.

Parameters
[out]Booleanwhich determines whether the tape is active.