Builtin Library
- ..
- README.md2.0 KB
- bindings.yaml2.9 KB
- shader.wgsl4.2 KB
README.md
scatter
Folds the elements of a column into the places a run of indices names: element
i of src goes to place index[i] of the result, and elements that meet in
one place are combined by the FOLD specialization (add, min, max,
mean, set). T is the scalar a lane holds (f32 or i32); an element is
lanes words. Alongside the result the kernel counts the elements folded into
each place (hits) and records one more than the greatest source index that
reached it (last, 0 when none), so a node can tell a place nothing reached from
one that holds zero. set keeps the element with the greatest source index, and
a place nothing reached holds zeros. An index outside 0 to size - 1 is
skipped.
It runs as three passes of one shader, init, fold and finish, chosen by the
PASS specialization. Min, max, set and every integer fold give the same answer
whatever order the contributions arrive in. Float add and float mean sum in
arrival order, and the kernel declares float_order for them; with EXACT on,
each float is rounded to a multiple of 1 / scale and summed as an integer,
which is the same on every run.
Over a live count (COUNT=device, see the abi README) the fold pass's n is the capacity of the indices and the first
domain_count of them are folded; an index past it reaches no place. The init and finish passes run over the places
(size) as they always do, and a node that sizes the places by a capacity states the live indices through the fold
pass alone. It binds 6 storage buffers (5 in the plain variant).
Over live places (SIZE=device) the places are the first size_count of the size the outputs are allocated for: the
node bound size as { live = count }, and the init and finish passes leave the places past it alone while the fold
pass sends an index past it nowhere. The result carries the count as its live count. It binds one storage buffer more.
core.scatter runs the three passes.