Skip to content

[SYCL][Unittests] Fix unloading of mock images on Windows #19068

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

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ GlobalHandler &GlobalHandler::instance() {
return *RTGlobalObjHandler;
}

bool GlobalHandler::isInstanceAlive() {
return GlobalHandler::getInstancePtr();
}

template <typename T, typename... Types>
T &GlobalHandler::getOrCreate(InstWithLock<T> &IWL, Types &&...Args) {
const LockGuard Lock{IWL.Lock};
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class GlobalHandler {
/// `__attribute__((destructor))` is called).
static GlobalHandler &instance();

/// \return true if the instance has not been deallocated yet.
static bool isInstanceAlive();

GlobalHandler(const GlobalHandler &) = delete;
GlobalHandler(GlobalHandler &&) = delete;
GlobalHandler &operator=(const GlobalHandler &) = delete;
Expand Down
9 changes: 7 additions & 2 deletions sycl/unittests/helpers/MockDeviceImage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,15 @@ template <size_t __NumberOfImages> class MockDeviceImageArray {
nullptr, // not used, put here for compatibility with OpenMP
};

__sycl_register_lib(&MAllBinaries);
sycl::detail::ProgramManager::getInstance().addImages(&MAllBinaries);
}

~MockDeviceImageArray() { __sycl_unregister_lib(&MAllBinaries); }
~MockDeviceImageArray() {
// If there is still a global handler, we are not doing full unloading yet.
// As such, we need to clean up the images we registered.
if (GlobalHandler::isInstanceAlive())
sycl::detail::ProgramManager::getInstance().removeImages(&MAllBinaries);
}

private:
sycl_device_binary_struct MNativeImages[NumberOfImages];
Expand Down