Graphite
Loading...
Searching...
No Matches
graphite::VertexDescriptor< T, S, VTraits > Class Template Reference

Represents a collection of optimizable variables to be processed together on the GPU. More...

#include <vertex.hpp>

Inheritance diagram for graphite::VertexDescriptor< T, S, VTraits >:
Collaboration diagram for graphite::VertexDescriptor< T, S, VTraits >:

Public Types

using InvP = std::conditional_t< is_low_precision< S >::value, T, S >
 
using Traits = VTraits
 
using VertexType = typename Traits::Vertex
 
using State = get_State_or_t< Traits, VertexType >
 
- Public Types inherited from graphite::BaseVertexDescriptor< T, S >
using InvP = std::conditional_t< is_low_precision< S >::value, T, S >
 

Public Member Functions

void apply_update_async (const T *delta_x, T *jacobian_scales, cudaStream_t stream) override
 Applies an update to the vertex parameters asynchronously.
 
void augment_block_diagonal_async (InvP *block_diagonal, InvP *scalar_diagonal, T mu, cudaStream_t stream) override
 Adds damping to the Hessian block diagonal asynchronously.
 
void apply_block_jacobi (T *z, const T *r, InvP *block_diagonal, cudaStream_t stream) override
 Applies the block Jacobi preconditioner asynchronously.
 
virtual void to_device () override
 Prepares descriptor for GPU processing.
 
VertexType ** vertices ()
 Returns a pointer to the array of vertex pointers for the descriptor.
 
virtual void backup_parameters_async () override
 Backs up the state of the vertices asynchronously.
 
virtual void restore_parameters_async () override
 Restores the state of the vertices from the backup asynchronously.
 
virtual size_t count () const override
 Returns the number of vertices in the descriptor (including fixed vertices).
 
void reserve (size_t size)
 Reserves memory for the specified number of vertices. You should call this before constructing the graph to avoid excessive reallocations.
 
void remove_vertex (const size_t id)
 Removes a vertex from the descriptor by its ID.
 
void replace_vertex (const size_t id, VertexType *vertex)
 Replaces a vertex pointer in the descriptor for the given ID.
 
void add_vertex (const size_t id, VertexType *vertex, const bool fixed=false)
 Adds a vertex to the descriptor.
 
void set_fixed (const size_t id, const bool fixed)
 Sets the fixed state of a vertex.
 
bool is_fixed (const size_t id) const override
 Checks if a vertex is fixed.
 
bool is_active (const size_t id) const override
 Checks if a vertex is active.
 
uint8_t * get_active_state () const override
 Retrieves a pointer to the active state array for the vertices.
 
const size_t * get_block_ids () const override
 Retrieves a pointer to the block IDs array for the vertices.
 
VertexType * get_vertex (const size_t id)
 Retrieves a pointer to the vertex associated with the given ID.
 
bool exists (const size_t id) const
 Checks if a vertex exists in the descriptor.
 
const std::unordered_map< size_t, size_t > & get_global_map () const override
 
size_t dimension () const override
 Returns the dimension of the vertex parameterization.
 
const size_t * get_hessian_ids () const override
 
void set_hessian_column (const size_t global_id, const size_t hessian_column, const size_t block_index)
 Sets the Hessian column and block index for a vertex.
 
void clear ()
 Clears all vertices and resets the descriptor to an empty state.
 

Public Attributes

std::unordered_map< size_t, size_t > global_to_local_map
 
std::vector< size_t > local_to_global_map
 
thrust::host_vector< size_t > local_to_hessian_offsets
 
thrust::device_vector< size_t > hessian_ids
 
managed_vector< size_t > block_ids
 
managed_vector< uint8_t > active_state
 

Static Public Attributes

static constexpr size_t dim = Traits::dimension
 

Private Attributes

thrust::device_vector< VertexType * > x_device
 
thrust::host_vector< VertexType * > x_host
 
thrust::device_vector< State > backup_state
 

Detailed Description

template<typename T, typename S, typename VTraits>
class graphite::VertexDescriptor< T, S, VTraits >

Represents a collection of optimizable variables to be processed together on the GPU.

Member Function Documentation

◆ add_vertex()

template<typename T , typename S , typename VTraits >
void graphite::VertexDescriptor< T, S, VTraits >::add_vertex ( const size_t  id,
VertexType *  vertex,
const bool  fixed = false 
)
inline

Adds a vertex to the descriptor.

Parameters
idThe ID of the vertex to add. Must be unique across all vertex descriptors in the same graph.
vertexThe pointer of the vertex to add.
fixedWhether the vertex is fixed or not.

◆ apply_block_jacobi()

template<typename T , typename S , typename VTraits >
void graphite::VertexDescriptor< T, S, VTraits >::apply_block_jacobi ( T *  z,
const T *  r,
InvP *  block_diagonal,
cudaStream_t  stream 
)
inlineoverridevirtual

Applies the block Jacobi preconditioner asynchronously.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ apply_update_async()

template<typename T , typename S , typename VTraits >
void graphite::VertexDescriptor< T, S, VTraits >::apply_update_async ( const T *  delta_x,
T *  jacobian_scales,
cudaStream_t  stream 
)
inlineoverridevirtual

Applies an update to the vertex parameters asynchronously.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ augment_block_diagonal_async()

template<typename T , typename S , typename VTraits >
void graphite::VertexDescriptor< T, S, VTraits >::augment_block_diagonal_async ( InvP *  block_diagonal,
InvP *  scalar_diagonal,
mu,
cudaStream_t  stream 
)
inlineoverridevirtual

Adds damping to the Hessian block diagonal asynchronously.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ backup_parameters_async()

template<typename T , typename S , typename VTraits >
virtual void graphite::VertexDescriptor< T, S, VTraits >::backup_parameters_async ( )
inlineoverridevirtual

Backs up the state of the vertices asynchronously.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ count()

template<typename T , typename S , typename VTraits >
virtual size_t graphite::VertexDescriptor< T, S, VTraits >::count ( ) const
inlineoverridevirtual

Returns the number of vertices in the descriptor (including fixed vertices).

Implements graphite::BaseVertexDescriptor< T, S >.

◆ dimension()

template<typename T , typename S , typename VTraits >
size_t graphite::VertexDescriptor< T, S, VTraits >::dimension ( ) const
inlineoverridevirtual

Returns the dimension of the vertex parameterization.

Returns
The dimension of the vertex parameterization.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ exists()

template<typename T , typename S , typename VTraits >
bool graphite::VertexDescriptor< T, S, VTraits >::exists ( const size_t  id) const
inline

Checks if a vertex exists in the descriptor.

Parameters
idThe ID of the vertex to check.
Returns
True if the vertex exists, false otherwise.

◆ get_active_state()

template<typename T , typename S , typename VTraits >
uint8_t * graphite::VertexDescriptor< T, S, VTraits >::get_active_state ( ) const
inlineoverridevirtual

Retrieves a pointer to the active state array for the vertices.

Returns
A pointer to the active state array.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ get_block_ids()

template<typename T , typename S , typename VTraits >
const size_t * graphite::VertexDescriptor< T, S, VTraits >::get_block_ids ( ) const
inlineoverridevirtual

Retrieves a pointer to the block IDs array for the vertices.

Returns
A pointer to the block IDs array.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ get_global_map()

template<typename T , typename S , typename VTraits >
const std::unordered_map< size_t, size_t > & graphite::VertexDescriptor< T, S, VTraits >::get_global_map ( ) const
inlineoverridevirtual

◆ get_hessian_ids()

template<typename T , typename S , typename VTraits >
const size_t * graphite::VertexDescriptor< T, S, VTraits >::get_hessian_ids ( ) const
inlineoverridevirtual

◆ get_vertex()

template<typename T , typename S , typename VTraits >
VertexType * graphite::VertexDescriptor< T, S, VTraits >::get_vertex ( const size_t  id)
inline

Retrieves a pointer to the vertex associated with the given ID.

Parameters
idThe ID of the vertex to retrieve.
Returns
A pointer to the vertex if found, or nullptr if the vertex does not exist in the descriptor.

◆ is_active()

template<typename T , typename S , typename VTraits >
bool graphite::VertexDescriptor< T, S, VTraits >::is_active ( const size_t  id) const
inlineoverridevirtual

Checks if a vertex is active.

Parameters
idThe ID of the vertex to check.
Returns
True if the vertex is active, false otherwise.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ is_fixed()

template<typename T , typename S , typename VTraits >
bool graphite::VertexDescriptor< T, S, VTraits >::is_fixed ( const size_t  id) const
inlineoverridevirtual

Checks if a vertex is fixed.

Parameters
idThe ID of the vertex to check.
Returns
True if the vertex is fixed, false otherwise.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ remove_vertex()

template<typename T , typename S , typename VTraits >
void graphite::VertexDescriptor< T, S, VTraits >::remove_vertex ( const size_t  id)
inline

Removes a vertex from the descriptor by its ID.

Parameters
idThe ID of the vertex to remove.

◆ replace_vertex()

template<typename T , typename S , typename VTraits >
void graphite::VertexDescriptor< T, S, VTraits >::replace_vertex ( const size_t  id,
VertexType *  vertex 
)
inline

Replaces a vertex pointer in the descriptor for the given ID.

Parameters
idThe ID of the vertex to replace.
vertexThe new pointer of the vertex.

◆ reserve()

template<typename T , typename S , typename VTraits >
void graphite::VertexDescriptor< T, S, VTraits >::reserve ( size_t  size)
inline

Reserves memory for the specified number of vertices. You should call this before constructing the graph to avoid excessive reallocations.

Parameters
sizeThe number of vertices to reserve space for.

◆ restore_parameters_async()

template<typename T , typename S , typename VTraits >
virtual void graphite::VertexDescriptor< T, S, VTraits >::restore_parameters_async ( )
inlineoverridevirtual

Restores the state of the vertices from the backup asynchronously.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ set_fixed()

template<typename T , typename S , typename VTraits >
void graphite::VertexDescriptor< T, S, VTraits >::set_fixed ( const size_t  id,
const bool  fixed 
)
inline

Sets the fixed state of a vertex.

Parameters
idThe ID of the vertex to update.
fixedWhether the vertex is fixed (true) or not (false).

◆ set_hessian_column()

template<typename T , typename S , typename VTraits >
void graphite::VertexDescriptor< T, S, VTraits >::set_hessian_column ( const size_t  global_id,
const size_t  hessian_column,
const size_t  block_index 
)
inlinevirtual

Sets the Hessian column and block index for a vertex.

Parameters
global_idThe global ID of the vertex.
hessian_columnThe Hessian column index.
block_indexThe block index.

Implements graphite::BaseVertexDescriptor< T, S >.

◆ to_device()

template<typename T , typename S , typename VTraits >
virtual void graphite::VertexDescriptor< T, S, VTraits >::to_device ( )
inlineoverridevirtual

Prepares descriptor for GPU processing.

Implements graphite::BaseVertexDescriptor< T, S >.


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