Design and optimization of DBSCAN Algorithm based on CUDA

Bingchen Wang, Chenglong Zhang, Lei Song, Lianhe Zhao, Yu Dou, Zihao YuarXiv 2015

Abstract

This paper presents a highly optimized parallel implementation of the DBSCAN (Density-Based Spatial Clustering of Applications with Noise) algorithm using NVIDIA's CUDA platform. By leveraging GPU-specific techniques such as memory coalescing, shared memory utilization, and mathematical expansion of distance formulas, the proposed implementation achieves a massive 97.89x speedup over traditional serial versions for large datasets. The results demonstrate that a matrix-based approach, while memory-intensive, is highly effective for maximizing hardware utilization on modern GPUs.

Introduction

DBSCAN is a fundamental algorithm in data science, valued for its ability to identify clusters of arbitrary shapes and handle outliers effectively. However, its computational complexity—specifically the requirement to calculate distances between pairs of points—presents a significant bottleneck when processing large-scale datasets. Traditional serial implementations struggle to scale, and previous parallel attempts using MPI or MapReduce often fail to fully exploit the SIMT (Single Instruction, Multiple Threads) architecture of GPUs due to branch divergence.

This research aims to develop a "GPU-friendly" DBSCAN implementation that minimizes stalls and maximizes throughput by decomposing the algorithm into three parallelizable stages: Distance Matrix Generation, Primitive Cluster Construction, and Cluster Merging.

Methodology and Optimization Strategies

Analysis of the serial DBSCAN algorithm reveals that distance calculation is the primary bottleneck, accounting for approximately 66.27% of total execution time. To address this, the authors implemented several advanced CUDA optimization techniques:

  1. Memory Coalescing: Data storage was rearranged to ensure that adjacent threads access adjacent memory addresses, significantly reducing memory latency.
  2. Shared Memory Utilization: High-speed on-chip shared memory was used as a cache to store point coordinates, reducing the need for frequent, slow global memory fetches.
  3. Mathematical Expansion: The standard Euclidean distance formula $(x-y)^2$ was expanded into $x^2 - 2xy + y^2$. This allowed the $x^2$ and $y^2$ terms to be pre-calculated outside the main kernel loop, reducing the number of floating-point operations per iteration from 8 to 6.
  4. Loop Unrolling: Loops were manually expanded to minimize the overhead associated with branch instructions and loop counters.
Impact of CUDA optimizations on kernel execution time and speedup.

As shown in the optimization breakdown, the cumulative effect of these techniques resulted in a distance calculation kernel that is 279.47x faster than the baseline GPU implementation.

Performance Evaluation

The algorithm was evaluated using synthetic 3D datasets of varying sizes (5,061 to 60,032 points) on an NVIDIA Tesla K10 GPU. The performance was compared against a serial CPU version to determine the overall system speedup.

Comparison of CPU and GPU execution times across different dataset sizes.

The experimental results indicate that the parallel implementation scales exceptionally well with data size. While the speedup for the smallest dataset was a modest 3.77x, it increased dramatically to 97.89x for the largest dataset of 60,032 points. This trend suggests that the overhead of data transmission between the CPU and GPU becomes less significant as the computational workload grows.

Conclusion and Future Work

By favoring a regular, matrix-based approach over complex tree structures (like KD-trees), this implementation avoids the branch divergence issues that typically plague GPU-based clustering. The primary limitation of this approach is its $O(N^2)$ memory consumption; at 60,000 points, the implementation approached the 8GB memory limit of the Tesla K10 hardware. Future research will focus on addressing these memory constraints through tiling or sparse matrix techniques to enable the processing of datasets with millions of points.

Summary updated

BibTeX
@misc{wang2015design,
  author = {Bingchen Wang and Chenglong Zhang and Lei Song and Lianhe Zhao and Yu Dou and Zihao Yu},
  title = {{Design and optimization of DBSCAN Algorithm based on CUDA}},
  year = {2015},
  eprint = {1506.02226},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1506.02226},
}
Figure