You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose that autoware_ndt_scan_matcher does its NDT computations through a backend that it loads with pluginlib. The first step adds the interface and puts the current ndt_omp code behind it, as the only backend. The behavior of the node does not change. After that, other NDT implementations, for example on the GPU, can live in their own repositories outside Autoware Core.
This discussion is only about the first step: the interface in Core, with ndt_omp as its only backend.
Why
GPU implementations of NDT are much faster than ndt_omp. I compared three of them inside Autoware's own localization loop, on Autoware's sample data, and published the setup and all results:
On the tiled sample map (NVIDIA GeForce RTX 3090, AMD Ryzen 9 5900X), ndt_cuda gives these results:
Measure
Autoware NDT (ndt_omp)
ndt_cuda
Scan to pose, median / p99
5.0 / 9.0 ms
0.75 / 1.2 ms
CPU at 10 Hz
17.6% of a core
3.3% of a core
Initial pose search
4.1 s
0.51 s
Poses against Autoware NDT, median
0.8 mm
Today, the only way to use such an implementation is to patch the source of the node. ndt_cuda, for example, ships a script that replaces the ndt_omp headers in autoware_ndt_scan_matcher. So every user must patch and rebuild Autoware Core, and the patch breaks when the node changes.
With a backend interface, a GPU backend becomes a normal package that registers a plugin. The node, its topics, its parameters, its launch files, the map update module and the covariance estimation stay the same. A backend package is a runtime package, so it can live in the Autoware Index instead of in Core.
Today, the node creates and copies the ndt_omp class directly. Another NDT implementation must patch the source of the node and rebuild Autoware Core.
After the change, the node uses the interface NdtBackend from a small header-only package. It loads one backend at startup, by the name in the parameter ndt.backend. The ndt_omp backend wraps ndt_omp in the node package. The algorithm of ndt_omp does not change. A GPU backend in another package implements the same interface.
The first step
A new interface autoware::ndt_scan_matcher::NdtBackend. It covers the 15 methods and the copies of the NDT object that the node, the map update module and the covariance estimation use today.
A backend ndt_omp: a thin wrapper of pclomp::MultiGridNormalDistributionsTransform. Its algorithm does not change. A separate PR renames its public methods to snake_case.
A new parameter ndt.backend. The parameter files set it to ndt_omp.
A new header-only package autoware_ndt_scan_matcher_common with the interface and its own types.
ndt_omp and the ndt_omp backend stay in autoware_ndt_scan_matcher.
The node loads the backend at startup. If it cannot load it, it stops with the names of the available backends.
The interface also states the rules that every backend must obey:
add_target(), remove_target() and commit_target() do all the map work, in the thread of the map update module. align() never does deferred map work.
clone() makes an independent instance. It can share immutable data with the original, for example a map that is already on the GPU.
One thread at a time uses one instance. Two instances (the active one and the one that the map update module builds) run at the same time.
initialize() throws if the backend cannot run on this computer, for example without a GPU.
A backend uses the same Eigen alignment and the same Eigen heap allocator as the node, because Eigen types pass between them. The node does not load a backend that differs.
The node never unloads a backend library, so the instances that clone() makes stay valid.
NdtResult must fill each field as its comments say, because the node uses each field to accept or reject an alignment.
Requirements of the first step
The first step must not change the behavior of Autoware. I set five requirements and measured each one. The setup is the benchmark above, with main and the change built as two overlay workspaces.
Requirement
Result
Same behavior
Open loop (the same initial guess for every scan), 3 runs: poses, iteration counts, TP and NVTL bit-identical to main for every scan that both sides recorded (283 or 284 of 284 in each run). colcon test-result of the two packages shows 166 results, 0 failures and 48 skipped cppcheck results. All 50 characterization tests pass.
No runtime cost
Open loop, 4 runs of each, taken in turns: median time per scan 3.60 to 3.76 ms against 3.58 to 3.88 ms. On the first version of the change, which had the same runtime path: latency median / p99 at 1x 3.97 / 7.25 ms against 4.04 / 7.30 ms, CPU at 10 Hz 16.2% against 16.1%, initial pose search 3.98 s against 3.98 s, memory 53 MiB against 54 MiB.
Small build cost
ndt_omp and the ndt_omp backend stay in the node package, and the backend library compiles in parallel with the node library. Clean build in Release, no ccache, median of 3 runs taken in turns: 57.4 s against 72.5 s wall time, and 116.8 s against 103.1 s CPU time. An earlier layout with ndt_omp in its own package built the packages one after the other and took 13% longer.
A second backend fits
A prototype backend for ndt_cuda (the package ndt_cuda_autoware_backend, a wrapper of about 180 lines) implements the interface without a change to the interface or to the node. In open loop on the sample rosbag with a tiled map, the node with this backend takes a median of 0.40 ms per scan, against 3.75 ms with ndt_omp. The largest position difference to ndt_omp is 1.2 cm.
Configuration
ndt.backend has no default value in the code, as the parameter guideline requires. A separate PR adds it to the parameter file of autoware_core first. The sync-params workflow then copies it to autoware_launch, before the node requires it. A private copy of the parameter file needs this one line.
A GPU backend. It comes as a separate package after the interface is in Core.
Automatic selection of a backend, for example "use the GPU if there is one, else the CPU".
A batch align() for the initial pose search and the multi-NDT covariance, where a GPU can align many poses at the same time.
Design decisions
Mechanism: pluginlib. Autoware Core already loads plugins with pluginlib in autoware_motion_velocity_planner and autoware_behavior_velocity_planner, and Universe modules register against them. No Core package depends on CUDA, so a selection at compile time either puts CUDA code paths into Core or needs a patched build of the node for each backend. The measured runtime cost of pluginlib is zero within the run-to-run noise.
Interface: a header-only package in Core, autoware_ndt_scan_matcher_common. The velocity planners keep their plugin interfaces in *_common packages too. A backend in the Autoware Index depends on this small package only, not on ndt_omp, the node or its ROS dependencies. ndt_omp and the ndt_omp backend stay in the node package, because earlier decisions rejected an autoware_-prefixed ndt_omp package and third parties include the ndt_omp headers. This also keeps the build fast. The interface has its own types and an ABI guard: a backend built with another interface version or another Eigen alignment (for example AVX) does not load.
Default value: none in the code. The parameter guideline requires declare_parameter() without a default value. The parameter goes into the parameter file of autoware_core first. Then the sync-params workflow copies it to autoware_launch, and only after that does the node require it.
Implementation
The implementation is a stack of autoware_core PRs. The sync-params PR of autoware_launch then copies the new parameter. This issue tracks them:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
I propose that
autoware_ndt_scan_matcherdoes its NDT computations through a backend that it loads with pluginlib. The first step adds the interface and puts the current ndt_omp code behind it, as the only backend. The behavior of the node does not change. After that, other NDT implementations, for example on the GPU, can live in their own repositories outside Autoware Core.This discussion is only about the first step: the interface in Core, with ndt_omp as its only backend.
Why
GPU implementations of NDT are much faster than ndt_omp. I compared three of them inside Autoware's own localization loop, on Autoware's sample data, and published the setup and all results:
On the tiled sample map (NVIDIA GeForce RTX 3090, AMD Ryzen 9 5900X), ndt_cuda gives these results:
Today, the only way to use such an implementation is to patch the source of the node. ndt_cuda, for example, ships a script that replaces the ndt_omp headers in
autoware_ndt_scan_matcher. So every user must patch and rebuild Autoware Core, and the patch breaks when the node changes.With a backend interface, a GPU backend becomes a normal package that registers a plugin. The node, its topics, its parameters, its launch files, the map update module and the covariance estimation stay the same. A backend package is a runtime package, so it can live in the Autoware Index instead of in Core.
Before and after
Today, the node creates and copies the ndt_omp class directly. Another NDT implementation must patch the source of the node and rebuild Autoware Core.
After the change, the node uses the interface
NdtBackendfrom a small header-only package. It loads one backend at startup, by the name in the parameterndt.backend. Thendt_ompbackend wraps ndt_omp in the node package. The algorithm of ndt_omp does not change. A GPU backend in another package implements the same interface.The first step
autoware::ndt_scan_matcher::NdtBackend. It covers the 15 methods and the copies of the NDT object that the node, the map update module and the covariance estimation use today.ndt_omp: a thin wrapper ofpclomp::MultiGridNormalDistributionsTransform. Its algorithm does not change. A separate PR renames its public methods to snake_case.ndt.backend. The parameter files set it tondt_omp.autoware_ndt_scan_matcher_commonwith the interface and its own types.ndt_ompbackend stay inautoware_ndt_scan_matcher.The interface also states the rules that every backend must obey:
add_target(),remove_target()andcommit_target()do all the map work, in the thread of the map update module.align()never does deferred map work.clone()makes an independent instance. It can share immutable data with the original, for example a map that is already on the GPU.initialize()throws if the backend cannot run on this computer, for example without a GPU.Eigenalignment and the sameEigenheap allocator as the node, becauseEigentypes pass between them. The node does not load a backend that differs.clone()makes stay valid.NdtResultmust fill each field as its comments say, because the node uses each field to accept or reject an alignment.Requirements of the first step
The first step must not change the behavior of Autoware. I set five requirements and measured each one. The setup is the benchmark above, with
mainand the change built as two overlay workspaces.mainfor every scan that both sides recorded (283 or 284 of 284 in each run).colcon test-resultof the two packages shows 166 results, 0 failures and 48 skipped cppcheck results. All 50 characterization tests pass.ndt_ompbackend stay in the node package, and the backend library compiles in parallel with the node library. Clean build in Release, no ccache, median of 3 runs taken in turns: 57.4 s against 72.5 s wall time, and 116.8 s against 103.1 s CPU time. An earlier layout with ndt_omp in its own package built the packages one after the other and took 13% longer.ndt_cuda_autoware_backend, a wrapper of about 180 lines) implements the interface without a change to the interface or to the node. In open loop on the sample rosbag with a tiled map, the node with this backend takes a median of 0.40 ms per scan, against 3.75 ms withndt_omp. The largest position difference tondt_ompis 1.2 cm.ndt.backendhas no default value in the code, as the parameter guideline requires. A separate PR adds it to the parameter file of autoware_core first. The sync-params workflow then copies it toautoware_launch, before the node requires it. A private copy of the parameter file needs this one line.The PR with the prototype backend for ndt_cuda:
Not in the first step
align()for the initial pose search and the multi-NDT covariance, where a GPU can align many poses at the same time.Design decisions
autoware_motion_velocity_plannerandautoware_behavior_velocity_planner, and Universe modules register against them. No Core package depends on CUDA, so a selection at compile time either puts CUDA code paths into Core or needs a patched build of the node for each backend. The measured runtime cost of pluginlib is zero within the run-to-run noise.autoware_ndt_scan_matcher_common. The velocity planners keep their plugin interfaces in*_commonpackages too. A backend in the Autoware Index depends on this small package only, not on ndt_omp, the node or its ROS dependencies. ndt_omp and thendt_ompbackend stay in the node package, because earlier decisions rejected anautoware_-prefixed ndt_omp package and third parties include the ndt_omp headers. This also keeps the build fast. The interface has its own types and an ABI guard: a backend built with another interface version or another Eigen alignment (for example AVX) does not load.declare_parameter()without a default value. The parameter goes into the parameter file of autoware_core first. Then the sync-params workflow copies it to autoware_launch, and only after that does the node require it.Implementation
The implementation is a stack of autoware_core PRs. The sync-params PR of autoware_launch then copies the new parameter. This issue tracks them:
AI usage
I wrote this with Claude Code (Claude Opus 5.5), from my direction. The agent also ran the benchmark and the measurements in it.
All reactions