Collective Variables Module - Developer Documentation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
colvarproxy_gpu Class Reference

Class for managing GPU memory allocation and data transfer. More...

#include <colvarproxy_gpu.h>

Inheritance diagram for colvarproxy_gpu:
Inheritance graph
[legend]

Public Types

enum class  event_type { copy_atoms , update_lattice , num_event_types }
 Available CUDA event types.
 

Public Member Functions

 colvarproxy_gpu ()
 Constructor.
 
bool has_gpu_support () const
 Whether the proxy supports GPU.
 
std::string gpu_name () const
 Get the GPU name.
 
std::string gpu_bus_id () const
 Get the GPU PCI bus ID.
 
int gpu_device_id () const
 Get the GPU device number.
 
std::string gpu_platform () const
 Get the GPU platform (CUDA, HIP or SYCL)
 
int gpu_warp_size () const
 CUDA warp size or HIP wave front size.
 
virtual cudaStream_t get_default_stream ()
 Get the default CUDA stream from the proxy.
 
int init_gpu ()
 Initialize the GPU data (called by colvarproxy::setup)
 
cudaEvent_t get_event (event_type type) const
 Get the default CUDA event from the proxy.
 
template<typename T >
int allocate_host (T **pp, const size_t len)
 Template function to allocate host-pinned memory. More...
 
template<typename T >
int deallocate_host (T **pp)
 Template function to deallocate host-pinned memory. More...
 
template<typename T >
int allocate_device (T **pp, const size_t len)
 Template function to allocate device memory. More...
 
template<typename T >
int reallocate_device (T **pp, const size_t len)
 Template function to reallocate device memory. More...
 
template<typename T >
int reallocate_host (T **pp, const size_t len)
 Template function to reallocate host-pinned memory. More...
 
template<typename T >
int allocate_device_async (T **pp, const size_t len, cudaStream_t stream)
 Template function to allocate device memory asynchronously. More...
 
template<typename T >
int deallocate_device (T **pp)
 Template function to deallocate device memory. More...
 
template<typename T >
int deallocate_device_async (T **pp, cudaStream_t stream)
 Template function to deallocate device memory asynchronously. More...
 
template<typename T >
int clear_device_array (T *data, const size_t ndata)
 Template function to clear a device array to zero. More...
 
template<typename T >
int clear_device_array_async (T *data, const size_t ndata, cudaStream_t stream)
 Template function to clear a device array to zero asynchronously. More...
 
template<typename T >
int copy_HtoD (const T *h_array, T *d_array, size_t array_len)
 Template function to copy data from host to device. More...
 
template<typename T >
int copy_HtoD_async (const T *h_array, T *d_array, size_t array_len, cudaStream_t stream)
 Template function to copy data from host to device asynchronously. More...
 
template<typename T >
int copy_DtoH (const T *d_array, T *h_array, size_t array_len)
 Template function to copy data from device to host. More...
 
template<typename T >
int copy_DtoH_async (const T *d_array, T *h_array, size_t array_len, cudaStream_t stream)
 Template function to copy data from device to host asynchronously. More...
 
template<typename T >
int copy_DtoD (const T *d_src, T *d_dst, size_t array_len)
 Template function to copy data from device to device. More...
 
template<typename T >
int copy_DtoD_async (const T *d_src, T *d_dst, size_t array_len, cudaStream_t stream)
 Template function to copy data from device to device asynchronously. More...
 
virtual ~colvarproxy_gpu ()
 Destructor.
 
virtual int allocate_host_T (void **pp, const size_t len, const size_t sizeofT)
 Memory management and data transfer implementations.
 
virtual int deallocate_host_T (void **pp)
 
virtual int allocate_device_T (void **pp, const size_t len, const size_t sizeofT)
 
virtual int deallocate_device_T (void **pp)
 
virtual int clear_device_array_T (void *data, const size_t ndata, const size_t sizeofT)
 
virtual int allocate_device_T_async (void **pp, const size_t len, const size_t sizeofT, cudaStream_t stream)
 
virtual int deallocate_device_T_async (void **pp, cudaStream_t stream)
 
virtual int clear_device_array_T_async (void *data, const size_t ndata, const size_t sizeofT, cudaStream_t stream)
 
virtual int copy_HtoD_T (const void *h_array, void *d_array, size_t array_len, const size_t sizeofT)
 
virtual int copy_HtoD_T_async (const void *h_array, void *d_array, size_t array_len, const size_t sizeofT, cudaStream_t stream)
 
virtual int copy_DtoH_T (const void *d_array, void *h_array, size_t array_len, const size_t sizeofT)
 
virtual int copy_DtoH_T_async (const void *d_array, void *h_array, size_t array_len, const size_t sizeofT, cudaStream_t stream)
 
virtual int copy_DtoD_T (const void *d_src, void *d_dst, size_t array_len, const size_t sizeofT)
 
virtual int copy_DtoD_T_async (const void *d_src, void *d_dst, size_t array_len, const size_t sizeofT, cudaStream_t stream)
 
virtual float * proxy_atoms_masses_gpu_float ()
 Functions to get device pointers for atom properties This functions should be overridden in derived proxy classes that manage actual GPU memory.
 
virtual float * proxy_atoms_charges_gpu_float ()
 
virtual cvm::realproxy_atoms_masses_gpu ()
 
virtual cvm::realproxy_atoms_charges_gpu ()
 
virtual cvm::realproxy_atoms_positions_gpu ()
 
virtual cvm::realproxy_atoms_total_forces_gpu ()
 
virtual cvm::realproxy_atoms_new_colvar_forces_gpu ()
 

Protected Attributes

bool support_gpu
 Whether the proxy supports GPU.
 
int warp_size
 Warp size.
 
std::array< cudaEvent_t, static_cast< int >(event_type::num_event_types)> events = {}
 

Detailed Description

Class for managing GPU memory allocation and data transfer.

Member Function Documentation

◆ allocate_device()

template<typename T >
int colvarproxy_gpu::allocate_device ( T **  pp,
const size_t  len 
)
inline

Template function to allocate device memory.

Template Parameters
TThe type of elements to allocate
Parameters
[out]ppPointer to the pointer that will hold the allocated device memory
[in]lenNumber of elements to allocate
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ allocate_device_async()

template<typename T >
int colvarproxy_gpu::allocate_device_async ( T **  pp,
const size_t  len,
cudaStream_t  stream 
)
inline

Template function to allocate device memory asynchronously.

Template Parameters
TThe type of elements to allocate
Parameters
[out]ppPointer to the pointer that will hold the allocated device memory
[in]lenNumber of elements to allocate
[in]streamThe CUDA stream to use for the allocation
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ allocate_host()

template<typename T >
int colvarproxy_gpu::allocate_host ( T **  pp,
const size_t  len 
)
inline

Template function to allocate host-pinned memory.

Template Parameters
TThe type of elements to allocate
Parameters
[out]ppPointer to the pointer that will hold the allocated host-pinned memory
[in]lenNumber of elements to allocate
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ clear_device_array()

template<typename T >
int colvarproxy_gpu::clear_device_array ( T *  data,
const size_t  ndata 
)
inline

Template function to clear a device array to zero.

Template Parameters
TThe type of elements in the array
Parameters
[in]dataPointer to the device array to clear
[in]ndataNumber of elements in the array
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ clear_device_array_async()

template<typename T >
int colvarproxy_gpu::clear_device_array_async ( T *  data,
const size_t  ndata,
cudaStream_t  stream 
)
inline

Template function to clear a device array to zero asynchronously.

Template Parameters
TThe type of elements in the array
Parameters
[in]dataPointer to the device array to clear
[in]ndataNumber of elements in the array
[in]streamThe CUDA stream to use for the operation
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ copy_DtoD()

template<typename T >
int colvarproxy_gpu::copy_DtoD ( const T *  d_src,
T *  d_dst,
size_t  array_len 
)
inline

Template function to copy data from device to device.

Template Parameters
TThe type of elements to copy
Parameters
[in]d_srcPointer to the source device array
[out]d_dstPointer to the destination device array
[in]array_lenNumber of elements to copy
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ copy_DtoD_async()

template<typename T >
int colvarproxy_gpu::copy_DtoD_async ( const T *  d_src,
T *  d_dst,
size_t  array_len,
cudaStream_t  stream 
)
inline

Template function to copy data from device to device asynchronously.

Template Parameters
TThe type of elements to copy
Parameters
[in]d_srcPointer to the source device array
[out]d_dstPointer to the destination device array
[in]array_lenNumber of elements to copy
[in]streamThe CUDA stream to use for the operation
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ copy_DtoH()

template<typename T >
int colvarproxy_gpu::copy_DtoH ( const T *  d_array,
T *  h_array,
size_t  array_len 
)
inline

Template function to copy data from device to host.

Template Parameters
TThe type of elements to copy
Parameters
[in]d_arrayPointer to the device array
[out]h_arrayPointer to the host array
[in]array_lenNumber of elements to copy
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ copy_DtoH_async()

template<typename T >
int colvarproxy_gpu::copy_DtoH_async ( const T *  d_array,
T *  h_array,
size_t  array_len,
cudaStream_t  stream 
)
inline

Template function to copy data from device to host asynchronously.

Template Parameters
TThe type of elements to copy
Parameters
[in]d_arrayPointer to the device array
[out]h_arrayPointer to the host array
[in]array_lenNumber of elements to copy
[in]streamThe CUDA stream to use for the operation
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ copy_HtoD()

template<typename T >
int colvarproxy_gpu::copy_HtoD ( const T *  h_array,
T *  d_array,
size_t  array_len 
)
inline

Template function to copy data from host to device.

Template Parameters
TThe type of elements to copy
Parameters
[in]h_arrayPointer to the host array
[in]d_arrayPointer to the device array
[in]array_lenNumber of elements to copy
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ copy_HtoD_async()

template<typename T >
int colvarproxy_gpu::copy_HtoD_async ( const T *  h_array,
T *  d_array,
size_t  array_len,
cudaStream_t  stream 
)
inline

Template function to copy data from host to device asynchronously.

Template Parameters
TThe type of elements to copy
Parameters
[in]h_arrayPointer to the host array
[out]d_arrayPointer to the device array
[in]array_lenNumber of elements to copy
[in]streamThe CUDA stream to use for the operation
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ deallocate_device()

template<typename T >
int colvarproxy_gpu::deallocate_device ( T **  pp)
inline

Template function to deallocate device memory.

Template Parameters
TThe type of elements to deallocate
Parameters
[in,out]ppPointer to the pointer that holds the allocated device memory
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ deallocate_device_async()

template<typename T >
int colvarproxy_gpu::deallocate_device_async ( T **  pp,
cudaStream_t  stream 
)
inline

Template function to deallocate device memory asynchronously.

Template Parameters
TThe type of elements to deallocate
Parameters
[in,out]ppPointer to the pointer that holds the allocated device memory
[in]streamThe CUDA stream to use for the deallocation
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ deallocate_host()

template<typename T >
int colvarproxy_gpu::deallocate_host ( T **  pp)
inline

Template function to deallocate host-pinned memory.

Template Parameters
TThe type of elements to deallocate
Parameters
[in,out]ppPointer to the pointer that holds the allocated host-pinned memory
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ reallocate_device()

template<typename T >
int colvarproxy_gpu::reallocate_device ( T **  pp,
const size_t  len 
)
inline

Template function to reallocate device memory.

This function first deallocates any existing memory pointed to by *pp, then allocates new device memory for len elements of type T.

Template Parameters
TThe type of elements to allocate
Parameters
[out]ppPointer to the pointer that will hold the allocated device memory
[in]lenNumber of elements to allocate
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

◆ reallocate_host()

template<typename T >
int colvarproxy_gpu::reallocate_host ( T **  pp,
const size_t  len 
)
inline

Template function to reallocate host-pinned memory.

This function first deallocates any existing memory pointed to by *pp, then allocates new host-pinned memory for len elements of type T.

Template Parameters
TThe type of elements to allocate
Parameters
[out]ppPointer to the pointer that will hold the allocated host-pinned memory
[in]lenNumber of elements to allocate
Returns
COLVARS_OK if successful, otherwise COLVARS_ERROR

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