Skip to content

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
Step-by-step guide: how to use GPU.jsInstall, first run, examples, tips and FAQs

How to get it

  1. 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. 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. 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

ProjectStarsTypeLevelUpdatedBest for
gpu.js (this)15.5kLibraryintermediate6 days agoDevelopers who need to speed up large numeric computations in the browser
pixijs48.6kLibraryintermediate6 days agoWeb developers building interactive 2D graphics or animations
WebGL-Fluid-Simulation16.8kAppbeginner2.0 years agoPeople curious about how fluids behave in a visual, hands-on way
three.js117kLibraryintermediate4 days agoWeb developers adding interactive 3D graphics to a website
manim42.1kLibraryintermediate4 days agoProgrammers who want to make math or science explainer videos
xterm.js21.3kLibraryintermediate7 days agoDevelopers 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.