Experiments with SHFL
- 1 min read
I wanted to double-check my understanding of Kepler’s shfl operation
when using negative indices or negative index offsets. The PTX
documentation on this instruction is accurate but a little terse so a
micro-test was in order.
The summary results are:
shfl.idxhandles negative indices without any problem which means “shuffle rotations” are feasible.shfl.uphas no chance to mask thelane - bvalvalue so it sets the in-range predicate to false when negative indices are produced and the lane’s current value is assigned.shfl.downhas similar behavior.- negative
shfl.[up|down]offsets are treated as unsigned 5-bit values. e.g. -5 = 27.
- negative
It’s also important to note that invoking shfl.idx with a signed
offset subtracted from the laneId results in no surprises and is a two
or three-instruction SASS sequence:
S2R R4, SR_LaneId;
IADD R4, R4, -<register or constant>;
SHFL.IDX pt, R4, R0, R4, 0x1f;
I like to think of this operation as a shfl.rot.
Source code can be found here.
Here’s a screenshot of the output. An ‘x’ indicates a false predicate.
