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

Remove usages of std::call_once. #5599

Merged
merged 5 commits into from
Aug 8, 2024
Merged

Conversation

mzient
Copy link
Contributor

@mzient mzient commented Aug 7, 2024

Category:

Other (e.g. Documentation, Tests, Configuration)
Workaround for a library bug.

Description:

Additional information:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78184

std::call_once has a bug in some versions of glibc. A custom implementation has been provided.
Usages with static once_flag have been replaced with "magic statics". Optical flow doesn't need atomicity and the once semantics were not required at all.
Other usages use the custom implementation.

A stale warning about antialiasing (also guarded with call once) was removed.

Affected modules and functionalities:

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

std::call_once has a bug in some versions of glibc.
A custom implementation has been provided.
Usages with static once_flag have been replaced with "magic statics".
Optical flow doesn't need atomicity and the once semantics were not
required at all.
Other usages use the custom implementation.

A stale warning about antialiasing (also guarded with call once) was
removed.

Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Comment on lines -96 to -105
if ((has_min && is_linear_default(make_cspan(min_arg_))) ||
(has_interp && is_linear_default(make_cspan(interp_type_arg_)))) {
static std::once_flag linear_default_warning_flag;
std::call_once(linear_default_warning_flag, [&]() {
DALI_WARN(
"The default behavior for LINEAR interpolation type has been changed to apply an "
"antialiasing filter. If you didn't mean to apply an antialiasing filter, please use "
"`antialias=False`");
});
}
Copy link
Contributor Author

@mzient mzient Aug 7, 2024

Choose a reason for hiding this comment

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

This warning was sitting here for 2 years now. Nobody complained during that time and the behavior is hardly a "change" any more.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have mixed filling about including this in this particular PR. But up to you.

Comment on lines -148 to -159
std::call_once(of_initialized_,
[&]() {
optical_flow_.reset(
new optical_flow::OpticalFlowImpl(of_params_,
width,
height,
channels,
image_type,
device_id,
stream));
optical_flow_->Init(of_params_);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is called from within setup. No atomicity is required, setup is never called in parallel with itself.

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [17296340]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [17296340]: BUILD FAILED

Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [17298715]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [17298715]: BUILD FAILED

Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [17313865]: BUILD STARTED

Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [17317992]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [17321143]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [17317992]: BUILD PASSED

@JanuszL JanuszL assigned JanuszL and unassigned szkarpinski Aug 8, 2024
@JanuszL
Copy link
Contributor

JanuszL commented Aug 8, 2024

Please excuse my naïve question, as I understand statics are used when the code doesn't throw, call_once where it might, right?

@mzient
Copy link
Contributor Author

mzient commented Aug 8, 2024

Please excuse my naïve question, as I understand statics are used when the code doesn't throw, call_once where it might, right?

I use "magic statics" when the call_once flag was also static. The compiler should take care of everything. I can double check it.

@mzient mzient merged commit c7ca14e into NVIDIA:main Aug 8, 2024
6 checks passed
@mzient
Copy link
Contributor Author

mzient commented Aug 8, 2024

Checked: magic statics do the trick on manylinux, whereas call_once hangs in a simple test program.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants