Skip to content

Modified g2o with GPU support for general matrix calculations.

Notifications You must be signed in to change notification settings

sfu-rsl/gpu-block-solver

Repository files navigation

g2o with GPU Block Solver

This is a custom version of g2o which implements GPU acceleration for the block solver component. The modified block solver performs general calculations using Vulkan compute shaders and is compatible with g2o's existing OpenMP support for further performance improvement. The block solver can be used in place of the original to obtain a small speedup for bundle adjustment problems.

The performance improvement partially depends on the workload (size, parameterization, problem structure, constraints, etc.). For small visual BA problems, in which pose and landmark variables have fixed sizes, the original CPU block solver may provide better performance via Eigen's vectorization support. The GPU block solver should work better for medium to large problems with variable-sized blocks, especially when combined with the PCG linear solver.

Our modifications are intended to work as a drop-in solution for existing g2o-based projects. It is expected that the speedup will be limited since there is no GPU acceleration for constraint-specific calculations.

Cloning and Building

This project uses submodules, which can be cloned easily using the --recursive option:

git clone https://github.com/sfu-rsl/gpu-block-solver.git --recursive

The same g2o build process applies, although there are additional dependencies for the Vulkan backend.

For specific instructions on how to build for ORB-SLAM3, please see this.

Example Usage

For usage, please refer to the implementation of the bal_gpu example. The datasets are available from here.

You may run the example with the following command:

./bal_gpu -v -gpu -pcg -implicit -i 10 -lambda 1e-5 ~/bal/problem-1778-993923-pre.txt 

Note: It may be necessary to lock the CPU and GPU frequencies to observe consistent performance.

Linear Solvers

  • Eigen Sparse/Dense LLT/LDLT (CPU)
  • CUDA cuSOLVER Sparse LLT (GPU)
  • Block PCG (GPU)
    • Supports explicit and implicit evaluation modes, which have different memory and performance characteristics

In general, Eigen solvers may work better for small/local BA problems, while the PCG solver works better for larger problems. Optimal PCG parameters must be determined experimentally.

An interface to implement support for custom linear solvers is also provided.

Limitations

  • Only double-precision is supported
  • Landmark variables must have no more than four parameters
  • No GPU acceleration for constraint-specific calculations
  • Hessian structure cannot be modified once built
  • Some other functionality is unsupported
    • Saving the Hessian
    • Debug output
    • computeMarginals

Components and License

  • The block solver implementation is in the g2o/gpu directory. For this, and edits/examples, the original g2o license applies.
  • It depends on the compute-engine submodule, which is licensed under MIT. It also contains other dependencies. Please refer to their individual licenses for more information.
    • See its README for build instructions.

Referencing

Original g2o README follows below.


g2o - General Graph Optimization

Linux/Mac: CI Windows: win64 Codacy Badge

g2o is an open-source C++ framework for optimizing graph-based nonlinear error functions. g2o has been designed to be easily extensible to a wide range of problems and a new problem typically can be specified in a few lines of code. The current implementation provides solutions to several variants of SLAM and BA.

A wide range of problems in robotics as well as in computer-vision involve the minimization of a non-linear error function that can be represented as a graph. Typical instances are simultaneous localization and mapping (SLAM) or bundle adjustment (BA). The overall goal in these problems is to find the configuration of parameters or state variables that maximally explain a set of measurements affected by Gaussian noise. g2o is an open-source C++ framework for such nonlinear least squares problems. g2o has been designed to be easily extensible to a wide range of problems and a new problem typically can be specified in a few lines of code. The current implementation provides solutions to several variants of SLAM and BA. g2o offers a performance comparable to implementations of state-of-the-art approaches for the specific problems (02/2011).

Python and updated memory management

The branch pymem contains a python wrapper and switches to smart pointer instead of RAW pointers. It is currently experimental but PRs and improvements are welcome - as always.

See g2o-python for the pypi release of g2o's python bindings.

Papers Describing the Approach

Rainer Kuemmerle, Giorgio Grisetti, Hauke Strasdat, Kurt Konolige, and Wolfram Burgard g2o: A General Framework for Graph Optimization IEEE International Conference on Robotics and Automation (ICRA), 2011

Documentation

A detailed description of how the library is structured and how to use and extend it can be found in /doc/g2o.pdf The API documentation can be generated as described in doc/doxygen/readme.txt

License

g2o is licensed under the BSD License. However, some libraries are available under different license terms. See below.

The following parts are licensed under LGPL3+:

  • csparse_extension

The following parts are licensed under GPL3+:

  • g2o_viewer
  • g2o_incremental
  • slam2d_g2o (example for 2D SLAM with a QGLviewer GUI)

Please note that some features of CHOLMOD (which may be used by g2o, see libsuitesparse below) are licensed under the GPL. To avoid the GPL, you may have to re-compile CHOLMOD without including its GPL features. The CHOLMOD library distributed with, for example, Ubuntu or Debian includes the GPL features. The supernodal factorization is considered by g2o, if it is available.

Within the folder g2o/EXTERNAL we include software not written by us to guarantee easy compilation.

  • ceres: BSD (see g2o/EXTERNAL/ceres/LICENSE) Headers to perform Automatic Differentiation

  • freeglut: X Consortium (Copyright (c) 1999-2000 Pawel W. Olszta) We use a stripped down version for drawing text in OpenGL.

See the doc folder for the full text of the licenses.

g2o is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the licenses for more details.

Requirements

On Ubuntu / Debian these dependencies are resolved by installing the following packages.

  • cmake
  • libeigen3-dev

Optional requirements

On Ubuntu / Debian these dependencies are resolved by installing the following packages.

  • libspdlog-dev
  • libsuitesparse-dev
  • qtdeclarative5-dev
  • qt5-qmake
  • libqglviewer-dev-qt5

Mac OS X

If using Homebrew, then

brew install brewsci/science/g2o

will install g2o together with its required dependencies. In this case no manual compilation is necessary.

Windows

If using vcpkg, then

script\install-deps-windows.bat

will build and install the required dependencies. The location of vcpkg and required triplet are determined by the environment variables VCPKG_ROOT_DIR and VCPKG_DEFAULT_TRIPLET.

Compilation

Our primary development platform is Linux. Experimental support for Mac OS X, Android and Windows (MinGW or MSVC). We recommend a so-called out of source build which can be achieved by the following command sequence.

  • mkdir build
  • cd build
  • cmake ../
  • make

The binaries will be placed in bin and the libraries in lib which are both located in the top-level folder.

On Windows with vcpkg the following two commands will generate build scripts for Visual Studio 2017 MSVC 15 tool set (please change the Visual Studio version number in accordance with your system):

  • mkdir build
  • cd build
  • cmake -G "Visual Studio 15 2017 Win64" -DG2O_BUILD_APPS=ON -DG2O_BUILD_EXAMPLES=ON -DVCPKG_TARGET_TRIPLET="%VCPKG_DEFAULT_TRIPLET%" -DCMAKE_TOOLCHAIN_FILE="%VCPKG_ROOT_DIR%\scripts\buildsystems\vcpkg.cmake" ..

If you are compiling on Windows and you are for some reasons not using vcpkg please download Eigen3 and extract it. Within cmake-gui set the variable EIGEN3_INCLUDE_DIR to that directory.

  • mkdir build
  • cd build
  • `cmake .. -G "Visual Studio 15 2017 Win64" -DG2O_BUILD_APPS=ON -DG2O_BUILD_EXAMPLES=ON -DEIGEN3_INCLUDE_DIR="<THE_PATH_WHERE_YOU_PLACED_EIGEN3_AND_THE_EIGEN3_CMakeLists.txt>"

Cross-Compiling for Android

  • mkdir build
  • cd build
  • cmake -DCMAKE_TOOLCHAIN_FILE=../script/android.toolchain.cmake -DANDROID_NDK=<YOUR_PATH_TO_ANDROID_NDK_r10d+> -DCMAKE_BUILD_TYPE=Release -DANDROID_ABI="armeabi-v7a with NEON" -DEIGEN3_INCLUDE_DIR="<YOUR_PATH_TO_EIGEN>" -DEIGEN3_VERSION_OK=ON .. && cmake --build .

Acknowledgments

We thank the following contributors for providing patches:

  • Simon J. Julier: patches to achieve compatibility with Mac OS X and others.
  • Michael A. Eriksen for submitting patches to compile with MSVC.
  • Mark Pupilli for submitting patches to compile with MSVC.

Projects using g2o

Contact information

About

Modified g2o with GPU support for general matrix calculations.

Resources

Stars

Watchers

Forks

Packages

No packages published