← All problems
#75 Sparse Matrix Dense Matrix Multiplication Medium

Implement a GPU program that multiplies a sparse matrix A of dimensions M × N by a dense matrix B of dimensions N × K, producing a dense output matrix C of dimensions M × K. All matrices are stored in row-major order using 32-bit floats. The matrix A is approximately 60–70% sparse (i.e., 60–70% of elements are zero), and nnz gives the number of non-zero elements in A.

Mathematically, the operation is defined as: \[ C_{ij} = \sum_{k=0}^{N-1} A_{ik} \cdot B_{kj} \quad \text{for} \quad i = 0, \ldots, M-1,\; j = 0, \ldots, K-1 \]

Implementation Requirements

Example

Input:
Matrix \(A\) (\(3 \times 4\)): \[ \begin{bmatrix} 2.0 & 0.0 & 0.0 & 1.0 \\ 0.0 & 3.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 4.0 & 0.0 \end{bmatrix} \] Matrix \(B\) (\(4 \times 2\)): \[ \begin{bmatrix} 1.0 & 2.0 \\ 3.0 & 4.0 \\ 5.0 & 6.0 \\ 7.0 & 8.0 \end{bmatrix} \] Output:
Matrix \(C\) (\(3 \times 2\)): \[ \begin{bmatrix} 9.0 & 12.0 \\ 9.0 & 12.0 \\ 20.0 & 24.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.