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

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

#include <device_memory_3d.hpp>

Public Types

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

Public Member Functions

 DeviceMemory3D (size_t first_dim, size_t second_dim, size_t third_dim)
 Construct a DeviceMemory3D object responsible from the GPU memory allocated with respect to the given host matrix. More...
 
 DeviceMemory3D (const DeviceMemory3D &)=delete
 Copy constructor (deleted). More...
 
DeviceMemory3Doperator= (const DeviceMemory3D &)=delete
 Copy assignment operator (deleted). More...
 
 DeviceMemory3D (DeviceMemory3D &&other)
 Move constructor. More...
 
DeviceMemory3Doperator= (DeviceMemory3D &&other)
 Move assignment operator. More...
 
 ~DeviceMemory3D ()
 Destruct the current DeviceMemory3D object by deallocating the held GPU memory. More...
 
cudaPitchedPtr pitched_ptr () const
 Get the cudaPitchedPtr type storing allocation parameters and the pointer to the device memory. More...
 
cudaExtent extent () const
 Get the cudaExtent type storing the extents of the allocation. More...
 
shape< 3 > dims () const
 Get the dimensions of this memory region in terms of elements. More...
 

Detailed Description

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

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

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

DeviceMemory3D 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.

DeviceMemory3D objects can be used with cuda::copy3D function along with HostMemory3D objects to copy memory from host/device to host/device locations. See cuda::copy3D 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::DeviceMemory3D< T >::value_type = T

Type of the values stored on GPU.

Constructor & Destructor Documentation

template<typename T>
bnmf_algs::cuda::DeviceMemory3D< T >::DeviceMemory3D ( size_t  first_dim,
size_t  second_dim,
size_t  third_dim 
)
inlineexplicit

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

This constructor allocates a 3D row-major pitched memory on the GPU using cudaMalloc3D function. The allocated tensor memory is in row-major order. Therefore, pitch of the GPU memory is set as the number of bytes of a single fiber of the tensor (along 3rd dimension). See cudaMalloc3D documentation to learn more about the intrinsics of the memory allocation procedure.

Parameters
first_dimFirst dimension of the 3D memory to allocate.
second_dimSecond dimension of the 3D memory to allocate.
third_dimThird dimension of the 3D memory to allocate. Since the tensor is allocated in row-major order, allocation pitch is set as the number of bytes required to store a single fiber along the third dimension.
template<typename T>
bnmf_algs::cuda::DeviceMemory3D< T >::DeviceMemory3D ( const DeviceMemory3D< T > &  )
delete

Copy constructor (deleted).

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

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

Move constructor.

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

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

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

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

Member Function Documentation

template<typename T>
shape<3> bnmf_algs::cuda::DeviceMemory3D< T >::dims ( ) const
inline

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

Returns
A bnmf_algs::shape object of the form {first_dim, second_dim, third_dim}.
template<typename T>
cudaExtent bnmf_algs::cuda::DeviceMemory3D< T >::extent ( ) const
inline

Get the cudaExtent type storing the extents of the allocation.

Parameters of the returned extent type is set according to a row-major tensor allocation. See cudaExtent type documentation for the parameters provided about the allocation.

Returns
cudaExtent type storing the extents of the allocation.
template<typename T>
DeviceMemory3D& bnmf_algs::cuda::DeviceMemory3D< T >::operator= ( const DeviceMemory3D< T > &  )
delete

Copy assignment operator (deleted).

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

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

Move assignment operator.

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

Parameters
otherOther DeviceMemory3D object to move from.
Returns
Reference to assigned object.
template<typename T>
cudaPitchedPtr bnmf_algs::cuda::DeviceMemory3D< T >::pitched_ptr ( ) const
inline

Get the cudaPitchedPtr type storing allocation parameters and the pointer to the device memory.

Parameters of the returned pitched pointer type is set according to a row-major tensor allocation. See cudaPitchedPtr type documentation for the parameters provided about the allocation.

Returns
cudaPitchedPtr type storing allocation parameters and the pointer itself.

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