Skip to content

[ExecuTorch][WebGPU] Fix per-op GPU-timestamp inflation on tile-based mobile GPUs#21033

Open
JCNTH wants to merge 1 commit into
gh/JCNTH/102/basefrom
gh/JCNTH/102/head
Open

[ExecuTorch][WebGPU] Fix per-op GPU-timestamp inflation on tile-based mobile GPUs#21033
JCNTH wants to merge 1 commit into
gh/JCNTH/102/basefrom
gh/JCNTH/102/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

The WebGPU per-op profiler (WebGPUQueryPool::extract_results) computed each pass's GPU time as end_of_pass - beginning_of_pass. On tile-based mobile GPUs (e.g. Arm Mali via Dawn -> Vulkan) the beginning-of-pass timestamps resolve at ~command-buffer start rather than per pass, so each (end - begin) measures time-since-start (cumulative) and the summed per-op time inflates by roughly the pass count (~100x on a Llama-1B decode). Desktop backends (Metal) capture beginning-of-pass correctly and are unaffected, which is why it only surfaces on-device.

Fix: compute each pass's duration from consecutive end timestamps by clamping each pass's base up to the previous pass's end (base = max(begin, prev_end)). On a well-behaved backend begin >= prev_end, so base == begin and the per-op numbers are byte-unchanged; on a tile-based GPU the clamp recovers the real per-pass time. The summed duration can no longer exceed the wall span by construction.

Key changes:

  • WebGPUQueryPool::fill_shader_durations (new free function) — sort by dispatch index, then per pass base = max(begin, prev_end), duration = end > base ? end - base : 0, tracking prev_end as a running max of end timestamps.
  • WebGPUQueryPool::extract_results — calls fill_shader_durations after mapping the readback (extraction makes the math unit-testable without a GPU).
  • #include <algorithm> for std::sort / std::max.
  • test_webgpu_native.cpp — device-free unit test QueryPoolDeltaMath covering the four regimes.

Entirely within #ifdef WGPU_BACKEND_ENABLE_PROFILING; no change to the non-profiling (production) build.

Differential Revision: D112643054

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21033

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit dc7e59e with merge base 44539fd (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 18, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant