Abstract
Convolutional Neural Networks (CNNs) are the backbone of modern computer vision, yet their primary operation—convolution—often faces performance bottlenecks on GPU architectures. On NVIDIA's Kepler architecture, a significant overhead arises from memory bank conflicts in Shared Memory (SM). This paper introduces a systematic approach to eliminate these conflicts by matching the data width of software threads to the physical width of memory banks. Our optimized kernels achieve substantial speedups over the industry-standard cuDNN library, reaching up to 5.16× for specialized cases and 35.5% for general multi-channel convolutions.
Introduction
The efficiency of CNNs is largely determined by the throughput of convolution layers. While GPUs provide massive parallel processing power, the hardware's memory hierarchy can become a limiting factor if data access patterns are not carefully aligned with the underlying architecture. Specifically, on NVIDIA Kepler GPUs, the Shared Memory is partitioned into 32 banks, each 8 bytes wide. Standard implementations that process single 4-byte float values per thread result in a mismatch, where two threads frequently target the same 8-byte bank, causing hardware serialization and halving effective bandwidth.
The "Matched" Memory Model
To resolve this bottleneck, we propose a model where the Shared Memory bank width ($W_{SMB}$) is treated as a multiple ($n$) of the thread's computation data width ($W_{CD}$). By ensuring $W_{SMB} = n \cdot W_{CD}$, we can saturate the memory pipeline.
As shown in the figure above, the "matched" approach (b) assigns a single thread to access contiguous data that spans the full width of a memory bank (e.g., using float2 for an 8-byte bank). This alignment prevents bank conflicts and allows the GPU to utilize its full theoretical bandwidth. Furthermore, this alignment ensures that multiple threads in a warp access the same Shared Memory address simultaneously, leveraging the GPU's broadcast mechanism to further reduce latency.
Specialized Kernel Architectures
We developed two distinct kernel strategies to apply this matching principle across different convolution scenarios.
1. Single-Channel Special Case
In the initial layers of many networks, such as those processing grayscale images, the input consists of a single channel. Our specialized kernel for this case utilizes a 2D data-sharing strategy. Data is shared horizontally through Shared Memory and vertically via private registers. By assigning each thread to process $n$ contiguous pixels, we perfectly match the bank width while reducing the total number of memory instructions through register-level reuse.
2. General Multi-Channel Case
For standard hidden layers with multiple input and output channels, we implemented a blocked strategy inspired by General Matrix Multiplication (GEMM). This approach focuses on maximizing data reuse to reach the theoretical lower bound of reading each input pixel from Global Memory only once.
Furthermore, we implemented software-managed prefetching to overlap Global Memory data transfers with Floating-Point Multiply-Add (FMA) operations, ensuring the arithmetic units remain busy.
Experimental Results
The proposed kernels were evaluated on an NVIDIA Kepler K40m GPU against cuDNN v5.1. The benchmarks covered a wide range of filter sizes (1x1 to 7x7) and input dimensions (32x32 to 512x512).
- Performance Gains: The single-channel kernel achieved an average speedup of 5.16× over cuDNN. In specific scenarios, such as when the number of filters ($F$) is 1, the speedup exceeded 10×. The general-case kernel provided a 35.5% average improvement.
- Peak Efficiency: Our general-case kernel reached a peak performance of 2020 GFlop/s, approximately 47% of the K40m's theoretical peak.
- Validation of the Model: In ablation studies, reverting to an "unmatched" layout (using standard
floatinstead of the optimizedfloat2layout) resulted in a 19% performance degradation, confirming the impact of bank conflict mitigation.
Conclusion
This work demonstrates that micro-architectural alignment is critical for high-performance deep learning. By matching software data widths to hardware bank widths, we can significantly surpass the performance of general-purpose libraries like cuDNN. While FFT and Winograd-based convolutions are popular for specific filter sizes, optimized direct convolution remains a universal and fundamental building block for deep learning hardware. As deep learning moves toward lower-precision data types like fp16 or int8, the mismatch problem is expected to intensify, making these alignment strategies even more essential for future hardware generations.
Summary updated