accel-gpu

NumPy for the browser GPU — zero shaders, zero dependencies.

WebGPU · WebGL2 · CPU fallback

Install

npm install accel-gpu

Initialize

const gpu = await init();
const gpu = await init({ forceCPU: true });   // Force CPU for testing
const gpu = await init({ forceWebGL: true }); // WebGL2
const gpu = await init({ profiling: true });  // Enable profiling

Quick Start

import { init, matmul, softmax } from "accel-gpu";

const gpu = await init();
const a = gpu.array([1, 2, 3, 4]);
const b = gpu.array([5, 6, 7, 8]);
await a.add(b);
console.log(await a.toArray()); // [6, 8, 10, 12]

Features

Shape inference

No M, N, K — inferred from array shapes

Method chaining

add, mul return Promises for chaining

ML primitives

softmax, layerNorm, batchNorm, attentionScores

FFT & signal

fft, ifft, spectrogram

Conv & pool

conv2d, maxPool2d, avgPool2d

Universal

Safari, Firefox, Node, headless

Shape inference

const A = gpu.array(new Float32Array([1,2,3,4,5,6]), [2, 3]);
const B = gpu.array(new Float32Array([1,2,3,4,5,6]), [3, 2]);
const C = await matmul(gpu, A, B);

Method chaining

Await each step — add/mul return Promises.

const x = gpu.array([1, 2, 3, 4]);
await (await x.add(1)).mul(2);
console.log(await x.toArray()); // [4, 6, 8, 10]

ML primitives

const probs = await softmax(gpu, logits);
const normed = await layerNorm(gpu, x, gamma, beta);
const scores = await attentionScores(gpu, Q, K);
const spec = await spectrogram(gpu, signal, 256, 128);

Matrix ops

const invA = await inv(gpu, A);
const d = await det(gpu, A);
const x = await solve(gpu, A, b);

Fallback chain