CpuModule
On this page

CpuModule

Interface in CPU oracle

The shape both CPU backends return, so a caller can compile with compileModuleJs and fall back to compileModule without touching call sites.

import type { CpuModule } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

interface CpuModule {
fns: Record<string, (...args: CpuValue[]) => CpuValue>;
setBinding(name: string, value: CpuValue): void;
dispatch(entry: string, workgroups: WorkgroupCount): DispatchReport;
}

Description

fns is a table of the module’s declared functions by name, each taking its parameters positionally in declaration order. setBinding supplies a storage or uniform binding’s value before a function that reads it runs. The two backends return the same value for the same call: compileModuleJs(m).fns.f(args) and compileModule(m).fns.f(args) agree under Object.is, element for element.

Instance properties

fns Record<string, (...args: CpuValue[]) => CpuValue>

The module’s declared functions by name. Parameters are positional, in declaration order; the return value is the function’s result as a CpuValue.

Instance methods

setBinding (name: string, value: CpuValue): void

Supply a storage or uniform binding’s value by its declared name, before invoking a function that reads it.

dispatch (entry: string, workgroups: WorkgroupCount): DispatchReport

Run a @compute entry over workgroups workgroups of its declared size (one number for a 1-D grid, or the three counts), every invocation of a workgroup in lockstep at each workgroupBarrier() / storageBarrier(), with the builtin parameters (global_invocation_id, local_invocation_id, local_invocation_index, workgroup_id, num_workgroups) filled in (roadmap 0.2 item 5). Workgroup memory starts zero for each workgroup and a per-invocation variable at its initializer for each invocation; the bindings are the ones setBinding supplied, arrays written in place. Throws when the invocations of one workgroup disagree about a barrier, naming its line and the counts. A kernel with no barrier may also be run one invocation at a time through fns.

In the guide

See also

Source

src/core/oracle.ts, line 130, at commit 26de7be8

Edit this page Report a problem