From bf5553649d220b28aac48c174002022d0971c1e3 Mon Sep 17 00:00:00 2001 From: Sergei Vinogradov Date: Wed, 8 Oct 2025 16:57:29 +0200 Subject: [PATCH 1/4] Check if xptiTraceEnabled only once on the hot paths --- sycl/source/detail/graph/graph_impl.cpp | 3 ++- sycl/source/detail/queue_impl.cpp | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sycl/source/detail/graph/graph_impl.cpp b/sycl/source/detail/graph/graph_impl.cpp index f094b5bfe20d..1a25aa59fa4b 100644 --- a/sycl/source/detail/graph/graph_impl.cpp +++ b/sycl/source/detail/graph/graph_impl.cpp @@ -742,8 +742,9 @@ exec_graph_impl::enqueueNodeDirect(const sycl::context &Ctx, const bool xptiEnabled = xptiTraceEnabled(); xpti_td *CmdTraceEvent = nullptr; uint64_t InstanceID = 0; - auto StreamID = detail::getActiveXPTIStreamID(); + uint8_t StreamID; if (xptiEnabled) { + StreamID = detail::getActiveXPTIStreamID(); sycl::detail::CGExecKernel *CGExec = static_cast(Node.MCommandGroup.get()); sycl::detail::code_location CodeLoc(CGExec->MFileName.c_str(), diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index b8c2a2866a62..4067ef10790e 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -448,11 +448,12 @@ EventImplPtr queue_impl::submit_kernel_scheduler_bypass( #ifdef XPTI_ENABLE_INSTRUMENTATION xpti_td *CmdTraceEvent = nullptr; uint64_t InstanceID = 0; - auto StreamID = detail::getActiveXPTIStreamID(); + uint8_t StreamID; // Only enable instrumentation if there are subscribes to the SYCL // stream - const bool xptiEnabled = xptiCheckTraceEnabled(StreamID); + const bool xptiEnabled = xptiTraceEnabled(); if (xptiEnabled) { + StreamID = detail::getActiveXPTIStreamID(); std::tie(CmdTraceEvent, InstanceID) = emitKernelInstrumentationData( StreamID, KernelImplPtr, CodeLoc, IsTopCodeLoc, *KData.getDeviceKernelInfoPtr(), this, KData.getNDRDesc(), @@ -843,8 +844,12 @@ void queue_impl::wait(const detail::code_location &CodeLoc) { void *TelemetryEvent = nullptr; uint64_t IId; std::string Name; - auto StreamID = detail::getActiveXPTIStreamID(); - TelemetryEvent = instrumentationProlog(CodeLoc, Name, StreamID, IId); + uint8_t StreamID; + const bool xptiEnabled = xptiTraceEnabled(); + if (xptiEnabled) { + StreamID = detail::getActiveXPTIStreamID(); + TelemetryEvent = instrumentationProlog(CodeLoc, Name, StreamID, IId); + } #endif if (!MGraph.expired()) { @@ -926,7 +931,9 @@ void queue_impl::wait(const detail::code_location &CodeLoc) { #ifdef XPTI_ENABLE_INSTRUMENTATION // There is an early return in instrumentationEpilog() if no subscribers are // subscribing to queue.wait(). - instrumentationEpilog(TelemetryEvent, Name, StreamID, IId); + if (xptiEnabled) { + instrumentationEpilog(TelemetryEvent, Name, StreamID, IId); + } #endif } From 0d929d0a90be19a5ad46ba62cc345e915fc3232f Mon Sep 17 00:00:00 2001 From: Sergei Vinogradov Date: Wed, 8 Oct 2025 18:46:31 +0200 Subject: [PATCH 2/4] Update sycl/source/detail/queue_impl.cpp Co-authored-by: Udit Kumar Agarwal --- sycl/source/detail/queue_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 4067ef10790e..9330b5aae2b0 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -844,7 +844,7 @@ void queue_impl::wait(const detail::code_location &CodeLoc) { void *TelemetryEvent = nullptr; uint64_t IId; std::string Name; - uint8_t StreamID; + uint8_t StreamID = 0; const bool xptiEnabled = xptiTraceEnabled(); if (xptiEnabled) { StreamID = detail::getActiveXPTIStreamID(); From b616b3cb51cd6e8cda24b963b2645f519b9b4bc7 Mon Sep 17 00:00:00 2001 From: Sergei Vinogradov Date: Wed, 8 Oct 2025 18:46:42 +0200 Subject: [PATCH 3/4] Update sycl/source/detail/queue_impl.cpp Co-authored-by: Udit Kumar Agarwal --- sycl/source/detail/queue_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 9330b5aae2b0..98af8f194484 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -448,7 +448,7 @@ EventImplPtr queue_impl::submit_kernel_scheduler_bypass( #ifdef XPTI_ENABLE_INSTRUMENTATION xpti_td *CmdTraceEvent = nullptr; uint64_t InstanceID = 0; - uint8_t StreamID; + uint8_t StreamID = 0; // Only enable instrumentation if there are subscribes to the SYCL // stream const bool xptiEnabled = xptiTraceEnabled(); From d67fe52a79537382b665e5303d9f1b4d20fe735b Mon Sep 17 00:00:00 2001 From: Sergei Vinogradov Date: Wed, 8 Oct 2025 18:46:51 +0200 Subject: [PATCH 4/4] Update sycl/source/detail/graph/graph_impl.cpp Co-authored-by: Udit Kumar Agarwal --- sycl/source/detail/graph/graph_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/detail/graph/graph_impl.cpp b/sycl/source/detail/graph/graph_impl.cpp index 1a25aa59fa4b..0427c0a0c6ad 100644 --- a/sycl/source/detail/graph/graph_impl.cpp +++ b/sycl/source/detail/graph/graph_impl.cpp @@ -742,7 +742,7 @@ exec_graph_impl::enqueueNodeDirect(const sycl::context &Ctx, const bool xptiEnabled = xptiTraceEnabled(); xpti_td *CmdTraceEvent = nullptr; uint64_t InstanceID = 0; - uint8_t StreamID; + uint8_t StreamID = 0; if (xptiEnabled) { StreamID = detail::getActiveXPTIStreamID(); sycl::detail::CGExecKernel *CGExec =