-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Windows Proxy Loader for DLLs #8242
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
Changes from all commits
d726e1c
1457761
052afd7
c723c45
5b70c21
c648c09
a935f29
defd2d7
06fdb87
454f4c8
1064627
731a83d
a1075d9
1753fd5
dd8b47c
6634c8c
5088e11
ad68a83
5e51e12
67d4c1b
dd7db2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//==------------ common_win_pi_trace.hpp - SYCL standard header file -------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// this .hpp is injected. Be sure to define __SYCL_PLUGIN_DLL_NAME before | ||
// including | ||
#ifdef _WIN32 | ||
#include <windows.h> | ||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, // handle to DLL module | ||
DWORD fdwReason, // reason for calling function | ||
LPVOID lpReserved) { // reserved | ||
|
||
bool PrintPiTrace = false; | ||
static const char *PiTrace = std::getenv("SYCL_PI_TRACE"); | ||
static const int PiTraceValue = PiTrace ? std::stoi(PiTrace) : 0; | ||
if (PiTraceValue == -1 || PiTraceValue == 2) { // Means print all PI traces | ||
PrintPiTrace = true; | ||
} | ||
|
||
// Perform actions based on the reason for calling. | ||
switch (fdwReason) { | ||
case DLL_PROCESS_DETACH: | ||
if (PrintPiTrace) | ||
std::cout << "---> DLL_PROCESS_DETACH " << __SYCL_PLUGIN_DLL_NAME << "\n" | ||
<< std::endl; | ||
|
||
break; | ||
case DLL_PROCESS_ATTACH: | ||
if (PrintPiTrace) | ||
std::cout << "---> DLL_PROCESS_ATTACH " << __SYCL_PLUGIN_DLL_NAME << "\n" | ||
<< std::endl; | ||
case DLL_THREAD_ATTACH: | ||
case DLL_THREAD_DETACH: | ||
break; | ||
} | ||
return TRUE; | ||
} | ||
#endif // WIN32 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,10 @@ void GlobalHandler::releaseDefaultContexts() { | |
// finished. To avoid calls to nowhere, intentionally leak platform to device | ||
// cache. This will prevent destructors from being called, thus no PI cleanup | ||
// routines will be called in the end. | ||
// Update: the win_proxy_loader addresses this for SYCL's own dependencies, | ||
// but the GPU device dlls seem to manually load yet another DLL which may | ||
// have been released when this function is called. So we still release() and | ||
// leak until that is addressed. context destructs fine on CPU device. | ||
MPlatformToDefaultContextCache.Inst.release(); | ||
#endif | ||
} | ||
|
@@ -212,6 +216,18 @@ 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(){ | ||
GlobalHandler *&Handler = GlobalHandler::getInstancePtr(); | ||
Handler->unloadPlugins(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add a comment saying that piTearDown might not be safe to call low level API, since there might be dependent libraries that are unloaded. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment to each definition of piTearDown in the plugin libs. |
||
} | ||
#else | ||
void shutdown() { | ||
const LockGuard Lock{GlobalHandler::MSyclGlobalHandlerProtector}; | ||
GlobalHandler *&Handler = GlobalHandler::getInstancePtr(); | ||
|
@@ -246,18 +262,36 @@ void shutdown() { | |
delete Handler; | ||
Handler = nullptr; | ||
} | ||
#endif | ||
|
||
#ifdef _WIN32 | ||
extern "C" __SYCL_EXPORT BOOL WINAPI DllMain(HINSTANCE hinstDLL, | ||
DWORD fdwReason, | ||
LPVOID lpReserved) { | ||
bool PrintPiTrace = false; | ||
static const char *PiTrace = std::getenv("SYCL_PI_TRACE"); | ||
static const int PiTraceValue = PiTrace ? std::stoi(PiTrace) : 0; | ||
if (PiTraceValue == -1 || PiTraceValue == 2) { // Means print all PI traces | ||
PrintPiTrace = true; | ||
} | ||
|
||
// Perform actions based on the reason for calling. | ||
switch (fdwReason) { | ||
case DLL_PROCESS_DETACH: | ||
if (!lpReserved) | ||
shutdown(); | ||
if (PrintPiTrace) | ||
std::cout << "---> DLL_PROCESS_DETACH syclx.dll\n" << std::endl; | ||
|
||
#ifdef XPTI_ENABLE_INSTRUMENTATION | ||
if (xptiTraceEnabled()) | ||
return TRUE; // When doing xpti tracing, we can't safely call shutdown. | ||
// TODO: figure out what XPTI is doing that prevents release. | ||
#endif | ||
|
||
shutdown(); | ||
break; | ||
case DLL_PROCESS_ATTACH: | ||
if (PrintPiTrace) | ||
std::cout << "---> DLL_PROCESS_ATTACH syclx.dll\n" << std::endl; | ||
case DLL_THREAD_ATTACH: | ||
case DLL_THREAD_DETACH: | ||
break; | ||
|
Uh oh!
There was an error while loading. Please reload this page.