← All problems
#22 GEMM Medium

Implement a basic General Matrix Multiplication (GEMM). Given matrix \(A\) of dimensions \(M \times K\), matrix \(B\) of dimensions \(K \times N\), input/output matrix \(C\) of dimensions \(M \times N\), and scalar multipliers \( \alpha \) and \( \beta \), compute the operation: \[ C = \alpha \cdot (A \times B) + \beta \cdot C_{initial} \]

The input matrices \(A\), \(B\), and the initial state of \(C\) contain 16-bit floating-point numbers (FP16/half). All matrices are stored in row-major order. The scalars \( \alpha \) and \( \beta \) are 32-bit floats.

Implementation Requirements

Example:

Input:
(Note: Input matrices A, B, C_initial are FP16 type for the problem)
Matrix \(A\) (\(M=2, K=3\)): \[ \begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \end{bmatrix} \] Matrix \(B\) (\(K=3, N=2\)): \[ \begin{bmatrix} 1.0 & 2.0 \\ 3.0 & 4.0 \\ 5.0 & 6.0 \end{bmatrix} \] Matrix \(C_{initial}\) (\(M=2, N=2\)): \[ \begin{bmatrix} 1.0 & 1.0 \\ 1.0 & 1.0 \end{bmatrix} \] \[\alpha = 1.0 \text{ (FP32)}\] \[\beta = 0.0 \text{ (FP32)}\] Output (FP16):
Matrix \(C\) (\(M=2, N=2\)): \[ \begin{bmatrix} 22.0 & 28.0 \\ 49.0 & 64.0 \end{bmatrix} \]

Constraints

Guided walkthrough coming soon. Below is the official starter signature in each language; the clickable line-by-line explanation hasn't been authored yet.
Problem text & starters from the official AlphaGPU/leetgpu-challenges. Solve it on leetgpu.com.