Skip to content
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
21 changes: 17 additions & 4 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ std::mutex &GlobalHandler::getHandlerExtendedMembersMutex() {
return getOrCreate(MHandlerExtendedMembersMutex);
}

void shutdown() {
// First, release resources, that may access plugins.
GlobalHandler::instance().MScheduler.Inst.reset(nullptr);
GlobalHandler::instance().MProgramManager.Inst.reset(nullptr);
void releaseSharedGlobalHandles() {
// Release shared-pointers to SYCL objects.
#ifndef _WIN32
GlobalHandler::instance().MPlatformToDefaultContextCache.Inst.reset(nullptr);
#else
Expand All @@ -104,6 +102,12 @@ void shutdown() {
GlobalHandler::instance().MPlatformToDefaultContextCache.Inst.release();
#endif
GlobalHandler::instance().MPlatformCache.Inst.reset(nullptr);
}

void shutdown() {
// First, release resources, that may access plugins.
GlobalHandler::instance().MScheduler.Inst.reset(nullptr);
GlobalHandler::instance().MProgramManager.Inst.reset(nullptr);

// Call to GlobalHandler::instance().getPlugins() initializes plugins. If
// user application has loaded SYCL runtime, and never called any APIs,
Expand Down Expand Up @@ -131,6 +135,7 @@ extern "C" __SYCL_EXPORT BOOL WINAPI DllMain(HINSTANCE hinstDLL,
// Perform actions based on the reason for calling.
switch (fdwReason) {
case DLL_PROCESS_DETACH:
releaseSharedGlobalHandles();
shutdown();
break;
case DLL_PROCESS_ATTACH:
Expand All @@ -141,6 +146,14 @@ extern "C" __SYCL_EXPORT BOOL WINAPI DllMain(HINSTANCE hinstDLL,
return TRUE; // Successful DLL_PROCESS_ATTACH.
}
#else
// Release shared SYCL object implementation handles at normal destructor
// priority to avoid the global handler from keeping the objects alive after
// the backends have destroyed any state they may rely on to correctly handle
// further operations.
__attribute__((destructor)) static void syclPreunload() {
releaseSharedGlobalHandles();
}

// Setting low priority on destructor ensures it runs after all other global
// destructors. Priorities 0-100 are reserved by the compiler. The priority
// value 110 allows SYCL users to run their destructors after runtime library
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class GlobalHandler {
std::mutex &getHandlerExtendedMembersMutex();

private:
friend void releaseSharedGlobalHandles();
friend void shutdown();

// Constructor and destructor are declared out-of-line to allow incomplete
Expand Down