Skip to content

[SYCL] Fix plugin deinit order #3024

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 4 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,27 @@ GlobalHandler::getDeviceFilterList(const std::string &InitValue) {
}

void shutdown() {
for (plugin &Plugin : GlobalHandler::instance().getPlugins()) {
// PluginParameter is reserved for future use that can control
// some parameters in the plugin tear-down process.
// Currently, it is not used.
void *PluginParameter = nullptr;
Plugin.call_nocheck<PiApiKind::piTearDown>(PluginParameter);
Plugin.unload();
// First, release resources, that may access plugins.
GlobalHandler::instance().MScheduler.reset(nullptr);
GlobalHandler::instance().MProgramManager.reset(nullptr);
GlobalHandler::instance().MPlatformCache.reset(nullptr);

// Call to GlobalHandler::instance().getPlugins() initializes plugins. If
// user application has loaded SYCL runtime, and never called any APIs,
// there's no need to load and unload plugins.
if (GlobalHandler::instance().MPlugins) {
for (plugin &Plugin : GlobalHandler::instance().getPlugins()) {
// PluginParameter is reserved for future use that can control
// some parameters in the plugin tear-down process.
// Currently, it is not used.
void *PluginParameter = nullptr;
Plugin.call_nocheck<PiApiKind::piTearDown>(PluginParameter);
Plugin.unload();
}
GlobalHandler::instance().MPlugins.reset(nullptr);
}

// Release the rest of global resources.
delete &GlobalHandler::instance();
}

Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ class GlobalHandler {

private:
friend void shutdown();

// Constructor and destructor are declared out-of-line to allow incomplete
// types as template arguments to unique_ptr.
GlobalHandler();
~GlobalHandler();

SpinLock MFieldsLock;

// Do not forget to update shutdown() function if needed.
std::unique_ptr<Scheduler> MScheduler;
std::unique_ptr<ProgramManager> MProgramManager;
std::unique_ptr<Sync> MSync;
Expand Down