Log inStart free
LESSON 27.09 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

GEMM vs GEMV

Watch one matrix meet one vector, then 64 vectors, and see the speed change.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 27.09 · GPU BAY1 GEMV · 8,192 FLOPS
01
Stage 1 of 5 · One vector
A GEMV multiplies the 64 × 64 matrix A by one vector x. Each row of A gives one value of y.
Explain it simply

A GEMV is a matrix times one vector. Each row of A meets x, and their 64 products add up to one value of y. When a language model writes one token for one user, its layers do GEMVs like this.

The 64 by 64 grid A, the column x and the column y. y fills from top to bottom; the first value is minus 3.328125. The GEMV does 8,192 FLOPs.

weights Ainputs x and B, memory timeoutputs y and C, math timecolumns not used yet
GEMV: y = A · xA · 64 × 64xy·=8,192 FLOPs2 · 64 · 64each weight does1 multiply-addper trip from HBMy[0] = Σₖ A[0][k] · x[k] = −3.328125GEMV: y = A · xA · 64 × 64xy·=8,192 FLOPs2 · 64 · 64each weight does1 multiply-addper trip from HBMy[0] = Σₖ A[0][k] · x[k] = −3.328125
Toy: the 64 × 64 matmul of 27.C2 on a toy GPU (64 GB/s, 512 or 4,096 GFLOP/s)
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
yi=∑kAik xk\sy{y}{out}{y_i} = \sum_k \sy{a}{param}{A_{ik}}\,\sy{x}{data}{x_k}
y0=−3.328125,F=2⋅64⋅64=8,192y_0 = -3.328125,\quad F = 2 \cdot 64 \cdot 64 = 8{,}192

Each value of y is one row of A times x.

Common mix-ups

MYTHTensor Cores make a GEMV faster.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With 4 vectors, is the GEMM memory-bound or compute-bound?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.