Skip to content

feat(autoware_ndt_scan_matcher_common): add the NDT backend interface - #1559

Merged
mitsudome-r merged 2 commits into
feat/ndt-backend-parameterfrom
feat/ndt-backend-interface
Nov 24, 2026
Merged

mitsudome-r merged 2 commits into
feat/ndt-backend-parameterfrom
feat/ndt-backend-interface

Conversation

@xmfcx

@xmfcx xmfcx commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR replaces the PR below. GitHub closed that PR as merged when I reordered the stack.

This PR adds the header-only package autoware_ndt_scan_matcher_common with the NDT backend interface. The top PR of this stack makes autoware_ndt_scan_matcher load its NDT implementation through this interface with pluginlib. Then other packages, for example a GPU implementation in the Autoware Index, can add backends. A backend package depends only on this package, not on the node.

The interface package holds NdtBackend, NdtParams, NdtResult and an ABI guard. The node calls the interface, and backend packages implement it.

The package holds:

  • autoware::ndt_scan_matcher::NdtBackend (ndt_backend.hpp): the interface. Its comments state the contract of a backend: instances, threads, the order of calls, exceptions, copies, the regularization and the lifetime of the library.
  • NdtParams and NdtResult (ndt_types.hpp): the parameters and the result of an alignment. They are new types, not the types of ndt_omp, so later changes in ndt_omp do not change the interface. The comments of NdtResult state how a backend must compute each score and how ndt_omp builds the voxels, because the node compares the scores with thresholds that are tuned for ndt_omp. They also state how the node uses each field. For example, an empty transformation_array changes which alignments the node accepts.
  • The CMake target autoware_ndt_scan_matcher_common::autoware_ndt_scan_matcher_common. It gives the include folder, Eigen and the common component of PCL. A backend links it with ${autoware_ndt_scan_matcher_common_TARGETS}, so the README example works without ament_target_dependencies(), which ROS 2 Lyrical removes.
  • A README with three diagrams, the steps to add a backend, complete CMakeLists.txt and plugins.xml examples, a naming rule for backends, the compile options, and the rule for changing the version of the interface.

The types and the interface are in an inline namespace (v1_eigen_align_16_malloc_std on x86_64 with the options of Autoware). Its name holds the version of the interface, the static alignment of Eigen (EIGEN_MAX_STATIC_ALIGN_BYTES) and the heap allocator of Eigen. A backend that was built against another version, or with options that change the alignment or the allocator (for example AVX or the address sanitizer of GCC), has other C++ symbols. Then the node cannot load it, and the error says why. Without this, the node and the backend read the same memory with different layouts, or one side frees memory with another allocator than the side that allocated it.

How the node uses a backend

The node has two instances of the backend: the active instance, and the instance that the map update thread builds. The interface follows the three places where the node calls them. The top PR of this stack connects the node to the interface.

At startup, pluginlib makes the backend and the node calls initialize(). The map update thread fills an instance and the node swaps the instances. The scan callback calls align() on the active instance.

How a package adds a backend

The README has these steps with complete CMakeLists.txt and plugins.xml examples.

Add a backend in four steps: depend, implement, build and register. Then the node loads the backend when ndt.backend has its name.

Before and after

The top PR of this stack connects the node to this interface.

Before: the NDT scan matcher node calls ndt_omp directly, and a GPU NDT must patch the node source.

After: the node uses the NdtBackend interface and loads the ndt_omp backend or a GPU backend with pluginlib.

Related links

Parent Issue:

Discussion:

How was this PR tested?

See the Verification block at the end.

Notes for reviewers

  • Backends register with pluginlib_export_plugin_description_file(autoware_ndt_scan_matcher_common <file>.xml), because pluginlib expects the package that holds the base class.
  • The package passes all of PCL on with ament_export_dependencies(), not only its common component. A package that first finds only some components of PCL can miss the targets of the other components when it finds PCL again. I saw this with pcl_ros (QHULL::QHULL not found). The target of the package links only pcl_common, and the README says that a backend links the other components that it uses.
  • The package has no library, so it writes its INTERFACE target and ament_export_targets() by hand. The flag EXPORT_LIBRARY_TARGETS of the target export plan exports only libraries that ament_auto_add_library() adds. The README example links ${<pkg>_TARGETS} without a scope keyword, as the plan decides for consumers:
  • The package adds no SIMD options of its own. SSE options do not change the Eigen layout, and exported SSE options break nvcc. The inline namespace catches the options that do change it. The pcl_common target passes on the compile options of PCL, which are empty in the Ubuntu 22.04 and 24.04 packages.

Interface changes

C++ interface

  • Added: autoware::ndt_scan_matcher::NdtBackend, NdtParams and NdtResult in the new package autoware_ndt_scan_matcher_common.

Effects on system behavior

None. No package uses the interface yet.

AI usage

AI usage: Written with Claude Code. I set the design and the requirements. Claude Code wrote the code, the tests and this description.

Self-review: Three review rounds with a clean context read the full diff, the earlier review comments, the node code of the top PR, and this description. The review found no correctness bug. It found one risk (the README example used ament_target_dependencies(), which ROS 2 Lyrical removes) and five small notes on comments, the test and the README. All six findings are fixed in the last commit.

Verification: On Jazzy, the package builds, and `colcon test-result` reports 23 results with 0 failures. A backend package that copies the README example builds in both install modes, and pluginlib loads it. Humble ran only in CI, and Lyrical did not run.

Build and tests

Jazzy, x86_64, an incremental build in the local workspace, at the top of the stack. There, the files of this package equal this PR at 286cc98a. The current head a8ddf9b6 has the same files: GitHub rebased it on main after the rename PR merged. The dependencies came from a local workspace install.

  • colcon build --symlink-install --packages-select autoware_ndt_scan_matcher_common autoware_ndt_scan_matcher --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=--coverage: Summary: 2 packages finished [49.7s].
  • colcon test --packages-select autoware_ndt_scan_matcher_common autoware_ndt_scan_matcher --event-handlers console_cohesion-, then colcon test-result --test-result-base build/autoware_ndt_scan_matcher_common: Summary: 23 tests, 0 errors, 0 failures, 4 skipped.
  • test_ndt_backend_abi --gtest_filter='*/0': [ PASSED ] 1 test. Before the last commit, the same filter printed Expected: (refused_count) >= (3), actual: 0 vs 3.
  • Not run locally: Humble and arm64.

ABI guard

  • test_ndt_backend_abi builds the same fake backend seven times as a plugin library: with no definition of its own, with a static alignment of 0, 16, 32 and 64 bytes, and with each of the two allocators of Eigen. class_loader must create a backend only from a library with the Eigen configuration of the test. A separate test makes sure that at least 3 libraries have another configuration. The file has 8 tests.
  • With one namespace name for all configurations (a temporary local edit, then reverted): [ FAILED ] 4 tests (align_0, align_32, align_64, allocator_eigen).
  • A build with -DCMAKE_CXX_FLAGS=-mavx and a build with -DCMAKE_CXX_FLAGS=-fsanitize=address: 8 passed in each. nm -DC shows the namespaces v1_eigen_align_32_malloc_eigen and v1_eigen_align_16_malloc_eigen in these builds.

A backend package from the README

  • A package my_package with the CMakeLists.txt and plugins.xml of the README, and a small loader package that links autoware_ndt_scan_matcher_common::autoware_ndt_scan_matcher_common.
  • With --symlink-install and with a copy install, the loader printed LOADED name=my max_iterations=30 has_target=1 poses=1 points=1.
  • In the review workspace, where the loader is an executable inside my_package, the same backend built with -mavx on the backend only did not load: Could not create object of class type my_package::MyNdtBackend as no factory exists for it.
  • Not run: a Lyrical build. The README example no longer calls ament_target_dependencies(), but no Lyrical build confirms it.

With the top PR of this stack

On an earlier version of the stack, before the rebase on the diagnostics change. The README example then still used ament_target_dependencies().

  • The node loads a backend package that follows only the README. The same package built with -mavx does not load, and the node stops with this message: Failed to create the NDT backend 'stub'. [...] The backend was possibly built against another version of autoware_ndt_scan_matcher_common, or with SIMD options that change the alignment of Eigen (for example AVX), [...]
  • 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.

CI

On this head a8ddf9b6:

  • The build-and-test jobs pass on Humble, Jazzy, Jazzy agnocast, Humble above and Jazzy above. clang-tidy-diff passes on Humble and Jazzy.
  • pre-commit-optional fails on two dead links in localization/autoware_pose_initializer/README.md, which this PR does not touch.

@xmfcx xmfcx added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Nov 23, 2026
@xmfcx xmfcx self-assigned this Nov 23, 2026
@github-actions

Copy link
Copy Markdown

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

@xmfcx
xmfcx added this pull request to stack #1560 November 23, 2026 14:33
@github-actions

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feat/ndt-backend-parameter@1f5c729). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...e/autoware/ndt_scan_matcher_common/ndt_backend.hpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##             feat/ndt-backend-parameter    #1559   +/-   ##
=============================================================
  Coverage                              ?   72.59%           
=============================================================
  Files                                 ?      500           
  Lines                                 ?    27778           
  Branches                              ?    13128           
=============================================================
  Hits                                  ?    20165           
  Misses                                ?     7531           
  Partials                              ?       82           
Flag Coverage Δ *Carryforward flag
daily-humble 82.29% <ø> (?) Carriedforward from 9d04c61
daily-jazzy 82.37% <ø> (?) Carriedforward from 9d04c61
differential-humble 0.00% <0.00%> (?)
differential-jazzy 0.00% <0.00%> (?)
total 50.35% <ø> (?) Carriedforward from 9d04c61
total-humble 82.30% <ø> (?) Carriedforward from 9d04c61
total-humble-agnocast 70.81% <ø> (?) Carriedforward from 9d04c61
total-jazzy 82.36% <ø> (?) Carriedforward from 9d04c61
total-jazzy-agnocast 70.71% <ø> (?) Carriedforward from 9d04c61

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xmfcx
xmfcx removed this pull request from stack #1560 November 23, 2026 14:42
@xmfcx
xmfcx force-pushed the feat/ndt-backend-interface branch from a18ea3d to bfe2a6d Compare November 23, 2026 14:43
@xmfcx
xmfcx requested a review from a team as a code owner November 23, 2026 14:43
@xmfcx
xmfcx changed the base branch from main to feat/ndt-backend-parameter November 23, 2026 14:43
@xmfcx
xmfcx added this pull request to stack #1561 November 23, 2026 14:44
@xmfcx
xmfcx force-pushed the feat/ndt-backend-interface branch from bfe2a6d to 235c10c Compare November 23, 2026 15:28
Add the header-only package autoware_ndt_scan_matcher_common with the interface NdtBackend and its types NdtParams and NdtResult. The next change makes autoware_ndt_scan_matcher load its NDT implementation through this interface with pluginlib, and other packages can then add implementations. A backend package depends only on this package.

The comments state the contract of a backend: how to compute each score and field of NdtResult, how ndt_omp builds the voxels, instances, threads, the order of calls, exceptions, copies, the regularization and the lifetime of the library. The README shows a complete backend package.

The interface is in an inline namespace whose name holds its version, the static alignment of Eigen and the heap allocator of Eigen. A backend that was built against another version, or with options that change the alignment or the allocator (for example AVX), has other symbols, and the node cannot create it. A test loads fake backends with other configurations and expects this failure.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>
…review notes

Export the INTERFACE target autoware_ndt_scan_matcher_common::autoware_ndt_scan_matcher_common, and use target_link_libraries() in the README example. ROS 2 Lyrical removes ament_target_dependencies().

State in the comments that the node also calls clone() on the instance of the map update thread, and which yaw the regularization uses. State in the README that the node and the backend must use the same PCL.

Count the libraries with another Eigen configuration in their own test, so that a gtest filter does not make the test fail.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>
/// The backend can keep the cloud. The node takes the ids from the map loader and does not
/// examine them. Normally, each map_id is unique among the added clouds and remove_target() gets
/// only ids that were added. remove_target() must ignore an id that was not added.
virtual void add_target(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could rename this to add_map instead of add_target to make it more obvious, but that can come after all the migration to pluginlib is done.

@mitsudome-r
mitsudome-r merged commit 202b3ae into main Nov 24, 2026
48 of 49 checks passed
@mitsudome-r
mitsudome-r deleted the feat/ndt-backend-interface branch November 24, 2026 05:42
xmfcx added a commit to xmfcx/ndt_cuda that referenced this pull request Nov 24, 2026
The interface merged in autowarefoundation/autoware_core#1559, but no release of Autoware Core has it yet.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>
xmfcx added a commit to open-localization/ndt_cuda that referenced this pull request Nov 24, 2026
* feat: add the package ndt_cuda_autoware_backend

The package is the NDT backend ndt_cuda for autoware_ndt_scan_matcher. It wraps MultiGridNormalDistributionsTransformCUDA behind the NdtBackend interface of autoware_ndt_scan_matcher_common. Autoware loads it with pluginlib when the parameter ndt.backend is ndt_cuda, so no file of Autoware changes.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* refactor(ndt_cuda_autoware_backend): use the new name ndt_omp of the CPU backend in the tests

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* style(pre-commit): autofix

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* fix(integrations): stop apply.sh on Autoware Core with the NDT backend interface

On such a version, the package ndt_cuda_autoware_backend loads ndt_cuda as a plugin, so the patch of the node source is not necessary.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* docs: say that only autoware_core main has the NDT backend interface

The interface merged in autowarefoundation/autoware_core#1559, but no release of Autoware Core has it yet.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* ci: run the build jobs for changes to ndt_cuda_autoware_backend

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* fix(ndt_cuda): give a copy its own point indices

pcl::PCLBase copies the pointer to the point indices, and each align() resizes them. So a copy and its original that aligned in two threads raced on one vector, and the process could crash. The copy constructor and the assignment now copy the indices.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* fix(ndt_cuda_autoware_backend): give the result of ndt_omp when the map has no voxels

Without a usable map, align() now returns the guess, the scores 0 and arrays of one value, as the backend ndt_omp does. Before, the arrays were empty or too short, and the node wrote a warning to the diagnostics for each scan.

The tests now also:
- align the original and its clone at the same time
- compare the score functions after align(), as the node uses them
- use a regularization pose away from the true pose
- fail, not skip, if initialize() fails on a computer with a CUDA device

The package declares its direct dependencies eigen and libpcl-all-dev.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* docs: run rosdep only for the library, and name all packages in the Eigen note

rosdep over the whole repository also reads the backend package, and it fails without Autoware. The note about the alignment of Eigen now names ndt_cuda too, because a mismatch there is not found at load time.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* fix(ndt_cuda_autoware_backend): do not keep the source cloud after align()

The interface does not let a backend keep the source after align() returns, but pcl::Registration keeps it until the next align(), and clone() copied it. The backend now drops it after each align().

The tests now also:
- update a clone of the active instance in another thread, as the incremental map update of the node does
- align the original and its clone 500 times each, not 100
- make sure that a change of the original does not change a clone
- align without voxels only while has_target() is true, as the node does

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* docs(integrations): hide the backend package in a workspace of an Autoware release

Without the NDT backend interface, the package ndt_cuda_autoware_backend does not build, and rosdep cannot resolve autoware_ndt_scan_matcher_common. A COLCON_IGNORE file hides it from colcon and rosdep.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

* test(ndt_cuda_autoware_backend): make sure that align() does not keep the source

Also use the PCL dependency tags of autoware_ndt_scan_matcher (libpcl-all, and libpcl-all-dev only to build), and say that ndt.num_threads has no effect in this backend, also for the CPU voxel build.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>

---------

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants