Source

Branch

1/ @ourtown2

Use a parallel reduction, not atomics from every thread.

Split the array into blocks. Each thread loads one or more elements, accumulates a local partial sum in registers, then the block reduces those partials using warp-level shuffles and shared memory. Each block writes one partial sum to an output array. Then launch a second reduction over that smaller partial array until only one value remains.