Legacy ICP (`registration_icp`) is not repeatable with more than one thread; `tbb::parallel_deterministic_reduce` fixes it at no measurable cost
Nessuno ha ancora preso questa issue.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Checklist
- I have searched for similar issues.
- For Python issues, I have tested with the latest development wheel.
- I have checked the release documentation and the latest documentation (for
mainbranch).
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di isl-org/Open3D
-
Add explicit list of supported format in io documentationForse già presa @SKSavale l’ha presa 60 giorni fa. Apertafeature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
feature request
Difficoltà 1/5 1-3 ore Idoneità per principianti 76/100
-
Getting Started page gives incorrect link to development wheelsForse già presa @SatvikMishra08 l’ha presa 59 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Window(title, width, height, flags) ignores the flags argumentForse già presa @Wahaj18 l’ha presa 56 giorni fa. Apertabug
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
-
compute_fpfh_feature stub incorrectly requires the optional indices argumentForse già presa @huxiaoyi-ovo l’ha presa 60 giorni fa. Apertabug
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
Tutte le issue di isl-org/Open3D
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
jaff-chemistry/jaff#231 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
ColumnDecimal::Append(Int128) stores a value outside the Decimal(P, S) range with no error: cut to 32/64 bits, or with too many digitsForse già presa @RUSHIT305 l’ha presa oggi. Apertabug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ClickHouse/clickhouse-cpp#645 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
documentation enhancement help wanted P0
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Awesome-Embedded-Learning-Studio/Tutorial_AwesomeModernCPP#359 ·
I maintainer di solito rispondono entro 1 giorno
-
DXF import: INSERT ignores the BLOCK base pointForse già presa @Kevinzhou03 l’ha presa oggi. ApertaType: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
openscad/openscad#7360 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno