Skip to content
BIASED

Vectors, SIMD and GPUs

Block 1 of 3~2 min

SIMD

DLP: one instruction, many elements — saves scalar fetch/decode/scheduling. SIMD packs a fixed count (four floats in 128 bits). Compilers vectorize loops without loop-carried dependences or aliasing (restrict helps). M1 saxpy: 31 vs 6 GFLOP/s from cache; 8.2 vs 3.4 from memory.

Notation. The running example is saxpy, yi←a xi+yiy_i ≤ftarrow a x_i + y_iyi​←axi​+yi​ for i=0,…,n−1i = 0, \dots, n - 1i=0,…,n−1, on 32-bit floating-point numbers (“single-precision aaa times xxx plus yyy”). For the RISC-V Vector extension, VLEN is the number of bits in one vector register, SEW the width of one element in bits, LMUL the number of registers grouped into one operand, and VLMAX=LMUL⋅VLEN/SEWVLMAX = LMUL · VLEN/SEWVLMAX=LMUL⋅VLEN/SEW the largest number of elements one instruction can process; vl\mathit{vl}vl is the number it actually processes, and AVL the number the program still has to process. For the roofline, PPP is a machine’s peak arithmetic rate in FLOP/s, BBB its memory bandwidth in bytes/s, and III the arithmetic intensity of a computation: floating-point operations per byte moved to or from memory.

Worked example. Saxpy on 128-bit registers handles four elements per iteration: load four xxx values, load four yyy values, one fused multiply-add for all four, store four yyy values, then the loop overhead. That is about eight instructions per four elements, two per element instead of the scalar loop’s nine.

The roofline of the A100 and the kernels of the worked example:

Answers are saved on the server and tied to this browser until you sign in.