NCHW vs. NHWC: Cache Misses in Deep Learning
The NCHW (Channels First) tensor layout often causes more cache misses on GPUs, especially for convolution operations, compared to NHWC (Channels Last), which offers better memory coalescing and cache utilization, achieving up to a 22% performance increase on NVIDIA GPUs with AMP.
The top 3
- Top 3 DL Ops Most Affected by Layout Cache Misses: Convolutional layers, pooling layers, and batch normalization layers are highly sensitive to NCHW/NHWC tensor layout choices, as suboptimal layouts lead to increased cache misses and reduced performance due to inefficient memory access patterns.
- Top 3 Hardware Favoring NCHW/NHWC for Cache: NVIDIA GPUs, especially those with Tensor Cores, generally prefer NHWC for optimal memory coalescing and vectorized operations, while older GPUs or certain cuDNN operations might favor NCHW. Intel CPUs with SIMD extensions (like AVX/AVX512) can also benefit from NHWC for better spatial locality in some convolution patterns.
- Top 3 Performance Optimizations Aided by Tensor Layout: Optimal tensor layout directly boosts performance by improving cache locality, enabling efficient GPU memory coalescing (NHWC for Tensor Cores), and maximizing CPU vectorization (NHWC for channel-wise operations).
Sources
Open the full topic