Skip to content

[SYCL] Avoid releasing UR objects on sycl destruction on windows #15182

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

Conversation

omarahmed1111
Copy link
Contributor

@omarahmed1111 omarahmed1111 commented Aug 23, 2024

SYCL-RT depends currently on the call to DLLMain to begin its destruction on windows. However, when sycl-rt DLLMain is called, UR have already began its destruction on another thread and in case of level_zero, level_zero_loader.dll also began its destruction far before that, this would lead to race condition and access violations. as when release of UR objects begin either level_zero loader/UR adapter/UR loader have been unloaded already.

So, this PR is a guard for that to not call UR objects release when sycl-rt began its destruction.

@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch 2 times, most recently from 65a9843 to bb59a3f Compare August 23, 2024 11:21
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch 2 times, most recently from 840c74e to c711d7b Compare August 27, 2024 10:00
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from c711d7b to 030abe2 Compare August 27, 2024 10:26
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from 030abe2 to 2e6d997 Compare August 27, 2024 13:41
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from 2e6d997 to 7423b42 Compare August 27, 2024 14:29
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from 7423b42 to 8b20f94 Compare August 27, 2024 17:14
@kbenzie kbenzie changed the title Release default context on windows before unloading adapters [SYCL] Release default context on windows before unloading adapters Aug 28, 2024
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from 8b20f94 to 429bb3d Compare August 28, 2024 10:00
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from 429bb3d to 639b76e Compare August 28, 2024 21:38
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from 639b76e to f6468ca Compare August 28, 2024 21:39
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from c3e7b46 to 565fb13 Compare September 3, 2024 09:32
@omarahmed1111 omarahmed1111 removed request for a team and againull September 3, 2024 09:33
@omarahmed1111 omarahmed1111 marked this pull request as draft September 3, 2024 11:00
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from 565fb13 to 436ec4f Compare September 5, 2024 23:32
@omarahmed1111 omarahmed1111 force-pushed the release-default-context-on-windows-before-unloading-adapters branch from 436ec4f to 498c7b6 Compare September 5, 2024 23:35
@omarahmed1111 omarahmed1111 changed the title [SYCL] Release default context on windows before unloading adapters [SYCL] Avoid releasing UR objects on sycl destruction on windows Sep 6, 2024
@omarahmed1111 omarahmed1111 marked this pull request as ready for review September 6, 2024 10:35
#ifdef _WIN32
if (!sycl::detail::GlobalHandler::instance().isUrTearDowned) {
const PluginPtr &Plugin = getSyclObjImpl(MContext)->getPlugin();
Plugin->call(urProgramRelease, MProgram);
Copy link
Contributor

Choose a reason for hiding this comment

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

would it be possible for the call function to internally check isUrTearDowned and return some 'unitinitalized' value (or just ignore it)? That way, we generically workaround this issue in one place, rather than doing in on a case-by-case basis.

@omarahmed1111 omarahmed1111 marked this pull request as draft September 6, 2024 15:46
@omarahmed1111
Copy link
Contributor Author

This would be redundant as a mechanism already exist for tracking URAdapterRelease call

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