[Paper Review] Optimizing Performance of Recurrent Neural Networks on GPUs
This paper presents a multi-stage optimization strategy to significantly accelerate recurrent neural network (RNN) training on GPUs by maximizing parallelism across RNN cells, layers, and the full network. By combining matrix operations, leveraging CUDA streams for concurrent execution, and tuning low-level cuBLAS heuristics, the authors achieve up to a 10x speedup over naive implementations, with performance approaching peak GPU throughput in cuDNN v5 for LSTM, GRU, and simple RNNs.
As recurrent neural networks become larger and deeper, training times for single networks are rising into weeks or even months. As such there is a significant incentive to improve the performance and scalability of these networks. While GPUs have become the hardware of choice for training and deploying recurrent models, the implementations employed often make use of only basic optimizations for these architectures. In this article we demonstrate that by exposing parallelism between operations within the network, an order of magnitude speedup across a range of network sizes can be achieved over a naive implementation. We describe three stages of optimization that have been incorporated into the fifth release of NVIDIA's cuDNN: firstly optimizing a single cell, secondly a single layer, and thirdly the entire network.
Motivation & Objective
- To address the growing training time of deep and large recurrent neural networks, which can span weeks or months.
- To improve GPU utilization in RNN training, which is often suboptimal in standard implementations despite GPUs being the primary hardware for training.
- To develop and integrate performance-optimized RNN kernels into NVIDIA’s cuDNN library for widespread use.
- To expose and exploit parallelism across individual RNN cells, entire layers, and the full network to maximize hardware throughput.
Proposed method
- Reformulating four matrix multiplications per LSTM gate into a single larger matrix multiplication to improve parallelism and reduce kernel launch overhead.
- Using CUDA streams to execute independent matrix multiplications (e.g., input and recurrent weights) concurrently, increasing GPU occupancy and hiding latency.
- Overlapping forward and backward passes across layers to improve memory and compute utilization, especially in deeper networks.
- Tuning cuBLAS heuristics manually to favor resource-efficient execution paths in high-parallelism scenarios, bypassing default heuristics that may underutilize hardware.
- Applying similar optimization strategies to GRUs (three matrix groups) and simple RNNs, though the latter cannot benefit from matrix grouping due to only one matrix per input.
- Implementing weight updates using single large matrix multiplications to achieve near-peak performance, with bias updates being computationally negligible.
Experimental results
Research questions
- RQ1Can significant performance gains in RNN training be achieved by exposing more parallelism across RNN cells and layers on modern GPUs?
- RQ2To what extent can combining matrix operations and using CUDA streams improve throughput in LSTM and GRU networks?
- RQ3How do low-level optimizations, such as manual tuning of cuBLAS heuristics, impact performance when the library is unaware of the higher-level algorithmic context?
- RQ4What is the performance impact of layer-level overlapping and batching strategies across different minibatch and hidden state sizes?
- RQ5Why does performance degrade at certain minibatch sizes (e.g., 32) for large hidden states, and how can this be mitigated?
Key findings
- A naive RNN implementation on an NVIDIA M40 GPU achieves only 0.4 TFLOPS, less than 10% of the hardware’s peak performance (~5.8 TFLOPS).
- Grouping matrix operations doubles throughput to 0.8 TFLOPS by improving parallelism and reducing kernel launch overhead.
- Using CUDA streams to run independent matrix multiplications concurrently increases performance by up to 2x, especially effective in low-parallelism cases.
- Layer overlapping provides significant speedups, particularly in deeper networks, and maintains performance gains even at large minibatch sizes (e.g., 256) and hidden states (e.g., 4096).
- Manual tuning of cuBLAS heuristics to favor resource efficiency over parallelism in high-streamed scenarios results in measurable performance improvements, especially in bandwidth-bound regimes.
- The final implementation in cuDNN v5 achieves near-peak performance across a wide range of network sizes, with the largest speedups observed in smaller, deeper networks where inherent parallelism is limited.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.