Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
correlation::core::gpu::DeviceBuffer< T > Class Template Reference

RAII wrapper for a typed GPU device allocation. More...

#include <DeviceBuffer.hpp>

Public Member Functions

 DeviceBuffer ()=default
 DeviceBuffer (std::size_t count)
 Allocates device memory for count elements of type T.
 ~DeviceBuffer ()
 DeviceBuffer (DeviceBuffer &&other) noexcept
DeviceBuffer & operator= (DeviceBuffer &&other) noexcept
 DeviceBuffer (const DeviceBuffer &)=delete
DeviceBuffer & operator= (const DeviceBuffer &)=delete
void copyFromHost (const T *host_data, std::size_t num_elements)
 Copies host data to this device buffer.
void copyToHost (T *host_data, std::size_t num_elements) const
 Copies device data back to a host buffer.
void setScalar (const T &value)
 Sets the entire buffer to a value via host-to-device copy of a single element.
T * get () noexcept
 Returns the raw device pointer.
const T * get () const noexcept
 Returns the raw device pointer (const overload).
std::size_t size () const noexcept
 Returns the number of allocated elements.

Private Member Functions

void release () noexcept

Private Attributes

T * ptr_ {nullptr}
std::size_t count_ {0}

Detailed Description

template<typename T>
class correlation::core::gpu::DeviceBuffer< T >

RAII wrapper for a typed GPU device allocation.

Allocates device memory on construction and releases it on destruction. Move-only — cannot be copied. Replaces raw hipMalloc/hipFree pairs to guarantee exception-safe cleanup.

Template Parameters
TElement type stored in the device buffer.

Constructor & Destructor Documentation

◆ DeviceBuffer() [1/4]

template<typename T>
correlation::core::gpu::DeviceBuffer< T >::DeviceBuffer ( )
default
Here is the caller graph for this function:

◆ DeviceBuffer() [2/4]

template<typename T>
correlation::core::gpu::DeviceBuffer< T >::DeviceBuffer ( std::size_t count)
inlineexplicit

Allocates device memory for count elements of type T.

Parameters
[in]countNumber of elements to allocate.
Exceptions
GPUErrorIf the device allocation fails.
Here is the call graph for this function:

◆ ~DeviceBuffer()

template<typename T>
correlation::core::gpu::DeviceBuffer< T >::~DeviceBuffer ( )
inline
Here is the call graph for this function:

◆ DeviceBuffer() [3/4]

template<typename T>
correlation::core::gpu::DeviceBuffer< T >::DeviceBuffer ( DeviceBuffer< T > && other)
inlinenoexcept
Here is the call graph for this function:

◆ DeviceBuffer() [4/4]

template<typename T>
correlation::core::gpu::DeviceBuffer< T >::DeviceBuffer ( const DeviceBuffer< T > & )
delete
Here is the call graph for this function:

Member Function Documentation

◆ copyFromHost()

template<typename T>
void correlation::core::gpu::DeviceBuffer< T >::copyFromHost ( const T * host_data,
std::size_t num_elements )
inline

Copies host data to this device buffer.

Parameters
[in]host_dataPointer to host source data.
[in]num_elementsNumber of elements to copy (must be ≤ count_).
Exceptions
GPUErrorIf the memory copy fails.
Here is the call graph for this function:

◆ copyToHost()

template<typename T>
void correlation::core::gpu::DeviceBuffer< T >::copyToHost ( T * host_data,
std::size_t num_elements ) const
inline

Copies device data back to a host buffer.

Parameters
[out]host_dataPointer to host destination buffer.
[in]num_elementsNumber of elements to copy (must be ≤ count_).
Exceptions
GPUErrorIf the memory copy fails.
Here is the call graph for this function:

◆ get() [1/2]

template<typename T>
const T * correlation::core::gpu::DeviceBuffer< T >::get ( ) const
inlinenodiscardnoexcept

Returns the raw device pointer (const overload).

Returns
Const device pointer.

◆ get() [2/2]

template<typename T>
T * correlation::core::gpu::DeviceBuffer< T >::get ( )
inlinenodiscardnoexcept

Returns the raw device pointer.

Returns
Device pointer (may be nullptr if default-constructed or moved-from).

◆ operator=() [1/2]

template<typename T>
DeviceBuffer & correlation::core::gpu::DeviceBuffer< T >::operator= ( const DeviceBuffer< T > & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

template<typename T>
DeviceBuffer & correlation::core::gpu::DeviceBuffer< T >::operator= ( DeviceBuffer< T > && other)
inlinenoexcept
Here is the call graph for this function:

◆ release()

template<typename T>
void correlation::core::gpu::DeviceBuffer< T >::release ( )
inlineprivatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScalar()

template<typename T>
void correlation::core::gpu::DeviceBuffer< T >::setScalar ( const T & value)
inline

Sets the entire buffer to a value via host-to-device copy of a single element.

Parameters
[in]valueThe value to write (copied to device for the first element).
Here is the call graph for this function:

◆ size()

template<typename T>
std::size_t correlation::core::gpu::DeviceBuffer< T >::size ( ) const
inlinenodiscardnoexcept

Returns the number of allocated elements.

Returns
Element count.

Member Data Documentation

◆ count_

template<typename T>
std::size_t correlation::core::gpu::DeviceBuffer< T >::count_ {0}
private

◆ ptr_

template<typename T>
T* correlation::core::gpu::DeviceBuffer< T >::ptr_ {nullptr}
private

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