gpujs/gpu.js
GPU Accelerated JavaScript
What it solves
GPU.js is a JavaScript acceleration library that enables General Purpose computing on GPUs (GPGPU) for both Web and Node.js environments. It allows developers to run computationally intensive tasks—such as matrix multiplication, convolutions, and simulations—on the GPU to achieve significant performance gains (often 1-15x or more) compared to regular JavaScript execution on the CPU.
How it works
The library automatically transpiles simple JavaScript functions (called kernels) into shader languages (like GLSL or WGSL) and compiles them to run on the GPU. It supports multiple backends, including WebGPU (via WGSL compute shaders), WebGL2, WebGL, and HeadlessGL for Node.js. If a GPU is unavailable, it provides a guaranteed fallback to plain JavaScript (CPU backend) or WebAssembly with SIMD and threads.
Who it’s for
It is designed for JavaScript and TypeScript developers who want to GPU-accelerate their applications without needing to write complex shader code manually. It is also used as a teaching tool for those learning the fundamentals of GPGPU programming.
Highlights
- Automatic Transpilation: Converts JS functions into GPU kernels.
- Multiple Backends: Supports WebGPU, WebGL, WebGL2, and HeadlessGL.
- Cross-Platform: Works in the browser and in Node.js.
- Pipelining: Allows keeping intermediate results on the GPU to avoid expensive read-backs to the CPU.
- Async-First Architecture: Moving toward an asynchronous API (v3) to better leverage WebGPU and prevent main-thread freezing.
Related
- Project
- Project
- Project
- Project
- Project