Open code, practice, and notes →
Download source with English comments · for reading
WebGPU · 25 CPU References and Error Budgets
Series contents · Technology map
Stage: Recovery, Measurement, and an Integrated Project · Editable example · Storage ID: webgpu-step-25
Goals and learning outcomes
- Write a CPU reference.
- Judge numerical error explicitly.
Prerequisites
Continue using the output and notes from unit 24. Preserve the previous inputs and reference outputs before the CPU References and Error Budgets experiment.
Key concepts and explanations
Floating Point
CPU JavaScript number and GPU f32 operations have different precision. Summation with a different association order can produce small errors.
Validation Criteria
Absolute and relative error serve different roles depending on magnitude. Define tolerances and special-value handling before viewing results.
Practice setup
First read the execution-scope guidance on the example screen. The following preparation is for extending the assignment in a separate project. This is a document-guided exercise to implement yourself in a separate localhost or HTTPS project. Check the secure context, navigator.gpu, and adapter request result, and provide an unsupported-environment message. Preserve device.lost handling and resource release.
The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.
Practice tasks
- In reference.js, write a CPU particle-update function and generate fixed-seed inputs.
- Calculate per-element absolute and relative errors against the readback result.
- For inputs containing 0, negative, small, and large values, print the maximum error and failing indices.
Variables to observe
| Variable | Baseline | Change | Expected change / hypothesis |
|---|---|---|---|
| Validation input | Small positive values | Mix of 0, negative, and large values | Inputs of different magnitudes are expected to expose limitations of a relative-error-only criterion. |
Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.
Completion criteria
- Record the tolerance abs<=1e-5+1e-4*abs(reference) in advance.
- On failure, print the element index, reference value, and GPU value.
Self-check
- Which tasks require exactly identical bit results?
- Can including NaN in error comparisons allow a check to pass?
Official references
Linked example and execution scope
Example source · Runtime environments and limits
Runs real WebGPU/WGSL. Requires HTTPS/localhost and a supported adapter; unsupported environments display a reason, and CPU results are not substituted for GPU results.
Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.
Next learning
Previous: The Scope of Timing · Next: Workgroup Size Experiments