DO NOT MERGE - AI prototype of reduction algorithm framework - #6765
DO NOT MERGE - AI prototype of reduction algorithm framework#6765blowekamp wants to merge 3 commits into
Conversation
Add ReduceAlgorithm base interface plus Greedy, Tree, and Linear implementations for combining per-work-unit partial results. Greedy is thread-safe but non-deterministic in merge order. Tree and Linear merge in a fixed, chunk-ID order so results are reproducible across runs regardless of thread scheduling.
Replace hand-rolled mutex swap-and-merge loops in LabelStatisticsImageFilter, LabelOverlapMeasuresImageFilter, and ImageToHistogramFilter with GreedyReduceAlgorithm. Also add a using-declaration in GreedyReduceAlgorithm to stop it from hiding the base class's chunk-ID Merge() overload (-Woverloaded-virtual).
|
IMHO: Given the scope of what is needed here, and the impact, it seems like a good candidate to schedule as part of a funded effort where adequate team resources can be assigned and committed to. Or at least given a separate planning session. It feels like this is the tip-of the iceberg of "work that should be done". ========================== Ran a "/code-review max" over the PR prototype — the 1. Two of the three new GTest files are never built. 2. No chunk-ID plumbing exists in ITK's threading API, which I think is the central design question rather than a defect. 3. Three silent-wrong-answer paths where a wrong result is returned with no exception — details below. The three silent-failure paths
Related: a missing chunk is also silent (Tree returns Thread-safety and lifecycle
Filter refactor: a deep copy replaces a swap
m_LabelStatistics = m_Reducer->GetResult();
Minor:
Why the tests wouldn't catch the aboveThe concurrency tests are structurally sound — real
Smaller notes
Reviewed against the reduce-interface request in #6622. Happy to open a PR against the branch for the CMake registration if that's useful. Review assisted by Claude Code (Opus 5); findings were traced against the source and verified by hand before posting. |
Prototype of a generic
ReduceAlgorithminterface (Greedy, Tree, Linearstrategies) for combining per-work-unit partial results, plus a
refactor of
LabelStatisticsImageFilter,LabelOverlapMeasuresImageFilter,and
ImageToHistogramFilterto useGreedyReduceAlgorithminstead ofhand-rolled mutex swap-and-merge loops. Opened as a draft for discussion,
not intended to merge as-is.
Background
Follows up on the deterministic-parallel-reduce discussion in #6622
(Mattes metric derivatives).
GreedyReduceAlgorithmmatches theexisting non-deterministic swap-and-merge pattern;
TreeReduceAlgorithmand
LinearReduceAlgorithmoffer deterministic, chunk-ID-orderedmerging for cases that need reproducible floating-point results.
AI assistance
ReduceAlgorithmclass hierarchy and GTestsuites, and refactored the three filters to use
GreedyReduceAlgorithmTest results
ITKCommonGTestDriver(Greedy/Tree/Linear reduce tests): all passingITKImageStatisticsTestDriver/GTestDriver,ITKStatisticsTestDriver/GTestDriver: all passing after fetching ExternalData