Knowledge note

Inner Product

The scalar dot product Σ xᵢyᵢ; GEMM is the matrix of inner products between rows of A and columns of B, and attention scores are dot products.

Updated September 16, 2026Confidence: High

Inner Product

Inner Product (dot product) is the scalar $\sum_i x_i y_i$ produced by multiplying two same-length vectors element-wise and summing; a GEMM output element is the inner product of a row of $A$ with a column of $B$.

Why It Exists

Every matrix product is a grid of inner products: $C[i][j] = A[i,:] \cdot B[:,j]$. Viewing GEMM this way makes each output element a self-contained reduction over the shared dimension $K$, which is how a single processing element (a multiply-accumulate unit) computes a result without needing its neighbors’ data. The same operation underlies attention, where query–key compatibility is scored by a dot product, so the term spans both matrix multiply and attention.

How It Works

For a single output element:

\[C[i][j] = \sum_{k=0}^{K-1} A[i][k] \cdot B[k][j]\]

The reduction over $k$ is the “inner” dimension — the one shared by both matrices. In an inner-product GEMM structure, each output element is computed by a full reduction over $k$ before moving to the next element; in an outer-product structure, all output elements advance one $k$-step together. In attention, the scaled dot product $q_i \cdot k_j / \sqrt{d_k}$ measures relevance before softmax.

Tradeoffs

  • Inner-product accumulation keeps each output element in one accumulator, minimizing on-chip storage per element, but serializes the reduction over $k$ per element.
  • On parallel hardware the outer-product structure is often preferred because it exposes all pairwise multiplications at once; inner products excel on scalar or vector SIMD units.
  • A dot product in a higher dimension is memory-bound when vectors are long relative to the work, which motivates matrix tiling.

Common Confusions

  • Dot product vs. inner product: The same operation; “dot product” emphasizes the element-wise product-sum, “inner product” the general vector-space notion.
  • Inner-product GEMM vs. outer-product GEMM: Both compute the same product; they differ in which loop is parallelized. Inner-product keeps the output element stationary; outer-product keeps the shared dimension step stationary.
  • Attention dot product vs. GEMM dot product: Same arithmetic, different role — attention scores are dot products between a query and a key, then normalized by softmax.

Where It Appears