Open code, practice, and notes →
Download source with English comments · for reading
WGSL · 28 Compute and Boundaries
Series contents · Technology map
Stage: Numeric Verification and Kernel Design · Editable example · Storage ID: wgsl-03
Goals and learning outcomes
- Apply a boundary strategy for each kernel.
- Verify layout, synchronization, and numeric correctness together.
Prerequisites
Continue using the output and records from Unit 27. Before experimenting with Compute and Boundaries, preserve the previous inputs and reference outputs.
Key concepts and explanations
Combining Boundary Strategies
Logical element counts may differ from invocation counts. Apply early return for independent kernels separately from neutral-value participation in cooperative kernels.
Combining Verification
Check correctness through the final element, partial workgroups, and repeated execution. Even with correct barriers and memory layout, incorrect formulas need separate CPU comparisons.
Practice setup
The existing wgsl-03 preview is a starting point. It does not replace implementation or verification of the full subsequent assignment. This document-guided exercise requires your own implementation in a separate localhost or HTTPS project. Check the secure context, navigator.gpu, and adapter request result, and provide an unsupported-environment message. Retain device.lost handling and resource cleanup.
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
- Run map, reduction, and stencil at lengths 1, 65, and 1003, and compare with CPU references.
- Mark pre-access checks in independent kernels and all-lane barrier participation in reduction in the source.
- In report.md, collect the final element, sentinel, maximum error, total latency, and device information, then judge the completion criteria.
Variables to observe
| Variable | Baseline | Change | Expected change / hypothesis |
|---|---|---|---|
| Element count | Multiple of 64 | 65 and 1003 | Correct handling of extra lanes is expected to produce CPU-matching results without missing elements. |
Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.
Completion criteria
- Results and final-element checks are recorded for three kernels and three lengths.
- Synchronization paths contain neither nonuniform barriers nor wait loops between groups.
Self-check
- Why does copying a bounds return directly into reduction cause failure?
- What must be saved for reproduction besides matching results?
Official references
Linked example and execution scope
Example source · Runtime environments and limits
Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.