Abstract Many recent deep learning platforms rely on third-party libraries (such as cuBLAS) to utilize the computing power of modern hardware accelerators (such as GPUs). However, we observe that they may achieve suboptimal performance because the library functions are not used appropriately. In this paper, we target at optimizing the operations of multiplying a matrix with the transpose of another matrix (referred to as NT operation hereafter), which contribute about half of the training time of fully connected deep neural networks. Rather than directly calling the library function, we propose a supervised learning based algorithm selection approach named MTNN, which uses a gradient boosted decision tree to select one from two alternative NT implementations intelligently: (1) calling the cuBLAS library function; (2) calling our proposed algorithm TNN that uses an efficient out-of-place matrix transpose. We evaluate the performance of MTNN on two modern GPUs: NVIDIA GTX 1080 and NVIDIA Titan X Pascal. MTNN can achieve 96% of prediction accuracy with very low computational overhead, which results in an average of 54% performance improvement on a range of NT operations. To further evaluate the impact of MTNN on the training process of deep neural networks, we have integrated MTNN into a popular deep learning platform Caffe. Our experimental results show that the revised Caffe can outperform the original one by an average of 28%.
The cuBLAS Performance Gap
Deep neural network (DNN) training is dominated by matrix multiplications. While libraries like NVIDIA’s cuBLAS are highly optimized for standard multiplications ($A \times B$), they often struggle with the "NT" operation ($A \times B^T$), where the second matrix is transposed. This operation is critical for the backpropagation phase of fully connected layers.
Our investigation revealed a significant "performance cliff" in standard libraries. As shown in the distribution of performance ratios, the standard NN (no transpose) operation in cuBLAS is frequently twice as fast as the NT operation on the same hardware. This discrepancy arises because memory access patterns for transposed matrices can be inefficient, or the library utilizes slow "in-place" transpositions to conserve memory.
Methodology: TNN and the MTNN Selector
To address this bottleneck, we propose a two-pronged solution:
- TNN (Transpose before Multiply): A custom algorithm that performs an efficient "out-of-place" matrix transpose of the second matrix first, followed by a call to the highly optimized cuBLAS NN function. While this requires additional memory, it significantly improves throughput for large matrices by enabling coalesced memory access.
- MTNN (The Selector): Because TNN is not universally faster—particularly for smaller matrices where the overhead of an extra transpose outweighs the compute gains—we developed an intelligent selector. We utilized a Gradient Boosted Decision Tree (GBDT) via the XGBoost library. The model considers 8 features: 5 GPU hardware characteristics (e.g., SM count, L2 cache size) and 3 matrix dimensions ($m, n, k$). GBDT was selected for its ability to model non-linear relationships with minimal prediction overhead (approximately $0.005$ ms).
Experimental Evaluation and Performance Landscape
We profiled performance across 1,000 test cases with matrix sizes ranging from $2^7$ to $2^{16}$ on NVIDIA GTX 1080 and Titan X Pascal GPUs. The results demonstrate that the optimal choice between cuBLAS and TNN is highly sensitive to both matrix dimensions and the underlying hardware architecture.
As illustrated in the performance landscape, TNN (represented by green circles) tends to dominate as matrix dimensions ($M, N, K$) increase. However, the boundary where cuBLAS NT (red squares) remains superior is not a simple linear threshold, justifying the use of a machine learning-based selector over hard-coded heuristics.
Key Results and Framework Integration
The MTNN selector achieved a high classification accuracy of 96.39%. By intelligently switching between algorithms, MTNN provided an average 54% performance improvement on NT operations across the tested range.
To evaluate real-world impact, we integrated MTNN into the Caffe framework. While small networks like MNIST saw modest gains (1.74%), large-scale synthetic networks simulating massive fully connected layers achieved a 28.2% average speedup in total training time. This demonstrates that algorithm selection is a viable micro-optimization strategy that can be performed at runtime with negligible cost.
Conclusion and Future Work
MTNN proves that standard GPU libraries can be significantly enhanced through intelligent, context-aware algorithm selection. Future work will focus on extending this framework to convolutional layers and exploring optimized in-place transpositions to mitigate the memory overhead associated with the TNN approach.
Summary updated