ADOL-C: Automatic Differentiation in C/C++ 2.7.3
Loading...
Searching...
No Matches
Classes | Functions
taperegistry.h File Reference
#include <adolc/adolcexport.h>
#include <cassert>
#include <memory>
#include <vector>
Include dependency graph for taperegistry.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  RecordingFrame
 One entry in the thread-local stack of nested recordings. More...
 

Functions

ADOLC_API std::vector< std::unique_ptr< ValueTape > > & tapeBuffer ()
 Returns the process-wide vector that owns all ValueTape instances.
 
std::vector< RecordingFrame > & currentTapeStack ()
 Returns a thread-local stack holding pointers to ValueTape instances.
 
ADOLC_API ValueTape * findTapePtr_ (short tapeId)
 Attempts to find a ValueTape pointer by tapeId without triggering an error.
 
ADOLC_API ValueTape * findTapePtr (short tapeId)
 Returns a pointer to a ValueTape by tape ID, or throws an error if not found.
 
ADOLC_API ValueTape & findTape (short tapeId)
 Returns a reference to a ValueTape by tapeId, or throws an error if not found.
 
ADOLC_API ValueTape *& currentTapePtr ()
 Returns a thread-local reference to the pointer to the current ValueTape.
 
ValueTape & currentTape ()
 Returns a reference to the current ValueTape.
 
void setCurrentTape (ValueTape *tape) noexcept
 Sets the current tape pointer to the given tape.
 
ADOLC_API void setCurrentTape (short tapeId)
 Sets the current tape pointer to the pointer of the tape with the specified ID.
 
ADOLC_API short createNewTape ()
 Creates a new tape and returns its ID.
 

Function Documentation

◆ createNewTape()

ADOLC_API short createNewTape ( )

Creates a new tape and returns its ID.

Allocates a process-wide unique tape ID and inserts the new tape into the global registry. If the calling thread has no current tape, the newly created tape becomes that thread's current tape.

Returns
The ID of the new created tape.

◆ currentTape()

ValueTape & currentTape ( )
inline

Returns a reference to the current ValueTape.

The current tape is used for creating new tape_locations, free locations, storing traced operations, etc...

Returns
Reference to the current ValueTape.
Note
Asserts if the current tape pointer is null.

◆ currentTapePtr()

ADOLC_API ValueTape *& currentTapePtr ( )
inline

Returns a thread-local reference to the pointer to the current ValueTape.

This pointer is specific to the thread and denotes the current tape. The current tape is used for creating new tape_locations, free locations, storing traced operations, etc...

Returns
Reference to the thread-local ValueTape pointer.

◆ currentTapeStack()

std::vector< RecordingFrame > & currentTapeStack ( )
inline

Returns a thread-local stack holding pointers to ValueTape instances.

This stack is modified in trace_on and trace_off. In trace_on the pointer of a possible previous current tape is pushed onto the stack. Then, the tape to be used is set to be the currentTape. Inside trace_off the pointer of the old tape is popped from the stack, and set as current tape again. This allows the nesting of trace_on ... trace_off calls.

Returns
Reference to the thread-local stack of tape pointers.

◆ findTape()

ADOLC_API ValueTape & findTape ( short  tapeId)

Returns a reference to a ValueTape by tapeId, or throws an error if not found.

This is a convenience wrapper around findTapePtr that dereferences the pointer.

Parameters
tapeIdThe ID of the tape to retrieve.
Returns
Reference to the corresponding ValueTape.
Exceptions
ADOLCError::ErrorType::NO_TAPE_IDif the specified tape does not exist.

◆ findTapePtr()

ADOLC_API ValueTape * findTapePtr ( short  tapeId)

Returns a pointer to a ValueTape by tape ID, or throws an error if not found.

Performs a synchronized lookup in the process-wide tape registry. If no matching tape is found, an ADOLCError is thrown.

Parameters
tapeIdThe ID of the tape to locate.
Returns
Pointer to the corresponding ValueTape.
Exceptions
ADOLCError::ErrorType::NO_TAPE_IDif the specified tape does not exist.

◆ findTapePtr_()

ADOLC_API ValueTape * findTapePtr_ ( short  tapeId)

Attempts to find a ValueTape pointer by tapeId without triggering an error.

Parameters
tapeIdThe ID of the tape to search for.
Returns
Pointer to the matching ValueTape if found, or nullptr otherwise.

◆ setCurrentTape() [1/2]

ADOLC_API void setCurrentTape ( short  tapeId)

Sets the current tape pointer to the pointer of the tape with the specified ID.

Parameters
tapeIdThe ID of the tape to set as current.
Exceptions
ADOLCError::ErrorType::NO_TAPE_IDif the specified tape does not exist.

◆ setCurrentTape() [2/2]

void setCurrentTape ( ValueTape *  tape)
inlinenoexcept

Sets the current tape pointer to the given tape.

Parameters
tapeThe tape to set as the current one

◆ tapeBuffer()

ADOLC_API std::vector< std::unique_ptr< ValueTape > > & tapeBuffer ( )

Returns the process-wide vector that owns all ValueTape instances.

Tape creation and lookup synchronize access to this registry internally. Pointers to contained tapes remain stable because the vector stores owning pointers and tapes are not removed.

Returns
Reference to the process-wide vector ValueTape pointers.