Skip to content

[WebGPU] Fix profiling timestamp alignment with ORT profiler - #29021

Merged
Guenther Schmuelling (guschmue) merged 2 commits into
microsoft:mainfrom
daijh:webgpu-profiler
Jun 24, 2026
Merged

Guenther Schmuelling (guschmue) merged 2 commits into
microsoft:mainfrom
daijh:webgpu-profiler

Conversation

@daijh

Copy link
Copy Markdown
Contributor

Description

Add CPU time offset to WebGPU GPU profiling timestamps so they align with the ORT profiler's time base (microseconds since profiling start). Previously GPU events started from 0, causing misalignment in trace viewers.

Motivation and Context

See above.

@daijh

Copy link
Copy Markdown
Contributor Author

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts WebGPU GPU profiling timestamps to better align with ONNX Runtime’s profiler time base (microseconds since profiling start), avoiding GPU events that previously appeared to start at time 0 and were hard to correlate with CPU events in trace viewers.

Changes:

  • Store the ORT profiler’s profiling_start_time in WebGpuProfiler and pass it down to the WebGPU context for session-level profiling.
  • Track a CPU-side offset for the first GPU submission and add it to GPU event timestamps when emitting profiling::EventRecords.
  • Reset profiling alignment state (gpu_timestamp_offset_, first-submit CPU offset) each time profiling starts.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
onnxruntime/core/providers/webgpu/webgpu_profiler.h Exposes session profiling start time and stores it in the profiler.
onnxruntime/core/providers/webgpu/webgpu_profiler.cc Captures the profiling start time provided by ORT.
onnxruntime/core/providers/webgpu/webgpu_execution_provider.cc Passes session profiling start time into the context when starting profiling.
onnxruntime/core/providers/webgpu/webgpu_context.h Updates StartProfiling API to accept an explicit TimePoint and stores alignment state.
onnxruntime/core/providers/webgpu/webgpu_context.cc Computes CPU offset for the first submit and applies it to GPU event timestamps.

Comment thread onnxruntime/core/providers/webgpu/webgpu_execution_provider.cc Outdated
@guschmue Guenther Schmuelling (guschmue) added the ep:WebGPU ort-web webgpu provider label Jun 15, 2026
auto-merge was automatically disabled June 16, 2026 00:53

Head branch was pushed to by a user without write access

Add CPU time offset to WebGPU GPU profiling timestamps so they align
with the ORT profiler's time base (microseconds since profiling start).
Previously GPU events started from 0, causing misalignment in trace
viewers.
Run-level profiling previously called context_.StartProfiling() with the
default now() timepoint, captured in OnRunStart. That is later than the
profiling_start_time captured in Profiler::StartProfiling, so the GPU
CPU-offset was measured from a different origin than ORT's CPU events,
shifting all GPU events for run-level profiling.

Route the framework's profiling_start_time through WebGpuContext: the
WebGpuProfiler (the single hook that receives it for both session- and
run-level profiling) now pushes it via SetProfilingStartTime, and
StartProfiling() no longer takes a timepoint. This reaches the run-level
case, whose temporary profiler OnRunStart cannot access directly.
@daijh

Copy link
Copy Markdown
Contributor Author

Rebase

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@guschmue
Guenther Schmuelling (guschmue) merged commit cb16936 into microsoft:main Jun 24, 2026
85 checks passed
@daijh
Jianhui Dai (daijh) deleted the webgpu-profiler branch July 1, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ep:WebGPU ort-web webgpu provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants