Repository navigation
Conversation
Contributor
Author
|
This PR is GPU batching for optimizers only. |
Adds a persistent cuSOLVER/cuBLAS backend that factorizes and solves B independent block-tridiagonal SPD linear systems in a single batched GPU call (block Thomas algorithm), plus the Hessian assembler that builds those block-tridiagonal normal equations from a batch of Jacobians on the device. This targets graphs whose factors only couple one or two adjacent variable blocks -- chain/window-graph structures such as DFG-TAMP's build_window_graph -- reducing factorize cost to O(numBlocks * blockDim^3) instead of forming and factorizing a dense n x n Hessian per item. This is scoped as a standalone linear-algebra layer, analogous to the existing LinearSolverSession split of system representation from backend selection and factorize/solve. It does not itself expose an optimizer or a differentiation API; those are separate, independent consumers of this solver (to follow as separate PRs) and should not need to re-implement block-tridiagonal factorization or Hessian assembly themselves. New classes: - BatchedBlockTridiagonalCholeskySolver (gtsam/linear/cuda/internal): factorize()/solve() over DeviceArray<double> diagonal/off-diagonal blocks and RHS, reusing persistent cuSOLVER/cuBLAS handles and device buffers across calls instead of allocating per step. - BatchedBlockHessianAssembler (gtsam/linear/cuda/internal): builds the block-tridiagonal A^T A / A^T b blocks for a batch of linearized systems directly on the GPU via cuBLAS, avoiding a host round-trip. - BatchedSolverOptions (gtsam/linear/cuda/internal): the device- selection struct shared by every batched CUDA backend built on top of this solver (deviceId -1 keeps the calling thread's current device, >= 0 pins an instance to one device). Tests: testCudaBatchedBlockHessianAssembler.cpp and testCudaBatchedBlockTridiagonalCholeskySolver.cpp validate assembly and factorize/solve against an Eigen ldlt() reference on the equivalent dense system, including rejection of a non-positive-definite block. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds BatchedBlockTridiagonalLevenbergMarquardtOptimizer, which runs Levenberg-Marquardt over B independent nonlinear factor graphs of the same block-tridiagonal shape in a single batched GPU call, built on the batched block-tridiagonal linear solver and Hessian assembler added in the prior PR. This targets GTSAM's existing data-parallel-training use case -- many small, independent, same-shaped graphs (e.g. one per timestep/window) -- where per-item CPU or single-graph-GPU optimization is dominated by kernel-launch/dispatch overhead rather than compute. Per-graph lambda, acceptance, and convergence state are tracked independently per item (BatchedBlockTridiagonalLevenbergMarquardtItemResult), and the optimizer reuses the same LM damping/acceptance policy as the existing single-graph implementation (gtsam::internal::LevenbergMarquardtPolicy) rather than reimplementing it, so behavior such as diagonal damping stays consistent with gtsam::LevenbergMarquardtOptimizer. optimize() runs to convergence per gtsam::LevenbergMarquardtParams; polish(n) takes n further accepted-if-improving steps per item afterward. BatchedFactorGroupHook lets a caller batch an expensive, cross-item factor evaluation (e.g. a neural-network energy function evaluated via vmap/jacrev) across the whole batch in one call instead of once per item per graph, which is the dominant cost for DFG-TAMP's energy-based factors; it has no effect on factors that don't register a hook. Tests (testCudaBatchedBlockTridiagonalLevenbergMarquardt.cpp) compare batched results against gtsam::LevenbergMarquardtOptimizer on scalar CPU Pose2 graphs, including an ill-scaled chain graph with diagonal damping enabled (one LM step), and exercise the factor-group hook path. A timing harness (timing/batched_lm) reports linearization, assembly, transfer, factorize, solve, and total time separately against a scalar CPU baseline, measured on DFG-TAMP's production chain-graph shape. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
kshaji3
force-pushed
the
gpu-batched-lm-optimizer
branch
from
December 2, 2026 15:23
baf9869 to
7fcabb7
Compare
kshaji3
marked this pull request as ready for review
December 2, 2026 15:36
Contributor
Author
|
Updated PR description. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BatchedBlockTridiagonalLevenbergMarquardtOptimizer, which runs Levenberg-Marquardt over a set of independent nonlinear factor graphs in a single batched GPU call.BatchedFactorGroupHooklets a caller batch an expensive, cross-item factor evaluation across a whole batch in one call instead of once per item per graph, which further streamlines operations.Multi-GPU usage
BatchedSolverOptions.deviceIdis left at its default (-1), an instance binds to whatever CUDA device is already current for the constructing thread. However, you can modify this externally by using PyTorch 'DistributedDataParallel`, so it can use different GPUs for each thread.This PR builds on #2954