TL;DR
Researchers have developed a high-performance direct convolution implementation that eliminates the memory-heavy "packing" step (im2col) used by almost all modern deep learning frameworks. By reordering loops and using hardware-aware data layouts, their method achieves 10% to 400% better performance than standard BLAS-based implementations while requiring zero additional memory overhead.
What Problem Does This Paper Address?
In the world of deep learning, convolution is king. However, computing it efficiently is notoriously difficult. The "conventional wisdom" in the field has long been that direct convolution (using nested loops) is too slow. To achieve high performance, most frameworks rely on a trick called im2col: they reshape and duplicate the input data into a large matrix so they can use highly optimized General Matrix Multiply (GEMM) routines from libraries like Intel MKL or OpenBLAS.
This standard approach has two major drawbacks:
- Memory Overhead: Reshaping and duplicating data (packing) consumes significant memory—often 2x to 4x the original input size. This is a dealbreaker for memory-constrained embedded and edge devices.
- Sub-optimal Performance: Standard BLAS libraries are optimized for the large, square-ish matrices found in traditional scientific computing. The matrices generated by convolution layers often have "skinny" or "wide" dimensions that don't play well with these optimizations, leading to lower-than-expected throughput.
Methods
The authors propose a "correctly implemented" direct convolution that maps the operation directly to the underlying hardware architecture without intermediate packing. Their approach relies on three main techniques:
- Hardware-Aware Loop Reordering: A naive convolution has six nested loops. The authors reorder these loops to maximize data reuse in registers and ensure that Fused Multiply-Add (FMA) units are constantly saturated. They specifically prioritize the loops that iterate over output channels and rows to minimize "stalls" in the processor.
- Register and Cache Blocking: To prevent the CPU from constantly waiting for data from main memory, the authors implement blocking strategies. They partition the computation into small "tiles" that fit perfectly into the CPU's registers and L1/L2 caches.
- Convolution-Friendly Data Layouts: Instead of using standard formats like NCHW (Batch, Channel, Height, Width), they introduce a blocked data layout. This ensures that when the CPU fetches data, it accesses it in "unit stride" (contiguous memory locations), which is significantly faster than jumping around in memory.
Datasets and Hardware
The implementation was evaluated using the convolution layers from three landmark neural network architectures: AlexNet, VGG, and GoogLeNet.
These were tested across three different hardware architectures to ensure broad applicability: Intel Haswell (i7-4770K), AMD Piledriver (FX-8350), and ARM Cortex-A57 (common in embedded systems).
Key Insights and Ideas
- Direct isn't slow; it's just hard to write: The paper proves that direct convolution isn't inherently inefficient. The perceived slowness was actually a result of poor mapping to hardware.
- Eliminating the "Packing Tax": By removing the
im2colstep, the authors don't just save memory; they save the time the CPU would have spent moving data around. This "bandwidth-bounded" operation is a hidden performance killer in traditional frameworks. - Better Scalability: Traditional GEMM-based convolutions often see diminishing returns as you add more CPU threads because the matrix partitioning becomes inefficient. The authors' direct approach scales much more linearly because it exploits parallelism across the output channel dimension more effectively.
- Closing the Gap to Peak Performance: Their implementation reached up to 87.5% of the theoretical peak performance of the Intel processor, coming within 3% of what a perfectly tuned GEMM can achieve on HPC-style matrices.
Key Results
- Speedups: The proposed direct convolution outperformed SGEMM-based implementations (like those in Caffe) by 10% to 400% across various layers and architectures.
- Efficiency: Against the industry-standard Intel MKL (Math Kernel Library), the direct approach still provided a minimum of 1.5x performance gain on 4-thread tests.
- Memory: It achieved these speeds with zero additional memory overhead, completely bypassing the significant memory footprint required by
im2col. - Scalability: On an AMD Piledriver system, the direct implementation maintained high efficiency even as the thread count increased, whereas the standard BLAS approach saw performance per core drop significantly.
Limitations and Future Work
- Weight Rearrangement: While the method has zero memory overhead during execution, it does require a one-time cost to rearrange the trained weights into the "convolution-friendly" layout.
- Backward Pass: This paper focuses exclusively on the forward pass (inference). The authors note that while the same principles apply to the backward pass (training), it would require minor changes to the loop ordering.
- Auto-tuning: Currently, the "blocking parameters" (the size of the data tiles) are chosen based on analytical models. The authors suggest that using auto-tuning (searching for the best parameters automatically) could close the remaining 3% performance gap to the theoretical peak.
- GPU Porting: The current work is focused on CPUs. Porting these specific data layout and reordering strategies to GPUs is mentioned as a promising future direction.
Summary updated