Skip to content

demskie/gpu-sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4f6a848 · Jan 4, 2023

History

88 Commits
Mar 14, 2020
Dec 31, 2022
Feb 15, 2020
Dec 31, 2022
Jan 23, 2020
Feb 1, 2020
Feb 15, 2020
Aug 28, 2019
Feb 16, 2020
Aug 28, 2019
Feb 16, 2020
Feb 15, 2020
Jan 4, 2023
Feb 24, 2020
Feb 16, 2020
Sep 17, 2019
Sep 17, 2019

Repository files navigation

gpu-sort

GPU accelerated asynchronous sorting

Build Status Coverage Status Dependency Status npm version

Why?

WebGL seems underutilized and sorting asynchronously is really handy.

Installation

npm install gpu-sort

Example

import * as gpu from "gpu-sort";

let numbers = new Float64Array([5, 4, 3, 2, 1, 0]);

// sort in place
gpu.sort(numbers);

// sort in place asynchronously
gpu.sortAsync(numbers).then(() => console.log("sorted!"));

NodeJS support

import * as gpu from "gpu-sort";

// For NodeJS an emulation library must be provided as it doesn't support WebGL
gpu.setWebGLContext(require("gl")(1, 1));

// sort using webgl emulated context
gpu.sort(foo);

Benchmarks

Limitations

  1. Only TypedArrays are supported.
  2. When sorting 8bit and 16bit numbers GPU acceleration is disabled (as it seems rather pointless).
  3. The maximum number of elements that can be sorted is constrained by the max texture width squared. For example 4096 ^ 2 = 16,777,216 (32bit) or 4096 ^ 2 / 2 = 8,388,608 (64bit). This can be increased in the future by up to 8 times by multiplexing the data across multiple framebuffers.