Rule 11.7
On this page

Rule 11.7

Chapter 11, Targets and the oracle Test

The CPU tier, which runs a host call of a module’s function and, where there is no GPU tier, the invocations of an entry a host calls and the pixels of a fragment entry a host draws (Rule 8.24), is the oracle’s generated code (generateModuleJs) at f32 precision, written into the module the bundler reads as module code, with no new Function, over the op library alone, typeshade/runtime/internal. The CPU tier holds a kernel function’s texture in memory of its own (change 0077): a CpuTexture of src/core/cpu-texture.ts, the texels of a 2D texture in row order as the bytes of its format, which device.texture() makes on a device with no WebGPU device and which an ImageData is copied into. Over such a texture textureLoad, textureStore and textureDimensions compute: a store converts the value as WebGPU converts it for the format (a float format keeps the f32, a unorm or snorm one clamps to its range and rounds to the nearest step, an integer one keeps the low bits), a load outside the texture reads the nearest texel inside and a store outside is dropped. Every other texture builtin, and any of these over a texture that is not in that memory, keeps the stub contract (GPU_STUBS).

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

Rationale

a host call computes what the GPU would, so it rounds as f32 does, which the default f64 algebra oracle is blind to by construction. The generated code computes each operation as the interpreter’s runtime helper does: a vector operation of a known width, on operands nothing can leave missing, is written one component at a time, each the scalar operation the helper applies to it (dot, length, distance, normalize and cross summed in the order their entries sum), and every other operation, one on an operand that may be missing (a helper’s discard, an element read past an array’s end) among them, calls the helper itself; src/core/cpu-codegen.test.ts holds the two to each other bit for bit in both precisions, so the tier is the oracle and not a fourth implementation (Rule 11.1). Building it with new Function at run time would need unsafe-eval, which a strict content security policy forbids, and would ship the IR and the generator; as module code it is minified with the application, and the application ships the op library only.

Derives from

change 0009 in changes/ (“The CPU tier’s precision”); src/core/oracle.ts (the 'f32' mode, “a correctly-rounding f32 machine over the same IR”); Rule 11.1.

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:

hostFace in src/compiler/ts/host-face.ts, which generates at precision: 'f32', and src/runtime/host/runtime.ts, what a generated module imports through typeshade/runtime/internal; pinned by src/compiler/ts/host-face.test.ts, where every call equals compileModule(m, { precision: 'f32' }) on inputs chosen so the f32 and f64 answers part, and the generated module holds no new Function. The texture memory is CpuTexture and cpuTextureCall in src/core/cpu-texture.ts, which the generated code’s gpuStub asks first (src/core/cpu-codegen-runtime.ts); pinned by src/core/cpu-texture.test.ts (each format’s conversion, the channels, the edge), by src/compiler/ts/host-kernel-texture.test.ts (a kernel call on a device of the CPU tier, each byte as the format rounds it) and by the import journey, whose CPU-tier run of invertImage gives each byte its WebGPU run gives (change 0077).

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