TL;DR
The authors introduce Caffe con Troll (CcT), a rebuilt version of the popular Caffe framework that drastically improves CPU performance for training Convolutional Neural Networks (CNNs). By applying standard batching optimizations to matrix multiplications, CcT achieves a 4.5x speedup on CPUs and enables a novel hybrid CPU-GPU execution model that speeds up end-to-end training by over 15%.
What Problem Does This Paper Address?
Deep learning is notoriously compute-bound, leading the industry to rely heavily on GPUs. However, GPUs suffer from slow PCI-e interconnect bottlenecks and, at the time this paper was written, were not universally available across all major cloud providers (like Azure or Google Compute). Meanwhile, modern CPUs have seen massive increases in SIMD parallelism, yet deep learning frameworks historically underutilized them.
Specifically, the default implementation of Caffe processed images through convolutional layers one at a time (a batch size of 1). This resulted in poor cache utilization and memory-bandwidth bottlenecks on CPUs. Furthermore, existing frameworks forced users into a binary choice: train on the CPU or train on the GPU. The authors recognized that by leaving the CPU idle during GPU training, systems were leaving valuable compute power on the table.
Methods
The authors forked Caffe to create Caffe con Troll (CcT), focusing heavily on optimizing the convolutional layers, which consume 70-90% of execution time.
- Batching Optimizations: Instead of processing images sequentially, CcT batches them during the convolution phase. This creates "thicker" matrices that allow underlying BLAS (Basic Linear Algebra Subprograms) libraries to properly utilize L2/L3 caches and parallelize across multiple CPU cores effectively.
- Lowering Tradeoff Analysis: Convolutions are typically computed via "lowering"—reshaping 3D image and kernel tensors into 2D matrices, performing a standard matrix multiplication (GEMM), and "lifting" the result back to 3D. The authors analyzed three different lowering strategies (Expensive Lowering, Balanced, and Expensive Lifting) to find the optimal balance of memory footprint and compute time.
- Hybrid CPU-GPU Scheduling: CcT introduces a system to split data parallelism within a single layer across both the CPU and GPU simultaneously. They use a simple but highly effective heuristic: route a fraction of the input batch to each device proportional to its theoretical peak FLOPS.
Datasets
- ImageNet: The system was evaluated using the standard ImageNet dataset, specifically training the CaffeNet (AlexNet) architecture.
Key Insights and Ideas
- CPUs are better at deep learning than reported: The massive performance gap between CPUs and GPUs in deep learning is partially a software artifact. Simple batching optimizations that feed CPU caches properly can close this gap significantly.
- Performance scales with FLOPS: Once software bottlenecks (like batch size 1 convolutions) are removed, the end-to-end training time of a CNN becomes directly proportional to the theoretical FLOPS delivered by the hardware.
- Hybrid execution is viable and easy to schedule: You don't need a complex, dynamic scheduler to use CPUs and GPUs together. A static split based purely on the ratio of peak FLOPS between the devices achieves within 5% of optimal performance.
- The math dictates the lowering strategy: The optimal way to reshape tensors for convolution depends entirely on the ratio of input channels to output channels. While the default strategy works fine for most current CNNs, edge-case architectures can see an order-of-magnitude speedup by switching strategies.
Key Results
- CPU Speedup: CcT achieved a 4.5x end-to-end throughput improvement over standard Caffe on an AWS EC2 CPU instance (c4.4xlarge).
- Hybrid CPU+GPU Speedup: By utilizing the CPU alongside the GPU, CcT achieved a >15% end-to-end speedup over using the GPU alone. On a single convolutional layer, the hybrid approach was 20% faster.
- Cost Viability: Running CcT on a CPU-only instance was only 2.6x more expensive per iteration than running on a GPU instance. This proved that CPU-based training is a financially viable fallback for cloud environments lacking GPU availability.
- Multi-GPU Scaling: CcT successfully scaled across 4 GPUs, achieving a 3.12x speedup compared to a single GPU.
Limitations and Future Work
- Data Parallelism Only: The current hybrid scheduling only supports data parallelism within a layer. It does not yet support model parallelism, which is often necessary for massive fully-connected layers.
- Kernel Fusion: The authors note that fusing the lowering, GEMM, and lifting steps into a single custom kernel avoids materialization costs and can improve performance by up to 60%. However, this was only a preliminary experiment and was not included in the main reported results.
- Future Directions: The authors plan to extend CcT to distributed (multi-node) training environments and hope to incorporate Fast Fourier Transform (FFT) based convolution optimizations in the future.
Summary updated