5 #include <cuda_runtime.h> 57 : m_dims(
shape<3>{first_dim, second_dim, third_dim}),
59 make_cudaExtent(third_dim *
sizeof(T), second_dim, first_dim)),
61 auto err = cudaMalloc3D(&m_ptr, m_extent);
64 "Error allocating memory in cuda::DeviceMemory3D::DeviceMemory3D");
93 : m_dims(other.m_dims), m_extent(other.m_extent), m_ptr(other.m_ptr) {
94 other.reset_members();
109 this->free_cuda_mem();
111 this->m_dims = other.m_dims;
112 this->m_extent = other.m_extent;
113 this->m_ptr = other.m_ptr;
115 other.reset_members();
152 cudaExtent
extent()
const {
return m_extent; }
166 void free_cuda_mem() {
167 auto err = cudaFree(m_ptr.ptr);
170 "Error deallocating memory in cuda::DeviceMemory3D::free_cuda_mem");
176 void reset_members() {
177 this->m_dims = {0, 0, 0};
178 this->m_extent = {0, 0, 0};
179 this->m_ptr = {
nullptr, 0, 0, 0};
197 cudaPitchedPtr m_ptr;
cudaExtent extent() const
Get the cudaExtent type storing the extents of the allocation.
Definition: device_memory_3d.hpp:152
A wrapper template class around 3D row-major pitched memory stored in device memory (GPU memory)...
Definition: device_memory_3d.hpp:30
DeviceMemory3D & operator=(DeviceMemory3D &&other)
Move assignment operator.
Definition: device_memory_3d.hpp:108
shape< 3 > dims() const
Get the dimensions of this memory region in terms of elements.
Definition: device_memory_3d.hpp:160
Eigen::array< size_t, N > shape
Shape of vectors, matrices, tensors, etc.
Definition: defs.hpp:66
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...
Definition: device_memory_3d.hpp:55
~DeviceMemory3D()
Destruct the current DeviceMemory3D object by deallocating the held GPU memory.
Definition: device_memory_3d.hpp:128
cudaPitchedPtr pitched_ptr() const
Get the cudaPitchedPtr type storing allocation parameters and the pointer to the device memory...
Definition: device_memory_3d.hpp:141
T value_type
Type of the values stored on GPU.
Definition: device_memory_3d.hpp:35
DeviceMemory3D & operator=(const DeviceMemory3D &)=delete
Copy assignment operator (deleted).
DeviceMemory3D(DeviceMemory3D &&other)
Move constructor.
Definition: device_memory_3d.hpp:92
Main namespace for bnmf-algs library.
Definition: alloc_model_funcs.hpp:12