device_array.hpp
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2011, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Anatoly Baskeheev, Itseez Ltd, (myname.mysurname@mycompany.com)
*/
#ifndef PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_
#define PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_
///////////////////// Inline implementations of DeviceArray ////////////////////////////////////////////
template<class T> inline pcl::gpu::DeviceArray<T>::DeviceArray() {}
template<class T> inline pcl::gpu::DeviceArray<T>::DeviceArray(std::size_t size) : DeviceMemory(size * elem_size) {}
template<class T> inline pcl::gpu::DeviceArray<T>::DeviceArray(T *ptr, std::size_t size) : DeviceMemory(ptr, size * elem_size) {}
template<class T> inline pcl::gpu::DeviceArray<T>::DeviceArray(const DeviceArray& other) : DeviceMemory(other) {}
template<class T> inline pcl::gpu::DeviceArray<T>& pcl::gpu::DeviceArray<T>::operator=(const DeviceArray& other)
{ DeviceMemory::operator=(other); return *this; }
template<class T> inline void pcl::gpu::DeviceArray<T>::create(std::size_t size)
{ DeviceMemory::create(size * elem_size); }
template<class T> inline void pcl::gpu::DeviceArray<T>::release()
{ DeviceMemory::release(); }
template<class T> inline void pcl::gpu::DeviceArray<T>::copyTo(DeviceArray& other) const
{ DeviceMemory::copyTo(other); }
template<class T> inline void pcl::gpu::DeviceArray<T>::upload(const T *host_ptr, std::size_t size)
{ DeviceMemory::upload(host_ptr, size * elem_size); }
template<class T> inline void pcl::gpu::DeviceArray<T>::download(T *host_ptr) const
{ DeviceMemory::download( host_ptr ); }
template<class T> void pcl::gpu::DeviceArray<T>::swap(DeviceArray& other_arg) { DeviceMemory::swap(other_arg); }
template<class T> inline pcl::gpu::DeviceArray<T>::operator T*() { return ptr(); }
template<class T> inline pcl::gpu::DeviceArray<T>::operator const T*() const { return ptr(); }
template<class T> inline std::size_t pcl::gpu::DeviceArray<T>::size() const { return sizeBytes() / elem_size; }
template<class T> inline T* pcl::gpu::DeviceArray<T>::ptr() { return DeviceMemory::ptr<T>(); }
template<class T> inline const T* pcl::gpu::DeviceArray<T>::ptr() const { return DeviceMemory::ptr<T>(); }
template<class T> template<class A> inline void pcl::gpu::DeviceArray<T>::upload(const std::vector<T, A>& data) { upload(&data[0], data.size()); }
template<class T> template<class A> inline void pcl::gpu::DeviceArray<T>::download(std::vector<T, A>& data) const { data.resize(size()); if (!data.empty()) download(&data[0]); }
///////////////////// Inline implementations of DeviceArray2D ////////////////////////////////////////////
template<class T> inline pcl::gpu::DeviceArray2D<T>::DeviceArray2D() {}
template<class T> inline pcl::gpu::DeviceArray2D<T>::DeviceArray2D(int rows, int cols) : DeviceMemory2D(rows, cols * elem_size) {}
template<class T> inline pcl::gpu::DeviceArray2D<T>::DeviceArray2D(int rows, int cols, void *data, std::size_t stepBytes) : DeviceMemory2D(rows, cols * elem_size, data, stepBytes) {}
template<class T> inline pcl::gpu::DeviceArray2D<T>::DeviceArray2D(const DeviceArray2D& other) : DeviceMemory2D(other) {}
template<class T> inline pcl::gpu::DeviceArray2D<T>& pcl::gpu::DeviceArray2D<T>::operator=(const DeviceArray2D& other)
{ DeviceMemory2D::operator=(other); return *this; }
template<class T> inline void pcl::gpu::DeviceArray2D<T>::create(int rows, int cols)
{ DeviceMemory2D::create(rows, cols * elem_size); }
template<class T> inline void pcl::gpu::DeviceArray2D<T>::release()
{ DeviceMemory2D::release(); }
template<class T> inline void pcl::gpu::DeviceArray2D<T>::copyTo(DeviceArray2D& other) const
{ DeviceMemory2D::copyTo(other); }
template<class T> inline void pcl::gpu::DeviceArray2D<T>::upload(const void *host_ptr, std::size_t host_step, int rows, int cols)
{ DeviceMemory2D::upload(host_ptr, host_step, rows, cols * elem_size); }
template<class T> inline void pcl::gpu::DeviceArray2D<T>::download(void *host_ptr, std::size_t host_step) const
{ DeviceMemory2D::download( host_ptr, host_step ); }
template<class T> template<class A> inline void pcl::gpu::DeviceArray2D<T>::upload(const std::vector<T, A>& data, int cols)
{ upload(&data[0], cols * elem_size, data.size()/cols, cols); }
template<class T> template<class A> inline void pcl::gpu::DeviceArray2D<T>::download(std::vector<T, A>& data, int& elem_step) const
{ elem_step = cols(); data.resize(cols() * rows()); if (!data.empty()) download(&data[0], colsBytes()); }
template<class T> void pcl::gpu::DeviceArray2D<T>::swap(DeviceArray2D& other_arg) { DeviceMemory2D::swap(other_arg); }
template<class T> inline T* pcl::gpu::DeviceArray2D<T>::ptr(int y) { return DeviceMemory2D::ptr<T>(y); }
template<class T> inline const T* pcl::gpu::DeviceArray2D<T>::ptr(int y) const { return DeviceMemory2D::ptr<T>(y); }
template<class T> inline pcl::gpu::DeviceArray2D<T>::operator T*() { return ptr(); }
template<class T> inline pcl::gpu::DeviceArray2D<T>::operator const T*() const { return ptr(); }
template<class T> inline int pcl::gpu::DeviceArray2D<T>::cols() const { return DeviceMemory2D::colsBytes()/elem_size; }
template<class T> inline int pcl::gpu::DeviceArray2D<T>::rows() const { return DeviceMemory2D::rows(); }
template<class T> inline std::size_t pcl::gpu::DeviceArray2D<T>::elem_step() const { return DeviceMemory2D::step()/elem_size; }
#endif /* PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_ */
pcl::gpu::DeviceArray2D::cols
int cols() const
Returns number of elements in each row.
Definition: device_array.hpp:109
pcl::gpu::DeviceArray2D::ptr
T * ptr(int y=0)
Returns pointer to given row in internal buffer.
Definition: device_array.hpp:103
pcl::gpu::DeviceArray2D::swap
void swap(DeviceArray2D &other_arg)
Performs swap of data pointed with another device array.
Definition: device_array.hpp:101
pcl::gpu::DeviceArray2D::create
void create(int rows, int cols)
Allocates internal buffer in GPU memory.
Definition: device_array.hpp:83
pcl::gpu::DeviceArray::copyTo
void copyTo(DeviceArray &other) const
Performs data copying.
Definition: device_array.hpp:55
pcl::gpu::DeviceArray::release
void release()
Decrements reference counter and releases internal buffer if needed.
Definition: device_array.hpp:52
pcl::gpu::DeviceArray2D
DeviceArray2D class
Definition: device_array.h:153
pcl::gpu::DeviceArray::create
void create(std::size_t size)
Allocates internal buffer in GPU memory.
Definition: device_array.hpp:50
pcl::gpu::DeviceArray::swap
void swap(DeviceArray &other_arg)
Performs swap of data pointed with another device array.
Definition: device_array.hpp:62
pcl::gpu::DeviceArray2D::operator=
DeviceArray2D & operator=(const DeviceArray2D &other)
Assignment operator.
Definition: device_array.hpp:80
pcl::gpu::DeviceArray2D::upload
void upload(const void *host_ptr, std::size_t host_step, int rows, int cols)
Uploads data to internal buffer in GPU memory.
Definition: device_array.hpp:90
pcl::gpu::DeviceArray2D::elem_step
std::size_t elem_step() const
Returns step in elements.
Definition: device_array.hpp:112
pcl::gpu::DeviceArray::ptr
T * ptr()
Returns pointer for internal buffer in GPU memory.
Definition: device_array.hpp:68
pcl::gpu::DeviceArray2D::DeviceArray2D
DeviceArray2D()
Empty constructor.
Definition: device_array.hpp:76
pcl::gpu::DeviceArray::operator=
DeviceArray & operator=(const DeviceArray &other)
Assignment operator.
Definition: device_array.hpp:47
pcl::gpu::DeviceArray2D::download
void download(void *host_ptr, std::size_t host_step) const
Downloads data from internal buffer to CPU memory.
Definition: device_array.hpp:92
pcl::gpu::DeviceArray::DeviceArray
DeviceArray()
Empty constructor.
Definition: device_array.hpp:43
pcl::gpu::DeviceArray2D::rows
int rows() const
Returns number of rows.
Definition: device_array.hpp:110
pcl::gpu::DeviceArray
DeviceArray class
Definition: device_array.h:56
pcl::gpu::DeviceMemory
DeviceMemory class
Definition: device_memory.h:54
pcl::gpu::DeviceArray::size
std::size_t size() const
Returns size in elements.
Definition: device_array.hpp:66
pcl::gpu::DeviceArray::upload
void upload(const T *host_ptr, std::size_t size)
Uploads data to internal buffer in GPU memory.
Definition: device_array.hpp:57
pcl::gpu::DeviceArray2D::copyTo
void copyTo(DeviceArray2D &other) const
Performs data copying.
Definition: device_array.hpp:88
pcl::gpu::DeviceMemory2D
DeviceMemory2D class
Definition: device_memory.h:142
pcl::gpu::DeviceArray2D::release
void release()
Decrements reference counter and releases internal buffer if needed.
Definition: device_array.hpp:85
pcl::gpu::DeviceArray::download
void download(T *host_ptr) const
Downloads data from internal buffer to CPU memory.
Definition: device_array.hpp:59