Skip to content

Commit

Permalink
Release resources on windows on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
omarahmed1111 committed Sep 18, 2024
1 parent 51dcb29 commit 55b2a9b
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 32 deletions.
22 changes: 4 additions & 18 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ using LockGuard = std::lock_guard<SpinLock>;
SpinLock GlobalHandler::MSyclGlobalHandlerProtector{};

// forward decl
void shutdown_win(); // TODO: win variant will go away soon
void shutdown_early();
void release_and_shutdown();
void shutdown_late();

// Utility class to track references on object.
Expand Down Expand Up @@ -244,7 +243,7 @@ struct EarlyShutdownHandler {
// on Windows we keep to the existing shutdown procedure
GlobalHandler::instance().releaseDefaultContexts();
#else
shutdown_early();
release_and_shutdown();
#endif
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~EarlyShutdownHandler",
Expand Down Expand Up @@ -298,19 +297,7 @@ void GlobalHandler::drainThreadPool() {
MHostTaskThreadPool.Inst->drain();
}

#ifdef _WIN32
// because of something not-yet-understood on Windows
// threads may be shutdown once the end of main() is reached
// making an orderly shutdown difficult. Fortunately, Windows
// itself is very aggressive about reclaiming memory. Thus,
// we focus solely on unloading the plugins, so as to not
// accidentally retain device handles. etc
void shutdown_win() {
GlobalHandler *&Handler = GlobalHandler::getInstancePtr();
Handler->unloadPlugins();
}
#else
void shutdown_early() {
void release_and_shutdown() {
const LockGuard Lock{GlobalHandler::MSyclGlobalHandlerProtector};
GlobalHandler *&Handler = GlobalHandler::getInstancePtr();
if (!Handler)
Expand Down Expand Up @@ -353,7 +340,6 @@ void shutdown_late() {
delete Handler;
Handler = nullptr;
}
#endif

#ifdef _WIN32
extern "C" __SYCL_EXPORT BOOL WINAPI DllMain(HINSTANCE hinstDLL,
Expand Down Expand Up @@ -381,7 +367,7 @@ extern "C" __SYCL_EXPORT BOOL WINAPI DllMain(HINSTANCE hinstDLL,
// release.
#endif

shutdown_win();
release_and_shutdown();
break;
case DLL_PROCESS_ATTACH:
if (PrintUrTrace)
Expand Down
3 changes: 1 addition & 2 deletions sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ class GlobalHandler {

bool OkToDefer = true;

friend void shutdown_win();
friend void shutdown_early();
friend void release_and_shutdown();
friend void shutdown_late();
friend class ObjectUsageCounter;
static GlobalHandler *&getInstancePtr();
Expand Down
3 changes: 1 addition & 2 deletions sycl/test-e2e/Basic/queue/release.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// RUN: %{build} -o %t.out
// RUN: env SYCL_UR_TRACE=2 %{run} %t.out | FileCheck %s
//
// TODO: Reenable on Windows, see https://github.com/intel/llvm/issues/14768
// XFAIL: hip_nvidia, windows
// XFAIL: hip_nvidia

#include <sycl/detail/core.hpp>
int main() {
Expand Down
3 changes: 0 additions & 3 deletions sycl/test-e2e/KernelAndProgram/disable-caching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
// RUN: env ZE_DEBUG=-6 SYCL_UR_TRACE=2 %{run} %t.out \
// RUN: | FileCheck %s --check-prefixes=CHECK-CACHE

// TODO: Reenable on Windows, see https://github.com/intel/llvm/issues/14768
// XFAIL: windows

#include <sycl/detail/core.hpp>

#include <sycl/specialization_id.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// RUN: %{build} -o %t.out
// RUN: env SYCL_UR_TRACE=2 %{run} %t.out 2>&1 | FileCheck %s
//
// TODO: Reenable on Windows, see https://github.com/intel/llvm/issues/14768
// XFAIL: hip_nvidia, windows
// XFAIL: hip_nvidia

#include <sycl/detail/core.hpp>

Expand Down
3 changes: 0 additions & 3 deletions sycl/test-e2e/Regression/pi_release.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// REQUIRES: opencl || level_zero || cuda
// RUN: %{build} -o %t.out
// RUN: env SYCL_UR_TRACE=2 %{run} %t.out 2>&1 | FileCheck %s
//
// TODO: Reenable on Windows, see https://github.com/intel/llvm/issues/14768
// XFAIL: windows

#include <sycl/detail/core.hpp>

Expand Down
3 changes: 1 addition & 2 deletions sycl/test-e2e/Scheduler/ReleaseResourcesTest.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// RUN: %{build} -Wno-error=unused-command-line-argument -fsycl-dead-args-optimization -o %t.out
// RUN: env SYCL_UR_TRACE=2 %{run} %t.out 2>&1 | FileCheck %s
//
// TODO: Reenable on Windows, see https://github.com/intel/llvm/issues/14768
// XFAIL: hip_nvidia, windows
// XFAIL: hip_nvidia

//==------------------- ReleaseResourcesTests.cpp --------------------------==//
//
Expand Down

0 comments on commit 55b2a9b

Please sign in to comment.