FuseScope
Interface in Runtime
What the body of a fuse call receives: the scope that records the kernel calls the body makes, and makes the scratch arrays they share.
import type { FuseScope } from 'typeshade/fuse'
The signature, the description and the examples come from the compiler's own source at commit af54ddad5.
Syntax
interface FuseScope { readonly recorded: number; scratch(length: number, element?: 'f32'): ScratchBuffer<'f32'>; scratch(length: number, element: 'i32'): ScratchBuffer<'i32'>; scratch(length: number, element: 'u32'): ScratchBuffer<'u32'>; scratch(length: number, element: 'vec4f'): ScratchBuffer<'vec4f'>;}Instance properties
recordedread onlynumberHow many kernel calls the body has made so far. The scope has recorded them and has not run them: they run when the body returns.
Instance methods
scratch(length: number, element?: 'f32'): ScratchBuffer<'f32'>Make a scratch array: a handle for an intermediate between the calls of the body, which the host never reads. A kernel call in the body takes it where it takes an
array<f32>,array<i32>,array<u32>orarray<vec4f>, as theelementsays. It holds zeros when the plan starts, as a new buffer does. A'vec4f'array holdslengthvectors, so4 × lengthnumbers. It is aBuffer(change 0138, Amendment A10, slice 1): aBuffer<vec4f>for'vec4f', whoselengthcounts vectors (Amendment A11, Q5).Where the plan fuses every call that takes it into one dispatch, and each call reaches it at exactly the loop’s counter and never by its length, the fused entry holds it as a local: no device buffer and no host array of
lengthelements is made. Otherwise the plan makes a zeroed device buffer for the scope, or on the CPU tier and WebGL2 a zeroed host array when the first call needs it, and frees it when the plan has run, on success and on failure.read(),set(),resize(),at()andneedsUpdateof the handle are aTypeErrornaming it as scratch, and so is a kernel call that takes it outside the body of the scope that made it or after the plan has run. So is an entry call that takes it, in the body or after the plan has run: only a kernel call of the body may take a scratch array.dispose()does nothing: the plan frees the array, so a host that disposes every handle it holds stays correct. ABufferfromarray()keeps its buffer and its write inside a fused group, so the host may read it after the scope.scratch(length: number, element: 'i32'): ScratchBuffer<'i32'>scratch(length: number, element: 'u32'): ScratchBuffer<'u32'>scratch(length: number, element: 'vec4f'): ScratchBuffer<'vec4f'>
Source
src/core/fuse-plan.ts, line 85, at commit af54ddad5