cheshirekow  v0.1.0
PointSet.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_CUDANN_POINTSET_H_
28 #define MPBLOCKS_CUDANN_POINTSET_H_
29 
30 
31 #include <map>
32 #include <string>
33 #include <mpblocks/cuda/bitonic.h>
34 
35 namespace mpblocks {
36 namespace cudaNN {
37 
38 
39 template <typename Format_t, unsigned int NDim>
41 {
42  public:
43  typedef unsigned int uint_t;
44 
45  private:
47  Format_t* m_buf;
48 
49  public:
51  m_cols(0),
52  m_buf(0)
53  {
54  allocate( cols );
55  }
56 
58  {
59  if( m_buf )
60  delete [] m_buf;
61  }
62 
63  void allocate( uint_t cols );
64 
65  Format_t* ptr() const { return m_buf; }
66  uint_t cols() const { return m_cols; }
67  uint_t pitch() const { return m_cols*sizeof(Format_t); }
68 
69  Format_t operator()( int i, int j )
70  {
71  return m_buf[ i*m_cols + j ];
72  }
73 };
74 
75 
76 struct EuclideanTag{};
77 struct SE3Tag
78 {
79  float w;
80  SE3Tag( float w=1 ):w(w){}
81  SE3Tag operator()( float w ) const{ return SE3Tag(w); }
82 };
83 
84 struct R2S1Tag
85 {
86  float w;
87  R2S1Tag( float w=1):w(w){}
88  R2S1Tag operator()( float w ) const{ return R2S1Tag(w); }
89 };
90 
92 const SE3Tag SE3;
93 const R2S1Tag R2S1;
94 
95 
98 template <typename Format_t, unsigned int NDim>
99 class PointSet
100 {
101  public:
102  typedef unsigned int uint_t;
105 
106  private:
109  uint_t m_dbSize;
111  size_t m_pitchIn;
112  size_t m_pitchOut;
113  Format_t* m_g_in;
114  Format_t* m_g_out;
115  Format_t* m_g_sorted;
116 
118 
121 
122  public:
123  PointSet(uint_t n=10);
124  ~PointSet();
125 
127  void deallocate();
128 
131  void allocate(uint_t n);
132 
134  void clear(bool clearmem=false);
135 
139  void config();
140 
144  void config(int dev);
145 
146  private:
149  void computeGrid( uint_t& blocks, uint_t& threads );
150 
151  public:
153  int insert( const Format_t q[NDim] );
154 
156  void distance( EuclideanTag, const Format_t q[NDim], Result_t& out );
157  void distance( SE3Tag, const Format_t q[NDim], Result_t& out );
158  void distance( R2S1Tag, const Format_t q[NDim], Result_t& out );
159 
160  void distance( EuclideanTag, const Format_t q[NDim], uint_t size, Result_t& out );
161  void distance( SE3Tag, const Format_t q[NDim], uint_t size, Result_t& out );
162  void distance( R2S1Tag, const Format_t q[NDim], uint_t size, Result_t& out );
163 
165  void nearest( EuclideanTag, const Format_t q[NDim], Result_t& out );
166  void nearest( SE3Tag, const Format_t q[NDim], Result_t& out );
167  void nearest( R2S1Tag, const Format_t q[NDim], Result_t& out );
168 
169  void nearest( EuclideanTag, const Format_t q[NDim], uint_t size, Result_t& out );
170  void nearest( SE3Tag, const Format_t q[NDim], uint_t size, Result_t& out );
171  void nearest( R2S1Tag, const Format_t q[NDim], uint_t size, Result_t& out );
172 };
173 
174 
175 
176 } //< namespace cudaNN
177 } //< namespace mpblocks
178 
179 #endif // POINTSET_H_
ResultBlock(uint_t cols=0)
Definition: PointSet.h:50
void allocate(uint_t cols)
Definition: PointSet.hpp:46
const R2S1Tag R2S1
Definition: PointSet.h:93
cuda::bitonic::Sorter< Format_t, Format_t > Sorter_t
Definition: PointSet.h:103
R2S1Tag operator()(float w) const
Definition: PointSet.h:88
Format_t * ptr() const
Definition: PointSet.h:65
provides a convenience interface for managing a point set in GPU memory, and dispatching brute force ...
Definition: PointSet.h:99
uint_t m_nSM
number of multiprocessors
Definition: PointSet.h:120
Format_t * m_g_in
kernel input buffer
Definition: PointSet.h:113
Format_t operator()(int i, int j)
Definition: PointSet.h:69
uint_t m_threadsPerBlock
maximum threads per block
Definition: PointSet.h:119
void deallocate()
deallocate and zero out pointers
Definition: PointSet.hpp:116
void computeGrid(uint_t &blocks, uint_t &threads)
compute the grid size given the current configuration and size of the point set
Definition: PointSet.hpp:225
void clear(bool clearmem=false)
clear the database and reset input iterator
Definition: PointSet.hpp:189
uint_t cols() const
Definition: PointSet.h:66
void distance(EuclideanTag, const Format_t q[NDim], Result_t &out)
batch compute distance to point set
uint_t m_dbAlloc2
size allocated for the sorted set, will be the next power of two of dbAlloc
Definition: PointSet.h:108
const SE3Tag SE3
Definition: PointSet.h:92
uint_t m_dbSize
size of the point set filled
Definition: PointSet.h:110
ResultBlock< Format_t, 2 > Result_t
Definition: PointSet.h:104
void config()
retreives device properties of the current device, used to calculate kernel peramaters, call once after setting the cuda device and before launching any kernels
Definition: PointSet.hpp:210
size_t m_pitchIn
row-pitch of buffers (in bytes)
Definition: PointSet.h:111
size_t m_pitchOut
row-pitch of buffers (in bytes)
Definition: PointSet.h:112
void nearest(EuclideanTag, const Format_t q[NDim], Result_t &out)
return k nearest children of q, k is columns of out
const EuclideanTag EUCLIDEAN
Definition: PointSet.h:91
Sorter_t m_sorter
wraps sort kernels
Definition: PointSet.h:117
SE3Tag operator()(float w) const
Definition: PointSet.h:81
int insert(const Format_t q[NDim])
insert a new state into the point set, and return it's id
Definition: PointSet.hpp:243
void allocate(uint_t n)
reallocates device storage for a point set of size n, also resets the database
Definition: PointSet.hpp:151
uint_t m_dbAlloc
size of the point set allocated
Definition: PointSet.h:107
Format_t * m_g_sorted
output for sorted results
Definition: PointSet.h:115
Format_t * m_g_out
kernel output buffer
Definition: PointSet.h:114
uint_t pitch() const
Definition: PointSet.h:67