Abstract
Nearest Neighbor (NN) search is a critical operation in various domains, often suffering from the "curse of dimensionality" where traditional indexing structures falter. This paper proposes a GPU-accelerated linear scan algorithm that offloads the entire search process—including distance calculations and minimum value identification—to the graphics hardware. By leveraging the parallel processing capabilities of mid-2000s GPUs via Cg fragment programs, the approach achieves significant speedups over optimized CPU implementations without requiring post-processing on the host.
Introduction
Finding the closest point in a dataset to a query point is fundamental to data mining, image retrieval, and bioinformatics. In high-dimensional spaces, complex index structures like KD-trees often degrade to the performance of a linear scan. Consequently, accelerating the "brute-force" linear scan becomes a viable path for performance gains. This research utilizes the massive parallel throughput of GPUs, traditionally used for rendering, to perform high-speed NN searches.
Methodology
The proposed algorithm implements a linear scan using a three-stage pipeline of Fragment Programs (FPs) written in Cg.
Data Organization and Distance Calculation
To maximize hardware utilization, database vectors are packed into 2D textures. Specifically, the four color channels (RGBA) of a single texel are used to store the same coordinate for four distinct vectors, effectively quadrupling the throughput of arithmetic units.
The first fragment program (FP1) calculates the Manhattan distance between the query point and the database objects. It processes multiple dimensions in parallel, aggregating results into a result texture.
Reduction and Search
The search for the global minimum is performed entirely on the GPU to avoid the bottleneck of transferring intermediate results back to the CPU.
- Channel Reduction (FP2): This stage examines the four distance values in each texel's RGBA channels, identifies the minimum distance ($d_{min}$), and pairs it with the corresponding object ID ($idx_{min}$).
- Iterative Spatial Reduction (FP3): The GPU iteratively compares groups of four texels, writing the "winner" (the one with the minimum distance) to a progressively smaller texture. Each pass reduces the texture size by a factor of four until a single $1 \times 1$ pixel remains, containing the final nearest neighbor result.
Experimental Evaluation
The algorithm was tested against a Pentium IV 3.0 GHz CPU implementation optimized with SSE2 instructions. Benchmarks included synthetic data (up to 256 dimensions) and real-world datasets such as Forest CoverType, Corel Image Features, and a 512-dimensional 3D CAD Database.
Key Results
The GPU implementation (NVIDIA GeForce 6800 Ultra) consistently outperformed the CPU by 4.2x to 6.4x. Notably, the performance lead was maintained even on the 512-dimensional CAD dataset, demonstrating the algorithm's robustness in high-dimensional scenarios where traditional indexing fails. The implementation scales linearly with both dataset size and dimensionality, making its performance highly predictable.
Conclusion
By achieving total GPU autonomy and exploiting the RGBA architecture of graphics hardware, this approach provides a scalable solution for large-scale NN search. While memory constraints and metric flexibility (e.g., Euclidean distance) present areas for refinement, the transition from graphics-specific hacks to modern GPGPU frameworks like CUDA promises even greater efficiency in future iterations.
Summary updated