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

[OpenMP] Remove optimization skipping reduction struct initialization #65697

Merged
merged 1 commit into from
Sep 12, 2023

Conversation

rodrigo-ceccato
Copy link
Contributor

This commit removes an optimization that skips the initialization of the
reduction struct if the number of threads in a team is 1. This optimization
caused a bug with Hidden Helper Threads. When the task group is initially
initialized by the master thread but a Hidden Helper Thread executes a target
nowait region, it requires the reduction struct initialization to properly
accumulate the data.

This commit also adds a LIT test for issue #57522 to ensure that the issue is
properly addressed and that the optimization removal does not introduce any
regressions.

Fixes: #57522

@shiltian shiltian changed the title [OpenMP Runtime] Remove optimization skipping reduction struct initialization [OpenMP] Remove optimization skipping reduction struct initialization Sep 8, 2023
@@ -2512,11 +2512,6 @@ void *__kmp_task_reduction_init(int gtid, int num, T *data) {
KMP_ASSERT(tg != NULL);
KMP_ASSERT(data != NULL);
KMP_ASSERT(num > 0);
if (nth == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of completely removing the branch, it might be better to check if HHT is enabled. If no, then we can safely return here.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how important single threaded reduction costs really are, but sure.

This commit ensures the initialization of the reduction struct in task loops,
even when the number of threads in a team is 1, provided that hidden helper
threads are active. Previously, an optimization skipped this initialization
in cases where there was only a single thread in the team, which led to a bug.

The bug behavior resulted in a segmentation fault when hidden helper threads
were active. This occurred because the reduction struct was not initialized
when the task group was created by a team with only one thread, causing the
hidden helper thread to encounter issues when accessing the reduction data.

In addition to this fix, a LIT test for issue llvm#57522 is included to validate
the resolution and prevent any regressions.

Fixes: llvm#57522
@rodrigo-ceccato
Copy link
Contributor Author

Squashed and updated the commit message.

ninja check-openmp
[0/1] Running OpenMP tests
-- Testing: 724 tests, 144 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 

Testing Time: 144.14s
  Unsupported: 100
  Passed     : 624

@josemonsalve2 josemonsalve2 merged commit f94b6f3 into llvm:main Sep 12, 2023
2 checks passed
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
…llvm#65697)

This commit removes an optimization that skips the initialization of the
reduction struct if the number of threads in a team is 1. This
optimization
caused a bug with Hidden Helper Threads. When the task group is
initially
initialized by the master thread but a Hidden Helper Thread executes a
target
nowait region, it requires the reduction struct initialization to
properly
accumulate the data.

This commit also adds a LIT test for issue llvm#57522 to ensure that the
issue is
properly addressed and that the optimization removal does not introduce
any
regressions.

Fixes: llvm#57522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Taskgroup task_reduction with target in_reduction segfaults
5 participants