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

[SYCL][ClangLinkerWrapper] Fix race condition #12378

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

maksimsab
Copy link
Contributor

@maksimsab maksimsab commented Jan 12, 2024

This patch fixes a data race in the following line of the code that is supposed to be run parallelly and needs mutex protection.

WrappedOutput.push_back(*SYCLOutputOrErr);

@maksimsab maksimsab requested a review from a team as a code owner January 12, 2024 13:50
@asudarsa
Copy link
Contributor

Hi @maksimsab

Can you please provide a very short description? Also, do we need a test to support this? Thanks

@maksimsab
Copy link
Contributor Author

In the listing below the lambda is being launched parallelly in threads.

SmallVector<StringRef> WrappedOutput;
auto Err = parallelForEachError(InputsForTarget, [&](auto &Input) -> Error {

Mutual modifying operations to Images and WrappedOutput should be performed under mutex protection as it is already done for Images here:

std::scoped_lock<decltype(ImageMtx)> Guard(ImageMtx);
OffloadingImage TheImage{};
TheImage.TheImageKind =
Args.hasArg(OPT_embed_bitcode) ? IMG_Bitcode : IMG_Object;
TheImage.TheOffloadKind = Kind;
TheImage.StringData["triple"] =
Args.MakeArgString(LinkerArgs.getLastArgValue(OPT_triple_EQ));
TheImage.StringData["arch"] =
Args.MakeArgString(LinkerArgs.getLastArgValue(OPT_arch_EQ));
TheImage.Image = std::move(*FileOrErr);
Images[Kind].emplace_back(std::move(TheImage));

We haven't caught this bug because we run our tests without --wrapped-jobs option and the default number of jobs is 1. The long-term plan to add such test in the end.

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

Sorry. Missed this one. Looks ok to me. Might want to make sure this is aligned with #12499

@bader bader merged commit ea400f7 into intel:sycl Mar 1, 2024
9 of 10 checks passed
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.

3 participants