Skip to content

[SYCL] Move xpti stream init (exception trace) to the first usage #8907

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 2 commits into from
Apr 1, 2023
Merged
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
28 changes: 12 additions & 16 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ void GlobalHandler::InitXPTI() {
}

void GlobalHandler::TraceEventXPTI(const char *Message) {
#ifdef XPTI_ENABLE_INSTRUMENTATION
if (!Message)
return;
#ifdef XPTI_ENABLE_INSTRUMENTATION
static std::once_flag InitXPTIFlag;
if (xptiTraceEnabled()) {
std::call_once(InitXPTIFlag, [&]() { InitXPTI(); });

// We have to handle the cases where: (1) we may have just the code location
// set and not UID and (2) UID set
detail::tls_code_loc_t Tls;
Expand Down Expand Up @@ -122,13 +125,6 @@ GlobalHandler *&GlobalHandler::getInstancePtr() {
GlobalHandler &GlobalHandler::instance() {
GlobalHandler *RTGlobalObjHandler = GlobalHandler::getInstancePtr();
assert(RTGlobalObjHandler && "Handler must not be deallocated earlier");

#ifdef XPTI_ENABLE_INSTRUMENTATION
static std::once_flag InitXPTIFlag;
if (xptiTraceEnabled()) {
std::call_once(InitXPTIFlag, [&]() { RTGlobalObjHandler->InitXPTI(); });
}
#endif
return *RTGlobalObjHandler;
}

Expand Down Expand Up @@ -289,13 +285,13 @@ void GlobalHandler::drainThreadPool() {
}

#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(){
// 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();
}
Expand Down Expand Up @@ -356,7 +352,7 @@ extern "C" __SYCL_EXPORT BOOL WINAPI DllMain(HINSTANCE hinstDLL,
#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.
// TODO: figure out what XPTI is doing that prevents release.
#endif

shutdown();
Expand Down