Systematic Approach in Optimizing Numerical Memory-Bound Kernels on GPU

Ahmad Abdelfattah, David E. Keyes, Hatem LtaiefEuro-Par Workshops 2012

Introduction

In high-performance GPU computing, kernels are typically categorized as either compute-bound or memory-bound. While compute-bound tasks like matrix-matrix multiplication (GEMM) are often limited by the raw processing power of the GPU, memory-bound tasks—such as General Matrix-Vector Multiplication (GEMV)—are constrained by the "bandwidth wall." This wall represents the maximum speed at which data can be transferred from the GPU's global memory to its processing cores.

Standard libraries like NVIDIA’s CUBLAS are highly optimized for large-scale matrices but often underperform on small-to-medium-sized matrices. This performance gap is critical because many high-level linear algebra algorithms, including Hessenberg and bidiagonal reductions, iteratively call GEMV on shrinking matrices. This paper presents a systematic optimization strategy for GEMV kernels that significantly outperforms industry standards.

Methodology

The proposed optimization strategy extends techniques previously applied to symmetric matrices (SYMV) to the general GEMV case, focusing on three primary pillars:

1. Block-Level Strategy

The input matrix is partitioned into $64 \times 64$ square blocks. To optimize memory access patterns, thread blocks traverse the matrix horizontally for non-transposed cases and vertically for transposed cases. This ensures efficient data reuse and coalesced memory accesses.

Block-level traversal strategies for non-transposed and transposed matrix cases.

2. Thread-Level Strategy and Double Buffering

To mitigate the latency of global memory fetches, the authors implement a double-buffering scheme. While the GPU processes one data "chunk," it simultaneously prefetches the subsequent chunk into registers. Although this approach increases register pressure and potentially reduces occupancy, the reduction in idle time for CUDA cores leads to a net performance gain.

3. Handling Irregular Dimensions

Real-world matrices rarely align perfectly with $64 \times 64$ block boundaries. To avoid performance-degrading branch divergence caused by complex "if-else" logic within the main kernel, the authors utilize a specialized "clean-up" kernel for edge cases. By leveraging CUDA streams, the main and clean-up kernels execute concurrently, maintaining a lean and fast "hot path" for the majority of the computation.

Performance Evaluation

The implementation was benchmarked on an NVIDIA Fermi-generation C2070 GPU against three state-of-the-art libraries: CUBLAS 5.0, MAGMA 1.2, and CULA Dense R14. The test suite included synthetic matrices ranging from $N=500$ to $N=15,000$ in both single-precision (SP) and double-precision (DP).

Performance comparison (Gflop/s) of the proposed GEMV kernel against CUBLAS, MAGMA, and CULA for single and double precision.

The results demonstrate substantial improvements:

  • Single Precision (SGEMV): The proposed kernel achieved an average 80% improvement over CUBLAS for matrices smaller than 1,700.
  • Double Precision (DGEMV): An average 47% improvement was observed for sizes up to 1,700.

Impact on High-Level Routines

The optimization of the low-level GEMV kernel has a "ripple effect" on higher-level LAPACK routines. When integrated into standard reduction algorithms, the cumulative speedup is significant:

  • Hessenberg Reduction: Improved by approximately 30% in SP and 15% in DP compared to CUBLAS 5.0.
  • Bidiagonal Reduction: Achieved speedups of up to 25% in SP and 14% in DP.

Conclusion and Future Work

This research highlights that maximizing GPU occupancy is not always the optimal path for memory-bound tasks; instead, aggressive prefetching and register-intensive strategies can yield better throughput. While the current implementation shows periodic performance dips due to load imbalances across Streaming Multiprocessors (SMs), future work will focus on dynamic workload distribution and adaptation for newer architectures like Kepler.

Summary updated

BibTeX
@inproceedings{abdelfattah2012systematic,
  author = {Ahmad Abdelfattah and David E. Keyes and Hatem Ltaief},
  title = {{Systematic Approach in Optimizing Numerical Memory-Bound Kernels on GPU}},
  booktitle = {Euro-Par Workshops},
  year = {2012},
  doi = {10.1007/978-3-642-36949-0\_23},
}
Figure