BCHOL
A GPU-accelerated LQR solver using recursively applied Schur complements
Install / Use
/learn @alexanderdu15/BCHOLREADME
BCHOL
A GPU-accelerated implementation of the sparse linear system solver described in rsLQR. Designed for optimal control, BCHOL exploits the structure of the LQR problem with recursive application of Schur complements, achieving a time complexity of $O(log(N))$.
src/solver.cu: CUDA kernels and C++ solver APIsrc/bchol.hpp: solver interface (used by pybind11)src/bchol_core.cuh: hierarchical Cholesky factorization device functionssrc/math.cuh: math device functionssrc/debug.cuh: debug utilsconfigs/robots.yaml: robotics-sized problem presetspython/bindings.cpp: pybind11 extensionspython/sweep.py: benchmarking across problem sizes and horizonspython/linsys.py: KKT linear systemexamples/solve_linsys.cpp: minimal C++ exampleexamples/bchol.ipynb: Python demo notebook
For further documentation please refer to Yana Botvinnik's notes and Python implementation.
Setup
BCHOL works with:
- CUDA 12.6
- C++17
- gcc 11.4.0
- CMake 3.22
- Python 3.10.12
uv sync
cmake -S . -B build \
-DBCHOL_N=8 \ # horizon
-DBCHOL_NX=12 \ # state size
-DBCHOL_NU=4 \ # control size
-DBCHOL_CUDA_ARCH=89 \
-DCMAKE_BUILD_TYPE=Release
CMake options
BCHOL_N,BCHOL_NX,BCHOL_NU: compile-time problem dimensionsBCHOL_CUDA_ARCH: CUDA compute capabilityBCHOL_USE_FAST_MATH:ONby defaultBCHOL_MAXRREG: optional register cap for CUDABCHOL_BUILD_PYBIND,BCHOL_BUILD_EXAMPLES,BCHOL_BUILD_TESTSBCHOL_PYBIND_MODULE_NAME: module name for pybind11 target (default:bchol_ext)BCHOL_PYBIND_OUTPUT_DIR: output dir for pybind11 module (default:python/ext)
Build (bindings + example)
cmake --build build -j
./build/solve_linsys # C++ example
Python bindings
- Specify problem size and horizon in
configs/robots.yaml - Modules are emitted to
python/ext/asbchol_ext_N*_nx*_nu*.so - Use
./build_all.shorpython/sweep.pyto build multiple configs
./build_all.sh
# or
uv run python/sweep.py --config-yaml configs/robots.yaml
Import and instantiate:
from linsys import make_solver
solver = make_solver("bchol_ext_N32_nx12_nu4")
The solver class BCHOL exposes:
- Properties:
nhorizon,nstates,ninputsq_r_dense_size,q_r_rhs_size,a_b_size,d_size,soln_size
- Methods:
solve(Q_R, q_r, A_B, d) -> (sol, solve_ms)- allocates outputsolve_into(Q_R, q_r, A_B, d, out) -> solve_ms- reuses output buffer
solve_into() is preferred for repeated solves since it avoids output allocation.
