bnmf-algs
|
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... | |
DeviceMemory2D & | operator= (const DeviceMemory2D &)=delete |
Copy assignment operator (deleted). More... | |
DeviceMemory2D (DeviceMemory2D &&other) | |
Move constructor. More... | |
DeviceMemory2D & | operator= (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... | |
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.
T | Type of the values in the given memory address. |
using bnmf_algs::cuda::DeviceMemory2D< T >::value_type = T |
Type of the values stored on GPU.
|
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.
rows | Number of rows of the row-major GPU matrix to allocate. |
cols | Number of columns of the row-major GPU matrix to allocate. |
|
delete |
Copy constructor (deleted).
Since DeviceMemory2D objects own the memory they own, only move operators are allowed.
|
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.
other | Other DeviceMemory2D object to move from. |
|
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.
|
inline |
Get a device pointer pointing to the pitched memory allocated by the current DeviceMemory2D object.
|
inline |
Get the dimensions of this memory region in terms of elements.
|
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.
|
delete |
Copy assignment operator (deleted).
Since DeviceMemory2D objects own the memory they own, only move operators are allowed.
|
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.
other | Other DeviceMemory2D object to move from. |
|
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.
|
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.