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

A wrapper template class around 2D row-major pitched memory stored in device memory (GPU memory). More...

#include <device_memory_2d.hpp>

Public Types

using value_type = T
 Type of the values stored on GPU. More...
 

Public Member Functions

 DeviceMemory2D (size_t rows, size_t cols)
 Construct a DeviceMemory2D object responsible from the GPU memory allocated with respect to the given host matrix. More...
 
 DeviceMemory2D (const DeviceMemory2D &)=delete
 Copy constructor (deleted). More...
 
DeviceMemory2Doperator= (const DeviceMemory2D &)=delete
 Copy assignment operator (deleted). More...
 
 DeviceMemory2D (DeviceMemory2D &&other)
 Move constructor. More...
 
DeviceMemory2Doperator= (DeviceMemory2D &&other)
 Move assignment operator. More...
 
 ~DeviceMemory2D ()
 Destruct the current DeviceMemory2D object by deallocating the held GPU memory. More...
 
T * data () const
 Get a device pointer pointing to the pitched memory allocated by the current DeviceMemory2D object. More...
 
size_t pitch () const
 Get the pitch of the allocation. More...
 
size_t width () const
 Get the width of the allocation in terms of bytes. More...
 
size_t height () const
 Get the height of the allocation in terms of number of elements. More...
 
shape< 2 > dims () const
 Get the dimensions of this memory region in terms of elements. More...
 

Detailed Description

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

A wrapper template class around 2D row-major pitched memory stored in device memory (GPU memory).

DeviceMemory2D class represents the memory of a row-major matrix type stored in device memory (GPU memory). The intended use of this class is to provide an interface that can be used with CUDA functions.

DeviceMemory2D class owns the memory it allocates on the GPU, and therefore is responsible from the deallocation of the allocated GPU memory. GPU memory allocation is performed upon object construction and deallocation is performed upon object destruction.

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

Template Parameters
TType of the values in the given memory address.

Member Typedef Documentation

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

Type of the values stored on GPU.

Constructor & Destructor Documentation

template<typename T>
bnmf_algs::cuda::DeviceMemory2D< T >::DeviceMemory2D ( size_t  rows,
size_t  cols 
)
inlineexplicit

Construct a DeviceMemory2D object responsible from the GPU memory allocated with respect to the given host matrix.

This constructor allocates a 2D pitched memory on the GPU using cudaMallocPitch function. The allocated matrix memory is in row-major order. Therefore, pitch of the GPU memory is set as the number of bytes of a single row of the matrix. See cudaMallocPitch documentation to learn more about the intrinsics of the memory allocation procedure.

Parameters
rowsNumber of rows of the row-major GPU matrix to allocate.
colsNumber of columns of the row-major GPU matrix to allocate.
template<typename T>
bnmf_algs::cuda::DeviceMemory2D< T >::DeviceMemory2D ( const DeviceMemory2D< T > &  )
delete

Copy constructor (deleted).

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

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

Move constructor.

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

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

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

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

Member Function Documentation

template<typename T>
T* bnmf_algs::cuda::DeviceMemory2D< T >::data ( ) const
inline

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

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

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

Returns
A bnmf_algs::shape<2> object of the form {rows, cols}.
template<typename T>
size_t bnmf_algs::cuda::DeviceMemory2D< T >::height ( ) const
inline

Get the height of the allocation in terms of number of elements.

Height of the allocation is defined as the number of elements in a single column of the allocated matrix.

Returns
Height (number of elements in a single column of the matrix).
template<typename T>
DeviceMemory2D& bnmf_algs::cuda::DeviceMemory2D< T >::operator= ( const DeviceMemory2D< T > &  )
delete

Copy assignment operator (deleted).

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

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

Move assignment operator.

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

Parameters
otherOther DeviceMemory2D object to move from.
Returns
Reference to assigned object.
template<typename T>
size_t bnmf_algs::cuda::DeviceMemory2D< T >::pitch ( ) const
inline

Get the pitch of the allocation.

Pitch of the allocation is defined as the number of bytes required to store a single row of the matrix, including the padding bytes.

Returns
Pitch (number of bytes of a single row including padding bytes).
template<typename T>
size_t bnmf_algs::cuda::DeviceMemory2D< T >::width ( ) const
inline

Get the width of the allocation in terms of bytes.

Width of the allocation is defined as the number of bytes required to store a single row of the matrix, excluding the padding bytes. Note that DeviceMemory2D pitch and width member function generally give different results due to the padding bytes used by cudaMallocPitch function.

Returns
Width (number of bytes of a single row excluding padding bytes).

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