πŸŽ‡ WebGPU the graphics card, as a general-purpose computer

Our WebGL cube used the GPU to draw. WebGPU β€” its successor β€” also lets pages use the GPU to compute: thousands of parallel cores running your kernel. This demo squares sixteen million numbers on the GPU and races the CPU doing the same, one at a time.

The entire GPU program β€” WGSL, a shading language, inline in this page:

@group(0) @binding(0) var<storage, read_write> data: array<f32>;

@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) id: vec3u) {
    data[id.x] = data[id.x] * data[id.x];
}