A matrix arranges elements in rows and columns, but its contents are stored in a one-dimensional memory array. In C and C++, rows are stored consecutively: this is row-major order. Column-major order stores each column consecutively instead. The layout determines which elements are near each other in memory. section 10.10
Figure 10.8 Row-major layout. Consecutive 1D indices fill each row before moving to the next. Each cell shows the 1D array index where that matrix element lives: row 0 holds [0] through [m−1], row 1 holds [m] through [2m−1], and so on, ending at [nm−1] in the bottom-right. The numbered arrows give the traversal order: across the columns first (1), then down to the next row (2).

See how consecutive memory indices fill one row before moving to the next. section 10.10
In CUDA, the layout and the threads’ access pattern together affect memory performance:
- With row-major data, threads accessing consecutive columns read nearby elements, allowing coalesced memory access. section 10.10
- A sumRows kernel assigns one thread to each row; at each load step, warp threads access different rows and widely separated addresses. A sumCols kernel assigns one thread to each column, so threads access consecutive elements of a row. section 10.10
- CUDA does not enforce a matrix layout. Check the convention used by the code or library that created the data. section 10.10


