From f48c90f9bfcc779a1ca31872f2a39cd6f5d63768 Mon Sep 17 00:00:00 2001 From: Matthew Michel Date: Mon, 26 Jan 2026 18:26:01 -0800 Subject: [PATCH 1/2] Support queue::ext_oneapi_get_state() and fix UR recording query --- sycl/source/detail/queue_impl.cpp | 18 ++++++++++++++++++ sycl/source/detail/queue_impl.hpp | 2 ++ sycl/source/queue.cpp | 4 +--- .../native_recording_multi_queue.cpp | 15 +++++++++++++++ .../level_zero/v2/command_list_manager.cpp | 7 ++++++- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 261b920bc637..9f1f16beefcd 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -76,6 +76,24 @@ template <> device queue_impl::get_info() const { return get_device(); } +ext::oneapi::experimental::queue_state +queue_impl::ext_oneapi_get_state_impl() const { + // A graph may either be recording at the SYCL level or recording at a lower + // level API (e.g. L0) + if (hasCommandGraph()) { + return ext::oneapi::experimental::queue_state::recording; + } + + bool IsGraphCaptureEnabled = false; + ur_result_t Result = + getAdapter().call_nocheck( + MQueue, &IsGraphCaptureEnabled); + if (Result == UR_RESULT_SUCCESS && IsGraphCaptureEnabled) { + return ext::oneapi::experimental::queue_state::recording; + } + return ext::oneapi::experimental::queue_state::executing; +} + static event prepareSYCLEventAssociatedWithQueue(detail::queue_impl &QueueImpl) { auto EventImpl = detail::event_impl::create_device_event(QueueImpl); diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index f1f5cb9922dc..f3856dbff521 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -639,6 +639,8 @@ class queue_impl : public std::enable_shared_from_this { bool hasCommandGraph() const { return !MGraph.expired(); } + ext::oneapi::experimental::queue_state ext_oneapi_get_state_impl() const; + EventImplPtr submit_command_to_graph( ext::oneapi::experimental::detail::graph_impl &GraphImpl, std::unique_ptr CommandGroup, sycl::detail::CGType CGType, diff --git a/sycl/source/queue.cpp b/sycl/source/queue.cpp index 1efa8a45b5d0..f700f07beff3 100644 --- a/sycl/source/queue.cpp +++ b/sycl/source/queue.cpp @@ -76,9 +76,7 @@ context queue::get_context() const { return impl->get_context(); } device queue::get_device() const { return impl->get_device(); } ext::oneapi::experimental::queue_state queue::ext_oneapi_get_state() const { - return impl->hasCommandGraph() - ? ext::oneapi::experimental::queue_state::recording - : ext::oneapi::experimental::queue_state::executing; + return impl->ext_oneapi_get_state_impl(); } ext::oneapi::experimental::command_graph< diff --git a/sycl/test-e2e/Graph/RecordReplay/native_recording_multi_queue.cpp b/sycl/test-e2e/Graph/RecordReplay/native_recording_multi_queue.cpp index 0c2544b4b4cd..a4d5028a1142 100644 --- a/sycl/test-e2e/Graph/RecordReplay/native_recording_multi_queue.cpp +++ b/sycl/test-e2e/Graph/RecordReplay/native_recording_multi_queue.cpp @@ -28,6 +28,15 @@ int main() { {property::queue::in_order{}, ext::intel::property::queue::immediate_command_list{}}}; + const exp_ext::queue_state Recording = exp_ext::queue_state::recording; + const exp_ext::queue_state Executing = exp_ext::queue_state::executing; + + auto assertQueueState = [&](exp_ext::queue_state ExpectedQ1, + exp_ext::queue_state ExpectedQ2) { + assert(Queue1.ext_oneapi_get_state() == ExpectedQ1); + assert(Queue2.ext_oneapi_get_state() == ExpectedQ2); + }; + // Create a graph - native recording is enabled via // SYCL_GRAPH_ENABLE_NATIVE_RECORDING environment variable exp_ext::command_graph Graph{Ctx, Dev}; @@ -41,8 +50,11 @@ int main() { int *PartialResult2 = malloc_device(1, Dev, Ctx); int *FinalResult = malloc_device(1, Dev, Ctx); + assertQueueState(Executing, Executing); + // Begin graph recording on Queue1 only Graph.begin_recording(Queue1); + assertQueueState(Recording, Executing); // Transform VecA event Fork = @@ -57,6 +69,7 @@ int main() { } PartialResult1[0] = sum; }); + assertQueueState(Recording, Recording); // Record partial dot product on second half (Queue1) exp_ext::single_task(Queue1, [=]() { @@ -71,8 +84,10 @@ int main() { Queue1.single_task({Join}, [=]() { FinalResult[0] = PartialResult1[0] + PartialResult2[0]; }); + assertQueueState(Recording, Executing); Graph.end_recording(); + assertQueueState(Executing, Executing); // Finalize and execute the graph auto ExecutableGraph = Graph.finalize(); diff --git a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp index 088510db822b..2779bf7a5288 100644 --- a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp @@ -1375,7 +1375,12 @@ ur_result_t ur_command_list_manager::isGraphCaptureActive(bool *pResult) { return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } - *pResult = graphCapture.isActive(); + ze_result_t ZeResult = hContext.get() + ->getPlatform() + ->ZeGraphExt.zeCommandListIsGraphCaptureEnabledExp( + getZeCommandList()); + + *pResult = (ZeResult == ZE_RESULT_QUERY_TRUE); return UR_RESULT_SUCCESS; } From e574d5d3a50b334e919d6c39f235e5a055e7cc2f Mon Sep 17 00:00:00 2001 From: Matthew Michel Date: Tue, 27 Jan 2026 16:23:52 -0800 Subject: [PATCH 2/2] Remove assert due to change in compute runtime behavior --- .../test-e2e/Graph/RecordReplay/native_recording_multi_queue.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sycl/test-e2e/Graph/RecordReplay/native_recording_multi_queue.cpp b/sycl/test-e2e/Graph/RecordReplay/native_recording_multi_queue.cpp index a4d5028a1142..d1db2817504b 100644 --- a/sycl/test-e2e/Graph/RecordReplay/native_recording_multi_queue.cpp +++ b/sycl/test-e2e/Graph/RecordReplay/native_recording_multi_queue.cpp @@ -84,7 +84,6 @@ int main() { Queue1.single_task({Join}, [=]() { FinalResult[0] = PartialResult1[0] + PartialResult2[0]; }); - assertQueueState(Recording, Executing); Graph.end_recording(); assertQueueState(Executing, Executing);