gpujs / gpu.js
GPU Accelerated JavaScript
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing gpujs/gpu.js in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewGPU.js GPU.js is a JavaScript Acceleration library for GPGPU (General purpose computing on GPUs) in JavaScript for Web and Node. GPU.js automatically transpiles simple JavaScript functions into shader language and compiles them so they run on your GPU. In case a GPU is not available, the functions will still run in regular JavaScript. For some more quick concepts, see Quick Concepts on the wiki. What is this sorcery? Creates a GPU accelerated kernel transpiled from a javascript function that computes a single element in the 512 x 512 matrix (2D array). The kernel functions are ran in tandem on the GPU often resulting in very fast computations! You can run a benchmark of this here. Typically, it will run 1-15x faster depending on your hardware. Matrix multiplication (perform matrix multiplication on 2 matrices of size 512 x 512) written in GPU.js: Browser CDN Node Typescript Click here for more typescript examples. Table of Contents Notice documentation is off? We do try our hardest, but if you find something, please bring it to our attention, or _become a contributor_! • Demos • Installation • Settings • Settings • Declaring variables/functions within kernels • Creating and Running Functions • Debugging • Accepting Input • Graphical Output • Combining Kernels • Create Kernel Map • Adding Custom Functions • Adding Custom Functions Directly to Kernel • Types • Loops • Pipelining • Cloning Textures • Cleanup pipeline texture memory • Offscreen Canvas • Cleanup • Flattened typed array support • Precompiled and Lighter Weight Kernels • using JSON • Exporting kernel • Supported Math functions • How to check what is supported • Typescript Typings • Destructured Assignments • Dealing With Transpilation • Full API reference • How possible in node • Testing • Building • Contributors • Contributing • Terms Explained • License Demos GPU.js in the wild, all around the net. Add yours here! • Temperature interpolation using GPU.js • Julia Set Fractal using GPU.js • Hello, gpu.js v2 • Basic gpu.js canvas example • Raster projection with GPU.js • GPU.js Example: Slow Fade • GPU.JS CA Proof of Concept • Image Convolution using GPU.js • Leaflet + gpu.js canvas • Image to GPU.js • GPU Accelerated Heatmap using gpu.js • Dijkstra’s algorithm in gpu.js • Voronoi with gpu.js • The gpu.js loop • GPU.js Example: Mandelbrot Set • GPU.js Example: Mandelbulb • Inverse of the distance with gpu.js • gpu.js laser detection v2 • GPU.js Canvas • Video Convolution using GPU.js • GPU Rock Paper Scissors • Shaded relief with gpujs and d3js • Caesar Cipher GPU.js Example • Matrix Multiplication GPU.js + Angular Example • Conway's game of life Installation On Linux, ensure you have the correct header files installed: (adjust for your distribution) npm yarn npm package Node Node Typescript **New in V2!** Browser Download the latest version of GPU.js and include the files in your HTML page using the following tags: Settings Settings are an object used to create an instance of . Example: • : . Optional. For sharing canvas. Example: use THREE.js and GPU.js on same canvas. • : or . For sharing rendering context. Example: use THREE.js and GPU.js on same rendering context. • : Defaults to 'gpu', other values generally for debugging: • 'dev' **New in V2!**: VERY IMPORTANT! Use this so you can breakpoint and debug your kernel! This wraps your javascript in loops but DOES NOT transpile your code, so debugging is much easier. • 'webgl': Use the for transpiling a kernel • 'webgl2': Use the for transpiling a kernel • 'headlessgl' **New in V2!**: Use the for transpiling a kernel • 'cpu': Use the for transpiling a kernel • : Removed in v2.11.0, use v8 coverage • : Removed in v2.11.0, use v8 coverage Settings Settings are an object used to create a or . Example: • or : or that describes the output of kernel. When using you _can_ call it after the kernel has compiled if is , to resize your output. Example: • as array: , , or • as object: • or **New in V2!**: boolean, default = • Causes calls to output a . To get array's from a , use: • Can be passed _directly_ into kernels, and is preferred: • or : boolean, default = • or : number, default = 1000 • or : object, default = null • or : boolean, default = false - turns dynamic output on or off • or : boolean, default = false - turns dynamic arguments (use different size arrays and textures) on or off • or **New in V2!**: boolean - causes a float32 texture to use all 4 channels rather than 1, using less memory, but consuming more GPU. • or **New in V2!**: 'single' or 'unsigned' - if 'single' output texture uses float32 for each colour channel rather than 8 • or : boolean - some cards have accuracy issues dividing by factors of three and some other primes (most apple kit?). Default on for affected cards, disable if accuracy not required. • or : array, array of functions to be used inside kernel. If undefined, inherits from instance. Can also be an array of . • or : object, defined as: . This is generally set via using GPU.addNativeFunction() • VERY IMPORTANT! - Use this to add special native functions to your environment when you need specific functionality is needed. • or **New in V2!**: string, defined as: . This is for injecting native code before translated kernel functions. • or : array, generally inherited from instance. • or : boolean, default = • VERY IMPORTANT! - This was removed in v2.4.0 - v2.7.0, and brought back in v2.8.0 by popular demand, please upgrade to get the feature • or : boolean, default = - allows undefined argumentTypes and function return values to use strict integer declarations. • or : boolean, default - more info here. • or **New in V2!**: Set the kernel's tactic for compilation. Allows for compilation to better fit how GPU.js is being used (internally uses for 'speed', for 'balanced', and for 'precision'). Default is lowest resolution supported for output. Creating and Running Functions Depending on your output type, specify the intended size of yo…