compute.kernels.sort¶
Summary¶
compute.kernels.sort orders a one-dimensional u32 GPU ndarray in ascending order. Pass { out: keys } to sort compatible storage in place. Use sortPairs when payload values must follow the same permutation.
Syntax¶
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
keys |
GPUndarray |
Yes | Rank-one u32 array. Strided input is accepted. |
opts |
KernelOutputOptions |
No | Kernel output and dispatch settings. Pass out: keys to sort a C-contiguous input in place. |
Returns¶
GPUndarray - Ascending u32 keys with the same length, including an empty result for an empty input.
Example¶
const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const { ndarray: nd, kernels } = wgpu.compute;
const keys = nd.fromArray("u32", [4], [5, 1, 9, 1], { residency: "gpu" });
kernels.sort(keys, { out: keys });
const cpu = await nd.toCPU(keys);
console.log(cpu.data()); // [1, 1, 5, 9]
cpu.destroy();
keys.destroy();