[compiler-rt][profile] Sum lane-varying GPU counter increments (#235978)
The GPU profiling helper adds each active lane's contribution to a
shared counter. Its `step` argument is the amount that lane contributes.
For an ordinary block counter, every active lane has step 1. For a
select counter, step is 1 when that lane's condition is true and 0
otherwise.
For example, consider a 64-lane wave executing this select:
result = (threadIdx.x % 2 == 0) ? a : b;
All 64 lanes are active, but even lanes have step 1 and odd lanes have
step 0. The counter should increase by 32. The old helper multiplies
the first active lane's step by the number of active lanes, so it adds
64 instead. Being active does not mean a lane's step is 1.
Compiler-generated counter steps are zero or one. Use a ballot to find
the lanes with step 1 and count its set bits. The first active lane adds
that count to the counter. Use the same count for the optional uniform
counter when the whole wave is active.
GitOrigin-RevId: 8b254e8fcfe9b54289670ebbe7f1ef2de3cd84e2
3 files changed