Skip to content

DO NOT MERGE - AI prototype of reduction algorithm framework - #6765

Draft
blowekamp wants to merge 3 commits into
InsightSoftwareConsortium:mainfrom
blowekamp:enh-parallel-reduce-algorithms
Draft

DO NOT MERGE - AI prototype of reduction algorithm framework#6765
blowekamp wants to merge 3 commits into
InsightSoftwareConsortium:mainfrom
blowekamp:enh-parallel-reduce-algorithms

Conversation

@blowekamp

Copy link
Copy Markdown
Member

Prototype of a generic ReduceAlgorithm interface (Greedy, Tree, Linear
strategies) for combining per-work-unit partial results, plus a
refactor of LabelStatisticsImageFilter, LabelOverlapMeasuresImageFilter,
and ImageToHistogramFilter to use GreedyReduceAlgorithm instead of
hand-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). GreedyReduceAlgorithm matches the
existing non-deterministic swap-and-merge pattern; TreeReduceAlgorithm
and LinearReduceAlgorithm offer deterministic, chunk-ID-ordered
merging for cases that need reproducible floating-point results.

AI assistance
  • Tool: GitHub Copilot (Claude Sonnet 4.5)
  • Role: implemented the ReduceAlgorithm class hierarchy and GTest
    suites, and refactored the three filters to use GreedyReduceAlgorithm
  • All code was built and tested locally before committing
Test results
  • ITKCommonGTestDriver (Greedy/Tree/Linear reduce tests): all passing
  • ITKImageStatisticsTestDriver/GTestDriver, ITKStatisticsTestDriver/GTestDriver: all passing after fetching ExternalData

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).
@github-actions github-actions Bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:Numerics Issues affecting the Numerics module labels Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:Numerics Issues affecting the Numerics module type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant