Repolode
gpujs

gpujs/gpu.js

GPU.js transpiles simple JavaScript functions into GPU shader code so they run on the GPU in browsers and Node.js, falling back to plain JavaScript.

Stars
15,511
Forks
666
Open issues
68
Last commit
14 days ago

What is it?

GPU.js is a JavaScript library for general-purpose computing on GPUs (GPGPU) in both the browser and Node.js. You write a plain JavaScript function that computes one element of an output array, and GPU.js transpiles it into shader language and compiles it to run in parallel on the GPU. If no GPU is available, the same function runs in regular JavaScript.

The library is built around kernels created with gpu.createKernel(), where the output size is set with setOutput() and each thread reads its position through this.thread.x, y and z. Supported backends include WebGL, WebGL2, headless GL for Node, WebAssembly, WebGPU (opt-in) and a CPU fallback. Kernels can be chained with combineKernels() or pipelined so intermediate results stay on the device.

GPU.js also supports graphical output to a canvas, a debug mode for stepping through kernel code with breakpoints, and TypeScript typings. Its v3 direction makes kernel calls return Promises, and an async mode is already available.

Key features

  • 01Transpiles plain JavaScript functions into GPU shader code automatically.
  • 02Falls back to regular JavaScript when no GPU is available.
  • 03Runs in browsers and Node.js with WebGL, WebGL2, headless GL and WebGPU backends.
  • 04Chains kernels with combineKernels() and pipelining to avoid repeated data transfers.
  • 05Renders results to a canvas in graphical mode.
  • 06Includes a dev mode for debugging kernels with breakpoints and TypeScript typings.

Use cases

  • Accelerating matrix operations or numerical computations in a web page.
  • Running image processing or filters on pixel data in the browser.
  • Prototyping GPU-parallel algorithms in JavaScript before porting to lower-level code.
  • Speeding up data-heavy calculations in Node.js services with a GPU available.

Quick start

  1. 1

    Install the package from npm

    npm install gpu.js
  2. 2

    Create a GPU instance and a kernel in Node.js

  3. 3

    Use the browser build via script tag or CDN

Things to know

  • The next major version v3 will make every kernel call return a Promise, breaking synchronous code written today.
  • Synchronous kernel calls rely on WebGL readback that blocks the main thread.

Topics

FAQ

What is gpu.js?
GPU.js transpiles simple JavaScript functions into GPU shader code so they run on the GPU in browsers and Node.js, falling back to plain JavaScript. GPU.js is a JavaScript library for general-purpose computing on GPUs (GPGPU) in both the browser and Node.js. You write a plain JavaScript function that computes one element of an output array, and GPU.js transpiles it into shader language and compiles it to run in parallel on the GPU. If no GPU is available, the same function runs in regular JavaScript.
Is gpu.js free to use? What license does it have?
gpu.js is open source under the MIT license. Check the license terms before using it in commercial products.
Is gpu.js still maintained?
Actively maintained. The last commit to gpu.js was on Oct 5, 2026.
What can I use gpu.js for?
Accelerating matrix operations or numerical computations in a web page. Running image processing or filters on pixel data in the browser. Prototyping GPU-parallel algorithms in JavaScript before porting to lower-level code. Speeding up data-heavy calculations in Node.js services with a GPU available.
How do I install gpu.js?
Install the package from npm: npm install gpu.js Create a GPU instance and a kernel in Node.js Use the browser build via script tag or CDN
Where can I get gpu.js?
The source code and installation instructions are on GitHub: https://github.com/gpujs/gpu.js

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects