← Academy

Room 01 / GPU execution / recovered engine notes

One command’s journey through the GPU.

The CPU describes work. The GPU performs thousands of tiny copies of that work. The interesting machinery is everything that happens between those two sentences.

IntuitiveVisualTraceTechnicalCode
01 Trace

Follow the operation.

Select each stage. Notice how little of the actual calculation belongs to the CPU.

CPUDescribe the work
GPU
Workers are waiting

Put data in buffers. The CPU prepares memory the GPU can see; it does not calculate every result itself.

02 Intuitive

A kitchen with a locked pass.

Imagine a kitchen that can prepare ten thousand identical plates at once. You cannot walk in and move ingredients around while it works. You arrange labelled trays at the pass, write one exact recipe, and ring the bell.

Buffers are the trays. A bind group says which tray means what. A compute pipeline combines that wiring with the recipe. A command encoder writes the order. Submission rings the bell.

03 Technical

The five objects that matter.

  1. GPUBuffer

    Typed bytes visible to GPU work. Usage flags declare what may happen to them.

  2. GPUBindGroup

    The concrete resources attached to shader binding slots.

  3. GPUComputePipeline

    Compiled WGSL plus its resource interface.

  4. GPUCommandEncoder

    A recorder for passes and copies. Recording is not execution.

  5. GPUQueue

    The ordered submission boundary between prepared commands and device work.

04 Code

One-dimensional dispatch.

For 1,000 items and workgroups of 64, dispatch 16 groups. The final 24 invocations are real, but have no item.

@compute @workgroup_size(64)
fn update(@builtin(global_invocation_id) id: vec3<u32>) {
  if (id.x >= config.item_count) {
    return; // overshoot guard
  }

  output[id.x] = transform(input[id.x]);
}

pass.dispatchWorkgroups(Math.ceil(1000 / 64));

Reconstruction check: Why is the bounds test inside the shader even when the CPU already knows the item count?

Evidence boundary

Recovered from implementation notes for a WebGPU simulation engine: its compute mental model, dispatch organisation, persistent-resource rule, and overshoot guard. This notebook explains the mechanism; it does not publish or link the private engine.

Limits: Browser WebGPU implementations schedule workgroups independently. This explanation does not promise a specific execution order, performance gain, or cross-device floating-point identity.