Multiply two matrices and view the resulting matrix, used in neural network layers.
Matrix multiplication (matmul) is the core operation in neural networks — every linear layer, attention mechanism, and convolution can be expressed as matmuls. For A(m×k) × B(k×n), the result is an m×n matrix requiring m×k×n multiplications and m×(k-1)×n additions.
Matrix Multiply
C[i,j] = sum(A[i,k] * B[k,j]) for k=1..K
Every fully connected layer computes Y = XW + b, which is a matrix multiplication. Transformers, CNNs (via im2col), and RNNs all reduce to batched matmuls, making it the single most performance-critical operation in ML.
The FLOPs for a matmul are typically counted as 2×m×k×n (counting multiply and add as separate operations), which is the standard used by hardware vendors and ML papers.