MegBA: A GPU-Based Distributed Library for Large-Scale Bundle Adjustment

Jie Ren, Wenteng Liang, Ran Yan, Luo Mai, Shiwen Liu, Xiao Liu

Abstract

Large-scale Bundle Adjustment (BA) requires massive memory and computation resources which are difficult to be fulfilled by existing BA libraries. In this paper, we propose MegBA, a GPU-based distributed BA library. MegBA can provide massive aggregated memory by automatically partitioning large BA problems and assigning the solvers of sub-problems to parallel nodes. The parallel solvers adopt distributed Preconditioned Conjugate Gradient (DPCG) and distributed Schur Elimination (DSE), so that an effective solution, which can match the precision of those computed by a single node, can be efficiently computed. Experiments show that MegBA can significantly outperform state-of-the-art BA libraries: Ceres (41.45x), RootBA (64.57x), and DeepLM (6.77x) in several large-scale BA benchmarks.

Introduction

Bundle Adjustment (BA) is a fundamental component in 3D computer vision, essential for refining camera poses and 3D point coordinates in applications like autonomous driving and city-scale mapping. However, as problem sizes scale to millions of points and billions of observations, two primary bottlenecks emerge: the Memory Wall, where a single node lacks sufficient RAM for massive Hessian matrices, and the Compute Bottleneck, where traditional CPU-based libraries fail to leverage modern GPU parallelism.

MegBA addresses these challenges by providing a distributed, GPU-native framework that achieves exact solutions at scale without the accuracy trade-offs common in approximation-based distributed solvers.

System Architecture

MegBA's architecture is built around three core innovations designed for high-performance distributed optimization.

Edge-Based Partitioning

Unlike traditional methods that partition by cameras or points, MegBA employs edge-based partitioning. By distributing the observations (edges) connecting cameras and points, the library ensures balanced memory usage and workload across multiple GPUs, avoiding "hotspots" that occur when specific cameras or points have disproportionately high connectivity.

Overview of the MegBA distributed pipeline.

GPU-Native Implementation

To maximize throughput, MegBA utilizes:

  • JetVector: A custom data structure optimized for SIMD (Single-Instruction-Multiple-Data) operations, enabling efficient automatic differentiation across millions of edges.
  • Memory-Efficient Runtime: A pre-allocated memory pool that predicts future iteration requirements, minimizing the overhead of frequent CUDA driver calls.

Distributed Optimization Algorithms

To maintain the precision of a single-node solver, MegBA implements distributed versions of standard optimization algorithms using NVIDIA’s NCCL library for inter-GPU synchronization.

Distributed Schur Elimination (DSE)

Schur elimination is critical for reducing the dimensionality of the linear system in BA. MegBA's DSE allows the computation to be split across nodes while maintaining mathematical equivalence to a centralized solver through synchronized allreduce operations.

Algorithm for Distributed Schur Elimination.

Distributed Preconditioned Conjugate Gradient (DPCG)

The DPCG solver iterates across GPUs to solve the reduced camera system. By synchronizing states across GPUs, MegBA ensures that the final result is mathematically identical to what a single-node solver would produce, avoiding the approximations found in consensus-based methods like ADMM.

Experimental Results

MegBA was evaluated against state-of-the-art libraries including Ceres, RootBA, and DeepLM across standard (BAL, 1DSfM) and synthetic datasets.

  • Performance: On the Final-13682 dataset (~29M observations), MegBA achieved a 41.45x speedup over Ceres and 64.57x over RootBA.
  • Scalability: In a massive synthetic test with 80 million observations, competing solvers (DeepLM, RootBA) failed due to Out-of-Memory (OOM) errors. MegBA successfully solved the problem in 216 seconds using 8 GPUs.
  • Precision: Mean Squared Error (MSE) metrics confirm that MegBA’s distributed approach does not compromise reconstruction quality, matching the high-precision output of centralized solvers like Ceres.

Conclusion

MegBA breaks the memory wall for large-scale 3D reconstruction by combining edge-based partitioning with high-performance GPU primitives and exact distributed algorithms. With an API compatible with Ceres and g2o, it serves as a powerful, drop-in replacement for massive optimization tasks.

Code availability: https://github.com/MegviiRobot/MegBA

Summary updated

BibTeX
@inproceedings{ren2022megba,
  author = {Jie Ren and Wenteng Liang and Ran Yan and Luo Mai and Shiwen Liu and Xiao Liu},
  title = {{MegBA: A GPU-Based Distributed Library for Large-Scale Bundle Adjustment}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  url = {https://openreview.net/forum?id=oils88tAC2D},
}
Figure