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