device_memory.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <kfusion/exports.hpp>
5 
6 namespace kfusion
7 {
8  namespace cuda
9  {
11  KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func = "");
12 
14 
22  {
23  public:
25  DeviceMemory();
26 
28  ~DeviceMemory();
29 
33  DeviceMemory(size_t sizeBytes_arg);
34 
39  DeviceMemory(void *ptr_arg, size_t sizeBytes_arg);
40 
42  DeviceMemory(const DeviceMemory& other_arg);
43 
45  DeviceMemory& operator=(const DeviceMemory& other_arg);
46 
50  void create(size_t sizeBytes_arg);
51 
53  void release();
54 
58  void copyTo(DeviceMemory& other) const;
59 
64  void upload(const void *host_ptr_arg, size_t sizeBytes_arg);
65 
69  void download(void *host_ptr_arg) const;
70 
74  void swap(DeviceMemory& other_arg);
75 
77  template<class T> T* ptr();
78 
80  template<class T> const T* ptr() const;
81 
83  template <class U> operator PtrSz<U>() const;
84 
86  bool empty() const;
87 
88  size_t sizeBytes() const;
89 
90  private:
92  void *data_;
93 
95  size_t sizeBytes_;
96 
98  int* refcount_;
99  };
100 
102 
110  {
111  public:
113  DeviceMemory2D();
114 
116  ~DeviceMemory2D();
117 
122  DeviceMemory2D(int rows_arg, int colsBytes_arg);
123 
124 
131  DeviceMemory2D(int rows_arg, int colsBytes_arg, void *data_arg, size_t step_arg);
132 
134  DeviceMemory2D(const DeviceMemory2D& other_arg);
135 
137  DeviceMemory2D& operator=(const DeviceMemory2D& other_arg);
138 
143  void create(int rows_arg, int colsBytes_arg);
144 
146  void release();
147 
151  void copyTo(DeviceMemory2D& other) const;
152 
159  void upload(const void *host_ptr_arg, size_t host_step_arg, int rows_arg, int colsBytes_arg);
160 
165  void download(void *host_ptr_arg, size_t host_step_arg) const;
166 
170  void swap(DeviceMemory2D& other_arg);
171 
175  template<class T> T* ptr(int y_arg = 0);
176 
180  template<class T> const T* ptr(int y_arg = 0) const;
181 
183  template <class U> operator PtrStep<U>() const;
184 
186  template <class U> operator PtrStepSz<U>() const;
187 
189  bool empty() const;
190 
192  int colsBytes() const;
193 
195  int rows() const;
196 
198  size_t step() const;
199  private:
201  void *data_;
202 
204  size_t step_;
205 
208 
210  int rows_;
211 
213  int* refcount_;
214  };
215  }
216 
217  namespace device
218  {
221  }
222 }
223 
225 
226 template<class T> inline T* kfusion::cuda::DeviceMemory::ptr() { return ( T*)data_; }
227 template<class T> inline const T* kfusion::cuda::DeviceMemory::ptr() const { return (const T*)data_; }
228 
229 template <class U> inline kfusion::cuda::DeviceMemory::operator kfusion::cuda::PtrSz<U>() const
230 {
231  PtrSz<U> result;
232  result.data = (U*)ptr<U>();
233  result.size = sizeBytes_/sizeof(U);
234  return result;
235 }
236 
238 
239 template<class T> T* kfusion::cuda::DeviceMemory2D::ptr(int y_arg) { return ( T*)(( char*)data_ + y_arg * step_); }
240 template<class T> const T* kfusion::cuda::DeviceMemory2D::ptr(int y_arg) const { return (const T*)((const char*)data_ + y_arg * step_); }
241 
242 template <class U> kfusion::cuda::DeviceMemory2D::operator kfusion::cuda::PtrStep<U>() const
243 {
244  PtrStep<U> result;
245  result.data = (U*)ptr<U>();
246  result.step = step_;
247  return result;
248 }
249 
250 template <class U> kfusion::cuda::DeviceMemory2D::operator kfusion::cuda::PtrStepSz<U>() const
251 {
252  PtrStepSz<U> result;
253  result.data = (U*)ptr<U>();
254  result.step = step_;
255  result.cols = colsBytes_/sizeof(U);
256  result.rows = rows_;
257  return result;
258 }
size_t step
stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!! ...
int * refcount_
Pointer to reference counter in CPU memory.
T * ptr()
Returns pointer for internal buffer in GPU memory.
int * refcount_
Pointer to reference counter in CPU memory.
size_t step_
Stride between two consecutive rows in bytes for internal buffer. Step is stored always and everywher...
size_t sizeBytes_
Allocated size in bytes.
__kf_hdevice__ void swap(T &a, T &b)
Definition: temp_utils.hpp:10
void * data_
Device pointer.
#define KF_EXPORTS
Definition: exports.hpp:6
FILE * file
int colsBytes_
Width of the buffer in bytes.
KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func="")
Error handler. All GPU functions from this subsystem call the function to report an error...
T * ptr(int y_arg=0)
Returns pointer to given row in internal buffer.
Utility.
Definition: capture.hpp:8
void * data_
Device pointer.


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06