bnmf-algs
Public Types | Public Member Functions | List of all members
bnmf_algs::cuda::DeviceMemory1D< T > Class Template Reference

A wrapper template class around a contiguous array of T types laid out in device memory (GPU memory). More...

#include <device_memory_1d.hpp>

Public Types

using value_type = T
 Type of the values wrapped around current DeviceMemory1D object. More...
 

Public Member Functions

 DeviceMemory1D (size_t num_elems)
 Construct a DeviceMemory1D object that allocates num_elems many T values on the GPU device. More...
 
 DeviceMemory1D (const DeviceMemory1D &)=delete
 Copy constructor (deleted). More...
 
DeviceMemory1Doperator= (const DeviceMemory1D &)=delete
 Copy assignment operator (deleted). More...
 
 DeviceMemory1D (DeviceMemory1D &&other)
 Move constructor. More...
 
DeviceMemory1Doperator= (DeviceMemory1D &&other)
 Move assignment operator. More...
 
 ~DeviceMemory1D ()
 Destruct the current DeviceMemory1D object by deallocating the held GPU memory. More...
 
T * data () const
 Get a device pointer pointing to the memory allocated by the current DeviceMemory1D object. More...
 
size_t bytes () const
 Get the number of bytes of the allocated memory on the GPU. More...
 
shape< 1 > dims () const
 Get the dimensions of this memory region in terms of elements. More...
 

Detailed Description

template<typename T>
class bnmf_algs::cuda::DeviceMemory1D< T >

A wrapper template class around a contiguous array of T types laid out in device memory (GPU memory).

DeviceMemory1D class represents the memory for a contiguous sequence of T values in device memory. The intended use of this class is to provide an interface that can be used with CUDA functions.

DeviceMemory1D class owns the device memory it allocates, and therefore is responsible from the deallocation of the allocated GPU memory. This operation is performed upon object destruction.

DeviceMemory1D objects can be used with cuda::copy1D function along with HostMemory1D objects to copy memory from host/device to host/device locations. See cuda::copy1D for details about copying memory using CUDA functions.

Template Parameters
TType of the values to be allocated in GPU device.

Member Typedef Documentation

template<typename T >
using bnmf_algs::cuda::DeviceMemory1D< T >::value_type = T

Type of the values wrapped around current DeviceMemory1D object.

Constructor & Destructor Documentation

template<typename T >
bnmf_algs::cuda::DeviceMemory1D< T >::DeviceMemory1D ( size_t  num_elems)
inlineexplicit

Construct a DeviceMemory1D object that allocates num_elems many T values on the GPU device.

After this DeviceMemory1D object is constructed, there will be num_elems many T types allocated on the GPU device. See cudaMalloc function documentation for memory allocation intrinsics.

Parameters
num_elemsNumber of T types to allocate on the GPU.
template<typename T >
bnmf_algs::cuda::DeviceMemory1D< T >::DeviceMemory1D ( const DeviceMemory1D< T > &  )
delete

Copy constructor (deleted).

Since DeviceMemory1D objects own the memory they own, only move operators are allowed.

template<typename T >
bnmf_algs::cuda::DeviceMemory1D< T >::DeviceMemory1D ( DeviceMemory1D< T > &&  other)
inline

Move constructor.

Move construct a new DeviceMemory1D object. After this constructor exits, the parameter DeviceMemory1D object does not point to any location and therefore must not be used.

Parameters
otherOther DeviceMemory1D object to move from.
template<typename T >
bnmf_algs::cuda::DeviceMemory1D< T >::~DeviceMemory1D ( )
inline

Destruct the current DeviceMemory1D object by deallocating the held GPU memory.

This function deallocates the GPU memory held by the current DeviceMemory1D object. See cudaFree function documentation for memory deallocation intrinsics.

Member Function Documentation

template<typename T >
size_t bnmf_algs::cuda::DeviceMemory1D< T >::bytes ( ) const
inline

Get the number of bytes of the allocated memory on the GPU.

Returns
Number of bytes of the allocated GPU memory.
template<typename T >
T* bnmf_algs::cuda::DeviceMemory1D< T >::data ( ) const
inline

Get a device pointer pointing to the memory allocated by the current DeviceMemory1D object.

Returns
Device pointer pointing to the allocated GPU memory.
template<typename T >
shape<1> bnmf_algs::cuda::DeviceMemory1D< T >::dims ( ) const
inline

Get the dimensions of this memory region in terms of elements.

Returns
A bnmf_algs::shape representing the dimension.
template<typename T >
DeviceMemory1D& bnmf_algs::cuda::DeviceMemory1D< T >::operator= ( const DeviceMemory1D< T > &  )
delete

Copy assignment operator (deleted).

Since DeviceMemory1D objects own the memory they own, only move operators are allowed.

template<typename T >
DeviceMemory1D& bnmf_algs::cuda::DeviceMemory1D< T >::operator= ( DeviceMemory1D< T > &&  other)
inline

Move assignment operator.

Move assign to this DeviceMemory1D object. After this constructor exits, the parameter DeviceMemor(1D object does not point to any location and therefore must not be used. Additionally, the old memory pointed by this DeviceMemory1D is freed.

Parameters
otherOther DeviceMemory1D object to move from.
Returns
Reference to assigned object.

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