From 3a9ab8545847bde4a698aa1c78563d10be6dae5b Mon Sep 17 00:00:00 2001 From: "Agarwal, Udit" Date: Fri, 21 Nov 2025 10:45:38 -0800 Subject: [PATCH 1/2] Reinit global hanlder in unittests --- sycl/source/detail/global_handler.hpp | 5 +++++ sycl/unittests/helpers/MockDeviceImage.hpp | 4 ++++ sycl/unittests/pipes/host_pipe_registration.cpp | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/sycl/source/detail/global_handler.hpp b/sycl/source/detail/global_handler.hpp index 5b0a01d8cef7d..c46d90df88594 100644 --- a/sycl/source/detail/global_handler.hpp +++ b/sycl/source/detail/global_handler.hpp @@ -92,6 +92,11 @@ class GlobalHandler { // For testing purposes only void attachScheduler(Scheduler *Scheduler); + // Used in SYCL unit tests to reset the GlobalHandler instance. + static void resetGlobalHandler() { + RTGlobalObjHandler = new GlobalHandler(); + }; + private: // Constructor and destructor are declared out-of-line to allow incomplete // types as template arguments to unique_ptr. diff --git a/sycl/unittests/helpers/MockDeviceImage.hpp b/sycl/unittests/helpers/MockDeviceImage.hpp index 40afada687c65..1811509ae4eb0 100644 --- a/sycl/unittests/helpers/MockDeviceImage.hpp +++ b/sycl/unittests/helpers/MockDeviceImage.hpp @@ -379,6 +379,10 @@ template class MockDeviceImageArray { static constexpr size_t NumberOfImages = __NumberOfImages; MockDeviceImageArray(MockDeviceImage *Imgs) { + + if (!GlobalHandler::isInstanceAlive()) + GlobalHandler::resetGlobalHandler(); + for (size_t Idx = 0; Idx < NumberOfImages; ++Idx) MNativeImages[Idx] = Imgs[Idx].convertToNativeType(); diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 6ba962c61bd08..0a603883ba0d5 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -16,6 +16,7 @@ #include #include #include +#include class TestKernel; MOCK_INTEGRATION_HEADER(TestKernel) @@ -32,6 +33,9 @@ using Pipe = sycl::ext::intel::experimental::pipe Date: Sun, 23 Nov 2025 19:18:30 +0100 Subject: [PATCH 2/2] clang format --- sycl/unittests/pipes/host_pipe_registration.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/unittests/pipes/host_pipe_registration.cpp b/sycl/unittests/pipes/host_pipe_registration.cpp index 0a603883ba0d5..ae73bd6327c9b 100644 --- a/sycl/unittests/pipes/host_pipe_registration.cpp +++ b/sycl/unittests/pipes/host_pipe_registration.cpp @@ -10,13 +10,13 @@ #include #include +#include #include #include #include #include #include #include -#include class TestKernel; MOCK_INTEGRATION_HEADER(TestKernel) @@ -34,7 +34,7 @@ static sycl::unittest::MockDeviceImage generateDefaultImage() { using namespace sycl::unittest; if (!GlobalHandler::isInstanceAlive()) - GlobalHandler::resetGlobalHandler(); + GlobalHandler::resetGlobalHandler(); sycl::detail::host_pipe_map::add(Pipe::get_host_ptr(), "test_host_pipe_unique_id");