How pwrliang/rayjoin works
1. What this repository is
RayJoin is a GPU-accelerated spatial join system focused on two queries: line-segment intersection (LSI) and point-in-polygon (PIP). A third workflow, polygon overlay, is built by combining the LSI and PIP results. The core design choice is to run these spatial operations on NVIDIA GPUs, with a ray-tracing-backed path using OptiX / RT Cores alongside software fallbacks.
2. Top-level execution boundary
The repository builds two main binaries from src/query.cc and src/overlay.cc:
- query_exec for LSI or PIP evaluation
- polyover_exec for polygon overlay
These binaries are the main entry points and wrap the same underlying data model and accelerator options.
3. High-level orchestration layer
src/app/ contains the application-facing orchestration for each workload and backend combination. It separates query/overlay behavior from accelerator choice, with variants for:
- grid
- lbvh
- rt
This is where mode selection, result checking, and output handling are coordinated.
4. Core algorithm layer
src/algo/ holds the shared algorithm logic for spatial joins:
- lsi.h for line-segment intersection
- pip.h for point-in-polygon
- rt_lsi_custom.cu and rt_pip_custom.cu for RT-specific implementations
- launch_parameters.h for GPU launch/configuration details
This layer is the main computation engine, with a backend-neutral interface and backend-specific implementations underneath.
5. Acceleration backends
The system has three distinct execution strategies:
- Uniform grid: software spatial partitioning in src/grid/
- LBVH: a linear BVH backend using the bundled third-party library in deps/lbvh/
- RT: OptiX-based ray tracing in src/rt/
This backend split is central to the architecture: the same spatial query is executed through different index structures and traversal engines.
6. Ray-tracing subsystem
src/rt/ is the hardware-accelerated path. It defines:
- the RT engine (rt_engine.cu/.h)
- primitive and SBT record abstractions
- OptiX-facing data structures
This subsystem is the bridge between spatial geometry and GPU ray tracing, and it is the part that depends most directly on NVIDIA OptiX and CUDA.
7. Geometry and map model
src/map/ contains the geometry/data model:
- polygon parsing
- bounding boxes
- planar graph representation
- scaling helpers
src/context.h and related config/flags files connect parsed polygon datasets to the runtime. The repository’s inputs are CDB-format polygon chains, and this layer is responsible for turning those into structures the accelerators can consume.
8. Output and result handling
src/app/output_chain.h and the overlay/query app headers indicate that results are not just boolean predicates; overlay workflows need to preserve intersection chains and output geometry. The -xsect_factor parameter in the README reflects this: the system preallocates space for intersection results because overlay can generate large intermediate outputs.
9. Utility and support code
src/util/ provides general-purpose infrastructure used across the system: timers, queues, bitsets, array views, rational/integer helpers, atomics, and math utilities. This is shared support code rather than a separate subsystem, but it underpins both CPU orchestration and GPU-facing data preparation.
10. Input preparation and dataset conversion
The repository assumes CDB format as the runtime input format. The misc/ directory contains preprocessing tools to convert from shapefiles or WKT and to generate derived datasets:
- wkt2shp.py, shp2cdb.py
- raster- and point-generation helpers
- TIGER/shape conversion utilities
This preprocessing pipeline is outside the runtime join path but is essential to getting datasets into RayJoin’s expected chain-based polygon representation.
11. Experiment and evaluation harness
expr/ is a large experiment/plotting area containing:
- shell scripts to run different evaluations
- logs for grid/LBVH/RT comparisons
- scripts that generate figures and speedup tables
This directory is not part of the production runtime, but it shows the intended benchmark flows: compare backends, vary enlargement factors, and evaluate scalability on both real and synthetic data.
12. Build and dependency boundaries
The project is CMake-based and targets CUDA builds with external dependencies on gflags, glog, OptiX 8, and CUDA 12.3+. The bundled deps/lbvh/ library provides the LBVH implementation. The architecture therefore spans standard C++ host code plus CUDA/OptiX device code, with explicit separation between third-party acceleration code and RayJoin’s own algorithms.
13. Operational flow to diagram
A useful architecture diagram would show:
CDB polygon inputs → map/parser layer → app/workload selection → chosen backend (grid / LBVH / RT) → query kernels / traversal engine → LSI/PIP results → overlay assembly or query output.
The main architectural distinction is between the shared geometry/query logic and the three alternative acceleration backends.
Main entry points: query_config.h Query app · lsi.h LSI core · pip.h PIP core · overlay_config.h Overlay app
Components 23
Entry points
Top-level binaries and runtime launchers.
- Query exec · Main executable for LSI and PIP queries.
src/query.cc - Overlay exec · Main executable for polygon overlay workflows.
src/overlay.cc - Query runner · GPU-side query launch and dispatch boundary.
src/run_query.cu - Overlay runner · GPU-side overlay launch and dispatch boundary.
src/run_overlay.cu
App layer
Workload orchestration and backend-specific wrappers.
- Query app · Shared query orchestration and mode selection.
src/app/query_config.h - Overlay app · Shared overlay orchestration and output handling.
src/app/overlay_config.h - LSI app · Application wrapper for line-segment intersection.
src/app/lsi.h - PIP app · Application wrapper for point-in-polygon.
src/app/pip.h - Map overlay app · Application wrapper that assembles overlay chains.
src/app/map_overlay.h
Core algorithms
Shared spatial join logic and GPU kernels.
- LSI core · Backend-neutral line-segment intersection logic.
src/algo/lsi.h - PIP core · Backend-neutral point-in-polygon logic.
src/algo/pip.h - RT LSI · Ray-tracing implementation for LSI.
src/algo/rt_lsi_custom.cu - RT PIP · Ray-tracing implementation for PIP.
src/algo/rt_pip_custom.cu - Launch params · Kernel launch and GPU configuration details.
src/algo/launch_parameters.h
Backends
Alternative execution and acceleration strategies.
- Uniform grid · Grid-based spatial partitioning backend.
src/grid/uniform_grid.h - LBVH library · Bundled linear BVH acceleration library.
deps/lbvh/lbvh.cuh - RT engine · OptiX-facing ray tracing engine and SBT plumbing.
src/rt/rt_engine.cu
Geometry model
Input parsing and spatial data structures.
- Map model · Polygon parsing, graph structure, and scaling helpers.
src/map/map.h - Polygon parser · Loads and interprets polygon chain input.
src/map/polygon_parser.h
Support
Shared utilities and configuration boundaries.
Experiments
Benchmarking, plotting, and preprocessing workflows.
- Preprocess tools · Input conversion and dataset generation scripts.
misc/shp2cdb.py - Experiments · Scripts and logs for query, overlay, and scalability evaluation.
expr/run_query.sh
Connections 34
- Query exec → Query app: orchestrates · CLI binary delegates query mode handling to the app layer.
- Overlay exec → Overlay app: orchestrates · CLI binary delegates overlay workflow handling to the app layer.
- Query exec → Query runner: launches · Entry binary reaches GPU query launch path.
- Overlay exec → Overlay runner: launches · Entry binary reaches GPU overlay launch path.
- Query runner → LSI core: executes · Query runner invokes the shared LSI engine when needed.
- Query runner → PIP core: executes · Query runner invokes the shared PIP engine when needed.
- Overlay runner → LSI core: combines · Overlay workflow uses LSI as one of its constituent stages.
- Overlay runner → PIP core: combines · Overlay workflow uses PIP to classify or filter results.
- Query app → LSI app: selects · Query orchestration routes to the LSI-specific wrapper.
- Query app → PIP app: selects · Query orchestration routes to the PIP-specific wrapper.
- Overlay app → Map overlay app: selects · Overlay orchestration routes to overlay-specific handling.
- LSI app → Uniform grid: backend · LSI can run on the uniform grid backend.
- LSI app → LBVH library: backend · LSI can run on the LBVH backend.
- LSI app → RT engine: backend · LSI can run through OptiX ray tracing.
- PIP app → Uniform grid: backend · PIP can run on the uniform grid backend.
- PIP app → LBVH library: backend · PIP can run on the LBVH backend.
- PIP app → RT engine: backend · PIP can run through OptiX ray tracing.
- Map overlay app → LSI core: uses · Overlay assembly depends on intersection computation.
- Map overlay app → PIP core: uses · Overlay assembly depends on containment computation.
- LSI core → RT LSI: specializes · RT-specific LSI implementation specializes the core algorithm.
- PIP core → RT PIP: specializes · RT-specific PIP implementation specializes the core algorithm.
- RT LSI → RT engine: runs on · OptiX LSI implementation uses the RT engine boundary.
- RT PIP → RT engine: runs on · OptiX PIP implementation uses the RT engine boundary.
- LSI core → Launch params: configures · LSI uses shared GPU launch settings.
- PIP core → Launch params: configures · PIP uses shared GPU launch settings.
- Query app → Map model: consumes · Query workflows consume parsed geometry and bounding structures.
- Overlay app → Map model: consumes · Overlay workflows consume parsed geometry and graph data.
- Map model → Polygon parser: parses · Map model is built from polygon chain input.
- Polygon parser → Context: binds · Parsed input and runtime flags are tied into execution context.
- Query app → Utilities: uses · Query orchestration relies on shared utilities.
- Overlay app → Utilities: uses · Overlay orchestration relies on shared utilities.
- Preprocess tools → Map model: prepares · Preprocessing tools convert external formats into runtime geometry.
- Experiments → Query exec: benchmarks · Experiment scripts evaluate the query binary.
- Experiments → Overlay exec: benchmarks · Experiment scripts evaluate the overlay binary.