Point Cloud Library (PCL)  1.11.0
device_array.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Author: Anatoly Baskeheev, Itseez Ltd, (myname.mysurname@mycompany.com)
35  */
36 
37 
38 #ifndef PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_
39 #define PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_
40 
41 
42 namespace pcl
43 {
44 
45 namespace gpu
46 {
47 
48 ///////////////////// Inline implementations of DeviceArray ////////////////////////////////////////////
49 
50 template<class T> inline DeviceArray<T>::DeviceArray() {}
51 template<class T> inline DeviceArray<T>::DeviceArray(std::size_t size) : DeviceMemory(size * elem_size) {}
52 template<class T> inline DeviceArray<T>::DeviceArray(T *ptr, std::size_t size) : DeviceMemory(ptr, size * elem_size) {}
53 template<class T> inline DeviceArray<T>::DeviceArray(const DeviceArray& other) : DeviceMemory(other) {}
54 template<class T> inline DeviceArray<T>& DeviceArray<T>::operator=(const DeviceArray& other)
55 { DeviceMemory::operator=(other); return *this; }
56 
57 template<class T> inline void DeviceArray<T>::create(std::size_t size)
58 { DeviceMemory::create(size * elem_size); }
59 template<class T> inline void DeviceArray<T>::release()
61 
62 template<class T> inline void DeviceArray<T>::copyTo(DeviceArray& other) const
63 { DeviceMemory::copyTo(other); }
64 template<class T> inline void DeviceArray<T>::upload(const T *host_ptr, std::size_t size)
65 { DeviceMemory::upload(host_ptr, size * elem_size); }
66 template<class T> inline void DeviceArray<T>::download(T *host_ptr) const
67 { DeviceMemory::download( host_ptr ); }
68 
69 template<class T> void DeviceArray<T>::swap(DeviceArray& other_arg) { DeviceMemory::swap(other_arg); }
70 
71 template<class T> inline DeviceArray<T>::operator T*() { return ptr(); }
72 template<class T> inline DeviceArray<T>::operator const T*() const { return ptr(); }
73 template<class T> inline std::size_t DeviceArray<T>::size() const { return sizeBytes() / elem_size; }
74 
75 template<class T> inline T* DeviceArray<T>::ptr() { return DeviceMemory::ptr<T>(); }
76 template<class T> inline const T* DeviceArray<T>::ptr() const { return DeviceMemory::ptr<T>(); }
77 
78 template<class T> template<class A> inline void DeviceArray<T>::upload(const std::vector<T, A>& data) { upload(&data[0], data.size()); }
79 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]); }
80 
81 ///////////////////// Inline implementations of DeviceArray2D ////////////////////////////////////////////
82 
83 template<class T> inline DeviceArray2D<T>::DeviceArray2D() {}
84 template<class T> inline DeviceArray2D<T>::DeviceArray2D(int rows, int cols) : DeviceMemory2D(rows, cols * elem_size) {}
85 template<class T> inline DeviceArray2D<T>::DeviceArray2D(int rows, int cols, void *data, std::size_t stepBytes) : DeviceMemory2D(rows, cols * elem_size, data, stepBytes) {}
86 template<class T> inline DeviceArray2D<T>::DeviceArray2D(const DeviceArray2D& other) : DeviceMemory2D(other) {}
87 template<class T> inline DeviceArray2D<T>& DeviceArray2D<T>::operator=(const DeviceArray2D& other)
88 { DeviceMemory2D::operator=(other); return *this; }
89 
90 template<class T> inline void DeviceArray2D<T>::create(int rows, int cols)
91 { DeviceMemory2D::create(rows, cols * elem_size); }
92 template<class T> inline void DeviceArray2D<T>::release()
94 
95 template<class T> inline void DeviceArray2D<T>::copyTo(DeviceArray2D& other) const
97 template<class T> inline void DeviceArray2D<T>::upload(const void *host_ptr, std::size_t host_step, int rows, int cols)
98 { DeviceMemory2D::upload(host_ptr, host_step, rows, cols * elem_size); }
99 template<class T> inline void DeviceArray2D<T>::download(void *host_ptr, std::size_t host_step) const
100 { DeviceMemory2D::download( host_ptr, host_step ); }
101 
102 template<class T> template<class A> inline void DeviceArray2D<T>::upload(const std::vector<T, A>& data, int cols)
103 { upload(&data[0], cols * elem_size, data.size()/cols, cols); }
104 
105 template<class T> template<class A> inline void DeviceArray2D<T>::download(std::vector<T, A>& data, int& elem_step) const
106 { elem_step = cols(); data.resize(cols() * rows()); if (!data.empty()) download(&data[0], colsBytes()); }
107 
108 template<class T> void DeviceArray2D<T>::swap(DeviceArray2D& other_arg) { DeviceMemory2D::swap(other_arg); }
109 
110 template<class T> inline T* DeviceArray2D<T>::ptr(int y) { return DeviceMemory2D::ptr<T>(y); }
111 template<class T> inline const T* DeviceArray2D<T>::ptr(int y) const { return DeviceMemory2D::ptr<T>(y); }
112 
113 template<class T> inline DeviceArray2D<T>::operator T*() { return ptr(); }
114 template<class T> inline DeviceArray2D<T>::operator const T*() const { return ptr(); }
115 
116 template<class T> inline int DeviceArray2D<T>::cols() const { return DeviceMemory2D::colsBytes()/elem_size; }
117 template<class T> inline int DeviceArray2D<T>::rows() const { return DeviceMemory2D::rows(); }
118 
119 template<class T> inline std::size_t DeviceArray2D<T>::elem_step() const { return DeviceMemory2D::step()/elem_size; }
120 
121 } // namespace gpu
122 } // namespace pcl
123 
124 #endif /* PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_ */
125 
DeviceArray2D class
Definition: device_array.h:154
std::size_t elem_step() const
Returns step in elements.
int rows() const
Returns number of rows.
DeviceArray2D & operator=(const DeviceArray2D &other)
Assignment operator.
void swap(DeviceArray2D &other_arg)
Performs swap of data pointed with another device array.
void release()
Decrements reference counter and releases internal buffer if needed.
void upload(const void *host_ptr, std::size_t host_step, int rows, int cols)
Uploads data to internal buffer in GPU memory.
int cols() const
Returns number of elements in each row.
void create(int rows, int cols)
Allocates internal buffer in GPU memory.
T * ptr(int y=0)
Returns pointer to given row in internal buffer.
void download(void *host_ptr, std::size_t host_step) const
Downloads data from internal buffer to CPU memory.
DeviceArray2D()
Empty constructor.
void copyTo(DeviceArray2D &other) const
Performs data copying.
DeviceArray class
Definition: device_array.h:57
DeviceArray()
Empty constructor.
void upload(const T *host_ptr, std::size_t size)
Uploads data to internal buffer in GPU memory.
std::size_t size() const
Returns size in elements.
void copyTo(DeviceArray &other) const
Performs data copying.
void download(T *host_ptr) const
Downloads data from internal buffer to CPU memory.
DeviceArray & operator=(const DeviceArray &other)
Assignment operator.
void swap(DeviceArray &other_arg)
Performs swap of data pointed with another device array.
void release()
Decrements reference counter and releases internal buffer if needed.
void create(std::size_t size)
Allocates internal buffer in GPU memory.
T * ptr()
Returns pointer for internal buffer in GPU memory.
DeviceMemory2D class
void swap(DeviceMemory2D &other_arg)
Performs swap of data pointed with another device memory.
std::size_t step() const
Returns stride between two consecutive rows in bytes for internal buffer.
void download(void *host_ptr_arg, std::size_t host_step_arg) const
Downloads data from internal buffer to CPU memory.
void create(int rows_arg, int colsBytes_arg)
Allocates internal buffer in GPU memory.
int colsBytes() const
Returns number of bytes in each row.
int rows() const
Returns number of rows.
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.
DeviceMemory2D & operator=(const DeviceMemory2D &other_arg)
Assignment operator.
void release()
Decrements reference counter and releases internal buffer if needed.
void copyTo(DeviceMemory2D &other) const
Performs data copying.
DeviceMemory class
Definition: device_memory.h:55
void swap(DeviceMemory &other_arg)
Performs swap of data pointed with another device memory.
DeviceMemory & operator=(const DeviceMemory &other_arg)
Assignment operator.
void copyTo(DeviceMemory &other) const
Performs data copying.
void release()
Decrements reference counter and releases internal buffer if needed.
void download(void *host_ptr_arg) const
Downloads data from internal buffer to CPU memory.
void upload(const void *host_ptr_arg, std::size_t sizeBytes_arg)
Uploads data to internal buffer in GPU memory.
void create(std::size_t sizeBytes_arg)
Allocates internal buffer in GPU memory.