Home › Practice › Accelerators › Four lanes, one instruction, one mask (GPU style)
Four lanes, one instruction, one mask (GPU style)
EasyRTLAcceleratorssequential
A GPU takes the opposite road from a systolic grid. It runs one instruction on many lanes at once, each lane working on its own data. When some of the threads should not take part (an if that only some of them take), the hardware does not run different code. It simply switches those lanes off with a mask, and the masked lane's result is not stored.
Concept first. Picture four lanes side by side, each with its own total register. The control side sends the same number k to every lane (one instruction, one scalar). Each lane has its own data x. A lane that is switched on adds k * x to its own total. A lane that is switched off keeps its total, as if nothing had happened. Example with other numbers: k = 3, lane data x = (1, 2, 3, 4), mask = 0101 (lanes 0 and 2 on, counting from the right): lane 0 adds 3, lane 2 adds 9, lanes 1 and 3 keep their totals.
Notice what a mask costs: a switched-off lane still occupies hardware and still waits for the instruction to finish. That waste is the price of the simple control.
rstis synchronous, active-high: on a risingclkwithrst=1all four totalsr0..r3become 0.- Otherwise, on every rising
clk, for each lane i: ifmask[i]=1thenr_igrows byk * x_i; ifmask[i]=0it keeps its value. kandx0..x3are unsigned 2-bit (0 to 3);r0..r3are 5 bits (kept small so the check stays fast).
No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.