|
Collective Variables Module - Developer Documentation
|
The main class for calculating the atom group properties on GPU. More...
#include <colvaratoms_gpu.h>

Public Member Functions | |
| colvaratoms_gpu () | |
| Constructor. More... | |
| ~colvaratoms_gpu () | |
| Destructor. | |
| int | init_gpu () |
| Initialize the object. More... | |
| int | destroy_gpu () |
| Destructor. More... | |
| int | sync_to_gpu_buffers (const cvm::atom_group *cpu_atoms) |
| Synchronize atom-wise data fields from the CPU buffers. More... | |
| int | clear_gpu_buffers (const cvm::atom_group *cpu_atoms) |
| Clear GPU atom-wise data fields. More... | |
| int | add_reset_atoms_data_nodes (const cvm::atom_group *cpu_atoms, cudaGraph_t &graph, std::unordered_map< std::string, cudaGraphNode_t > &nodes_map) |
| Add a node for resetting some atom-wise data fields to the CUDA graph. More... | |
| int | add_read_positions_nodes (const cvm::atom_group *cpu_atoms, cudaGraph_t &graph, std::unordered_map< std::string, cudaGraphNode_t > &nodes_map) |
| Add a node for reading positions and velocities to the CUDA graph. More... | |
| int | add_calc_required_properties_nodes (const cvm::atom_group *cpu_atoms, cudaGraph_t &graph, std::unordered_map< std::string, cudaGraphNode_t > &nodes_map, const std::vector< cudaGraphNode_t > &extra_initial_dependencies={}) |
| Add nodes for calculating the required properties to the CUDA graph. More... | |
| int | add_update_cpu_buffers_nodes (cvm::atom_group *cpu_atoms, cudaGraph_t &graph, std::unordered_map< std::string, cudaGraphNode_t > &nodes_map) |
| Add nodes for updating the CPU buffers after the GPU calculation. More... | |
| int | after_read_data_sync (cvm::atom_group *cpu_atoms, bool copy_to_cpu, cudaStream_t stream) |
| Update the CPU COM, COG and rotation object after GPU synchronization. More... | |
| int | begin_apply_force_gpu () |
| Clear the CPU force buffer for scalar components before applying forces on GPU. | |
| int | add_apply_force_nodes (const cvm::atom_group *cpu_atoms, cudaGraph_t &graph, std::unordered_map< std::string, cudaGraphNode_t > &nodes_map, const std::vector< cudaGraphNode_t > &extra_initial_dependencies={}) |
| Add nodes for applying forces to the CUDA graph. More... | |
| int | add_calc_fit_gradients_nodes (cvm::atom_group *cpu_atoms, cudaGraph_t &graph, std::unordered_map< std::string, cudaGraphNode_t > &nodes_map, bool use_cpu_buffers=false) |
| Add nodes for calculating the fit gradients to the CUDA graph. More... | |
| int | read_positions_gpu_debug (cvm::atom_group *cpu_atoms, bool change_fitting_group, size_t change_atom_i, int xyz, bool to_cpu, double sign, cudaStream_t stream) |
| Function for reading atom positions used for debug gradients. More... | |
| int | calc_required_properties_gpu_debug (cvm::atom_group *cpu_atoms, bool to_cpu, cudaStream_t stream) |
| Function for calculating the required properties used for debug gradients. More... | |
| void | do_feature_side_effects_gpu (cvm::atom_group *cpu_atoms, int id) |
| Function to be called when a colvardeps feature is enabled. More... | |
| int | setup_rotation (const cvm::atom_group *cpu_atoms) |
| Setup the rotation object and copy the reference positions to GPU. More... | |
| int | setup_rotation_derivative (const cvm::atom_group *cpu_atoms) |
| Setup the rotation derivative object on GPU. More... | |
| colvaratoms_gpu_buffer_t & | get_gpu_buffers () |
| Get the GPU buffers. More... | |
| int | read_total_forces (cvm::atom_group *cpu_atoms) |
| Read the total forces from the proxy buffer to the GPU buffer. More... | |
| void | apply_colvar_force_from_cpu (cvm::real const &cpu_force) |
| Function to intercept the forces applied from the CPU interface. More... | |
| void | set_use_cpu_group_force (bool yesno) |
| Set whether to use the CPU atom group force. More... | |
Private Attributes | |
| colvaratoms_gpu_buffer_t | gpu_buffers |
| colvaratoms_gpu_calc_fit_info_t | calc_fit_gradients_gpu_info |
| Temporary variables for calc_fit_gradients GPU kernel. | |
| colvaratoms_gpu_calc_fit_info_t | calc_fit_forces_gpu_info |
| Temporary variables for calc_fit_forces (or "calc_fit_gradients" for vector CVCs) GPU kernel. | |
| colvaratoms_gpu_debug_graph_t | debug_graphs |
| Separate CUDA graphs for supporting debug gradients. | |
| cvm::real * | h_sum_applied_colvar_force |
| For intercepting the forces applied from the CPU interface. | |
| bool | use_apply_colvar_force |
| If the CPU code path use apply_colvar_force(), this will be set to true, and then reset to false in begin_apply_force_gpu() | |
| bool | use_group_force |
| If the CPU code path use group_force_object, this will be set to true, and then reset to false in begin_apply_force_gpu() | |
| colvars_gpu::rotation_gpu | rot_gpu |
| GPU rotation object. | |
| colvars_gpu::rotation_derivative_gpu * | rot_deriv_gpu |
| GPU Rotation derivative;. | |
The main class for calculating the atom group properties on GPU.
| colvars_gpu::colvaratoms_gpu::colvaratoms_gpu | ( | ) |
Constructor.
All variables are expected to initialize to 0.
| int colvars_gpu::colvaratoms_gpu::add_apply_force_nodes | ( | const cvm::atom_group * | cpu_atoms, |
| cudaGraph_t & | graph, | ||
| std::unordered_map< std::string, cudaGraphNode_t > & | nodes_map, | ||
| const std::vector< cudaGraphNode_t > & | extra_initial_dependencies = {} |
||
| ) |
Add nodes for applying forces to the CUDA graph.
| [in] | cpu_atoms | CPU atom group class |
| [in] | graph | CUDA graph object |
| [in,out] | nodes_map | A map to store the added nodes with operation name |
| [in] | extra_initial_dependencies | Additional dependencies to be added to the initial nodes |
| int colvars_gpu::colvaratoms_gpu::add_calc_fit_gradients_nodes | ( | cvm::atom_group * | cpu_atoms, |
| cudaGraph_t & | graph, | ||
| std::unordered_map< std::string, cudaGraphNode_t > & | nodes_map, | ||
| bool | use_cpu_buffers = false |
||
| ) |
Add nodes for calculating the fit gradients to the CUDA graph.
| [in] | cpu_atoms | CPU atom group class |
| [in] | graph | CUDA graph object |
| [in,out] | nodes_map | A map to store the added nodes with operation name |
| [in] | use_cpu_buffers | If true, add a node for copying fit gradients from GPU to CPU |
| int colvars_gpu::colvaratoms_gpu::add_calc_required_properties_nodes | ( | const cvm::atom_group * | cpu_atoms, |
| cudaGraph_t & | graph, | ||
| std::unordered_map< std::string, cudaGraphNode_t > & | nodes_map, | ||
| const std::vector< cudaGraphNode_t > & | extra_initial_dependencies = {} |
||
| ) |
Add nodes for calculating the required properties to the CUDA graph.
This function adds nodes for calculating COM, COG, rotation matrix, rotated positions, and reference COG to the CUDA graph.
| [in] | cpu_atoms | CPU atom group class |
| [in] | graph | CUDA graph object |
| [in,out] | nodes_map | A map to store the added nodes with operation name |
| [in] | extra_initial_dependencies | Additional dependencies to be added to the initial nodes |
| int colvars_gpu::colvaratoms_gpu::add_read_positions_nodes | ( | const cvm::atom_group * | cpu_atoms, |
| cudaGraph_t & | graph, | ||
| std::unordered_map< std::string, cudaGraphNode_t > & | nodes_map | ||
| ) |
Add a node for reading positions and velocities to the CUDA graph.
This function adds cudaMemcpy nodes to read positions and velocities from the CPU buffers to the GPU buffers to the CUDA graph.
| [in] | cpu_atoms | CPU atom group class |
| [in] | graph | CUDA graph object |
| [in,out] | nodes_map | A map to store the added nodes with operation name |
| int colvars_gpu::colvaratoms_gpu::add_reset_atoms_data_nodes | ( | const cvm::atom_group * | cpu_atoms, |
| cudaGraph_t & | graph, | ||
| std::unordered_map< std::string, cudaGraphNode_t > & | nodes_map | ||
| ) |
Add a node for resetting some atom-wise data fields to the CUDA graph.
This function adds cudaMemset nodes to clear gradients, total forces and applied forces to the CUDA graph. The positions and velocities are not cleared since they are expected to be overwritten.
| [in] | cpu_atoms | CPU atom group class |
| [in] | graph | CUDA graph object |
| [in,out] | nodes_map | A map to store the added nodes with operation name |
| int colvars_gpu::colvaratoms_gpu::add_update_cpu_buffers_nodes | ( | cvm::atom_group * | cpu_atoms, |
| cudaGraph_t & | graph, | ||
| std::unordered_map< std::string, cudaGraphNode_t > & | nodes_map | ||
| ) |
Add nodes for updating the CPU buffers after the GPU calculation.
This function adds cudaMemcpy nodes to update COM, COG, original COG, rotation matrix, and fit gradients to the CPU buffers.
| [in] | cpu_atoms | CPU atom group class |
| [in] | graph | CUDA graph object |
| [in,out] | nodes_map | A map to store the added nodes with operation name |
| int colvars_gpu::colvaratoms_gpu::after_read_data_sync | ( | cvm::atom_group * | cpu_atoms, |
| bool | copy_to_cpu, | ||
| cudaStream_t | stream | ||
| ) |
Update the CPU COM, COG and rotation object after GPU synchronization.
| [in] | cpu_atoms | CPU atom group class |
| [in] | copy_to_cpu | If true, copy the COM, COG and rotation object to CPU buffers |
| [in] | stream | CUDA stream to be synchronized |
| void colvars_gpu::colvaratoms_gpu::apply_colvar_force_from_cpu | ( | cvm::real const & | cpu_force | ) |
Function to intercept the forces applied from the CPU interface.
This function is called when apply_colvar_force() is called on CPU. It stores the applied force in a temporary variable, which will be added to the GPU buffer.
| [in] | cpu_force | Force applied from the CPU interface |
| int colvars_gpu::colvaratoms_gpu::calc_required_properties_gpu_debug | ( | cvm::atom_group * | cpu_atoms, |
| bool | to_cpu, | ||
| cudaStream_t | stream | ||
| ) |
Function for calculating the required properties used for debug gradients.
| [in] | cpu_atoms | CPU atom group class |
| [in] | to_cpu | If true, copy the calculated properties to CPU buffers |
| [in] | stream | CUDA stream to be used |
| int colvars_gpu::colvaratoms_gpu::clear_gpu_buffers | ( | const cvm::atom_group * | cpu_atoms | ) |
Clear GPU atom-wise data fields.
This function clears the GPU buffers for proxy indices, charges, masses, weights, positions, gradients, total forces, velocities, and applied forces.
| [in] | cpu_atoms | CPU atom group class |
| int colvars_gpu::colvaratoms_gpu::destroy_gpu | ( | ) |
Destructor.
| void colvars_gpu::colvaratoms_gpu::do_feature_side_effects_gpu | ( | cvm::atom_group * | cpu_atoms, |
| int | id | ||
| ) |
Function to be called when a colvardeps feature is enabled.
This function performs any side effects needed when a feature is enabled. Specifically, it allocates the GPU buffers for unrotated positions if f_ag_fit_gradients is enabled, and sets up the rotation object if f_ag_rotate is enabled.
| [in] | cpu_atoms | CPU atom group class |
| [in] | id | Feature ID that has been enabled |
|
inline |
Get the GPU buffers.
| int colvars_gpu::colvaratoms_gpu::init_gpu | ( | ) |
Initialize the object.
This function re-allocates the GPU buffers for COM, COG, atomic counters, reference COG, and the temporary variables used for fit gradients. However, it does not (re)allocate the atom-wise data fields like positions. The atom-wise data fields are expected to be updated when sync_to_gpu_buffers is called.
| int colvars_gpu::colvaratoms_gpu::read_positions_gpu_debug | ( | cvm::atom_group * | cpu_atoms, |
| bool | change_fitting_group, | ||
| size_t | change_atom_i, | ||
| int | xyz, | ||
| bool | to_cpu, | ||
| double | sign, | ||
| cudaStream_t | stream | ||
| ) |
Function for reading atom positions used for debug gradients.
This function reads the atom positions from the proxy buffer to the atom group GPU buffer, and optionally modifies one of the coordinates for testing the numerical gradients.
| [in] | cpu_atoms | CPU atom group class |
| [in] | change_fitting_group | If true, change the fitting group atom position |
| [in] | change_atom_i | Index of the atom to be changed |
| [in] | xyz | Coordinate index (0, 1, or 2) to be changed |
| [in] | to_cpu | If true, copy the changed positions to CPU buffers |
| [in] | sign | Sign of the change (+1 or -1) |
| [in] | stream | CUDA stream to be used |
| int colvars_gpu::colvaratoms_gpu::read_total_forces | ( | cvm::atom_group * | cpu_atoms | ) |
Read the total forces from the proxy buffer to the GPU buffer.
| [in] | cpu_atoms | CPU atom group class |
|
inline |
Set whether to use the CPU atom group force.
This function is called when group_force_object is used on CPU. It sets a flag to indicate that the group force should be added to the GPU buffer.
| [in] | yesno | True to use the CPU group force, false otherwise |
| int colvars_gpu::colvaratoms_gpu::setup_rotation | ( | const cvm::atom_group * | cpu_atoms | ) |
Setup the rotation object and copy the reference positions to GPU.
| [in] | cpu_atoms | CPU atom group class |
| int colvars_gpu::colvaratoms_gpu::setup_rotation_derivative | ( | const cvm::atom_group * | cpu_atoms | ) |
Setup the rotation derivative object on GPU.
| [in] | cpu_atoms | CPU atom group class |
| int colvars_gpu::colvaratoms_gpu::sync_to_gpu_buffers | ( | const cvm::atom_group * | cpu_atoms | ) |
Synchronize atom-wise data fields from the CPU buffers.
This function (re)allocates the GPU buffers for proxy indices, charges, masses, weights, positions, velocities, total forces, gradients, and forces that will be applied. Then the proxy indices, charges, masses, positions, velocities, gradients and total forces will be updated from the corresponding CPU buffers.
| [in] | cpu_atoms | CPU atom group class |