Implement a CUDA kernel that computes the matrix product C=A⋅B, where A has shape (M,K) and B has shape (K,N), producing C of shape (M,N). For each output element:
C[i,j]=k=0∑K−1A[i,k]⋅B[k,j]All buffers are stored in row-major layout: A has M⋅K floats, B has K⋅N floats, and C has M⋅N floats. The kernel writes one output element per thread into the preallocated C buffer.
Input: M = 2, K = 3, N = 2, A = [[1, 2, 3], [4, 5, 6]], B = [[7, 8], [9, 10], [11, 12]]
Output: C = [[58, 64], [139, 154]]
Each output cell is a dot product of an A row and a B column.
Input: M = 3, K = 2, N = 3, A = [[1, 0], [0, 1], [1, 1]], B = [[2, 3, 4], [5, 6, 7]]
Output: C = [[2, 3, 4], [5, 6, 7], [7, 9, 11]]
Rectangular product where M, K, N all differ.
The inner loop runs over the shared dimension K, which appears in both A and B but not in C.
Each output cell C[i,j] is independent of every other output cell, so one thread can own one (i,j) pair.
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Accepts: number
Submit a correct solution to see your kernel performance.
Implement a CUDA kernel that computes the matrix product C=A⋅B, where A has shape (M,K) and B has shape (K,N), producing C of shape (M,N). For each output element:
C[i,j]=k=0∑K−1A[i,k]⋅B[k,j]All buffers are stored in row-major layout: A has M⋅K floats, B has K⋅N floats, and C has M⋅N floats. The kernel writes one output element per thread into the preallocated C buffer.
Input: M = 2, K = 3, N = 2, A = [[1, 2, 3], [4, 5, 6]], B = [[7, 8], [9, 10], [11, 12]]
Output: C = [[58, 64], [139, 154]]
Each output cell is a dot product of an A row and a B column.
Input: M = 3, K = 2, N = 3, A = [[1, 0], [0, 1], [1, 1]], B = [[2, 3, 4], [5, 6, 7]]
Output: C = [[2, 3, 4], [5, 6, 7], [7, 9, 11]]
Rectangular product where M, K, N all differ.
The inner loop runs over the shared dimension K, which appears in both A and B but not in C.
Each output cell C[i,j] is independent of every other output cell, so one thread can own one (i,j) pair.
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Accepts: number
Submit a correct solution to see your kernel performance.