Skip to content

WebGPU SortingWebGPU Sorting Library and Demo

Sort Uint32Array workloads in the browser, inspect the implementation, and benchmark on your own hardware.

WebGPU Sorting Logo
2GPU sorters
1Demo playground
4Core validation commands
1Root changelog

Quick Start

typescript
import { GPUContext, BitonicSorter } from 'webgpu-sorting';

// Initialize WebGPU context
const gpu = new GPUContext();
await gpu.initialize();

// Create sorter
const sorter = new BitonicSorter(gpu);

// Sort data on GPU
const data = new Uint32Array([5, 2, 8, 1, 9, 3, 7, 4, 6, 0]);
const { sortedData } = await sorter.sort(data);

console.log(sortedData); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Browser Support

🌐
Chrome 113+Supported
🌊
Edge 113+Supported
🦊
Firefox NightlyFlag Required
🧭
Safari 18+macOS 14+

Why GPU Sorting?

GPU sorting becomes advantageous when:

  • Array size is large enough - Buffer upload and readback overhead is amortized
  • Batch processing - Multiple sorts can share GPU context
  • Real-time applications - Low-latency sorting for visualizations, simulations
  • Integer-heavy workloads - Radix sort excels on Uint32Array data

Use the interactive demo to measure the crossover point on your own hardware instead of relying on fixed benchmark claims.

Architecture Overview

mermaid
graph TB
    subgraph CPU["CPU Side"]
        A[Input Array] --> B[Generate Data]
        B --> C[Create GPU Buffer]
    end

    subgraph GPU["GPU Compute Shader"]
        D[Read Buffer] --> E[Bitonic/Radix Sort]
        E --> F[Parallel Passes]
        F --> G[Write Sorted Buffer]
    end

    subgraph Output
        G --> H[Read Back to CPU]
        H --> I[Validation & Timing]
    end

    C --> D

Learn more in the Architecture documentation.

Released under the MIT License.