Skip to content

[SYCL][UR][OpenCL] Fix profiling tag ordering on OpenCL GPU#22641

Open
crystarm wants to merge 1 commit into
intel:syclfrom
crystarm:profiling-tag-opencl-timestamp-recording
Open

[SYCL][UR][OpenCL] Fix profiling tag ordering on OpenCL GPU#22641
crystarm wants to merge 1 commit into
intel:syclfrom
crystarm:profiling-tag-opencl-timestamp-recording

Conversation

@crystarm

Copy link
Copy Markdown
Contributor

Related to #22229.

submit_profiling_tag returned timestamps in the wrong order on opencl:gpu: the end tag's command_end could be earlier than the completion of work submitted before it, so E2End <= EndTagEnd failed and the e2e tests were masked with UNSUPPORTED: opencl && gpu.

Why

OpenCL devices don't advertise ext_oneapi_queue_profiling_tag (the adapter hard-codes UR_DEVICE_INFO_TIMESTAMP_RECORDING_SUPPORT_EXP to false), so the tag fell back to ext_oneapi_submit_barrier() and read its profiling info straight off the barrier event.

The NEO driver timestamps clEnqueueBarrierWithWaitList / clEnqueueMarkerWithWaitList when the command enters the pipeline, not when the preceding work completes. So the barrier's CL_PROFILING_COMMAND_END can be earlier than the end of a kernel enqueued before it.

I confirmed this with a small pure-OpenCL reproducer on Intel Iris Xe (NEO 26.05.037020): any synchronization-only tag (barrier/marker, empty or explicit wait list) fails 100% of the time, while any real device command (kernel or buffer fill) gives correct timestamps - including a fill into a
dedicated buffer, which is what this PR does.

Changes

  • unified-runtime/.../opencl/event.cpp: implement urEnqueueTimestampRecordingExpusingclEnqueueFillBufferon a small internal buffer, whose timestamps do reflect completion of prior work. It needs command profiling, so if the queue isn't profiling-enabled we returnUR_RESULT_ERROR_UNSUPPORTED_FEATURE`.

  • unified-runtime/.../opencl/context.hpp: lazily-created, thread-safe 4-byte buffer per context, released with the context. It's never read - only the fill command's timestamps are used.

  • sycl/.../scheduler/commands.cpp (CGType::ProfilingTag): issue the recording with call_nocheck and fall back to a barrier on UR_RESULT_ERROR_UNSUPPORTED_FEATURE. Also addresses the existing TODO here.

  • sycl/.../experimental/profiling_tag.hpp: when the device lacks the aspect but the queue has profiling enabled, submit a profiling-tag command group (reusing the scheduler's in-order/out-of-order marker+barrier handling) instead of a bare barrier.

The device aspect stays false for OpenCL: the emulation needs queue profiling, but the aspect promises the tag works without it. Enabling the aspect (e.g. via an internal profiling queue) is a possible follow-up.

Level Zero / CUDA / HIP are unaffected - they advertise the aspect and already implement the recording, so they never take the fallback branch. The scheduler change only adds the fallback branch and turns a throwing call into a checked one; the success path is unchanged.

Testing

  • Unit tests (sycl/unittests/Extensions/ProfilingTag.cpp): split the old fallback test into two - native recording used on a profiling queue without the aspect, and the barrier fallback when the backend reports the recording unsupported.

  • E2E: dropped UNSUPPORTED: opencl && gpu from ProfilingTag/in_order_profiling_queue.cpp and ProfilingTag profiling_queue.cpp.

  • The reproducer's dedicated-buffer fill (matching this implementation) passes 200/200 iterations on Intel Iris Xe, vs. the old barrier fallback failing 200/200.

The NEO timestamping behavior is arguably a driver bug worth reporting separately; this is a runtime workaround that doesn't touch the public API or other backends.

P.S. I may have gone a little overboard with the code comments. If anyone else feels the same way, I will clean them up.

@crystarm crystarm requested review from a team as code owners July 15, 2026 11:33
@crystarm crystarm requested a review from againull July 15, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant