Two-Input Shuffles

These functions make a distinction between shuffles with one input per work-item and shuffles with two inputs per work-item. The two-input versions map naturally to SIMD execution (see the shuffle2 vector operation from OpenCL), and they enable developers to avoid certain undefined behaviors from the one-input versions. The simplest way to think of the two-input shuffles is that their operation is equivalent to a one-input shuffle on a virtual sub-group twice as big.

Member function Description
template <typename T>
T shuffle(T x, T y, id<1> local_id) const

Exchanges values of x and y between work-items in the sub-group in an arbitrary pattern. If local_id is between 0 and the sub-group size, it returns the value of x from the work-item with the specified id. If local_id is between the sub-group size and twice the sub-group size, it returns the value of y from the work-item with the specified id (modulo the sub-group size).

The value of local_id must be between 0 and twice the sub-group size.

template <typename T>
T shuffle_down(T x, T y, uint32_t delta) const

Exchanges values of x and y between work-items in the sub-group via a shift. If the calling work-item's id + delta is between 0 and the sub-group size, it returns the value of x from the work-item whose id is delta larger than the calling work-item. If the calling work-item's id + delta is between the sub-group size and twice the sub-group size, it returns the value of y from the work-item with the specified id (modulo the sub-group size).

The value of delta must be less than the sub-group size.

template <typename T>
T shuffle_up(T x, T y, uint32_t delta) const

Exchanges values of x and y between work-items in the sub-group via a shift. If the calling work-item's iddelta is between 0 and the sub-group size, it returns the value of x from the work-item whose id is delta smaller than the calling work-item. If the calling work-item's iddelta is between the sub-group size and twice the sub-group size, it returns the value of y from the work-item with the specified id (modulo the sub-group size).

The value of delta must be less than the sub-group size.