liveBook · Manning

Select instruction

As explained in Grokking GPU Programming

A select instruction chooses one of two values based on a condition without splitting warp control flow.

A select instruction checks each thread’s condition and keeps one of two results. Unlike a branch, it does not split the warp. Compilers may use it for short branches, especially when both paths are cheap and do not write to memory; otherwise, computing both results may waste work. section 14.3

// Branchless: compute both, select
int sum = a + b;    #A
int diff = a - b;
result = condition ? sum : diff;    #B

This branchless example computes both arithmetic results, then uses the condition to select one. section 14.3

How Grokking GPU Programming covers it

How deep it goes
Defines selection and explains its tradeoff with branching, but leaves expensive branches to a later strategy.
Examples
Uses conditional selection between a sum and a difference after computing both values.
What you can do after
Understand how selection avoids splitting a warp and when computing both results is worthwhile.
How it connects
Connects select instructions to predication, branches, compiler optimization, and warp divergence.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking GPU Programming. The section links point to the parts of the book it draws on.