Skip to content

[SYCL] Fix static destruction order issue in OpenCL extension fptr cache #9254

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

Merged
merged 2 commits into from
May 2, 2023

Conversation

sergey-semenov
Copy link
Contributor

@sergey-semenov sergey-semenov commented Apr 28, 2023

OpenCL plugin uses several static maps for caching extension function pointers retrieved from the backend. If a user application has a static variable that indirectly calls one of those functions in its destructor, the corresponding map might have already been destroyed.

This patch fixes the problem by tying the lifetime of those maps to piTearDown.

OpenCL plugin uses several static maps for caching extension function
pointers retrieved from the backend. If a user application has a static
variable that indirectly calls one of those functions in its destructor,
the corresponding map might have already been destroyed.

This patch fixes the problem by tying the lifetime of those maps to
piTeardown.
@sergey-semenov sergey-semenov requested a review from a team as a code owner April 28, 2023 16:31
Comment on lines +216 to +217
FuncPtrCache<clHostMemAllocINTEL_fn> clHostMemAllocINTELCache;
FuncPtrCache<clDeviceMemAllocINTEL_fn> clDeviceMemAllocINTELCache;
Copy link
Contributor

@aelovikov-intel aelovikov-intel Apr 28, 2023

Choose a reason for hiding this comment

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

Can we use an std::tuple here so that a particular cache could be accessed via

  tuple.get<FuncPtrCache<ExtFuncTy>>()

?

There might be a minor issue with the fact that C++'s using Ty = doesn't create a new type, so we might need to change the typedefs above to something like

Struct ExtFuncNameTy {
  using FnPtr = /* current typedef */;
};

in order to introduce a unique type alias, but I think it will be worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's exactly the issue, to go this route we would need to provide unique type aliases for all functions used including the ones defined in the OpenCL headers. I think it will end up being just as verbose as the current version.

@sergey-semenov sergey-semenov temporarily deployed to aws April 28, 2023 16:57 — with GitHub Actions Inactive
@sergey-semenov
Copy link
Contributor Author

@aelovikov-intel Do you mind if I address the rest of your comments in a follow-up PR? I'd rather leave those out of this one (especially the ones touching already existing code) to avoid delaying the fix.

Copy link
Contributor

@aelovikov-intel aelovikov-intel left a comment

Choose a reason for hiding this comment

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

LGTM, comments are stylistic and can be addressed in a separate PR.

@sergey-semenov sergey-semenov temporarily deployed to aws April 28, 2023 18:00 — with GitHub Actions Inactive
@sergey-semenov sergey-semenov temporarily deployed to aws April 28, 2023 19:07 — with GitHub Actions Inactive
@sergey-semenov sergey-semenov merged commit 379a094 into intel:sycl May 2, 2023
sergey-semenov added a commit to sergey-semenov/llvm that referenced this pull request May 2, 2023
- Replace typedef with using
- Change pi_context to cl_context to reduce casting

Applies comments from intel#9254
sergey-semenov added a commit that referenced this pull request May 3, 2023
…9281)

- Replace typedef with using
- Change pi_context to cl_context to reduce casting

Applies comments from #9254
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.

2 participants