RTNN: accelerating neighbor search using hardware ray tracing

Yuhao Zhu

Abstract

Neighbor search is a fundamental operation in scientific computing, computer vision, and physics simulations. Historically, researchers have faced a trade-off between hardware-friendly grid-based algorithms and work-efficient tree-based structures that suffer from irregular memory access on GPUs. RTNN addresses this by repurposing dedicated ray-tracing hardware (RT cores) in modern GPUs to accelerate neighbor search. By formulating neighbor search as a ray-casting problem and introducing novel query scheduling and partitioning optimizations, RTNN achieves up to a 65x speedup over existing state-of-the-art GPU libraries.

Introduction

Neighbor search—finding all points within a fixed radius or the $K$ closest points (KNN)—is the "bread and butter" of modern computational science. While GPUs are highly parallel, they struggle with the irregular traversal required by tree-based algorithms like k-d trees or Octrees, often leading to "warp divergence." With the advent of Nvidia’s Turing architecture, GPUs now include specialized RT Cores designed specifically to traverse Bounding Volume Hierarchies (BVH) at high speeds. RTNN explores the feasibility of hijacking this gaming-centric silicon to solve the hardware-unfriendly nature of spatial neighbor queries.

Methodology: Mapping Search to Silicon

The core innovation of RTNN is mapping neighbor search to a ray-casting problem. Instead of searching for points near a query, the system wraps every point in the dataset in a tiny Axis-Aligned Bounding Box (AABB). To find neighbors, a "ray" is cast from the query point. If the ray intersects a box, the hardware triggers a callback to verify the point's distance.

Mapping neighbor search to BVH traversal and hardware execution timelines.

To maximize efficiency, RTNN utilizes extremely short rays (length $\approx 0$). This ensures the hardware only registers a hit if the query point is physically located inside the neighbor's bounding box, effectively turning a ray-intersection test into a point-in-box test.

Spatially-Ordered Query Scheduling

Naive mapping can lead to performance degradation if adjacent GPU threads access distant parts of a 3D scene. RTNN implements a pre-pass to identify which leaf node a query falls into and sorts queries using a Morton (Z-order) curve. This spatial reordering ensures that neighboring threads process physically close points, improving cache hits and reducing thread divergence by up to 5x.

Query Partitioning and Bundling

Recognizing that scene density varies, RTNN avoids using a single global tree. Instead, it partitions queries based on local point density and uses a mathematical cost model to "bundle" these partitions. This determines whether it is more efficient to build a specialized tree for a dense region or reuse an existing structure, a technique that provided up to a 154x speedup for KNN search in specific scenarios.

Hardware Insights: The 'Condition 2' Breakthrough

A critical technical insight of RTNN involves exploiting specific hardware behavior for ray-box intersections. Standard ray-tracing hardware typically looks for rays hitting the surface of a box (Condition 1). However, RTNN relies on "Condition 2," where a hit is registered if the ray origin $O$ is already inside the bounding box.

Comparison of standard ray-box intersection (Condition 1) and the internal origin hit (Condition 2) used by RTNN.

By leveraging this hardware feature, the irregular portion of the search (BVH traversal) is handled by dedicated silicon, while the standard CUDA cores are reserved for regular floating-point distance calculations.

Experimental Results

RTNN was evaluated on an Nvidia RTX 2080 across diverse datasets, including KITTI LiDAR point clouds, the Stanford 3D Repository, and the Millennium cosmological simulation. Compared to established libraries like cuNSearch and FRNN, RTNN demonstrated significant performance gains:

  • Range Search: Geometric mean speedup of 2.2x to 44.0x.
  • KNN Search: Geometric mean speedup of 3.5x to 65.0x.
  • Scalability: The performance advantage of RTNN increases as the dataset size grows, making it particularly suitable for large-scale scientific data.

Conclusion and Future Work

RTNN demonstrates that specialized gaming hardware can be effectively repurposed for general-purpose scientific computing. While currently optimized for Nvidia's OptiX framework, the underlying principles are applicable to any ray-tracing API. Future work may explore approximate neighbor searches for further speed gains and the application of RT cores to other irregular algorithms like collision detection or spatial joins.

Summary updated

BibTeX
@inproceedings{zhu2022rtnn,
  author = {Yuhao Zhu},
  title = {{RTNN: accelerating neighbor search using hardware ray tracing}},
  booktitle = {PPoPP},
  year = {2022},
  doi = {10.1145/3503221.3508409},
}
Figure