reduceWGSL¶
Overview¶
A template that performs a reduce operation on a single workgroup. The value will be valid at local_id.x === 0.
@author Jonathan Olson <jonathan.olson@colorado.edu>
Type reduceWGSLOptions¶
- value: WGSLVariableName
the "input" and "output" variable name - scratch: WGSLVariableName
name for var<workgroup> array<T, workgroupSize> TODO: consider abstracting, so we could run multiple reduces TODO: concurrently - binaryOp: BinaryOp<T>
- mapScratchIndex?: ( index: WGSLExpressionU32 ) => WGSLExpressionU32
allows overriding the index used for the scratch array, so that we can run multiple smaller loads in the same workgroup - convergent?: boolean
Whether we should reduce in a convergent order. This will reduce control divergence when running, and will potentially allow warps to exit early. This should result in a speed-up, but the data either needs to have a commutative combine operation, OR the order should be in a "convergent" order. That would mean that for each data chunk read by each workgroup, the indices are bit-reversed (e.g. if we have a workgroup size of 256, then we are reversing the last 8 bits of the index, thus the first element should be stored at index 0, the second element at index 128, the third element at index 64, etc.). See get_convergent_index for more information. For instance, the order of reduction of the first 16 hex digits (in a convergent order) would be 084c2a6e195d3b7f. - scratchPreloaded?: boolean
If true, we won't need to load the value INTO the scratch array - valuePreloaded?: boolean
If true, we won't need to load the value FROM the scratch array - & WorkgroupSizable & LocalIndexable
Source Code¶
See the source for reduceWGSL.ts in the alpenglow repository.