Legacy ICP (`registration_icp`) is not repeatable with more than one thread; `tbb::parallel_deterministic_reduce` fixes it at no measurable cost

Aperta
#7,644 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

bug
Checklist
Describe the issue

open3d.pipelines.registration.registration_icp` returns different transformations for repeated calls on
identical input when more than one thread is used. The differences start in the last bits, but ICP iterates,
so they can grow: in a pose-estimation pipeline that selects among several ICP-refined candidates we saw
final poses differ by millimeters between runs.

ICP has no random sampling and no early cutoff, so the only source is the order in which the partial sums of
the parallel reductions are merged. With tbb::parallel_reduce (auto partitioner) the split and join order
depends on scheduling; floating-point addition is not associative, so the sums differ. The same happens in
0.19.0 with OpenMP (omp for nowait + omp critical in Registration.cpp, ComputeJTJandJTr in
Eigen.cpp).

On main the affected reductions are:

cpp/open3d/pipelines/registration/Registration.cpp:87 (fitness / RMSE sums in
GetRegistrationResultAndCorrespondences)

cpp/open3d/utility/Eigen.cpp:209 and :274 (ComputeJTJandJTr)

cpp/open3d/pipelines/registration/Registration.cpp:476 (GetInformationMatrixFromPointClouds; same
pattern, not tested by us)

RANSAC already uses tbb::parallel_deterministic_reduce (Registration.cpp:376, PR #7540). Using it at the
sites above as well makes ICP bit-repeatable, and also independent of the thread count.

Related: #6225 (asks how to run RANSAC + ICP deterministically), #7475 (RANSAC). In #7475 it was noted that
full determinism needs num_threads=1; for ICP that is not necessary, see below.

Steps to reproduce the bug
import sys, time, numpy as np, open3d as o3d

if len(sys.argv) > 1:
    o3d.utility.set_max_threads(int(sys.argv[1]))
reg = o3d.pipelines.registration
rng = np.random.default_rng(0)
p = rng.random((20000, 3)) * [60, 30, 10]
a = o3d.geometry.PointCloud(o3d.utility.Vector3dVector(p))
a.estimate_normals()
b = o3d.geometry.PointCloud(
    o3d.utility.Vector3dVector(p[::8] + 0.05 * rng.standard_normal((2500, 3))))
T = np.eye(4)
T[:3, 3] = [0.3, -0.2, 0.1]


def run():
    return reg.registration_icp(
        b, a, 2.0, T, reg.TransformationEstimationPointToPlane(),
        reg.ICPConvergenceCriteria(max_iteration=30))


run()
t0 = time.perf_counter()
rs = [np.asarray(run().transformation) for _ in range(10)]
dt = (time.perf_counter() - t0) / 10
print(f"open3d {o3d.__version__}: "
      f"distinct results {len({r.tobytes() for r in rs})}/10, "
      f"max |diff| {max(np.abs(r - rs[0]).max() for r in rs):.2e}, "
      f"{1000 * dt:.1f} ms/call")
Error message

No error; the results differ. Ten identical calls, pip wheels:

Version Threads Distinct results Max abs. difference Time per call
0.19.0 default 10 of 10 about 1e-16 3.5 ms
0.19.0 OMP_NUM_THREADS=1 1 of 10 0 5.9 ms
0.20.0 default 10 of 10 about 1e-16 3.7 ms
0.20.0 set_max_threads(1) 1 of 10 0 5.8 ms
Expected behavior

Identical input gives a bit-identical result, for any number of threads.

Open3D, Python and System information
- Operating system: Ubuntu 22.04 (wheel), Ubuntu 24.04 (source build)
- Python version: 3.11 (wheel), 3.12 (source build)
- Open3D version: 0.19.0 and 0.20.0
- System architecture: x86_64
- Is this a remote workstation?: no
- How did you install Open3D?: pip (0.19.0, 0.20.0) and build from source (0.20.0 + patch)
Additional information

Proposed fix and measurements

Replace tbb::parallel_reduce by tbb::parallel_deterministic_reduce at the three ICP sites
(Registration.cpp:87, Eigen.cpp:209, Eigen.cpp:274). Built from v0.20.0 (b6c5e19) with only this change:

  • repeated calls: one distinct result in every round, for every cloud size tried
  • 1, 2, 4 and 8 threads: identical result
  • median time per ICP call, stock / patched, 8 threads, three cloud sizes:
    1.13 / 1.13 ms, 6.79 / 6.78 ms, 32.8 / 32.7 ms
    (single-threaded, the only repeatable setting today: 4.0 ms, 26-27 ms, 146-148 ms)

Not checked: machines with many more cores, much larger clouds, and the Tensor pipeline.

Lingua principale
C++
Stelle
14.3k
Fork
2.7k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di isl-org/Open3D

Tutte le issue di isl-org/Open3D

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.