Skip to content

WasmGPU.compute.kernels.histogramU32

Summary

WasmGPU.compute.kernels.histogramU32 accumulates a histogram from unsigned integer keys. Keys are interpreted as bin indices in [0, binCount - 1]. You can reuse an output bins buffer and optionally skip clearing with opts.clear: false. Use this for categorical counts and integer distribution analysis.

Syntax

WasmGPU.compute.kernels.histogramU32(keys: StorageBuffer, binCount: number, opts?: HistogramOptions): StorageBuffer
const bins = wgpu.compute.kernels.histogramU32(keys, binCount, opts);

Parameters

Name Type Required Description
keys StorageBuffer Yes Input key buffer of u32 bin indices.
binCount number Yes Number of output bins.
opts HistogramOptions No Optional histogram settings (count, reusable bins, clear behavior, dispatch options).

Returns

StorageBuffer - Histogram bins buffer with u32 counts.

Type Details

type HistogramOptions = {
    encoder?: GPUCommandEncoder;
    label?: string;
    validateLimits?: boolean;
    count?: number;
    bins?: StorageBuffer;
    clear?: boolean;
};

Example

const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);

const keys = wgpu.compute.createStorageBuffer({ data: new Uint32Array([0, 2, 1, 2, 2, 0]), copySrc: true });
const bins = wgpu.compute.kernels.histogramU32(keys, 3);
console.log(Array.from(await wgpu.compute.readback.readU32(bins, 0, 3)));

See Also