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.

    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 browser GPU API, shipping in Chrome 113+ and Firefox nightly. 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 does not support f64 natively, so this library currently implements single-precision (f32) routines only.

    Each routine runs a compute shader written in WGSL (a GPU program that runs thousands of instances in parallel, each processing one element). 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