Skip to main content

GPU operations and composition

Overview​

GPUGraph stores semantic operations. GPUGraphCompiler lowers them into explicit command nodes and the command graph compiles those nodes into executable WebGPU work.

At a glance

QuestionAnswer
ProblemDescribe GPU work semantically before selecting concrete backend commands.
Reads / writesOperations name logical inputs and outputs through metadata or typed properties.
OwnershipSemantic operations own no GPU resources and perform no command submission.
Output contractAn inspectable operation tree that a backend compiler can lower.
Expected workMetadata describes logical work; the selected lowering determines physical commands.
ChunksLogical shapes remain explicit and are not implicitly combined or repacked.
Conditions / budgetsA GPUGraphCompiler selects and records the executable realization.
Neighborhoodapplication intent → GPUGraphOperationInstance tree → backend lowering → command graph.
const program = new GPUGraph({id: 'analysis'});
program.add([operation1, operation2]);
program.add(composite, [spmv, dot, update], {id: 'solver-step'});
const compilation = new GPUGraphCompiler(device).compile(program, bindings);
const executable = compilation.graph.compile();

Arrays add sibling operations; composites preserve named hierarchy for inspection. Neither implies synchronization. Resource hazards and explicit dependencies determine execution order.

A GPUGraphOperationInstance declares id, type, and optional metadata. Its registered backend lowerer resolves logical resources and emits nodes. GPUGraphCommandProducer instead exposes getCommandNodes(graph): readonly GPUCommandGraphEntry[]. It may declare graph-owned scratch resources, but must not schedule nodes, encode, submit, or read back data while constructing them.

Existing graph-bound primitives can be scheduled directly with graph.add(primitive). Program primitives must construct resources against the graph supplied by the compiler.

add() returns the builder on both graph types. A configured GPUCommandGraphContributor can contribute work and a result under a unique ID. Look up its borrowed result with graph.getContribution(id) before compilation so downstream commands can bind its resources. The command graph owns the contribution. A GPUGraph operation declares logical ports and lowers through the program compiler.

graph.if() and graph.loop() capture structured control flow. WebGPU lowers GPU predicates using indirect dispatch and bounded loops using repeated commands; compiler support nodes remain unconditional.

A producer can return child producers or nested arrays from getCommandNodes(graph). Both builders expand these execution nodes in order. Use graph.createScope({id}) and graph.add(scope) to preserve a named semantic hierarchy for inspection.