Point Cloud Library (PCL)  1.8.0
kernel_containers.h
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_CONTAINERS_KERNEL_CONTAINERS_HPP_
39 #define PCL_GPU_CONTAINERS_KERNEL_CONTAINERS_HPP_
40 
41 
42 #if defined(__CUDACC__)
43  #define __PCL_GPU_HOST_DEVICE__ __host__ __device__ __forceinline__
44 #else
45  #define __PCL_GPU_HOST_DEVICE__
46 #endif
47 
48 #include <cstddef>
49 
50 namespace pcl
51 {
52  namespace gpu
53  {
54  template<typename T> struct DevPtr
55  {
56  typedef T elem_type;
57  const static size_t elem_size = sizeof(elem_type);
58 
59  T* data;
60 
61  __PCL_GPU_HOST_DEVICE__ DevPtr() : data(0) {}
62  __PCL_GPU_HOST_DEVICE__ DevPtr(T* data_arg) : data(data_arg) {}
63 
64  __PCL_GPU_HOST_DEVICE__ size_t elemSize() const { return elem_size; }
65  __PCL_GPU_HOST_DEVICE__ operator T*() { return data; }
66  __PCL_GPU_HOST_DEVICE__ operator const T*() const { return data; }
67  };
68 
69  template<typename T> struct PtrSz : public DevPtr<T>
70  {
71  __PCL_GPU_HOST_DEVICE__ PtrSz() : size(0) {}
72  __PCL_GPU_HOST_DEVICE__ PtrSz(T* data_arg, size_t size_arg) : DevPtr<T>(data_arg), size(size_arg) {}
73 
74  size_t size;
75  };
76 
77  template<typename T> struct PtrStep : public DevPtr<T>
78  {
79  __PCL_GPU_HOST_DEVICE__ PtrStep() : step(0) {}
80  __PCL_GPU_HOST_DEVICE__ PtrStep(T* data_arg, size_t step_arg) : DevPtr<T>(data_arg), step(step_arg) {}
81 
82  /** \brief stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!! */
83  size_t step;
84 
85  __PCL_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr<T>::data + y * step); }
86  __PCL_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr<T>::data + y * step); }
87 
88  __PCL_GPU_HOST_DEVICE__ T& operator()(int y, int x) { return ptr(y)[x]; }
89  __PCL_GPU_HOST_DEVICE__ const T& operator()(int y, int x) const { return ptr(y)[x]; }
90  };
91 
92  template <typename T> struct PtrStepSz : public PtrStep<T>
93  {
94  __PCL_GPU_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {}
95  __PCL_GPU_HOST_DEVICE__ PtrStepSz(int rows_arg, int cols_arg, T* data_arg, size_t step_arg)
96  : PtrStep<T>(data_arg, step_arg), cols(cols_arg), rows(rows_arg) {}
97 
98  int cols;
99  int rows;
100  };
101  }
102 
103  namespace device
104  {
105  using pcl::gpu::PtrSz;
106  using pcl::gpu::PtrStep;
107  using pcl::gpu::PtrStepSz;
108  }
109 }
110 
111 #undef __PCL_GPU_HOST_DEVICE__
112 
113 #endif /* PCL_GPU_CONTAINERS_KERNEL_CONTAINERS_HPP_ */
114 
__PCL_GPU_HOST_DEVICE__ const T & operator()(int y, int x) const
__PCL_GPU_HOST_DEVICE__ T & operator()(int y, int x)
__PCL_GPU_HOST_DEVICE__ PtrStepSz()
__PCL_GPU_HOST_DEVICE__ size_t elemSize() const
__PCL_GPU_HOST_DEVICE__ DevPtr(T *data_arg)
__PCL_GPU_HOST_DEVICE__ PtrSz()
__PCL_GPU_HOST_DEVICE__ DevPtr()
size_t step
stride between two consecutive rows in bytes.
static const size_t elem_size
__PCL_GPU_HOST_DEVICE__ const T * ptr(int y=0) const
__PCL_GPU_HOST_DEVICE__ PtrStep(T *data_arg, size_t step_arg)
__PCL_GPU_HOST_DEVICE__ PtrStepSz(int rows_arg, int cols_arg, T *data_arg, size_t step_arg)
__PCL_GPU_HOST_DEVICE__ PtrStep()
__PCL_GPU_HOST_DEVICE__ T * ptr(int y=0)
__PCL_GPU_HOST_DEVICE__ PtrSz(T *data_arg, size_t size_arg)