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

A wrapper template class around a row-major matrix type stored in main memory (host memory). More...

#include <host_memory_2d.hpp>

Public Types

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

Public Member Functions

 HostMemory2D (T *data, size_t rows, size_t cols)
 Construct a HostMemory2D class around the memory given by the pointer and the rows and columns of the matrix. More...
 
T * data () const
 Get the beginning address of the 2D memory wrapped by this HostMemory2D object. More...
 
size_t pitch () const
 Get the pitch of the 2D matrix memory wrapped by this HostMemory2D object. More...
 
size_t width () const
 Get the width of the 2D matrix in terms of bytes. More...
 
size_t height () const
 Get the height of the 2D matrix 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::HostMemory2D< T >

A wrapper template class around a row-major matrix type stored in main memory (host memory).

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

HostMemory2D class does not own the memory it is given. Therefore, no allocation, copying or memory freeing is performed. The only use case of HostMemory2D is to provide a unified interface with DeviceMemory2D so that the two classes can be used interchangeably by cuda::copy2D function. See cuda::copy2D for details about copying 2D memory using CUDA functions from host/device to host/device memory.

If the pointer pointing to the memory is const, then the type of this class must be marked as const to prevent illegal mutating code from accessing the memory. For example,

const matrix_t<int> mat(5, 3);
// mark T as const so that the instantiations of the template functions
// and the member pointers are marked as const.
HostMemory2D<const int> host_memory(mat.data(), mat.rows(), mat.cols());
Template Parameters
TType of the values in the given memory address.

Member Typedef Documentation

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

Type of the values wrapped around current DeviceMemory1D object.

Constructor & Destructor Documentation

template<typename T>
bnmf_algs::cuda::HostMemory2D< T >::HostMemory2D ( T *  data,
size_t  rows,
size_t  cols 
)
inlineexplicit

Construct a HostMemory2D class around the memory given by the pointer and the rows and columns of the matrix.

The memory given by pointer is assumed to reside in main memory. Therefore, this function does not perform any memory allocation on main memory or GPU device.

Parameters
dataAddress of the beginning of the memory storing the row-major 2D matrix.
rowsNumber of rows of the matrix.
colsNumber of columns of the matrix.

Member Function Documentation

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

Get the beginning address of the 2D memory wrapped by this HostMemory2D object.

Returns
Pointer to the beginning of the 2D matrix memory.
template<typename T>
shape<2> bnmf_algs::cuda::HostMemory2D< 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::HostMemory2D< T >::height ( ) const
inline

Get the height of the 2D matrix in terms of number of elements.

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

Returns
Height (number of elements in a single column of the matrix).
template<typename T>
size_t bnmf_algs::cuda::HostMemory2D< T >::pitch ( ) const
inline

Get the pitch of the 2D matrix memory wrapped by this HostMemory2D object.

Pitch of the allocation is defined as the number of bytes of a single row of the 2D matrix memory, including the padding bytes, stored in row-major order.

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

Get the width of the 2D matrix in terms of bytes.

Width is defined as the number of bytes of a single row of the 2D matrix memory, without the padding bytes, stored in row-major order.

The fact that width member returning a value in terms of bytes whereas height returning in terms of number of elements may seem weird to new users of this API. However, this is the convention adopted by CUDA functions. Since this library tries to be as compatible with CUDA function usage conventions as possible, we follow the same pattern and return the width of a matrix in terms of bytes.

It is assumed that the 2D matrix stored in the main memory does not use any padding bytes. Therefore, the results of width and pitch member functions are the same for host memory matrices.

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

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