Skip to content

Commit 67ac635

Browse files
[SYCL][NFC] Reinitialize global handler before using in SYCL unittests (#20733)
1 parent fd898e7 commit 67ac635

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

sycl/source/detail/global_handler.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ class GlobalHandler {
9292
// For testing purposes only
9393
void attachScheduler(Scheduler *Scheduler);
9494

95+
// Used in SYCL unit tests to reset the GlobalHandler instance.
96+
static void resetGlobalHandler() {
97+
RTGlobalObjHandler = new GlobalHandler();
98+
};
99+
95100
private:
96101
// Constructor and destructor are declared out-of-line to allow incomplete
97102
// types as template arguments to unique_ptr.

sycl/unittests/helpers/MockDeviceImage.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ template <size_t __NumberOfImages> class MockDeviceImageArray {
379379
static constexpr size_t NumberOfImages = __NumberOfImages;
380380

381381
MockDeviceImageArray(MockDeviceImage *Imgs) {
382+
383+
if (!GlobalHandler::isInstanceAlive())
384+
GlobalHandler::resetGlobalHandler();
385+
382386
for (size_t Idx = 0; Idx < NumberOfImages; ++Idx)
383387
MNativeImages[Idx] = Imgs[Idx].convertToNativeType();
384388

sycl/unittests/pipes/host_pipe_registration.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <sycl/sycl.hpp>
1111

1212
#include <detail/device_binary_image.hpp>
13+
#include <detail/global_handler.hpp>
1314
#include <detail/host_pipe_map_entry.hpp>
1415
#include <gtest/gtest.h>
1516
#include <helpers/MockDeviceImage.hpp>
@@ -32,6 +33,9 @@ using Pipe = sycl::ext::intel::experimental::pipe<PipeID, int, 10,
3233
static sycl::unittest::MockDeviceImage generateDefaultImage() {
3334
using namespace sycl::unittest;
3435

36+
if (!GlobalHandler::isInstanceAlive())
37+
GlobalHandler::resetGlobalHandler();
38+
3539
sycl::detail::host_pipe_map::add(Pipe::get_host_ptr(),
3640
"test_host_pipe_unique_id");
3741

0 commit comments

Comments
 (0)