wgblas
    Preparing search index...

    Module devdocs

    A repo tour for contributors, learners, and anyone curious how a GPU BLAS library is built. Each section mirrors a major folder or system in the repository and explains the reasoning behind it — not just what the code does, but why it is shaped the way it is.

    The sidebar's top-level modules mirror the repository's top-level folders. devdocs stands in for src/ — the module you're reading right now is a narrated walkthrough of it, with devdocs/blas-routines and devdocs/shaders covering src/index.mjs and src/shaders/ respectively. Its siblings — assets, benchmarks, examples, scripts, tests — each document the identically-named top-level folder.

    docs is the one exception: it's the public API reference generated from index.d.mts, not a tour of the top-level docs/ folder. That folder is this site's own generated output — the two just happen to share a name.

    BLAS (Basic Linear Algebra Subprograms) is a standard API for vector and matrix operations — dot products, norms, scalar multiplies, matrix-vector products. It is the computational backbone of numerical computing, machine learning frameworks, and scientific software. The reference spec lives at netlib.org/blas.

    GPUs are well-suited for BLAS: operations like saxpy (y = αx + y) are embarrassingly parallel — each element is independent — so thousands of GPU threads can work simultaneously. NVIDIA's cuBLAS is the canonical example; this library applies the same idea to the browser via WebGPU.

    WebGPU is the modern GPU API for JavaScript — shipping in Chrome and Edge (113+), Safari (26+) and Firefox (141+, Windows first), and available in Node.js through Dawn (the webgpu npm package, which is what this library's tests and benchmarks run on). It lets JavaScript programs upload data to the GPU, run compute programs on it, and read results back — without plugins or native code.

    Note: WGSL has no native f64, so the double-precision d* routines emulate it with double-double arithmetic: each value is a pair of f32s (hi + lo), giving about 48 bits of significand but f32's exponent range — close to, not identical to, IEEE double. See devdocs/utility-functions/f64 for the host-side split and merge.

    Each routine runs a compute shader written in WGSL (a GPU program that runs thousands of instances in parallel, each handling a slice of the work — one element, a strided run of elements, or a tile). WebGPU has vertex and fragment shaders for graphics too — compute shaders are specifically for general computation. This library only uses compute shaders, so we call them simply "shaders" throughout.

    Read these two chapters from the CUDA Programming Guide — the mental models transfer directly to WebGPU; only the terminology changes. Then come back here.

    CUDA WebGPU
    Thread Invocation
    Thread block Workgroup
    Grid Dispatch
    __global__ function @compute shader
    threadIdx.x local_invocation_id
    blockIdx.x workgroup_id
    blockDim.x @workgroup_size(N)
    Shared memory var<workgroup>
    Global memory Storage buffer
    cudaMemcpy host→device device.queue.writeBuffer
    cudaMemcpy device→host mapAsync + getMappedRange