Top 3 Cache Thrashing Culprits: Strided Access

Tensor operations with large, non-unit strides, such as dilated convolutions, frequently cause cache thrashing by loading cache lines where only a small portion of the data is used, leading to inefficient memory bandwidth utilization and performance degradation.

The top 3

  1. Matrix Transposition's Cache Catastrophe: Naive matrix transposition algorithms often access memory in a non-contiguous, strided fashion, frequently evicting useful cache lines before reuse, leading to significant performance degradation, sometimes only achieving a fraction of optimal bandwidth. Using techniques like cache blocking or shared memory can mitigate this by reordering accesses for better locality.
  2. Multi-Dimensional Array Access Order Pitfalls: Accessing 2D arrays against their native storage order (e.g., column-major access on a row-major array in C/C++) creates large, detrimental strides that bypass cache locality, causing repeated cache misses and significantly slowing down execution. Modern CPUs' prefetchers, optimized for sequential access, are often defeated by these large strides.
  3. Sparse Data Structures: The Indirect Stride Trap: Operations on sparse matrices or graphs, particularly when using formats like Compressed Row Storage (CRS), involve indirect indexing. This leads to highly unpredictable and irregular strided memory access patterns that are difficult for hardware prefetchers to predict, resulting in frequent cache misses and thrashing.

Sources

Open the full topic