Skip to content

[ExecuTorch][WebGPU] Add GPU timestamp-query profiling (WebGPUQueryPool)#20167

Open
JulianCloudNTH wants to merge 2 commits into
gh/JulianCloudNTH/21/basefrom
gh/JulianCloudNTH/21/head
Open

[ExecuTorch][WebGPU] Add GPU timestamp-query profiling (WebGPUQueryPool)#20167
JulianCloudNTH wants to merge 2 commits into
gh/JulianCloudNTH/21/basefrom
gh/JulianCloudNTH/21/head

Conversation

@JulianCloudNTH

@JulianCloudNTH JulianCloudNTH commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Add a faithful re-port of Vulkan's vkapi::QueryPool (backends/vulkan/runtime/vk_api/QueryPool.{h,cpp}) so a bench can read true on-GPU per-kernel time, isolated from submit/readback latency — the basis for comparing the WGSL SDPA kernels against the Vulkan reference. Opt-in via the WEBGPU_TIMESTAMP_QUERY env var; off by default, so the production execute() path is byte-identical.

WebGPUQueryPool mirrors the Vulkan ShaderDuration data model and the ticks->ns conversion exactly. Three deviations are forced by the WebGPU API (not unforced divergences): per-dispatch bracketing uses a compute-pass timestampWrites descriptor (begin/end-of-pass) since WebGPU has no mid-encoder writeTimestamp; results are read via resolveQuerySet + buffer map (no host-side vkGetQueryPoolResults); and the TimestampQuery capability is requested as an explicit device feature (fail-open if the adapter lacks it). WebGPUGraph::execute() brackets each compute pass when the pool is active; chained update_cache/QK/softmax/AV dispatches carry a kernel_name label for attribution.

Co-authored-with Claude.
@exported-using-ghexport

Differential Revision: D107678235

Differential Revision: D107678235

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 8a99e7a with merge base af92b60 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@github-actions

github-actions Bot commented Jun 9, 2026

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.

JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
Pull Request resolved: #20167

Add a faithful re-port of Vulkan's `vkapi::QueryPool` (`backends/vulkan/runtime/vk_api/QueryPool.{h,cpp}`) so a bench can read true on-GPU per-kernel time, isolated from submit/readback latency — the basis for comparing the WGSL SDPA kernels against the Vulkan reference. Opt-in via the `WEBGPU_TIMESTAMP_QUERY` env var; off by default, so the production `execute()` path is byte-identical.

`WebGPUQueryPool` mirrors the Vulkan `ShaderDuration` data model and the ticks->ns conversion exactly. Three deviations are forced by the WebGPU API (not unforced divergences): per-dispatch bracketing uses a compute-pass `timestampWrites` descriptor (begin/end-of-pass) since WebGPU has no mid-encoder `writeTimestamp`; results are read via `resolveQuerySet` + buffer map (no host-side `vkGetQueryPoolResults`); and the `TimestampQuery` capability is requested as an explicit device feature (fail-open if the adapter lacks it). `WebGPUGraph::execute()` brackets each compute pass when the pool is active; chained `update_cache`/QK/softmax/AV dispatches carry a `kernel_name` label for attribution.

Co-authored-with Claude.
ghstack-source-id: 391669549
@exported-using-ghexport

Differential Revision: [D107678235](https://our.internmc.facebook.com/intern/diff/D107678235/)
JulianCloudNTH added a commit that referenced this pull request Jun 9, 2026
Pull Request resolved: #20167

Add a faithful re-port of Vulkan's `vkapi::QueryPool` (`backends/vulkan/runtime/vk_api/QueryPool.{h,cpp}`) so a bench can read true on-GPU per-kernel time, isolated from submit/readback latency — the basis for comparing the WGSL SDPA kernels against the Vulkan reference. Opt-in via the `WEBGPU_TIMESTAMP_QUERY` env var; off by default, so the production `execute()` path is byte-identical.

`WebGPUQueryPool` mirrors the Vulkan `ShaderDuration` data model and the ticks->ns conversion exactly. Three deviations are forced by the WebGPU API (not unforced divergences): per-dispatch bracketing uses a compute-pass `timestampWrites` descriptor (begin/end-of-pass) since WebGPU has no mid-encoder `writeTimestamp`; results are read via `resolveQuerySet` + buffer map (no host-side `vkGetQueryPoolResults`); and the `TimestampQuery` capability is requested as an explicit device feature (fail-open if the adapter lacks it). `WebGPUGraph::execute()` brackets each compute pass when the pool is active; chained `update_cache`/QK/softmax/AV dispatches carry a `kernel_name` label for attribution.

Co-authored-with Claude.
ghstack-source-id: 391669549
@exported-using-ghexport

Differential Revision: [D107678235](https://our.internmc.facebook.com/intern/diff/D107678235/)
[ghstack-poisoned]
JulianCloudNTH added a commit that referenced this pull request Jun 10, 2026
Pull Request resolved: #20167

Add a faithful re-port of Vulkan's `vkapi::QueryPool` (`backends/vulkan/runtime/vk_api/QueryPool.{h,cpp}`) so a bench can read true on-GPU per-kernel time, isolated from submit/readback latency — the basis for comparing the WGSL SDPA kernels against the Vulkan reference. Opt-in via the `WEBGPU_TIMESTAMP_QUERY` env var; off by default, so the production `execute()` path is byte-identical.

`WebGPUQueryPool` mirrors the Vulkan `ShaderDuration` data model and the ticks->ns conversion exactly. Three deviations are forced by the WebGPU API (not unforced divergences): per-dispatch bracketing uses a compute-pass `timestampWrites` descriptor (begin/end-of-pass) since WebGPU has no mid-encoder `writeTimestamp`; results are read via `resolveQuerySet` + buffer map (no host-side `vkGetQueryPoolResults`); and the `TimestampQuery` capability is requested as an explicit device feature (fail-open if the adapter lacks it). `WebGPUGraph::execute()` brackets each compute pass when the pool is active; chained `update_cache`/QK/softmax/AV dispatches carry a `kernel_name` label for attribution.

Co-authored-with Claude.
ghstack-source-id: 391741952
@exported-using-ghexport

Differential Revision: [D107678235](https://our.internmc.facebook.com/intern/diff/D107678235/)
JulianCloudNTH added a commit that referenced this pull request Jun 10, 2026
Pull Request resolved: #20167

Add a faithful re-port of Vulkan's `vkapi::QueryPool` (`backends/vulkan/runtime/vk_api/QueryPool.{h,cpp}`) so a bench can read true on-GPU per-kernel time, isolated from submit/readback latency — the basis for comparing the WGSL SDPA kernels against the Vulkan reference. Opt-in via the `WEBGPU_TIMESTAMP_QUERY` env var; off by default, so the production `execute()` path is byte-identical.

`WebGPUQueryPool` mirrors the Vulkan `ShaderDuration` data model and the ticks->ns conversion exactly. Three deviations are forced by the WebGPU API (not unforced divergences): per-dispatch bracketing uses a compute-pass `timestampWrites` descriptor (begin/end-of-pass) since WebGPU has no mid-encoder `writeTimestamp`; results are read via `resolveQuerySet` + buffer map (no host-side `vkGetQueryPoolResults`); and the `TimestampQuery` capability is requested as an explicit device feature (fail-open if the adapter lacks it). `WebGPUGraph::execute()` brackets each compute pass when the pool is active; chained `update_cache`/QK/softmax/AV dispatches carry a `kernel_name` label for attribution.

Co-authored-with Claude.
ghstack-source-id: 391801048
@exported-using-ghexport

Differential Revision: [D107678235](https://our.internmc.facebook.com/intern/diff/D107678235/)
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant