Skip to content

Commit ddb72bc

Browse files
[SYCL][Unittests] Fix unloading of mock images on Windows (#19068)
The implementation of mock images try to unload the images using __sycl_unregister_lib. However, this is a no-op on Windows under the assumption that shutdown will handle the images. This causes unittests, like RootGroup, to leave dead binaries in the program manager that subsequent test runs may pick up. This commit fixes this issue by having the mock image arrays forciby remove the images from the program manager instead. Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
1 parent 4fd438a commit ddb72bc

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

sycl/source/detail/global_handler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ GlobalHandler &GlobalHandler::instance() {
134134
return *RTGlobalObjHandler;
135135
}
136136

137+
bool GlobalHandler::isInstanceAlive() {
138+
return GlobalHandler::getInstancePtr();
139+
}
140+
137141
template <typename T, typename... Types>
138142
T &GlobalHandler::getOrCreate(InstWithLock<T> &IWL, Types &&...Args) {
139143
const LockGuard Lock{IWL.Lock};

sycl/source/detail/global_handler.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class GlobalHandler {
4949
/// `__attribute__((destructor))` is called).
5050
static GlobalHandler &instance();
5151

52+
/// \return true if the instance has not been deallocated yet.
53+
static bool isInstanceAlive();
54+
5255
GlobalHandler(const GlobalHandler &) = delete;
5356
GlobalHandler(GlobalHandler &&) = delete;
5457
GlobalHandler &operator=(const GlobalHandler &) = delete;

sycl/unittests/helpers/MockDeviceImage.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,15 @@ template <size_t __NumberOfImages> class MockDeviceImageArray {
363363
nullptr, // not used, put here for compatibility with OpenMP
364364
};
365365

366-
__sycl_register_lib(&MAllBinaries);
366+
sycl::detail::ProgramManager::getInstance().addImages(&MAllBinaries);
367367
}
368368

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

371376
private:
372377
sycl_device_binary_struct MNativeImages[NumberOfImages];

0 commit comments

Comments
 (0)