bnmf-algs
host_memory_3d.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "defs.hpp"
4 #include <cstddef>
5 #include <cuda_runtime.h>
6 
7 namespace bnmf_algs {
8 namespace cuda {
37 template <typename T> class HostMemory3D {
38  public:
42  using value_type = T;
43 
64  explicit HostMemory3D(T* data, size_t first_dim, size_t second_dim,
65  size_t third_dim)
66  : m_dims(shape<3>{first_dim, second_dim, third_dim}),
67  m_extent(
68  make_cudaExtent(third_dim * sizeof(T), second_dim, first_dim)),
69  m_ptr() {
70  m_ptr.pitch = third_dim * sizeof(T);
71  m_ptr.xsize = third_dim;
72  m_ptr.ysize = second_dim;
73  m_ptr.ptr = (void*)(data);
74  }
75 
87  cudaPitchedPtr pitched_ptr() const { return m_ptr; }
88 
98  cudaExtent extent() const { return m_extent; }
99 
106  shape<3> dims() const { return m_dims; }
107 
108  private:
113  shape<3> m_dims;
114 
118  cudaExtent m_extent;
119 
123  cudaPitchedPtr m_ptr;
124 };
125 } // namespace cuda
126 } // namespace bnmf_algs
shape< 3 > dims() const
Get the dimensions of this memory region in terms of elements.
Definition: host_memory_3d.hpp:106
A wrapper template class around a row-major 3D tensor stored in main memory (host memory)...
Definition: host_memory_3d.hpp:37
cudaExtent extent() const
Get the cudaExtent type storing the extents of the allocation.
Definition: host_memory_3d.hpp:98
T value_type
Type of the values stored in main memory.
Definition: host_memory_3d.hpp:42
Eigen::array< size_t, N > shape
Shape of vectors, matrices, tensors, etc.
Definition: defs.hpp:66
cudaPitchedPtr pitched_ptr() const
Get the cudaPitchedPtr type storing allocation parameters and the pointer to the host memory...
Definition: host_memory_3d.hpp:87
Main namespace for bnmf-algs library.
Definition: alloc_model_funcs.hpp:12
HostMemory3D(T *data, size_t first_dim, size_t second_dim, size_t third_dim)
Construct a HostMemory3D class around the memory given by the pointer and the dimensions of a 3D row-...
Definition: host_memory_3d.hpp:64