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_DUBINS_CURVES_CUDA2_POINTSET_H_
28 #define MPBLOCKS_DUBINS_CURVES_CUDA2_POINTSET_H_
29 
30 
31 #include <map>
32 #include <string>
33 
34 namespace mpblocks {
35 namespace dubins {
36 namespace curves_cuda {
37 
38 
39 template <typename Format_t>
41 {
42  public:
43  typedef unsigned int uint_t;
44 
45  private:
48 
49  Format_t* m_buf;
50 
51  public:
53  m_rows(0),
54  m_cols(0),
55  m_buf(0)
56  {
57  allocate( rows, cols );
58  }
59 
61  {
62  if( m_buf )
63  delete [] m_buf;
64  }
65 
66  void allocate( uint_t rows, uint_t cols );
67 
68  Format_t* ptr() const { return m_buf; }
69  uint_t rows() const { return m_rows; }
70  uint_t cols() const { return m_cols; }
71  uint_t pitch() const { return m_cols*sizeof(Format_t); }
72 
73  Format_t operator()( int i, int j )
74  {
75  return m_buf[ i*m_cols + j ];
76  }
77 };
78 
79 
80 
83 template <typename Format_t>
84 class PointSet
85 {
86  public:
87  typedef unsigned int uint_t;
88  typedef std::map< std::string, cuda::FuncAttributes > fattrMap_t;
90 
91  private:
97  size_t m_pitchIn;
98  size_t m_pitchOut;
99  Format_t* m_g_in;
100  Format_t* m_g_out;
101  Format_t* m_g_sorted;
102 
104 
107 
108  public:
109  PointSet(uint_t n=10, Format_t r=1);
110  ~PointSet();
111 
113  void deallocate();
114 
117  void allocate(uint_t n);
118 
120  void set_r( Format_t r );
121 
123  void clear(bool clearmem=false);
124 
128  void config();
129 
133  void config(int dev);
134 
135  private:
138  void computeGrid( uint_t& blocks, uint_t& threads );
139 
140  public:
142  int insert( Format_t q[3] );
143 
145  void distance_to_set( Format_t q[3], ResultBlock<Format_t>& out );
146 
148  void distance_from_set( Format_t q[3], ResultBlock<Format_t>& out );
149 
151  void nearest_children( Format_t q[3], ResultBlock<Format_t>& out );
152 
154  void nearest_parents( Format_t q[3], ResultBlock<Format_t>& out );
155 
157  void group_distance_to_set( Format_t q[3], ResultBlock<Format_t>& out );
158 
160  void group_distance_neighbors( Format_t q[3], ResultBlock<Format_t>& out );
161 
164  static void get_fattr( fattrMap_t& );
165 };
166 
167 
168 
169 } // curves
170 } // dubins
171 } // mpblocks
172 
173 #endif // POINTSET_H_
void distance_to_set(Format_t q[3], ResultBlock< Format_t > &out)
batch compute distance to point set
Format_t * m_g_sorted
output for sorted results
Definition: PointSet.h:101
size_t m_pitchIn
row-pitch of buffers (in bytes)
Definition: PointSet.h:97
void allocate(uint_t n)
reallocates device storage for a point set of size n, also resets the database
Definition: PointSet.cu.hpp:97
ResultBlock(uint_t rows=0, uint_t cols=0)
Definition: PointSet.h:52
void clear(bool clearmem=false)
clear the database and reset input iterator
size_t m_pitchOut
row-pitch of buffers (in bytes)
Definition: PointSet.h:98
static void get_fattr(fattrMap_t &)
retrieve kernel attributes into the map, intended only for printing out statistics ...
void deallocate()
deallocate and zero out pointers
Definition: PointSet.cu.hpp:75
cuda::bitonic::Sorter< Format_t, Format_t > Sorter_t
Definition: PointSet.h:89
std::map< std::string, cuda::FuncAttributes > fattrMap_t
Definition: PointSet.h:88
void group_distance_to_set(Format_t q[3], ResultBlock< Format_t > &out)
batch compute euclidean distances
Format_t * m_g_out
kernel output buffer
Definition: PointSet.h:100
void nearest_parents(Format_t q[3], ResultBlock< Format_t > &out)
return k nearest parents of q
Format_t operator()(int i, int j)
Definition: PointSet.h:73
void set_r(Format_t r)
set the radius
void distance_from_set(Format_t q[3], ResultBlock< Format_t > &out)
batch compute distance from point set
void nearest_children(Format_t q[3], ResultBlock< Format_t > &out)
return k nearest children of q
uint_t m_dbAlloc
size of the point set allocated
Definition: PointSet.h:93
void computeGrid(uint_t &blocks, uint_t &threads)
compute the grid size given the current configuration and size of the point set
Params< Format_t > m_params
query parameters
Definition: PointSet.h:92
int insert(Format_t q[3])
insert a new state into the point set, and return it's id
provides a convenience interface for managing a point set of dubins states in GPU memory...
Definition: PointSet.h:84
uint_t m_dbAlloc2
size allocated for the sorted set, will be the next power of two of dbAlloc
Definition: PointSet.h:94
uint_t m_dbSize
size of the point set filled
Definition: PointSet.h:96
uint_t m_threadsPerBlock
maximum threads per block
Definition: PointSet.h:105
Sorter_t m_sorter
wraps sort kernels
Definition: PointSet.h:103
uint_t m_nSM
number of multiprocessors
Definition: PointSet.h:106
PointSet(uint_t n=10, Format_t r=1)
Definition: PointSet.cu.hpp:47
void group_distance_neighbors(Format_t q[3], ResultBlock< Format_t > &out)
find k euclidean nearest neighbors
Format_t * m_g_in
kernel input buffer
Definition: PointSet.h:99
void allocate(uint_t rows, uint_t cols)
Definition: PointSet.cu.hpp:37
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