Skip to content
Closed
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
11 changes: 11 additions & 0 deletions sycl/source/detail/context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,23 @@ context_impl::~context_impl() {
DeviceGlobal);
DGEntry->removeAssociatedResources(this);
}
#ifdef _WIN32
if (!sycl::detail::GlobalHandler::instance().isUrTearDowned) {
for (auto LibProg : MCachedLibPrograms) {
assert(LibProg.second && "Null program must not be kept in the cache");
getPlugin()->call(urProgramRelease, LibProg.second);
}
// TODO catch an exception and put it to list of asynchronous exceptions
getPlugin()->call_nocheck(urContextRelease, MContext);
}
#else
for (auto LibProg : MCachedLibPrograms) {
assert(LibProg.second && "Null program must not be kept in the cache");
getPlugin()->call(urProgramRelease, LibProg.second);
}
// TODO catch an exception and put it to list of asynchronous exceptions
getPlugin()->call_nocheck(urContextRelease, MContext);
#endif
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~context_impl", e);
}
Expand Down
7 changes: 7 additions & 0 deletions sycl/source/detail/device_image_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,15 @@ class device_image_impl {
~device_image_impl() {
try {
if (MProgram) {
#ifdef _WIN32
if (!sycl::detail::GlobalHandler::instance().isUrTearDowned) {
const PluginPtr &Plugin = getSyclObjImpl(MContext)->getPlugin();
Plugin->call(urProgramRelease, MProgram);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible for the call function to internally check isUrTearDowned and return some 'unitinitalized' value (or just ignore it)? That way, we generically workaround this issue in one place, rather than doing in on a case-by-case basis.

}
#else
const PluginPtr &Plugin = getSyclObjImpl(MContext)->getPlugin();
Plugin->call(urProgramRelease, MProgram);
#endif
}
if (MSpecConstsBuffer) {
std::lock_guard<std::mutex> Lock{MSpecConstAccessMtx};
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void GlobalHandler::drainThreadPool() {
// accidentally retain device handles. etc
void shutdown_win() {
GlobalHandler *&Handler = GlobalHandler::getInstancePtr();
Handler->isUrTearDowned = true;
Handler->unloadPlugins();
}
#else
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 @@ -50,6 +50,7 @@ class GlobalHandler {
/// as runtime library is loaded (i.e. untill `DllMain` or
/// `__attribute__((destructor))` is called).
static GlobalHandler &instance();
bool isUrTearDowned = false;

GlobalHandler(const GlobalHandler &) = delete;
GlobalHandler(GlobalHandler &&) = delete;
Expand Down
7 changes: 7 additions & 0 deletions sycl/source/detail/kernel_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ kernel_impl::kernel_impl(ur_kernel_handle_t Kernel, ContextImplPtr ContextImpl,

kernel_impl::~kernel_impl() {
try {
#ifdef _WIN32
if (!sycl::detail::GlobalHandler::instance().isUrTearDowned) {
// TODO catch an exception and put it to list of asynchronous exceptions
getPlugin()->call(urKernelRelease, MKernel);
}
#else
// TODO catch an exception and put it to list of asynchronous exceptions
getPlugin()->call(urKernelRelease, MKernel);
#endif
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~kernel_impl", e);
}
Expand Down
14 changes: 14 additions & 0 deletions sycl/source/detail/kernel_program_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ class KernelProgramCache {
~ProgramBuildResult() {
try {
if (Val) {
#ifdef _WIN32
if (!sycl::detail::GlobalHandler::instance().isUrTearDowned) {
ur_result_t Err = Plugin->call_nocheck(urProgramRelease, Val);
__SYCL_CHECK_UR_CODE_NO_EXC(Err);
}
#else
ur_result_t Err = Plugin->call_nocheck(urProgramRelease, Val);
__SYCL_CHECK_UR_CODE_NO_EXC(Err);
#endif
}
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~ProgramBuildResult",
Expand Down Expand Up @@ -140,8 +147,15 @@ class KernelProgramCache {
~KernelBuildResult() {
try {
if (Val.first) {
#ifdef _WIN32
if (!sycl::detail::GlobalHandler::instance().isUrTearDowned) {
ur_result_t Err = Plugin->call_nocheck(urKernelRelease, Val.first);
__SYCL_CHECK_UR_CODE_NO_EXC(Err);
}
#else
ur_result_t Err = Plugin->call_nocheck(urKernelRelease, Val.first);
__SYCL_CHECK_UR_CODE_NO_EXC(Err);
#endif
}
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~KernelBuildResult", e);
Expand Down