gpujs /gpu.js

GPU Accelerated JavaScript

★ 15,530⑂ 667👁 232⑃ 238● 631▤ 121
JavaScriptMITCreated 2016-02-09gpu.rocks
Download: 2.24.12.24.1 ↓2.24.12026-09-24
+0
Daily
15,530
stars
667
forks
232
watchers
238
prs
631
issues
121
releases

README

GPU.js
GPU.js is a JavaScript Acceleration library for GPGPU (General purpose computing on GPUs) in JavaScript for Web and Node.
GPU.js automatically transpiles simple JavaScript functions into shader language and compiles them so they run on your GPU.
In case a GPU is not available, the functions will still run in regular JavaScript.
For some more quick concepts, see Quick Concepts on the wiki.

New to GPU programming? Learn GPGPU in your browser — a free, hands-on course that teaches the subject itself, not just this library. See Learn GPGPU below.







 What is this sorcery?

Creates a GPU accelerated kernel transpiled from a javascript function that computes a single element in the 512 x 512 matrix (2D array).
The kernel functions are ran in tandem on the GPU often resulting in very fast computations!
You can run a benchmark of this here. Typically, it will run 1-15x faster depending on your hardware.
Matrix multiplication (perform matrix multiplication on 2 matrices of size 512 x 512) written in GPU.js:

 Browser
html


    // GPU is a constructor and namespace for browser
    const gpu = new GPU();
    const multiplyMatrix = gpu.createKernel(function(a, b) {
        let sum = 0;
        for (let i = 0; i 


 CDN
 
https://unpkg.com/gpu.js@latest/dist/gpu-browser.min.js
https://cdn.jsdelivr.net/npm/gpu.js@latest/dist/gpu-browser.min.js


 Node
js
const { GPU } = require('gpu.js');
const gpu = new GPU();
const multiplyMatrix = gpu.createKernel(function(a, b) {
    let sum = 0;
    for (let i = 0; i  [!WARNING]
 The next major version of GPU.js will make every kernel call return a Promise.  This is a breaking API change: synchronous kernel calls as you write them today will not survive the v3 upgrade unchanged.  Code written against mode: 'async' (new in 2.20.0) already conforms and will run on v3 unchanged — the migration guide below is six steps.

This breaks the API you are using today, so it warrants both notice and an apology.  We owe you the apology because the original synchronous design was not forward-thinking, and we should have started async in the first place.  A GPU is an asynchronous device: you hand it work, and the results are ready later.  WebGL let this library pretend otherwise — readPixels silently freezes the page until the GPU catches up, and we built our API on that pretense because it made the first example look like an ordinary function call.  The cost has been paid by every user since: every kernel readback blocks the main thread for its full duration (measurably ~96% of a readback-heavy loop frozen, in one stall as long as the whole loop), and WebGPU — which has no synchronous readback at all, correctly — cannot be offered under the synchronous contract except as a walled-off special mode.  An async-first API would have cost one await in the examples and none of this debt.

v3 corrects the mistake: async everywhere, one contract, every backend.  The WebGL backends keep a synchronous escape hatch (setAsyncMode(false

Top issues

Latest release

2.24.1 2.24.1 2026-09-24
Kernels that subtract a negated value — a - -b — now compile on every backend instead of failing with a shader syntax error. No breaking changes.

 a - -b no longer compiles to a decrement

A negated operand was emitted with nothing between its minus sign and the one before it, so a - -b came out as a--b. GLSL, WGSL and JavaScript all read -- as the decrement operator, and the kernel failed to build: a syntax error on the webgl, webgl2 and headless-gl backends, a WGSL parse error on webgpu, and invalid generated JavaScript on cpu. Only webasm, which has its own code generator, was unaffected.

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON