Rule 11.23
On this page

Rule 11.23

Chapter 11, Targets and the oracle Test

A compiled program may carry more than one WGSL text of a compute entry (a variant). Every variant of an entry must write the same bits for every input, except where a rule records a divergence between them. The runtime must select a variant when it opens a device, from the device’s features and from a known-answer probe that runs the variant’s shape once on the device and compares what it wrote with the known answer; a variant whose probe fails, or whose feature the device lacks, must not be selected, and the device’s report must say what the probe saw and which text each kernel call ran. A feature a variant alone needs must not be in the module’s requiredFeatures (Rule 10.2); the runtime requests it where the adapter has it. The subgroup variant of a kernel function’s loop (Rule 8.22) is one: it needs subgroups, createDevice({ subgroups: 'off' }) keeps it off, DeviceInfo.subgroups is the probe’s observation and DeviceStatistics.variants the text each call ran.

The rule text and the parts under it are the compiler's own English, as the design document writes them.

Rationale

docs/compiler-owns-performance.md (sections 1 and 6): a program must become faster when the compiler improves with no change to its source, and a device difference belongs to the compiler and the runtime, so a faster form a device may lack is a text the runtime picks, as the emulated double’s flavor is picked (changes 0073 and 0085), and a probe selects it on a device with unknown signals and refuses it on one whose driver folds wrongly. A WGSL module that spells enable subgroups; does not compile on a device without the feature, so a branch inside one text cannot choose. The bits are held equal so that selection is invisible to the author; a divergence a rule records (an f32 sum, Rule 7.2) is kept out of every variant until the rule changes.

Derives from

changes/0119-subgroup-reduction-variant.md (sections 2 to 5, decisions O1, O3 and O4); docs/compiler-owns-performance.md; changes 0073 and 0085 (the flavor axis); #536.

How it is verified

Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.

Where the rule says the compiler enforces it:

src/core/subgroup-probe.ts (the probe’s text, its known answers and probeSubgroups), pinned by src/core/subgroup-probe.test.ts; createDevice and DeviceImpl in src/runtime/device.ts and gpuDevice in src/core/host-entry.ts (the probe at open, the option, the observation and the statistics), pinned by src/runtime/device.test.ts (a device that passes, fails, lacks the feature or keeps it off, and the default owner); textOf in src/core/host-kernel.ts (the dispatch’s choice); journeys/subgroup-folds/ (equal bits on a device that selects the variant).

The files that verify it at commit af54ddad5, each at the first line that names the rule:

Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

See also

Source

The rule at commit af54ddad5:

Edit this page Report a problem