Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitdd348ac6c3

README.md

reduce

Folds a run of elements to one element per group: the sum, least, greatest, mean, count, or the index of the least or greatest, of the whole run or of each segment of it.

SpecializeOptionsMeaning
Tf32, i32, vec2 to vec4 of eitherthe element; a vector folds lane by lane
FOLDadd, min, max, mean, count, argmin, argmaxthe fold

The dispatch size n is the number of elements. One workgroup folds one group at a time, so a segmented fold runs its segments side by side and an unsegmented one is a single group; any workgroup count from 1 up folds every group.

params.segments above 0 makes starts partition the run into that many segments: it holds where each segment begins (a segment ends where the next begins, the last at n), and dst holds one element per segment. With segments 0 the whole run is one group, starts is any one-word run, and dst holds one element. An empty group answers 0 for every fold. argmin and argmax write the lowest index among equal elements to picked (for a vector element, the element that beats the best before it in every lane); every other fold writes -1 there. The mean of an integer run is the integer quotient. The bounds of a run are its min and its max.

Exact: every group folds its elements in a fixed order and combines the 256 partial results in a fixed tree, so the same run gives the same bits on every dispatch, and an integer fold is the exact integer answer.

Over a live count (COUNT=device) n is the capacity and the first domain_count elements are the run: the last segment ends at the live count. Over live segments (SEGMENTS=device) params.segments is the most segments there can be, which sizes dst and picked, and the first segment_count of them are live; a group past them is not written, and a run of no live segments folds nothing.

Nodes that fold columns run it, among them core.reduce, core.select, core.arclength, core.normals.face, attribute.promote and sim.particles.