Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unique LabelMap filters producing non-unique labels and causing concurrent pixel writes. #4668

Merged

Conversation

blowekamp
Copy link
Member

@blowekamp blowekamp commented May 15, 2024

Address bugs in unique label map filters
Two bugs were addressed which could cause overlapping and/or errouneous
outputs.

  1. When a line we trimmed in the front, it is not placed back into the
    queue to ensure that it is still the first one, and the asserted
    assumptions of the order remain true.
  2. Fix comparisons between start and ends to be correct for an
    interval of pixels where the start+length is not included.

closes #4655
closes #3031

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

Refer to the ITK Software Guide for
further development details if necessary.

@github-actions github-actions bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Filtering Issues affecting the Filtering module labels May 15, 2024
@seanm
Copy link
Contributor

seanm commented May 15, 2024

@blowekamp are you set up to use TSan, or do you want me to try with patch with TSan?

@dzenanz
Copy link
Member

dzenanz commented May 15, 2024

I believe this does not patch it, it just explicitly checks for label overlaps.

@blowekamp blowekamp force-pushed the bug_label_unique branch 2 times, most recently from d97dc16 to ae7566b Compare May 16, 2024 13:07
@blowekamp
Copy link
Member Author

I think this is pretty close to fixing the issue, more testing is needed.

Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the commit message, label map filers -> label map filters. The rest looks good on a glance.

@blowekamp blowekamp force-pushed the bug_label_unique branch 2 times, most recently from 7be77cd to 30b24f3 Compare May 16, 2024 17:58
@blowekamp blowekamp force-pushed the bug_label_unique branch 2 times, most recently from 07ae8d7 to 1766c13 Compare May 17, 2024 19:16
@github-actions github-actions bot added the type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots label May 17, 2024
@blowekamp blowekamp marked this pull request as ready for review May 17, 2024 19:17
@blowekamp
Copy link
Member Author

@seanm You can run the sanitizer. However I was able to detect the bug with additional checks before the threading issue occurs.

@seanm
Copy link
Contributor

seanm commented May 17, 2024

I'm getting a build error:

/Users/sean/external/ITK/Modules/Filtering/LabelMap/test/itkStatisticsUniqueLabelMapFilterTest1.cxx:46:7: error: use of undeclared identifier 'TEST_EXPECT_TRUE'
/Users/sean/external/ITK/Modules/Filtering/LabelMap/test/itkStatisticsUniqueLabelMapFilterTest1.cxx:158:18: note: in instantiation of function template specialization 'CheckLabelMapOverlap<itk::LabelMap<itk::StatisticsLabelObject<unsigned char, 2>>>' requested here
  int exitCode = CheckLabelMapOverlap(unique->GetOutput());
                 ^

and

/Users/sean/external/ITK/Modules/Filtering/LabelMap/test/itkStatisticsUniqueLabelMapFilterTest1.cxx:46:7: error: attempt to use a poisoned identifier
      TEST_EXPECT_TRUE(line.GetLength() <= labelObject->GetNumberOfPixels());
      ^

Check the label maps are none overlapping. Overlapping labels are
causing thread race conditions in the LabelMapToLabelImage filter.
Two bugs were addressed which could cause overlapping and/or errouneous
outputs.

1. When a line we trimmed in the front, it is not placed back into the
queue to ensure that it is still the first one, and the asserted
assumptions of the order remain true.
2. Fix comparisons between start and ends to be correct for an
interval of pixels where the start+length is not included.
@blowekamp
Copy link
Member Author

@seanm Thanks looks like that should have been ITK_TEST_EXPECT_TRUE. I am surprised that did not produce a warning on any of the builds.

@blowekamp blowekamp changed the base branch from master to release-5.4 May 21, 2024 13:09
@blowekamp blowekamp changed the title BUG: Check output of StatisticsUniqueLabelMapFilterTest1 Fix Unique LabelMap filters producing non-unique labels and causing concurrent pixel writes. May 21, 2024
Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to have these addressed! 🥇

Copy link
Contributor

@seanm seanm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves the itkStatisticsUniqueLabelMapFilterTest1 test failure under TSan! Amazing! We'll see on cdash if it solves other similar failures too...

@seanm
Copy link
Contributor

seanm commented May 30, 2024

So this is mergeable now?

@blowekamp
Copy link
Member Author

@thewtex I was hoping to get this in for 5.4 but missed it. The current target branch is release-5.4. What should be do to merge this patch?

@thewtex
Copy link
Member

thewtex commented May 30, 2024

@thewtex I was hoping to get this in for 5.4 but missed it. The current target branch is release-5.4. What should be do to merge this patch?

@blowekamp outstanding!

I will go ahead and merge this one. For future reference, the process is:

  1. merge topic branch into release-5.4 via GitHub Web UI
  2. merge release-5.4 into release locally (git checkout release-5.4; git pull --ff-only upstream release-5.4; git checkout release; git pull --ff-only upstream release; git merge release-5.4)
  3. merge release into master locally (git checkout master; git pull --ff-only upstream master; git merge release)
  4. locally git push upstream release master

@thewtex thewtex merged commit 9834ed2 into InsightSoftwareConsortium:release-5.4 May 30, 2024
14 checks passed
@seanm
Copy link
Contributor

seanm commented May 30, 2024

Cool, I'm excited to see on tomorrow's TSan cdash is this fixes any other tests too:

https://open.cdash.org/builds/9649990

@seanm
Copy link
Contributor

seanm commented May 31, 2024

Seems it fixed itkStatisticsUniqueLabelMapFilterTest2, but not any other test.

@blowekamp
Copy link
Member Author

Seems it fixed itkStatisticsUniqueLabelMapFilterTest2, but not any other test.

Are any of the other failure related to label maps?

@seanm
Copy link
Contributor

seanm commented May 31, 2024

Are any of the other failure related to label maps?

I haven't analyzed each in depth, but here's the list:

https://open.cdash.org/viewTest.php?onlyfailed&buildid=9652708

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Filtering Issues affecting the Filtering module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances 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
4 participants