Skip to content

Commit f3e9844

Browse files
author
bwang_laptop
committed
updated readme
1 parent 03e9643 commit f3e9844

File tree

5 files changed

+111
-45
lines changed

5 files changed

+111
-45
lines changed

LSH.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#include <random>
1010
#include <algorithm>
1111
#include "omp.h"
12-
#include "ALSH.h"
1312

1413
//#define DEBUG
15-
#define MAGIC_NUMBER 100
14+
#define MAGIC_NUMBER 100 // For debugging purpose, ignore.
1615

1716
#define UNIVERSAL_HASH(x,M,a,b) ((unsigned) (a * x + b) >> (32 - M))
1817
#define BINARY_HASH(x,a,b) ((unsigned) (a * x + b) >> 31)

LSHReservoirSampler_config.h

+34-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
11
#pragma once
22

3-
// Comment out if not using GPU.
4-
//#define USE_OPENCL
3+
// Customize processing architecture.
4+
//#define OPENCL_HASHTABLE // Placing the hashtable in the OpenCL device.
5+
//#define OPENCL_HASHING // Perform hashing in the OpenCL device.
6+
#define OPENCL_KSELECT // Perform k-selection in the OpenCL device.
57

6-
// Comment out if using OpenCL 1.XX. Does not matter if not usng GPU.
7-
#define OPENCL_2XX
8+
// Comment out if using OpenCL 1.XX.
9+
//#define OPENCL_2XX
810

911
// Select the id of the desired platform and device, only relevant when using OpenCl.
1012
// An overview of the platforms and devices can be queried through the OpenCL framework.
1113
// On Linux, a package "clinfo" is also capable of outputing the platform and device information.
12-
#define CL_PLATFORM_ID 0
14+
#define CL_PLATFORM_ID 1
1315
#define CL_DEVICE_ID 0
1416

15-
#if defined USE_OPENCL
16-
// The parts of the program using OpenCL can be customized.
17-
#define OPENCL_HASHTABLE
18-
//#define CPU_TB
19-
#define OPENCL_HASHING
20-
//#define CPU_HASHING
21-
#define OPENCL_KSELECT
22-
//#define CPU_KSELECT
23-
#else
24-
#define CPU_TB
25-
#define CPU_HASHING
26-
#define CPU_KSELECT
27-
#endif
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
2832

2933
/* Performance tuning params, Do not touch. */
3034
#define wg_segSize 512 // Number of workgroup element, an integral factor of the segmentSize.
3135
#define l_segSize 64 // Number of elements each thread will tally.
3236
//#define SECONDARY_HASHING
37+
38+
#if !defined(OPENCL_HASHTABLE)
39+
#define CPU_TB
40+
#endif
41+
42+
#if !defined(OPENCL_HASHING)
43+
#define CPU_HASHING
44+
#endif
45+
46+
#if !defined(OPENCL_KSELECT)
47+
#define CPU_KSELECT
48+
#endif

README.md

+74-22
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ FLASH (Fast LSH Algorithm for Similarity Search Accelerated with HPC) is a libra
44

55
## Performance
66

7-
We tested our system on a few large scale sparse datasets including [url](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#url), [webspam](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#webspam) and [kdd12](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#kdd2012).
8-
9-
The following results are from a head-to-head comparison with [NMSLIB](https://github.com/searchivarius/nmslib) v1.6 hnsw, one of the best methods available (see [ann-benchmarks](https://github.com/erikbern/ann-benchmarks)) on these datasets. In particular, we compared the timing for the construction of full knn-graph from grounds up, and the per-query timing (after building the index). We also estimated and compared the memory consumption of the index.
7+
We tested our system on a few large scale sparse datasets including [url](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#url), [webspam](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#webspam) and [kdd12](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#kdd2012), and also a dense dataset [SIFT1M](http://corpus-texmex.irisa.fr/).
108

119
### Quality Metrtics
1210

1311
*R@k* is the recall of the 1-nearest neighbor in the top-k results.
1412
*S@k* is the average cosine similarity of the top-k results concerning the query datapoint.
1513

14+
For the dense SIFT1M dataset, we used 1 GPU (Nvidia Tesla P100) for all the processing. We constructed the hashtable within 3 seconds and achieved R@100 = 0.659, S@1 = 0.844 and S@100 = 0.751 with per query runtime of 0.038 milliseconds.
15+
16+
For the testing of the sparse datasets, we present results on 2 CPUs (Intel Xeon E5 2660v4) and 2 CPUs + 1 GPU. The following results are from a head-to-head comparison with [NMSLIB](https://github.com/searchivarius/nmslib) v1.6 hnsw, one of the best methods available (see [ann-benchmarks](https://github.com/erikbern/ann-benchmarks)). In particular, we compared the timing for the construction of full knn-graph from grounds up, and the per-query timing (after building the index). We also estimated and compared the memory consumption of the index.
17+
18+
1619
**Webspam, Url**
1720

1821
<img src="https://github.com/RUSH-LAB/Flash/blob/master/plots/webspam_url_table.PNG" width="668" height="85" />
@@ -33,43 +36,92 @@ An active installation of OpenCL 1.1 or OpenCL 2.0 is required to support the GP
3336

3437
Then, install clinfo by `apt-get install clinfo` and verify the number of OpenCL platforms and devices. These information will be used in the configurations.
3538

36-
## Configuration and Compilation
39+
## System Configuration
3740

38-
Navigate to the FLASH directory. Configure the system by editing the following section of *LSHReservoir_config.h* guided by the comments:
41+
Navigate to the FLASH directory. First configure the system by editing the following section of *LSHReservoir_config.h* to choose the devices to use.
3942

4043
```
41-
// Comment out if not using GPU.
42-
#define USE_GPU
43-
// Comment out if using OpenCL 1.XX. Does not matter if not usng GPU.
44+
// Customize processing architecture.
45+
#define OPENCL_HASHTABLE // Placing the hashtable in the OpenCL device.
46+
#define OPENCL_HASHING // Perform hashing in the OpenCL device.
47+
#define OPENCL_KSELECT // Perform k-selection in the OpenCL device.
48+
49+
// Comment out if using OpenCL 1.XX.
4450
#define OPENCL_2XX
4551
46-
#define CL_GPU_PLATFORM 0 // Does not matter if not usng OpenCL-GPU.
47-
#define CL_CPU_PLATFORM 1 // Does not matter if not usng OpenCL-CPU.
48-
#define CL_GPU_DEVICE 0 // Does not matter if not usng OpenCL-GPU.
49-
#define CL_CPU_DEVICE 0 // Does not matter if not usng OpenCL-CPU.
52+
// Select the id of the desired platform and device, only relevant when using OpenCl.
53+
// An overview of the platforms and devices can be queried through the OpenCL framework.
54+
// On Linux, a package "clinfo" is also capable of outputing the platform and device information.
55+
#define CL_PLATFORM_ID 0
56+
#define CL_DEVICE_ID 0
5057
```
58+
For dense datasets:
59+
1. GPU only
5160

52-
Fill in CL_GPU_PLATFORM / CL_GPU_PLATFORM according to the order that the cpu/gpu platforms appear in the output of clinfo (make sure that for gpu is correct, OpenCL for cpu is currently experimental and is not required). If multiple devices exist, fill in CL_GPU_DEVICE / CL_CPU_DEVICE to choose the desired device according to their order in the output of clinfo.
53-
54-
Save and close the file. Type in terminal:
61+
```
62+
// Customize processing architecture.
63+
#define OPENCL_HASHTABLE // Placing the hashtable in the OpenCL device.
64+
#define OPENCL_HASHING // Perform hashing in the OpenCL device.
65+
#define OPENCL_KSELECT // Perform k-selection in the OpenCL device.
66+
```
67+
For sparse datasets:
68+
1. CPU + GPU
5569

5670
```
57-
make
71+
// Customize processing architecture.
72+
//#define OPENCL_HASHTABLE // Placing the hashtable in the OpenCL device.
73+
//#define OPENCL_HASHING // Perform hashing in the OpenCL device.
74+
#define OPENCL_KSELECT // Perform k-selection in the OpenCL device.
75+
```
76+
2. CPU only
5877
```
78+
// Customize processing architecture.
79+
//#define OPENCL_HASHTABLE // Placing the hashtable in the OpenCL device.
80+
//#define OPENCL_HASHING // Perform hashing in the OpenCL device.
81+
//#define OPENCL_KSELECT // Perform k-selection in the OpenCL device.
82+
```
83+
Install clinfo by `apt-get install clinfo`. Fill in CL_PLATFORM_ID / CL_DEVICE_ID to choose the desired platform and device based on to the order that the GPU platforms and devices appear in the output of clinfo. Comment out `OPENCL_2XX` if using OpenCL 1.X. Save and close the file.
5984

60-
The compilation is complete if no errors appear.
85+
Complete the dataset setup as detailed in the **Tutorial** section (or any customized usage, please refer to our [documentation](https://github.com/RUSH-LAB/Flash/blob/master/doc.pdf)), and compile the program:
86+
```
87+
make clean; make
88+
```
89+
The compilation is complete if no errors appear. Run the program by:
90+
```
91+
./runme
92+
```
6193

6294
## Tutorial
6395

64-
The current example code in the main() function verifies one of the results presented in [our paper](https://arxiv.org/pdf/1709.01190.pdf) on the Webspam dataset. Download the dataset from [libsvm](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#webspam), and rename the libsvm-format file as trigram.svm. Download the groundtruths from this [link](https://github.com/wangyiqiu/webspam). Place the dataset and groundtruth files in the FLASH directory. Run the program from the terminal:
96+
We will present very detailed steps to replicate one result presented in [our paper](https://arxiv.org/pdf/1709.01190.pdf), in particular the webspam dataset. Other results can be replicated in a very similar manner. For customized usage, please refer to our [documentation](https://github.com/RUSH-LAB/Flash/blob/master/doc.pdf) generated by [doxygen](http://www.stack.nl/~dimitri/doxygen/).
97+
98+
Download the dataset from [libsvm](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/binary.html#webspam), and the groundtruths from this [link](https://github.com/wangyiqiu/webspam). Place the dataset and groundtruth files in a directory you like.
99+
100+
Open `benchmarking.h` and follow the following configuration. Make sure to set the **path** of the dataset and groundtruth files correctly under `#elif defined WEBSPAM_TRI`.
65101

66102
```
67-
./runme
68-
```
103+
/* Select a dataset below by uncommenting it.
104+
Then modify the file location and parameters below in the Parameters section. */
105+
106+
//#define SIFT1M
107+
//#define URL
108+
#define WEBSPAM_TRI
109+
//#define KDD12
110+
111+
...
69112
70-
The test program builds multiple hash tables for the dataset and query 10,000 test vectors followed by quality evaluations. The program will run with console outputs, indicating the progress and performance. The parameters, such as L, K and R can be edited in main.cpp. A re-compilation is required after changing the parameters. Please note that the time for parsing the dataset from disk might take about 5-10 minutes.
113+
#elif defined WEBSPAM_TRI
114+
115+
...
116+
117+
#define BASEFILE ".../trigram.svm"
118+
#define QUERYFILE ".../trigram.svm"
119+
#define GTRUTHINDICE ".../webspam_tri_gtruth_indices.txt"
120+
#define GTRUTHDIST ".../webspam_tri_gtruth_distances.txt"
121+
```
122+
Configure the system for **sparse data**, CPU or CPU + GPU and run the program (if not already done, see **System Configuration** above).
71123

72-
A basic [documentation](https://github.com/RUSH-LAB/Flash/blob/master/doc.pdf) of the API generated by [doxygen](http://www.stack.nl/~dimitri/doxygen/) is available. Tutorial codes in main.cpp could be used as a reference.
124+
The test program builds multiple hash tables for the dataset and query 10,000 test vectors followed by quality evaluations. The program will run with console outputs, indicating the progress and performance. `make clean; make` is required after changing the parameters. Please note that the time for parsing the webspam dataset from disk might take about 5-10 minutes.
73125

74126
## Authors
75127

benchmarking.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Then modify the file location and parameters below in the Parameters section. */
55

66
//#define SIFT1M
7-
#define URL
8-
//#define WEBSPAM_TRI
7+
//#define URL
8+
#define WEBSPAM_TRI
99
//#define KDD12
1010

1111
/* Parameters. */

main.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ int main(void) {
3131
#elif defined(DENSE_DATASET)
3232
benchmark_dense();
3333
#endif
34-
system("pause");
3534
return 0;
3635
}
3736

0 commit comments

Comments
 (0)