Repository navigation
Conversation
This was referenced Nov 27, 2026
kshaji3
pushed a commit
to kshaji3/gtsam
that referenced
this pull request
Nov 27, 2026
Adds BatchedBlockTridiagonalLevenbergMarquardtOptimizer and BatchedBlockTridiagonalDeviceGradients together, since they are a matched forward/backward pair used jointly in practice (one GTSAM batched solve per device in a multi-process training setup, with the optimizer producing the forward solution and the gradients class producing the backward signal for the surrounding neural-network parameters) and cannot be used independently of each other for that use case. Both build on the batched block-tridiagonal linear solver and Hessian assembler added in borglab#2954. BatchedBlockTridiagonalLevenbergMarquardtOptimizer runs Levenberg- Marquardt over B independent nonlinear factor graphs of the same block-tridiagonal shape in a single batched GPU call. 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 across the whole batch in one call instead of once per item per graph. BatchedBlockTridiagonalDeviceGradients is a batched GPU adjoint/ gradient API over the same batch of block-tridiagonal systems, tested against gtsam::Gradients on scalar CPU graphs. Multi-GPU usage: when BatchedSolverOptions.deviceId is left at its default (-1), an instance binds to whatever CUDA device is already current for the constructing thread rather than forcing a particular device. In practice this is used from a multi-process, one-GPU-per- process training setup: each process selects its own device before constructing the optimizer and gradients instances, so one batched pair runs independently per GPU. Cross-device gradient synchronization of the surrounding neural-network parameters is handled externally (e.g. PyTorch DistributedDataParallel), not by these classes. Tests: testCudaBatchedBlockTridiagonalLevenbergMarquardt.cpp compares batched results against gtsam::LevenbergMarquardtOptimizer on scalar CPU Pose2 graphs, including an ill-scaled chain graph with diagonal damping enabled (one LM step), and exercises 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. This supersedes the separately-proposed optimizer-only PR; it and this PR's prior gradients-only content are combined here so the forward and backward paths needed together for multi-GPU training ship as one reviewable, independently buildable unit, while the batched linear solver (borglab#2954) remains a separate foundational PR that both depend on. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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>
kshaji3
force-pushed
the
gpu-batched-linear-solvers
branch
from
December 2, 2026 15:23
6c6e4fb to
85ee321
Compare
kshaji3
pushed a commit
to kshaji3/gtsam
that referenced
this pull request
Dec 2, 2026
Adds BatchedBlockTridiagonalLevenbergMarquardtOptimizer and BatchedBlockTridiagonalDeviceGradients together, since they are a matched forward/backward pair used jointly in practice (one GTSAM batched solve per device in a multi-process training setup, with the optimizer producing the forward solution and the gradients class producing the backward signal for the surrounding neural-network parameters) and cannot be used independently of each other for that use case. Both build on the batched block-tridiagonal linear solver and Hessian assembler added in borglab#2954. BatchedBlockTridiagonalLevenbergMarquardtOptimizer runs Levenberg- Marquardt over B independent nonlinear factor graphs of the same block-tridiagonal shape in a single batched GPU call. 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 across the whole batch in one call instead of once per item per graph. BatchedBlockTridiagonalDeviceGradients is a batched GPU adjoint/ gradient API over the same batch of block-tridiagonal systems, tested against gtsam::Gradients on scalar CPU graphs. Multi-GPU usage: when BatchedSolverOptions.deviceId is left at its default (-1), an instance binds to whatever CUDA device is already current for the constructing thread rather than forcing a particular device. In practice this is used from a multi-process, one-GPU-per- process training setup: each process selects its own device before constructing the optimizer and gradients instances, so one batched pair runs independently per GPU. Cross-device gradient synchronization of the surrounding neural-network parameters is handled externally (e.g. PyTorch DistributedDataParallel), not by these classes. Tests: testCudaBatchedBlockTridiagonalLevenbergMarquardt.cpp compares batched results against gtsam::LevenbergMarquardtOptimizer on scalar CPU Pose2 graphs, including an ill-scaled chain graph with diagonal damping enabled (one LM step), and exercises 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. This supersedes the separately-proposed optimizer-only PR; it and this PR's prior gradients-only content are combined here so the forward and backward paths needed together for multi-GPU training ship as one reviewable, independently buildable unit, while the batched linear solver (borglab#2954) remains a separate foundational PR that both depend on. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
New classes
BatchedBlockTridiagonalCholeskySolver(gtsam/linear/cuda/internal):factorize()/solve()overDeviceArray<double>diagonal/off-diagonal blocks and RHS, reusing persistent cuSOLVER/cuBLAS handles and device buffersBatchedBlockHessianAssembler(gtsam/linear/cuda/internal): builds the block-tridiagonalA^T A/A^T bblocks for a batch of linearized systems directly on the GPU via cuBLASBatchedSolverOptions(gtsam/linear/cuda/internal): the device-selection struct shared by every batched CUDA backend, including ones built laterdeviceId-1 keeps the calling thread's current device, >= 0 pins an instance to one device).Follow up PR - #2955