Abstract
Leveraging large data sets, deep Convolutional Neural Networks (CNNs) achieve state-of-the-art recognition accuracy. Due to the substantial compute and memory operations, however, they require significant execution time. The massive parallel computing capability of GPUs make them as one of the ideal platforms to accelerate CNNs and a number of GPU-based CNN libraries have been developed. While existing works mainly focus on the computational efficiency of CNNs, the memory efficiency of CNNs have been largely overlooked. Yet CNNs have intricate data structures and their memory behavior can have significant impact on the performance. In this work, we study the memory efficiency of various CNN layers and reveal the performance implication from both data layouts and memory access patterns. Experiments show the universal effect of our proposed optimizations on both single layers and various networks, with up to 27.9x for a single layer and up to 5.6x on the whole networks.
Introduction
Deep Convolutional Neural Networks (CNNs) are the backbone of modern computer vision, but their performance is often bottlenecked by resource constraints. Historically, optimization efforts have focused on "compute-bound" scenarios—maximizing the throughput of arithmetic operations. However, as GPU compute capabilities continue to outpace memory bandwidth, memory efficiency has emerged as a critical, yet often overlooked, performance killer.
Existing libraries like cuDNN and Caffe typically employ a fixed data layout (usually NCHW) across the entire network. This rigid approach fails to account for the fact that different layers—such as convolutional versus pooling layers—and varying tensor shapes have distinct preferences for data organization to ensure "coalesced" memory access. Furthermore, memory-bounded layers like Pooling and Softmax often suffer from redundant off-chip memory traffic due to sequential kernel launches.
Methodology
To address these inefficiencies, this research proposes a three-pronged optimization strategy focused on data layout and kernel execution:
- Heuristic Layout Selection: The researchers analyzed the impact of 4D tensor dimensions—Batch size ($N$), Channels ($C$), Height ($H$), and Width ($W$)—on performance. They developed a lightweight heuristic to dynamically choose between NCHW (optimized for large-scale matrix multiplication) and CHWN (optimized for memory coalescing and data reuse in specific layer types).
- Fast Layout Transformation: Recognizing that different layers within a single network may require different layouts, the authors implemented a high-performance GPU kernel for on-the-fly transpositions. This kernel utilizes shared memory "tiles" and vectorization (via
float2) to saturate available memory bandwidth. - Kernel Fusion & Thread Coarsening:
- Pooling: By adopting the CHWN layout, the implementation ensures coalesced access. "Thread fusion" is applied to cache input elements in registers, significantly reducing redundant loads from VRAM.
- Softmax: Five separate kernels were fused into a single operation, allowing intermediate results to remain in fast, on-chip shared memory or registers, eliminating the need for costly round-trips to global memory.
Key Insights: The Impact of Data Layout
A central finding of this work is that the choice of data layout dictates thread mapping and, consequently, memory efficiency. Convolution is not always compute-bound; for layers with low channel counts or small batch sizes, the overhead of data transformation for matrix multiplication can make the layer memory-bound. In these instances, a "Direct Convolution" approach using a CHWN layout proves significantly faster.
As shown in the figure above, simply selecting the appropriate layout can lead to substantial performance swings, particularly in pooling layers where CHWN often outperforms NCHW by a wide margin.
Experimental Results
The proposed optimizations were evaluated using five representative CNN architectures (LeNet, Cifar, AlexNet, ZFNet, and VGG) across the MNIST, CIFAR10, and ImageNet datasets.
The performance gains were substantial:
- Individual Layers: Pooling layers achieved speedups of up to 16.3x using CHWN, while Softmax layers improved by up to 20.1x through kernel fusion.
- Convolutional Performance: The study found that CHWN is generally superior when the channel count ($C$) is small (e.g., < 32) or the batch size ($N$) is large (e.g., $\ge$ 128).
On a whole-network level, the optimizations yielded impressive results:
- LeNet: Achieved a 5.61x speedup over the best cuDNN implementation.
- AlexNet: Achieved a 1.46x speedup.
- VGG: Even on this compute-heavy architecture, a 1.05x improvement was observed, demonstrating that memory efficiency remains relevant even at scale.
Conclusion and Future Work
This research highlights that memory efficiency is a vital frontier for CNN optimization on GPUs. While the heuristic thresholds for layout selection are hardware-dependent—requiring a one-time profiling step for different GPU architectures—the universal benefits of layout flexibility and kernel fusion are clear.
Future work may extend these techniques to other accelerators like FPGAs or ASICs. Furthermore, as the industry moves toward lower-precision formats (e.g., FP16), the importance of minimizing memory traffic will only increase, making these memory-centric optimizations even more critical for next-generation deep learning performance.
Summary updated