explaingit

gpujs/gpu.js

15,358JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A JavaScript library that automatically runs heavy number-crunching code on the GPU for big speed gains, working in browsers and Node.js with a transparent CPU fallback when no GPU is available.

Mindmap

mindmap
  root((gpu.js))
    What it does
      GPU compute in JavaScript
      Auto shader transpilation
      CPU fallback
    Use cases
      Matrix multiplication
      Image processing
      Physics simulations
      Scientific computing
    Environments
      Web browser
      Node.js
    Tech
      JavaScript TypeScript
      WebGL shaders
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Speed up matrix multiplication or large array math in a browser app by running it on the GPU instead of in JavaScript.

USE CASE 2

Build real-time image or video processing (filters, convolution) that runs many times faster than plain JavaScript.

USE CASE 3

Create smooth interactive simulations, fractals, Game of Life, Voronoi, in the browser without server-side compute.

USE CASE 4

Accelerate a Node.js data-processing script that needs to crunch large numerical datasets in parallel.

Tech stack

JavaScriptTypeScript

Getting it running

Difficulty · easy Time to first run · 30min

In plain English

GPU.js is a JavaScript library that lets you run computations on a computer's GPU (graphics processing unit) from JavaScript code, either in a web browser or in Node (a runtime that lets JavaScript run outside the browser). A GPU is the chip normally used to draw graphics, but it is also very fast at doing many small numerical calculations in parallel, a technique called GPGPU, or general-purpose computing on GPUs. The way it works is that you write a regular JavaScript function that describes how to compute one element of a result, for example one cell of a large matrix. GPU.js then automatically transpiles that function into shader language, the specialized code GPUs understand, and compiles it so it can run on the GPU. Many copies of your function then execute in parallel, which can make a heavy computation finish far faster than ordinary JavaScript. The README's headline example performs matrix multiplication on two 512-by-512 matrices, and notes that depending on hardware GPU.js typically runs 1 to 15 times faster than plain JavaScript. If no GPU is available, the same function will still run on the CPU as normal JavaScript. You would reach for GPU.js when a JavaScript project needs to do a lot of math, image processing, simulations, fractals, cellular automata, graph algorithms, or scientific visualizations, and plain JavaScript is too slow. The README links to demos including Mandelbrot rendering, image and video convolution, heatmaps, Dijkstra's algorithm, Conway's Game of Life, and Voronoi diagrams. The library is JavaScript with TypeScript typings, installs through npm or yarn, and can also be loaded into a browser via a CDN script tag.

Copy-paste prompts

Prompt 1
Using GPU.js, write a browser script that multiplies two 1024x1024 matrices on the GPU and compares the time against plain JavaScript.
Prompt 2
Show me how to implement a Gaussian blur image filter in GPU.js that processes a canvas element in real time.
Prompt 3
Build an interactive Mandelbrot set renderer in GPU.js that re-renders instantly when the user zooms in or out.
Prompt 4
How do I use GPU.js in a Node.js script to parallelize a large numerical array computation that's too slow in plain JavaScript?
Prompt 5
Write a GPU.js kernel that simulates Conway's Game of Life on a 2000x2000 grid and renders it on a canvas at 60fps.
Open on GitHub → Explain another repo

← gpujs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.