Add two float32 matrices elementwise on the GPU.
Cij=Aij+BijHere, A and B are the input matrices, C is the output matrix, M is the number of rows, N is the number of columns, and i and j are valid row and column indices. All buffers use contiguous row-major storage, with each row's N values placed consecutively.
Write the result into the preallocated float32 device buffer C with shape (M, N), leaving A and B unchanged. The function returns no value.
Input: A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]], M = 2, N = 2
Output: [[6.0, 8.0], [10.0, 12.0]]
Explanation: Each output entry adds the two inputs at the same row and column.
Input: A = [[0, 1, 2], [3, 4, 5]], B = [[10, 10, 10], [20, 20, 20]], M = 2, N = 3
Output: [[10.0, 11.0, 12.0], [23.0, 24.0, 25.0]]
Use the x and y thread coordinates to distinguish columns from rows.
The row stride in either flat input buffer is N elements.
Check both coordinates before accessing a matrix element.
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Submit a correct solution to see your kernel performance.
Add two float32 matrices elementwise on the GPU.
Cij=Aij+BijHere, A and B are the input matrices, C is the output matrix, M is the number of rows, N is the number of columns, and i and j are valid row and column indices. All buffers use contiguous row-major storage, with each row's N values placed consecutively.
Write the result into the preallocated float32 device buffer C with shape (M, N), leaving A and B unchanged. The function returns no value.
Input: A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]], M = 2, N = 2
Output: [[6.0, 8.0], [10.0, 12.0]]
Explanation: Each output entry adds the two inputs at the same row and column.
Input: A = [[0, 1, 2], [3, 4, 5]], B = [[10, 10, 10], [20, 20, 20]], M = 2, N = 3
Output: [[10.0, 11.0, 12.0], [23.0, 24.0, 25.0]]
Use the x and y thread coordinates to distinguish columns from rows.
The row stride in either flat input buffer is N elements.
Check both coordinates before accessing a matrix element.
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Submit a correct solution to see your kernel performance.