bnmf-algs
|
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... | |
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,
T | Type of the values in the given memory address. |
using bnmf_algs::cuda::HostMemory2D< T >::value_type = T |
Type of the values wrapped around current DeviceMemory1D object.
|
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.
data | Address of the beginning of the memory storing the row-major 2D matrix. |
rows | Number of rows of the matrix. |
cols | Number of columns of the matrix. |
|
inline |
Get the beginning address of the 2D memory wrapped by this HostMemory2D object.
|
inline |
Get the dimensions of this memory region in terms of elements.
|
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.
|
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.
|
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.