updated readme
[RBC.git] / readme.txt
1 ***Random Ball Cover (RBC) v0.2.4***
2 Lawrence Cayton
3 lcayton@tuebingen.mpg.de
4
5 (C) Copyright 2010, Lawrence Cayton [lcayton@tuebingen.mpg.de]
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
21 ---------------------------------------------------------------------
22 SUMMARY
23
24 This is a C and CUDA implementation of the Random Ball Cover data
25 structure for fast nearest neighbor search on a GPU. The code
26 implements the one-shot algorithm.
27
28 See the following papers for a detailed description of the search
29 algorithm and the theory behind it.
30
31 * L. Cayton, A nearest neighbor data structure for graphics hardware.
32 ADMS, 2010.
33 * L. Cayton, Accelerating nearest neighbor search on manycore systems.
34 Submitted, 2011.
35
36
37 ---------------------------------------------------------------------
38 COMPILATION
39
40 Type make in a shell. Requires GCC and NVCC (CUDA). The code has
41 been developed under GCC 4.4 and CUDA 3.1.
42
43
44 ---------------------------------------------------------------------
45 USE
46
47 A sample driver is provided for the RBC. To try it out, type
48 $ testRBC
49 at the prompt and a list of options will be displayed.
50
51 The output file format is a list of the queries' NNs,
52 followed by a list of the distances to those NNs. Note that by
53 default, all input and output is stored in single-precision (float)
54 format.
55
56 Basic functionality is provided through this driver, but I recommend
57 integrating the RBC code directly into your code for the best
58 results. For many applications, the RBC needs to be built only once,
59 and then can be queried many times.
60
61 The method requires a single parameter, the number of
62 representatives. This parameter allows you to trade-off between
63 search quality and search speed. The best way to set this parameter
64 is to try a few different values out; a good starting point is
65 generally 5*sqrt(n), where n is the number of database points. Use
66 the eval option (-e) to print out the error rate. See the paper
67 (Cayton, 2011) for detailed information on this parameter.
68
69
70 ---------------------------------------------------------------------
71 FILES
72
73 * brute.{h,cu} -- implementation of brute force search (CPU and GPU
74 versions)
75 * defs.h -- definitions of constants and macros, including the
76 distance metric.
77 * driver.cu -- example code for using the RBC data structure.
78 * kernels.{h,cu} -- implementation of all the (device) kernel functions,
79 except those related to the scan (see sKernels below)
80 * kernelWrap.{h,cu} -- CPU wrapper code around the kernels.
81 * rbc.{h,cu} -- the core of the RBC data structure. Includes the
82 implementation of build and search algorithms.
83 * sKernel.{h,cu} -- implementation of the kernel functions related to
84 the parallel scan algorithm (used within the build method).
85 * sKernelWrap.{h,cu} -- wrappers for the kernels in sKernel.
86 * utils.{h,cu} -- misc utilities used in the code.
87 * utilsGPU.{h,cu} -- misc utilities related to the GPU.
88
89
90 ---------------------------------------------------------------------
91 MISC NOTES ON THE CODE
92
93 * The code currently computes distance using the L_2 (Euclidean)
94 metric. If you wish to use a different notion of distance, you must
95 modify defs.h. It is quite simple to switch to any metric that
96 operates alongs the coordinates independently (eg, any L_p metric),
97 but more complex metrics will require some aditional work. The L_1
98 metric (manhatten distance) is already defined in defs.h.
99
100 * The k-NN code is currently hard-coded for k=32. It is hard-coded
101 because it uses a manually implemented sorting network. This design
102 allows all sorting to take place in on-chip (shared) memory, and is
103 highly efficient. Note that the NNs are returned in sorted order,
104 so that if one wants only, say, 5 NNs, one can simply ignore the
105 last 27 returned indices. For k>32, contact the author.
106
107 * The code requires that the entire DB and query set fit into the
108 device memory.
109
110 * Currently the software works in single precision. If you wish to
111 switch to double precision, you must edit the defs.h file. Simply
112 uncomment the lines
113
114 typedef double real;
115 #define MAX_REAL DBL_MAX
116
117 and comment out the lines
118
119 typedef float real;
120 #define MAX_REAL FLT_MAX
121
122 Then, you must do a
123 $ make clean
124 followed by another make.
125
126 * For the most part, device variables (ie arrays residing on the GPU)
127 begin with a lowercase d. For example, the device version of the
128 DB variable x is dx.
129
130 * The computePlan code is a bit more complex than is needed for the
131 version of the RBC search algorithm described in the paper. The
132 search algorithm described in the paper has two steps: (1) Find the
133 closest representative to the query. (2) Explore the points owned
134 by that representative (ie the s-closest points to the representative
135 in the DB). The computePlan code is more complex to make it easy
136 to try out other options. For example, one could search the points
137 owned by the *two* closest representatives to the query instead. This
138 would require only minor changes to the code, though is currently
139 untested.
140
141 * This software has been tested on the following graphics cards:
142 NVIDIA GTX 285, GT 430, GTX 480, GeForce 320M, Tesla c2050
143
144 * This sotware has been developed under the following software setup:
145 Ubuntu 10.04 (linux)
146 gcc 4.4
147 cuda 3.2
148
149 It has also been tested under Mac OSX. Please share your
150 experience getting it to work under Windows!
151
152 * If you are running this code on a GPU which is also driving your
153 display: A well-known issue with CUDA code in this situation is that
154 a process within the operating system will automatically kill
155 kernels that have been running for more than 5-10 seconds or so.
156 You can get around this in Linux by switching out of X-Windows (often
157 CTRL-ALT-F1 does the trick) and running the code directly from the
158 terminal.