[BUG] GridTransformer threaded transformGrid is not deterministic
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- computer-graphics, data
Direzione di ricerca
Start in openvdb/openvdb/tools/GridTransformer.h: transformBBox (called per input leaf from the RangeProcessor, around line 815), the affine branch that steps the sample position incrementally (around lines 1014-1023), and join(), which calls Tree::merge (around line 854). Build the reproducer in the issue body and confirm threaded runs differ from the non-threaded reference. Done means repeated threaded runs produce identical values and signs, and the existing GridTransformer tests still pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment
Operating System: Ubuntu 24.04
Version / Commit SHA: OpenVDB 13.2 and 14.0
Describe the bug
Running tools::GridTransformer::transformGrid() twice on the same input with the same affine
transform gives different voxel values when threading is on (the default).
With a 180° rotation of a level-set box, voxels whose exact value is 0 become ±1.8e-14, so
some voxel change sign (100–400 differing voxels per run).
Topologically the results are the same.
If I deactivate the threading on the grid transformer with setThreaded(false) then
I do not get any issue.
To Reproduce
See the reproducer at the bottom, you can compile it against current OpenVDB 14.0.0
you will get something along that in the result (note since it is a scheduling issue, you will
definetly get different numbers than me)
FAILED: threaded=1 iteration 0: 122 differing values, 52 sign flips
FAILED: threaded=1 iteration 1: 324 differing values, 132 sign flips
FAILED: threaded=1 iteration 2: 226 differing values, 124 sign flips
FAILED: threaded=1 iteration 3: 154 differing values, 68 sign flips
FAILED: threaded=1 iteration 4: 130 differing values, 68 sign flips
FAILED: threaded=1 iteration 5: 108 differing values, 60 sign flips
FAILED: threaded=1 iteration 6: 302 differing values, 152 sign flips
FAILED: threaded=1 iteration 7: 202 differing values, 68 sign flips
FAILED: threaded=1 iteration 8: 322 differing values, 172 sign flips
FAILED: threaded=1 iteration 9: 234 differing values, 72 sign flips
FAILED (10 runs)
The reproducer is just calling grid transform with a rotation of 180 and comparing it to the next 10 same transforms.
Bug root cause
This bug happens because of two things:
-
Resulting value does depend on the input leaf.
transformBBoxis called by theRangeProcessorfor every input leaf (here).- The output regions of neighbouring leaves overlap (
Sampler::radius()padding), so a shared output voxel is computed by several leaves. - The affine branch steps the sample position incrementally from the leaf-specific
outMin(inXYZ += deltaZ, here), so each leaf rounds differently. sin(π) ≈ 1.2e-16 != 0, so the deltas are not exactly integer and the sample positions differ in the last bits.
-
Which value will be written depends on TBB scheduling.
- Each
parallel_reducebody writes into its own tree. join()callsTree::merge()(here), which keeps the left tree's value on overlapping active voxels.- Split/join points vary between runs. When disabling threading we get deterministic results because the last leaf always wins.
- Each
Fix for this issue
Instead of using positions which might be different, use a fixed position depending of the coordinate for every leaf so when you merge back into the tree you get identical values
--- a/openvdb/openvdb/tools/GridTransformer.h
+++ b/openvdb/openvdb/tools/GridTransformer.h
@@ -1021,6 +1021,8 @@
if (interrupt && interrupt()) break;
Vec3R inXYZ = inStartY;
for (z = outMin.z(); z <= outMax.z(); ++z, inXYZ += deltaZ) {
+ // Sample position as a pure function of the output voxel
+ inXYZ = xform.invTransform(Vec3R(x, y, z));
ValueT result;
if (sampler.sample(inTree, inXYZ, result)) {
outTree.setValueOn(outXYZ, result);
Additional context
#include <openvdb/tools/GridOperators.h>
#include <openvdb/tools/GridTransformer.h>
#include <openvdb/tools/LevelSetSphere.h>
#include <openvdb/tools/LevelSetUtil.h>
#include <openvdb/tools/MeshToVolume.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
int main()
{
const double voxel_size = 5.0;
const openvdb::FloatGrid::Ptr input = openvdb::tools::createLevelSetBox<openvdb::FloatGrid>(
openvdb::BBoxd({ -300.0, -150.0, 0.0 }, { 300.0, 150.0, 90.0 }), *openvdb::math::Transform::createLinearTransform(voxel_size));
openvdb::Mat4R flip;
flip.setToRotation(openvdb::Vec3R(1.0, 0.0, 0.0), -M_PI);
const auto transformed = [&](const bool threaded) {
openvdb::tools::GridTransformer transformer(flip);
transformer.setThreaded(threaded);
openvdb::FloatGrid::Ptr output = openvdb::FloatGrid::create(*input);
transformer.transformGrid<openvdb::tools::BoxSampler>(*input, *output);
return output;
};
int failures = 0;
for (const bool threaded : { false, true })
{
const openvdb::FloatGrid::Ptr reference = transformed(threaded);
for (int i = 0; i < 10; ++i)
{
const openvdb::FloatGrid::Ptr output = transformed(threaded);
if (!reference->tree().hasSameTopology(output->tree()))
{
std::printf("FAILED: different topology, threaded=%d iteration %d\n", threaded, i);
return EXIT_FAILURE;
}
const openvdb::FloatGrid::ConstAccessor accessor = output->getConstAccessor();
size_t differing_values = 0;
size_t differing_signs = 0;
for (auto voxel = reference->tree().cbeginValueAll(); voxel; ++voxel)
{
const float value = accessor.getValue(voxel.getCoord());
if (value != voxel.getValue())
{
++differing_values;
if (std::signbit(value) != std::signbit(voxel.getValue()))
{
++differing_signs;
}
}
}
if (differing_values != 0)
{
std::printf("FAILED: threaded=%d iteration %d: %zu differing values, %zu sign flips\n", threaded, i, differing_values, differing_signs);
++failures;
}
}
}
std::printf(failures ? "FAILED (%d runs)\n" : "OK\n", failures);
return failures ? EXIT_FAILURE : EXIT_SUCCESS;
}
- Lingua principale
- C++
- Stelle
- 3.6k
- Fork
- 807
- Merge medio
- 6g 4h
- PR unite (30g)
- 20
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la 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 AcademySoftwareFoundation/openvdb
-
bug nanovdb
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
AcademySoftwareFoundation/openvdb#2345 ·
I maintainer di solito rispondono entro 2 giorni
-
[BUG] typo: vdb_tool: OPENVDB_TOOL_USE_PDAL=ON cannot configure on Windows — find_package(libdpal …) typoForse già presa @najibna l’ha presa 69 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
AcademySoftwareFoundation/openvdb#2344 ·
I maintainer di solito rispondono entro 2 giorni
-
nanovdb
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
AcademySoftwareFoundation/openvdb#2274 ·
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
AcademySoftwareFoundation/openvdb#1896 ·
I maintainer di solito rispondono entro 2 giorni
-
[BUG] NanoVDB line fails with syntax error in /std:c++20Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug nanovdb
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
AcademySoftwareFoundation/openvdb#1521 · 5 commenti · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di AcademySoftwareFoundation/openvdb
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
mw00/project-maya#1368 ·
I maintainer di solito rispondono entro 2 giorni
-
needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
[LLK][QSR][PERF] eltwise_binary: perf harness INIT enables direct indexing, production does notAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
tenstorrent/tt-metal#67662 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
maplibre/maplibre-native#5159 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement question
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
lbr-stack/lbr_fri_ros2_stack#420 · 1 commento ·