Compile expression metrics to WGSL so the GPU backend serves them - #9658
Draft
kube wants to merge 8 commits into
Draft
Compile expression metrics to WGSL so the GPU backend serves them#9658kube wants to merge 8 commits into
kube wants to merge 8 commits into
Conversation
kube
added this pull request to stack #9549
September 11, 2026 01:15
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
…che on the artifact fingerprint
…etric state binder
kube
force-pushed
the
claude/opt-proto-gpu-metrics
branch
from
September 11, 2026 02:34
491f060 to
69b5a79
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Experimental
Behind the WebGPU feature flag.
Summary
Before this PR, the GPU backend measured one kind of metric: a place's token count, sampled into a per-frame histogram of unsigned integers with one bin per count. Every expression metric, which is every optimizer objective and most of the bundled examples' metrics, forced the whole experiment back to the CPU, and the editor's GPU switch refused it with a sentence of its own before core was asked. Frame 0 was built on the host from the initial marking, and the shader compiler was keyed on the artifact object's identity.
This PR compiles metric HIR to WGSL. The lowered metric function travels on its artifact under the existing
includeHiroption, one device-free probe decides per metric whether the emitter can translate it, and the gate, the compilation report and the editor's switch all read that probe. The emitter learns a place's live tokens as a runtime-length span:tokens.lengthreads the count andtokens.reducewith a numeric accumulator becomes a loop over the live slots, the shape the dynamics already emit. Every metric, place counts included, is sampled as an f32 and binned through one window with a calibrated range, exact integer labels kept for integer metrics. Frame 0 is sampled on the device before the first step. Of the bundled examples' 30 model metrics, 28 now run on the GPU; the two.concatbodies stay on the CPU with the reason shown per metric. Measured on the SIR example, the GPU's Infected Fraction agrees with the CPU within 0.1% per frame at 2000 runs.Links
Changes
Metric HIR to the shader
Emitter
Histograms
sampleRunshonouredReport and editor
metricrowsKnown issues
allsampling on the GPUNext steps
.concatover several places' tokens as a list of spansTest coverage
emit-wgsl.test.ts:compile-net-shader.test.ts:try-translate-metric.test.ts:metric-windows.test.ts,runner/histogram-frames.test.ts,gpu-experiment-handle/calibration.test.ts:gpu-metric-frames.test.ts,compilation-report.test.ts,artifacts.test.ts,gpu-backend-cache.test.ts:create-optimization-drawer.test.tsx,create-experiment-drawer.test.tsx,provider.test.tsx:How to test