1#ifndef COLVARATOMS_GPU_H
2#define COLVARATOMS_GPU_H
5#include "colvartypes.h"
6#include "colvar_rotation_derivative.h"
13namespace colvars_gpu {
15#if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
162 std::unordered_map<std::string, cudaGraphNode_t>& nodes_map);
176 std::unordered_map<std::string, cudaGraphNode_t>& nodes_map);
192 std::unordered_map<std::string, cudaGraphNode_t>& nodes_map,
193 const std::vector<cudaGraphNode_t>& extra_initial_dependencies = {});
207 std::unordered_map<std::string, cudaGraphNode_t>& nodes_map);
234 std::unordered_map<std::string, cudaGraphNode_t>& nodes_map,
235 const std::vector<cudaGraphNode_t>& extra_initial_dependencies = {});
247 std::unordered_map<std::string, cudaGraphNode_t>& nodes_map,
248 bool use_cpu_buffers =
false);
265 cvm::atom_group* cpu_atoms,
bool change_fitting_group,
size_t change_atom_i,
266 int xyz,
bool to_cpu,
double sign, cudaStream_t stream);
2-dimensional array of real numbers with three components along each dimension (works with colvarmodu...
Definition: colvartypes.h:901
vector of real numbers with three components
Definition: colvartypes.h:726
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:98
The main class for calculating the atom group properties on GPU.
Definition: colvaratoms_gpu.h:95
int begin_apply_force_gpu()
Clear the CPU force buffer for scalar components before applying forces on GPU.
Definition: colvaratoms_gpu.cpp:681
int clear_gpu_buffers(const cvm::atom_group *cpu_atoms)
Clear GPU atom-wise data fields.
Definition: colvaratoms_gpu.cpp:158
int setup_rotation(const cvm::atom_group *cpu_atoms)
Setup the rotation object and copy the reference positions to GPU.
Definition: colvaratoms_gpu.cpp:950
int sync_to_gpu_buffers(const cvm::atom_group *cpu_atoms)
Synchronize atom-wise data fields from the CPU buffers.
Definition: colvaratoms_gpu.cpp:132
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.
Definition: colvaratoms_gpu.cpp:899
int destroy_gpu()
Destructor.
Definition: colvaratoms_gpu.cpp:80
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 b...
Definition: colvaratoms_gpu.h:349
colvaratoms_gpu_calc_fit_info_t calc_fit_gradients_gpu_info
Temporary variables for calc_fit_gradients GPU kernel.
Definition: colvaratoms_gpu.h:340
void do_feature_side_effects_gpu(cvm::atom_group *cpu_atoms, int id)
Function to be called when a colvardeps feature is enabled.
Definition: colvaratoms_gpu.cpp:921
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.
Definition: colvaratoms_gpu.cpp:689
colvaratoms_gpu_debug_graph_t debug_graphs
Separate CUDA graphs for supporting debug gradients.
Definition: colvaratoms_gpu.h:344
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.
Definition: colvaratoms_gpu.cpp:469
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.
Definition: colvaratoms_gpu.cpp:202
colvars_gpu::rotation_derivative_gpu * rot_deriv_gpu
GPU Rotation derivative;.
Definition: colvaratoms_gpu.h:356
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 beg...
Definition: colvaratoms_gpu.h:352
cvm::real * h_sum_applied_colvar_force
For intercepting the forces applied from the CPU interface.
Definition: colvaratoms_gpu.h:346
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.
Definition: colvaratoms_gpu.cpp:529
colvaratoms_gpu()
Constructor.
Definition: colvaratoms_gpu.cpp:15
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.
Definition: colvaratoms_gpu.cpp:589
colvaratoms_gpu_buffer_t & get_gpu_buffers()
Get the GPU buffers.
Definition: colvaratoms_gpu.h:309
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.
Definition: colvaratoms_gpu.cpp:178
void apply_colvar_force_from_cpu(cvm::real const &cpu_force)
Function to intercept the forces applied from the CPU interface.
Definition: colvaratoms_gpu.cpp:997
int init_gpu()
Initialize the object.
Definition: colvaratoms_gpu.cpp:30
void set_use_cpu_group_force(bool yesno)
Set whether to use the CPU atom group force.
Definition: colvaratoms_gpu.h:336
colvars_gpu::rotation_gpu rot_gpu
GPU rotation object.
Definition: colvaratoms_gpu.h:354
int read_total_forces(cvm::atom_group *cpu_atoms)
Read the total forces from the proxy buffer to the GPU buffer.
Definition: colvaratoms_gpu.cpp:977
~colvaratoms_gpu()
Destructor.
Definition: colvaratoms_gpu.cpp:26
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.
Definition: colvaratoms_gpu.cpp:235
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.
Definition: colvaratoms_gpu.cpp:856
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.
Definition: colvaratoms_gpu.h:342
int setup_rotation_derivative(const cvm::atom_group *cpu_atoms)
Setup the rotation derivative object on GPU.
Definition: colvaratoms_gpu.cpp:960
Definition: colvartypes.h:1578
Store the information of a group of atoms in a structure-of-arrays (SoA) style.
Definition: colvaratoms.h:52
Collective variables main module.
A struct for holding GPU atom group buffers.
Definition: colvaratoms_gpu.h:19
cvm::rvector * d_cog
GPU center-of-geometry.
Definition: colvaratoms_gpu.h:49
cvm::rvector * d_com
GPU center-of-mass.
Definition: colvaratoms_gpu.h:45
cvm::real * d_atoms_pos_unrotated
GPU atom positions (size: 3 * num_atoms)
Definition: colvaratoms_gpu.h:43
cvm::rvector * d_com_tmp
GPU temporary buffer for COM, used for avoiding memset.
Definition: colvaratoms_gpu.h:47
cvm::real * d_atoms_charge
GPU atom charges (size: num_atoms)
Definition: colvaratoms_gpu.h:25
cvm::rvector * d_cog_orig
GPU center of geometry before any fitting.
Definition: colvaratoms_gpu.h:53
cvm::rvector * h_com
Center-of-mass on the host-pinned memory for CPU compatibility.
Definition: colvaratoms_gpu.h:57
cvm::real * d_ref_pos
GPU reference coordinates for f_ag_center or f_ag_rotate.
Definition: colvaratoms_gpu.h:41
cvm::rvector * h_cog
Center-of-geometry on the host-pinned memory for CPU compatibility.
Definition: colvaratoms_gpu.h:59
cvm::real * d_fit_gradients
GPU fit gradients.
Definition: colvaratoms_gpu.h:39
cvm::rvector * h_cog_orig
Center-of-geometry before any fitting on the host-pinned memory for CPU compatibility.
Definition: colvaratoms_gpu.h:61
cvm::real * d_atoms_total_force
GPU atom total forces (size: 3 * num_atoms)
Definition: colvaratoms_gpu.h:33
cvm::rvector * d_ref_pos_cog
GPU center of geometry of the reference coordinates.
Definition: colvaratoms_gpu.h:63
cvm::real * d_atoms_pos
GPU atom positions (size: 3 * num_atoms)
Definition: colvaratoms_gpu.h:23
cvm::real * d_atoms_weight
Atom masses divided by total mass (size: num_atoms)
Definition: colvaratoms_gpu.h:35
cvm::real * d_atoms_applied_force
GPU atom applied force.
Definition: colvaratoms_gpu.h:37
unsigned int * d_com_cog_tbcount
GPU atomic counter for block reduction.
Definition: colvaratoms_gpu.h:55
cvm::real * d_atoms_vel
GPU atom velocities (size: 3 * num_atoms)
Definition: colvaratoms_gpu.h:27
cvm::real * d_atoms_grad
GPU atom gradients (size: 3 * num_atoms)
Definition: colvaratoms_gpu.h:31
cvm::real * d_atoms_mass
GPU atom mass (size: num_atoms)
Definition: colvaratoms_gpu.h:29
int * d_atoms_index
GPU atom proxy indices (size: num_atoms)
Definition: colvaratoms_gpu.h:21
cvm::rvector * d_cog_tmp
GPU temporary buffer for COG, used for avoiding memset.
Definition: colvaratoms_gpu.h:51
A struct for temporary variables for calculating the fit gradients.
Definition: colvaratoms_gpu.h:69
double3 * d_atom_grad
Fit gradients due to centering.
Definition: colvaratoms_gpu.h:71
unsigned int * d_tbcount
GPU atomic counter for block reduction.
Definition: colvaratoms_gpu.h:77
cvm::rmatrix * d_dxdC
Gradients of the CV with respect to the correlation matrix.
Definition: colvaratoms_gpu.h:75
double * d_sum_dxdq
Gradients of the CV with respect to the quaternion.
Definition: colvaratoms_gpu.h:73
A struct for the graph for debug gradients.
Definition: colvaratoms_gpu.h:83
bool initialized
Flag to describe whether the graph has been initialized.
Definition: colvaratoms_gpu.h:85
cudaGraph_t graph_calc_required_properties
CUDA Graph of calc_required_properties.
Definition: colvaratoms_gpu.h:87
cudaGraphExec_t graph_exec_calc_required_properties
CUDA Graph execution instance of calc_required_properties.
Definition: colvaratoms_gpu.h:89
Definition: colvar_rotation_derivative.h:622