Point Cloud Library (PCL)  1.9.1-dev
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 #ifndef PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_
38 #define PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_
39 
40 
41 ///////////////////// Inline implementations of DeviceArray ////////////////////////////////////////////
42 
43 template<class T> inline pcl::gpu::DeviceArray<T>::DeviceArray() {}
44 template<class T> inline pcl::gpu::DeviceArray<T>::DeviceArray(size_t size) : DeviceMemory(size * elem_size) {}
45 template<class T> inline pcl::gpu::DeviceArray<T>::DeviceArray(T *ptr, size_t size) : DeviceMemory(ptr, size * elem_size) {}
46 template<class T> inline pcl::gpu::DeviceArray<T>::DeviceArray(const DeviceArray& other) : DeviceMemory(other) {}
48 { DeviceMemory::operator=(other); return *this; }
49 
50 template<class T> inline void pcl::gpu::DeviceArray<T>::create(size_t size)
52 template<class T> inline void pcl::gpu::DeviceArray<T>::release()
54 
55 template<class T> inline void pcl::gpu::DeviceArray<T>::copyTo(DeviceArray& other) const
56 { DeviceMemory::copyTo(other); }
57 template<class T> inline void pcl::gpu::DeviceArray<T>::upload(const T *host_ptr, size_t size)
58 { DeviceMemory::upload(host_ptr, size * elem_size); }
59 template<class T> inline void pcl::gpu::DeviceArray<T>::download(T *host_ptr) const
60 { DeviceMemory::download( host_ptr ); }
61 
62 template<class T> void pcl::gpu::DeviceArray<T>::swap(DeviceArray& other_arg) { DeviceMemory::swap(other_arg); }
63 
64 template<class T> inline pcl::gpu::DeviceArray<T>::operator T*() { return ptr(); }
65 template<class T> inline pcl::gpu::DeviceArray<T>::operator const T*() const { return ptr(); }
66 template<class T> inline size_t pcl::gpu::DeviceArray<T>::size() const { return sizeBytes() / elem_size; }
67 
68 template<class T> inline T* pcl::gpu::DeviceArray<T>::ptr() { return DeviceMemory::ptr<T>(); }
69 template<class T> inline const T* pcl::gpu::DeviceArray<T>::ptr() const { return DeviceMemory::ptr<T>(); }
70 
71 template<class T> template<class A> inline void pcl::gpu::DeviceArray<T>::upload(const std::vector<T, A>& data) { upload(&data[0], data.size()); }
72 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]); }
73 
74 ///////////////////// Inline implementations of DeviceArray2D ////////////////////////////////////////////
75 
76 template<class T> inline pcl::gpu::DeviceArray2D<T>::DeviceArray2D() {}
77 template<class T> inline pcl::gpu::DeviceArray2D<T>::DeviceArray2D(int rows, int cols) : DeviceMemory2D(rows, cols * elem_size) {}
78 template<class T> inline pcl::gpu::DeviceArray2D<T>::DeviceArray2D(int rows, int cols, void *data, size_t stepBytes) : DeviceMemory2D(rows, cols * elem_size, data, stepBytes) {}
79 template<class T> inline pcl::gpu::DeviceArray2D<T>::DeviceArray2D(const DeviceArray2D& other) : DeviceMemory2D(other) {}
81 { DeviceMemory2D::operator=(other); return *this; }
82 
83 template<class T> inline void pcl::gpu::DeviceArray2D<T>::create(int rows, int cols)
84 { DeviceMemory2D::create(rows, cols * elem_size); }
85 template<class T> inline void pcl::gpu::DeviceArray2D<T>::release()
87 
88 template<class T> inline void pcl::gpu::DeviceArray2D<T>::copyTo(DeviceArray2D& other) const
89 { DeviceMemory2D::copyTo(other); }
90 template<class T> inline void pcl::gpu::DeviceArray2D<T>::upload(const void *host_ptr, size_t host_step, int rows, int cols)
91 { DeviceMemory2D::upload(host_ptr, host_step, rows, cols * elem_size); }
92 template<class T> inline void pcl::gpu::DeviceArray2D<T>::download(void *host_ptr, size_t host_step) const
93 { DeviceMemory2D::download( host_ptr, host_step ); }
94 
95 template<class T> template<class A> inline void pcl::gpu::DeviceArray2D<T>::upload(const std::vector<T, A>& data, int cols)
96 { upload(&data[0], cols * elem_size, data.size()/cols, cols); }
97 
98 template<class T> template<class A> inline void pcl::gpu::DeviceArray2D<T>::download(std::vector<T, A>& data, int& elem_step) const
99 { elem_step = cols(); data.resize(cols() * rows()); if (!data.empty()) download(&data[0], colsBytes()); }
100 
101 template<class T> void pcl::gpu::DeviceArray2D<T>::swap(DeviceArray2D& other_arg) { DeviceMemory2D::swap(other_arg); }
102 
103 template<class T> inline T* pcl::gpu::DeviceArray2D<T>::ptr(int y) { return DeviceMemory2D::ptr<T>(y); }
104 template<class T> inline const T* pcl::gpu::DeviceArray2D<T>::ptr(int y) const { return DeviceMemory2D::ptr<T>(y); }
105 
106 template<class T> inline pcl::gpu::DeviceArray2D<T>::operator T*() { return ptr(); }
107 template<class T> inline pcl::gpu::DeviceArray2D<T>::operator const T*() const { return ptr(); }
108 
109 template<class T> inline int pcl::gpu::DeviceArray2D<T>::cols() const { return DeviceMemory2D::colsBytes()/elem_size; }
110 template<class T> inline int pcl::gpu::DeviceArray2D<T>::rows() const { return DeviceMemory2D::rows(); }
111 
112 template<class T> inline size_t pcl::gpu::DeviceArray2D<T>::elem_step() const { return DeviceMemory2D::step()/elem_size; }
113 
114 
115 #endif /* PCL_GPU_CONTAINER_DEVICE_ARRAY_IMPL_HPP_ */
void download(void *host_ptr, size_t host_step) const
Downloads data from internal buffer to CPU memory.
void download(void *host_ptr_arg, size_t host_step_arg) const
Downloads data from internal buffer to CPU memory.
void upload(const void *host_ptr_arg, size_t host_step_arg, int rows_arg, int colsBytes_arg)
Uploads data to internal buffer in GPU memory.
void copyTo(DeviceMemory &other) const
Performs data copying.
DeviceArray2D & operator=(const DeviceArray2D &other)
Assignment operator.
size_t sizeBytes() const
DeviceArray()
Empty constructor.
void release()
Decrements reference counter and releases internal buffer if needed.
size_t step() const
Returns stride between two consecutive rows in bytes for internal buffer.
void upload(const void *host_ptr_arg, size_t sizeBytes_arg)
Uploads data to internal buffer in GPU memory.
void copyTo(DeviceArray2D &other) const
Performs data copying.
void release()
Decrements reference counter and releases internal buffer if needed.
int rows() const
Returns number of rows.
DeviceArray2D class
Definition: device_array.h:153
int colsBytes() const
Returns number of bytes in each row.
void copyTo(DeviceArray &other) const
Performs data copying.
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 upload(const void *host_ptr, size_t host_step, int rows, int cols)
Uploads data to internal buffer in GPU memory.
DeviceArray2D()
Empty constructor.
void swap(DeviceArray2D &other_arg)
Performs swap of data pointed with another device array.
void download(T *host_ptr) const
Downloads data from internal buffer to CPU memory.
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.
DeviceMemory2D class
int rows() const
Returns number of rows.
DeviceMemory2D & operator=(const DeviceMemory2D &other_arg)
Assignment operator.
DeviceArray class
Definition: device_array.h:56
DeviceArray & operator=(const DeviceArray &other)
Assignment operator.
void create(size_t size)
Allocates internal buffer in GPU memory.
void copyTo(DeviceMemory2D &other) const
Performs data copying.
void create(size_t sizeBytes_arg)
Allocates internal buffer in GPU memory.
void release()
Decrements reference counter and releases internal buffer if needed.
void swap(DeviceMemory &other_arg)
Performs swap of data pointed with another device memory.
void download(void *host_ptr_arg) const
Downloads data from internal buffer to CPU memory.
int cols() const
Returns number of elements in each row.
void swap(DeviceMemory2D &other_arg)
Performs swap of data pointed with another device memory.
T * ptr()
Returns pointer for internal buffer in GPU memory.
void upload(const T *host_ptr, size_t size)
Uploads data to internal buffer in GPU memory.
size_t size() const
Returns size in elements.
size_t elem_step() const
Returns step in elements.
DeviceMemory & operator=(const DeviceMemory &other_arg)
Assignment operator.
void create(int rows_arg, int colsBytes_arg)
Allocates internal buffer in GPU memory.
DeviceMemory class
Definition: device_memory.h:54