27 enum { elem_size =
sizeof(T) };
52 void create(
size_t size);
66 void upload(
const T *host_ptr,
size_t size);
71 void download(T *host_ptr)
const;
77 void upload(
const std::vector<T, A>& data);
83 void download(std::vector<T, A>& data)
const;
102 operator const T*()
const;
124 enum { elem_size =
sizeof(T) };
141 DeviceArray2D(
int rows,
int cols,
void *data,
size_t stepBytes);
153 void create(
int rows,
int cols);
169 void upload(
const void *host_ptr,
size_t host_step,
int rows,
int cols);
175 void download(
void *host_ptr,
size_t host_step)
const;
187 void upload(
const std::vector<T, A>& data,
int cols);
194 void download(std::vector<T, A>& data,
int& cols)
const;
204 const T* ptr(
int y = 0)
const;
212 operator const T*()
const;
221 size_t elem_step()
const;
239 { DeviceMemory::operator=(other);
return *
this; }
242 { DeviceMemory::create(size * elem_size); }
244 { DeviceMemory::release(); }
247 { DeviceMemory::copyTo(other); }
249 { DeviceMemory::upload(host_ptr, size * elem_size); }
251 { DeviceMemory::download( host_ptr ); }
272 { DeviceMemory2D::operator=(other);
return *
this; }
275 { DeviceMemory2D::create(rows, cols * elem_size); }
277 { DeviceMemory2D::release(); }
280 { DeviceMemory2D::copyTo(other); }
282 { DeviceMemory2D::upload(host_ptr, host_step, rows, cols * elem_size); }
284 { DeviceMemory2D::download( host_ptr, host_step ); }
287 { upload(&data[0], cols * elem_size, data.size()/cols, cols); }
290 { elem_step = cols(); data.resize(cols() * rows());
if (!data.empty()) download(&data[0], colsBytes()); }
void create(size_t size)
Allocates internal buffer in GPU memory. If internal buffer was created before the function recreates...
size_t size() const
Returns size in elements.
void copyTo(DeviceArray &other) const
Performs data copying. If destination size differs it will be reallocated.
T * ptr(int y=0)
Returns pointer to given row in internal buffer.
void upload(const void *host_ptr, size_t host_step, int rows, int cols)
Uploads data to internal buffer in GPU memory. It calls create() inside to ensure that intenal buffer...
__kf_hdevice__ void swap(T &a, T &b)
int rows() const
Returns number of rows.
DeviceArray2D & operator=(const DeviceArray2D &other)
Assigment operator. Just increments reference counter.
DeviceArray2D()
Empty constructor.
DeviceArray & operator=(const DeviceArray &other)
Assigment operator. Just increments reference counter.
T * ptr()
Returns pointer for internal buffer in GPU memory.
size_t elem_step() const
Returns step in elements.
void upload(const T *host_ptr, size_t size)
Uploads data to internal buffer in GPU memory. It calls create() inside to ensure that intenal buffer...
DeviceArray()
Empty constructor.
void download(T *host_ptr) const
Downloads data from internal buffer to CPU memory.
void release()
Decrements reference counter and releases internal buffer if needed.
void swap(DeviceArray2D &other_arg)
Performs swap of data pointed with another device array.
void swap(DeviceArray &other_arg)
Performs swap of data pointed with another device array.
void download(void *host_ptr, size_t host_step) const
Downloads data from internal buffer to CPU memory. User is resposible for correct host buffer size...
void create(int rows, int cols)
Allocates internal buffer in GPU memory. If internal buffer was created before the function recreates...
void release()
Decrements reference counter and releases internal buffer if needed.
int cols() const
Returns number of elements in each row.
void copyTo(DeviceArray2D &other) const
Performs data copying. If destination size differs it will be reallocated.