
GPU.js
A JavaScript library that runs simple math functions on your GPU, with a CPU fallback.
- Stars
- 15.5k
- Forks
- 667
- Licence
- MIT
- Language
- JavaScript
- Last update
- 6 days ago
- Type
- Library
What it is
GPU.js lets you write ordinary JavaScript functions that it converts into GPU shader code, so they run in parallel on a graphics card. If no GPU is available, the same functions run as regular JavaScript. It works in browsers and in Node.js, and is aimed at heavy numeric work like matrix multiplication.
- Multiply two 512 x 512 matrices in the browser using a kernel
- Run the same numeric function on a grid of values in parallel
- Chain several kernels together so intermediate results stay on the GPU
- Use the same kernel code in Node.js and in a web page
Great for
- Developers who need to speed up large numeric computations in the browser
- Developers working with matrix or array math in JavaScript
- Students learning GPU-style parallel computing through JavaScript
- Projects that want a GPU path with an automatic CPU fallback
Not ideal for
- Projects that need a stable, non-breaking API long term, since the README says v3 will make kernel calls asynchronous and break existing sync code
- Simple tasks with small data, where GPU setup overhead may outweigh any speedup (the README gives no figures for small inputs)
- Users who need a general-purpose GPU framework for non-JavaScript languages
How to get it
- 1
Install with a package manager
You'll need: Node.js (version not specified in the README excerpt)
Install via npm (Node)
npm install gpu.js - 2
Run it
- Install the package with npm install gpu.js, or include the browser script from the CDN
- Create a GPU instance with new GPU()
- Write a function that computes one output element, using this.thread.x and this.thread.y
- Call gpu.createKernel(fn).setOutput([512, 512]) and invoke the returned kernel with your inputs
- 3
Get the most out of it
- Use mode: 'async' (added in 2.20.0) to write code that already matches the planned v3 API
- Use pipeline: true to chain kernels without reading back to the CPU between steps
- Follow the README migration guide with await and toArray() when moving to async
- Check the examples folder linked in the README for TypeScript usage
Downloads
Strengths
- Write plain JavaScript functions instead of shader language
- Falls back to regular JavaScript when no GPU is available
- Works in both browsers and Node.js, with TypeScript examples
Trade-offs
- The README announces a breaking v3 change making every kernel call return a Promise
- Synchronous readbacks block the main thread on WebGL backends, per the README
- Speedups vary; the README says typically 1-15x depending on hardware
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| gpu.js (this) | 15.5k | Library | intermediate | 6 days ago | Developers who need to speed up large numeric computations in the browser |
| pixijs | 48.6k | Library | intermediate | 6 days ago | Web developers building interactive 2D graphics or animations |
| WebGL-Fluid-Simulation | 16.8k | App | beginner | 2.0 years ago | People curious about how fluids behave in a visual, hands-on way |
| three.js | 117k | Library | intermediate | 4 days ago | Web developers adding interactive 3D graphics to a website |
| manim | 42.1k | Library | intermediate | 4 days ago | Programmers who want to make math or science explainer videos |
| xterm.js | 21.3k | Library | intermediate | 7 days ago | Developers building a browser-based IDE or cloud workspace that needs an integrated terminal |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.