roofline.devPublic Beta

Matrix Multiply

0MEDIUMPracticeReport issue

Compute the dense matrix multiplication C=ABC = AB.

Given matrices AA of shape M×KM \times K and BB of shape K×NK \times N, produce matrix CC of shape M×NM \times N such that

Cij=kKAikBkjC_{ij} = \sum_{k}^{K} A_{ik} \cdot B_{kj}

All matrices are stored in row-major order.

Input

  • A - input matrix of shape [m][k] stored in row-major order.
  • B - input matrix of shape [k][n] stored in row-major order.
  • m - the number of rows in A and C.
  • n - the number of columns in B and C.
  • k - the number of columns in A and rows in B.

Output

  • C - output matrix of shape [m][n] such that C=ABC = AB.
Open on a desktop browser to write and submit code.

Public submissions

Practice problem · every submission below is public, click to view code