Prime Candidates: Top 3 Data Structures for Loop Interchange

Multi-dimensional arrays, especially those accessed in a non-stride-1 pattern (e.g., column-major access in row-major ordered languages like C/C++), are the primary beneficiaries, along with certain matrix operations like multiplication and transposition.

The top 3

  1. Row-Major vs. Column-Major: Matrix Layout Speed Kings: C and C++ languages default to row-major order, making row-wise data access cache-friendly, whereas Fortran, MATLAB, Julia, and R use column-major order, which optimizes column-wise access for better cache performance.
  2. 3D Array Cache Misses: Worst-Case Access Pattern: For C/C++'s row-major 3D arrays (e.g., `array[dim1][dim2][dim3]` where `dim3` is contiguous), the highest cache miss rates occur when the outermost loop iterates over the dimension *most contiguous in memory*, forcing frequent non-sequential memory fetches.
  3. Deep Learning's Top 3 Tensor Operations Cache Bottlenecks: In deep learning, matrix multiplication (GEMM), convolution, and element-wise operations are critical for performance, frequently becoming cache bottlenecks due to memory access latency, often requiring specialized hardware (like Tensor Cores) and optimized data layouts to mitigate.

Sources

Open the full topic