bnmf-algs
host_memory_2d.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "defs.hpp"
4 #include <cstddef>
5 
6 namespace bnmf_algs {
7 namespace cuda {
37 template <typename T> class HostMemory2D {
38  public:
43  using value_type = T;
44 
58  explicit HostMemory2D(T* data, size_t rows, size_t cols)
59  : m_data(data), m_pitch(cols * sizeof(T)),
60  m_dims(shape<2>{rows, cols}){};
61 
68  T* data() const { return m_data; }
69 
81  size_t pitch() const { return m_pitch; }
82 
103  size_t width() const { return m_dims[1] * sizeof(T); }
104 
114  size_t height() const { return m_dims[0]; }
115 
121  shape<2> dims() const { return m_dims; }
122 
123  private:
127  T* m_data;
128 
133  size_t m_pitch;
134 
138  shape<2> m_dims;
139 };
140 } // namespace cuda
141 } // namespace bnmf_algs
T * data() const
Get the beginning address of the 2D memory wrapped by this HostMemory2D object.
Definition: host_memory_2d.hpp:68
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...
Definition: host_memory_2d.hpp:58
shape< 2 > dims() const
Get the dimensions of this memory region in terms of elements.
Definition: host_memory_2d.hpp:121
Eigen::array< size_t, N > shape
Shape of vectors, matrices, tensors, etc.
Definition: defs.hpp:66
size_t pitch() const
Get the pitch of the 2D matrix memory wrapped by this HostMemory2D object.
Definition: host_memory_2d.hpp:81
T value_type
Type of the values wrapped around current DeviceMemory1D object.
Definition: host_memory_2d.hpp:43
size_t height() const
Get the height of the 2D matrix in terms of number of elements.
Definition: host_memory_2d.hpp:114
A wrapper template class around a row-major matrix type stored in main memory (host memory)...
Definition: host_memory_2d.hpp:37
size_t width() const
Get the width of the 2D matrix in terms of bytes.
Definition: host_memory_2d.hpp:103
Main namespace for bnmf-algs library.
Definition: alloc_model_funcs.hpp:12