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_
namespace pcl {
namespace gpu {
//////////////////// Inline implementations of DeviceArray //////////////////
template <class T>
inline DeviceArray<T>::DeviceArray()
{}
template <class T>
inline DeviceArray<T>::DeviceArray(std::size_t size) : DeviceMemory(size * elem_size)
{}
template <class T>
inline DeviceArray<T>::DeviceArray(T* ptr, std::size_t size)
: DeviceMemory(ptr, size * elem_size)
{}
template <class T>
inline DeviceArray<T>::DeviceArray(const DeviceArray& other) : DeviceMemory(other)
{}
template <class T>
inline DeviceArray<T>&
DeviceArray<T>::operator=(const DeviceArray& other)
{
DeviceMemory::operator=(other);
return *this;
}
template <class T>
inline void
DeviceArray<T>::create(std::size_t size)
{
DeviceMemory::create(size * elem_size);
}
template <class T>
inline void
DeviceArray<T>::release()
{
DeviceMemory::release();
}
template <class T>
inline void
DeviceArray<T>::copyTo(DeviceArray& other) const
{
DeviceMemory::copyTo(other);
}
template <class T>
inline void
DeviceArray<T>::upload(const T* host_ptr, std::size_t size)
{
DeviceMemory::upload(host_ptr, size * elem_size);
}
template <class T>
inline bool
DeviceArray<T>::upload(const T* host_ptr,
std::size_t device_begin_offset,
std::size_t num_elements)
{
std::size_t begin_byte_offset = device_begin_offset * sizeof(T);
std::size_t num_bytes = num_elements * sizeof(T);
return DeviceMemory::upload(host_ptr, begin_byte_offset, num_bytes);
}
template <class T>
inline void
DeviceArray<T>::download(T* host_ptr) const
{
DeviceMemory::download(host_ptr);
}
template <class T>
inline bool
DeviceArray<T>::download(T* host_ptr,
std::size_t device_begin_offset,
std::size_t num_elements) const
{
std::size_t begin_byte_offset = device_begin_offset * sizeof(T);
std::size_t num_bytes = num_elements * sizeof(T);
return DeviceMemory::download(host_ptr, begin_byte_offset, num_bytes);
}
template <class T>
void
DeviceArray<T>::swap(DeviceArray& other_arg)
{
DeviceMemory::swap(other_arg);
}
template <class T>
inline DeviceArray<T>::operator T*()
{
return ptr();
}
template <class T>
inline DeviceArray<T>::operator const T*() const
{
return ptr();
}
template <class T>
inline std::size_t
DeviceArray<T>::size() const
{
return sizeBytes() / elem_size;
}
template <class T>
inline T*
DeviceArray<T>::ptr()
{
return DeviceMemory::ptr<T>();
}
template <class T>
inline const T*
DeviceArray<T>::ptr() const
{
return DeviceMemory::ptr<T>();
}
template <class T>
template <class A>
inline void
DeviceArray<T>::upload(const std::vector<T, A>& data)
{
upload(&data[0], data.size());
}
template <class T>
template <class A>
inline void
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 DeviceArray2D<T>::DeviceArray2D()
{}
template <class T>
inline DeviceArray2D<T>::DeviceArray2D(int rows, int cols)
: DeviceMemory2D(rows, cols * elem_size)
{}
template <class T>
inline DeviceArray2D<T>::DeviceArray2D(int rows,
int cols,
void* data,
std::size_t stepBytes)
: DeviceMemory2D(rows, cols * elem_size, data, stepBytes)
{}
template <class T>
inline DeviceArray2D<T>::DeviceArray2D(const DeviceArray2D& other)
: DeviceMemory2D(other)
{}
template <class T>
inline DeviceArray2D<T>&
DeviceArray2D<T>::operator=(const DeviceArray2D& other)
{
DeviceMemory2D::operator=(other);
return *this;
}
template <class T>
inline void
DeviceArray2D<T>::create(int rows, int cols)
{
DeviceMemory2D::create(rows, cols * elem_size);
}
template <class T>
inline void
DeviceArray2D<T>::release()
{
DeviceMemory2D::release();
}
template <class T>
inline void
DeviceArray2D<T>::copyTo(DeviceArray2D& other) const
{
DeviceMemory2D::copyTo(other);
}
template <class T>
inline void
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
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
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
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
DeviceArray2D<T>::swap(DeviceArray2D& other_arg)
{
DeviceMemory2D::swap(other_arg);
}
template <class T>
inline T*
DeviceArray2D<T>::ptr(int y)
{
return DeviceMemory2D::ptr<T>(y);
}
template <class T>
inline const T*
DeviceArray2D<T>::ptr(int y) const
{
return DeviceMemory2D::ptr<T>(y);
}
template <class T>
inline DeviceArray2D<T>::operator T*()
{
return ptr();
}
template <class T>
inline DeviceArray2D<T>::operator const T*() const
{
return ptr();
}
template <class T>
inline int
DeviceArray2D<T>::cols() const
{
return DeviceMemory2D::colsBytes() / elem_size;
}
template <class T>
inline int
DeviceArray2D<T>::rows() const
{
return DeviceMemory2D::rows();
}
template <class T>
inline std::size_t
DeviceArray2D<T>::elem_step() const
{
return DeviceMemory2D::step() / elem_size;
}
} // namespace gpu
} // namespace pcl
#endif /* PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_ */
pcl::gpu::DeviceArray2D
DeviceArray2D class
Definition: device_array.h:188
pcl::gpu::DeviceArray2D::elem_step
std::size_t elem_step() const
Returns step in elements.
Definition: device_array.hpp:324
pcl::gpu::DeviceArray2D::rows
int rows() const
Returns number of rows.
Definition: device_array.hpp:317
pcl::gpu::DeviceArray2D::operator=
DeviceArray2D & operator=(const DeviceArray2D &other)
Assignment operator.
Definition: device_array.hpp:212
pcl::gpu::DeviceArray2D::swap
void swap(DeviceArray2D &other_arg)
Performs swap of data pointed with another device array.
Definition: device_array.hpp:277
pcl::gpu::DeviceArray2D::release
void release()
Decrements reference counter and releases internal buffer if needed.
Definition: device_array.hpp:227
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:241
pcl::gpu::DeviceArray2D::cols
int cols() const
Returns number of elements in each row.
Definition: device_array.hpp:310
pcl::gpu::DeviceArray2D::create
void create(int rows, int cols)
Allocates internal buffer in GPU memory.
Definition: device_array.hpp:220
pcl::gpu::DeviceArray2D::ptr
T * ptr(int y=0)
Returns pointer to given row in internal buffer.
Definition: device_array.hpp:284
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:251
pcl::gpu::DeviceArray2D::DeviceArray2D
DeviceArray2D()
Empty constructor.
Definition: device_array.hpp:189
pcl::gpu::DeviceArray2D::copyTo
void copyTo(DeviceArray2D &other) const
Performs data copying.
Definition: device_array.hpp:234
pcl::gpu::DeviceArray
DeviceArray class
Definition: device_array.h:54
pcl::gpu::DeviceArray::DeviceArray
DeviceArray()
Empty constructor.
Definition: device_array.hpp:47
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:94
pcl::gpu::DeviceArray::size
std::size_t size() const
Returns size in elements.
Definition: device_array.hpp:149
pcl::gpu::DeviceArray::copyTo
void copyTo(DeviceArray &other) const
Performs data copying.
Definition: device_array.hpp:87
pcl::gpu::DeviceArray::download
void download(T *host_ptr) const
Downloads data from internal buffer to CPU memory.
Definition: device_array.hpp:112
pcl::gpu::DeviceArray::operator=
DeviceArray & operator=(const DeviceArray &other)
Assignment operator.
Definition: device_array.hpp:65
pcl::gpu::DeviceArray::swap
void swap(DeviceArray &other_arg)
Performs swap of data pointed with another device array.
Definition: device_array.hpp:130
pcl::gpu::DeviceArray::release
void release()
Decrements reference counter and releases internal buffer if needed.
Definition: device_array.hpp:80
pcl::gpu::DeviceArray::create
void create(std::size_t size)
Allocates internal buffer in GPU memory.
Definition: device_array.hpp:73
pcl::gpu::DeviceArray::ptr
T * ptr()
Returns pointer for internal buffer in GPU memory.
Definition: device_array.hpp:156
pcl::gpu::DeviceMemory2D
DeviceMemory2D class
Definition: device_memory.h:181
pcl::gpu::DeviceMemory2D::swap
void swap(DeviceMemory2D &other_arg)
Performs swap of data pointed with another device memory.
pcl::gpu::DeviceMemory2D::step
std::size_t step() const
Returns stride between two consecutive rows in bytes for internal buffer.
pcl::gpu::DeviceMemory2D::download
void download(void *host_ptr_arg, std::size_t host_step_arg) const
Downloads data from internal buffer to CPU memory.
pcl::gpu::DeviceMemory2D::create
void create(int rows_arg, int colsBytes_arg)
Allocates internal buffer in GPU memory.
pcl::gpu::DeviceMemory2D::colsBytes
int colsBytes() const
Returns number of bytes in each row.
pcl::gpu::DeviceMemory2D::rows
int rows() const
Returns number of rows.
pcl::gpu::DeviceMemory2D::upload
void upload(const void *host_ptr_arg, std::size_t host_step_arg, int rows_arg, int colsBytes_arg)
Uploads data to internal buffer in GPU memory.
pcl::gpu::DeviceMemory2D::operator=
DeviceMemory2D & operator=(const DeviceMemory2D &other_arg)
Assignment operator.
pcl::gpu::DeviceMemory2D::release
void release()
Decrements reference counter and releases internal buffer if needed.
pcl::gpu::DeviceMemory2D::copyTo
void copyTo(DeviceMemory2D &other) const
Performs data copying.
pcl::gpu::DeviceMemory
DeviceMemory class
Definition: device_memory.h:52
pcl::gpu::DeviceMemory::swap
void swap(DeviceMemory &other_arg)
Performs swap of data pointed with another device memory.
pcl::gpu::DeviceMemory::operator=
DeviceMemory & operator=(const DeviceMemory &other_arg)
Assignment operator.
pcl::gpu::DeviceMemory::copyTo
void copyTo(DeviceMemory &other) const
Performs data copying.
pcl::gpu::DeviceMemory::release
void release()
Decrements reference counter and releases internal buffer if needed.
pcl::gpu::DeviceMemory::download
void download(void *host_ptr_arg) const
Downloads data from internal buffer to CPU memory.
pcl::gpu::DeviceMemory::upload
void upload(const void *host_ptr_arg, std::size_t sizeBytes_arg)
Uploads data to internal buffer in GPU memory.
pcl::gpu::DeviceMemory::create
void create(std::size_t sizeBytes_arg)
Allocates internal buffer in GPU memory.
pcl
Definition: convolution.h:46