Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Attributes | List of all members
colvars_gpu::colvarmodule_gpu_calc Class Reference

Class for managing the GPU calculation of CVCs. More...

#include <colvar_gpu_calc.h>

Collaboration diagram for colvars_gpu::colvarmodule_gpu_calc:
Collaboration graph
[legend]

Classes

class  compute_gpu_graph_t
 A struct for holding a CUDA graph and its execution object. More...
 
struct  compute_node_t
 A struct for holding a compute node in the CUDA graph and its corresponding atom group or CVC (child of colvardeps) More...
 

Public Member Functions

 colvarmodule_gpu_calc ()
 Constructor.
 
 ~colvarmodule_gpu_calc ()
 Destructor.
 
int init ()
 Initialize all the GPU compute graphs. More...
 
int calc_cvs (const std::vector< colvar * > &colvars, colvarmodule *colvar_module)
 Calculate the colvar {...} blocks. More...
 
int apply_forces (const std::vector< colvar * > &colvars, colvarmodule *colvar_module)
 Apply the forces to the atom groups from the CVCs. More...
 

Private Member Functions

Internal functions used in calc_cvs()
int cv_update_flags (const std::vector< colvar * > &colvars)
 
int cvc_calc_total_force (const std::vector< colvar * > &colvars, colvarmodule *colvar_module, bool use_current_step=false)
 
int atom_group_read_data_gpu (const std::vector< colvar * > &colvars, colvarmodule_gpu_calc::compute_gpu_graph_t &g, colvarmodule *colvar_module)
 
int cvc_calc_value (const std::vector< colvar * > &colvars, colvarmodule *colvar_module)
 
int cvc_calc_gradients (const std::vector< colvar * > &colvars, colvarmodule *colvar_module)
 
int atom_group_calc_fit_gradients (const std::vector< colvar * > &colvars, colvarmodule_gpu_calc::compute_gpu_graph_t &g, colvarmodule *colvar_module)
 
int cvc_debug_gradients (const std::vector< colvar * > &colvars, colvarmodule *colvar_module)
 
int cvc_calc_Jacobian_derivative (const std::vector< colvar * > &colvars, colvarmodule *colvar_module)
 
int cv_collect_cvc_data (const std::vector< colvar * > &colvars, colvarmodule *colvar_module)
 

Private Attributes

compute_gpu_graph_t read_data_compute
 CUDA graph for reading data to GPU and calculating required properties.
 
compute_gpu_graph_t calc_fit_gradients_compute
 CUDA graph for calculating fit gradients.
 
compute_gpu_graph_t apply_forces_compute
 CUDA graph for applying forces to atom groups.
 
std::vector< colvardeps * > forced_atom_groups
 A list of atom groups that require forces to be applied. More...
 
Timers for profiling
colvars_gpu::colvar_nvtx_prof ag_read_data_prof
 
colvars_gpu::colvar_nvtx_prof cvc_calc_value_prof
 
colvars_gpu::colvar_nvtx_prof cvc_calc_gradients_prof
 
colvars_gpu::colvar_nvtx_prof ag_calc_fit_gradients_prof
 
colvars_gpu::colvar_nvtx_prof cvc_calc_Jacobian_derivative_prof
 
colvars_gpu::colvar_nvtx_prof cvc_calc_total_force_prof
 
colvars_gpu::colvar_nvtx_prof cv_collect_cvc_data_prof
 
colvars_gpu::colvar_nvtx_prof apply_forces_prof
 

Detailed Description

Class for managing the GPU calculation of CVCs.

Note
This class is basically a GPU version of colvarmodule::calc_colvars(). In the future, the atom groups are supposed to be shared among CVCs, so instead of iterating over all colvars and computing them one by one, this class will flatten the colvardeps* tree, then compute all atom groups in one pass with CUDA graphs, then all CVCs, and finally collect the colvar values.

Member Function Documentation

◆ apply_forces()

int colvarmodule_gpu_calc::apply_forces ( const std::vector< colvar * > &  colvars,
colvarmodule colvar_module 
)

Apply the forces to the atom groups from the CVCs.

On the first call, the CUDA graph for apply atom group forces will be constructed and instantiated. On subsequent calls, the existing CUDA graph will be launched.

Parameters
[in]colvarsA vector of all colvar objects
[in]colvar_moduleThe main colvarmodule object
Returns
COLVARS_OK if succeeded

◆ calc_cvs()

int colvarmodule_gpu_calc::calc_cvs ( const std::vector< colvar * > &  colvars,
colvarmodule colvar_module 
)

Calculate the colvar {...} blocks.

This function performs the following operations:

  1. Call cv_update_flags to update the flags of all colvars and cvcs
  2. If the current step is greater than 0, call cvc_calc_total_force to calculate the total force on each CVC
  3. Call atom_group_read_data_gpu to read the atom positions to GPU buffers and calculate the required properties
  4. Call cvc_calc_value to calculate the values of all CVCs
  5. Call cvc_calc_gradients to calculate the gradients of all CVCs
  6. Call atom_group_calc_fit_gradients to calculate the fit gradients
  7. Call cvc_calc_Jacobian_derivative to calculate the Jacobian derivatives of all CVCs
  8. Call cv_collect_cvc_data to sum up the colvar values On the first call, the CUDA graphs will be constructed and instantiated. On subsequent calls, the existing CUDA graphs will be launched for "atom_group_read_data_gpu" and "atom_group_calc_fit_gradients".
Parameters
[in]colvarsA vector of all colvar objects
[in]colvar_moduleThe main colvarmodule object
Returns
COLVARS_OK if succeeded

◆ init()

int colvarmodule_gpu_calc::init ( )

Initialize all the GPU compute graphs.

Returns
COLVARS_OK if succeeded

Member Data Documentation

◆ forced_atom_groups

std::vector<colvardeps*> colvars_gpu::colvarmodule_gpu_calc::forced_atom_groups
private

A list of atom groups that require forces to be applied.

Note
I have no way to forward declare cvm::atom_group here so I have to use colvardeps as a workaround.

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