Flatten Matrices into Linear Memory
•Generally memory allocated dynamically on device (GPU) and
we cannot not use two-dimensional indices (e.g. A[row][column])
to access matrices.
•We will need to know how the matrix is laid out in memory and
then compute the distance from the beginning of the matrix.
•C uses row-major order --- rows are stored one after the
other in memory, i.e. row 0 then row 1 etc.
M
2,0!
M
1,1!
M
1,0!
M
0,0!
M
0,1!
M
3,0!
M
2,1!
M
3,1!
M
1,2!
M
0,2!
M
2,2!
M
3,2!
M
1,3!
M
0,3!
M
2,3!
M
3,3!
M
2,0!
M
1,0!
M
0,0!
M
3,0!
M
1,1!
M
0,1!
M
2,1!
M
3,1!
M
1,2!
M
0,2!
M
2,2!
M
3,2!
M
1,3!
M
0,3!
M
2,3!
M
3,3!